本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::_beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::_beforeSave方法的具体用法?PHP AbstractModel::_beforeSave怎么用?PHP AbstractModel::_beforeSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::_beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* Processing object before save data
*
* @return $this
*/
protected function _beforeSave()
{
if (!$this->getRuleId() && $this->_rule instanceof \Magento\SalesRule\Model\Rule) {
$this->setRuleId($this->_rule->getId());
}
return parent::_beforeSave();
}
示例2: _beforeSave
/**
* Check order id
*
* @return $this
*/
public function _beforeSave()
{
if (null == $this->getOrderId()) {
throw new \Exception(__('Order id cannot be null'));
}
return parent::_beforeSave();
}
示例3: _beforeSave
/**
* @return $this
*/
protected function _beforeSave()
{
parent::_beforeSave();
if ($this->getAddress()) {
$this->setAddressId($this->getAddress()->getId());
}
return $this;
}
示例4: _beforeSave
/**
* Prevent blocks recursion
*
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Framework\Model\Exception
*/
protected function _beforeSave()
{
$needle = 'block_id="' . $this->getBlockId() . '"';
if (false == strstr($this->getContent(), $needle)) {
return parent::_beforeSave();
}
throw new \Magento\Framework\Model\Exception(__('Make sure that static block content does not reference the block itself.'));
}
示例5: _beforeSave
/**
* Before save prepare process
*
* @return $this
*/
protected function _beforeSave()
{
parent::_beforeSave();
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->productFactory->create();
$product->load($this->getProductId());
$typeId = $product->getTypeId() ? $product->getTypeId() : $this->getTypeId();
$isQty = $this->stockItemService->isQty($typeId);
if ($isQty) {
if (!$this->getId()) {
$this->processIsInStock();
}
if ($this->getManageStock() && !$this->verifyStock()) {
$this->setIsInStock(false)->setStockStatusChangedAutomaticallyFlag(true);
}
// if qty is below notify qty, update the low stock date to today date otherwise set null
$this->setLowStockDate(null);
if ($this->verifyNotification()) {
$this->setLowStockDate($this->_localeDate->date(null, null, null, false)->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
}
$this->setStockStatusChangedAuto(0);
if ($this->hasStockStatusChangedAutomaticallyFlag()) {
$this->setStockStatusChangedAuto((int) $this->getStockStatusChangedAutomaticallyFlag());
}
} else {
$this->setQty(0);
}
return $this;
}
示例6: _beforeSave
/**
* Initialize item identifier before save data
*
* @return $this
*/
protected function _beforeSave()
{
if ($this->getItem()) {
$this->setWishlistItemId($this->getItem()->getId());
}
return parent::_beforeSave();
}
示例7: _beforeSave
/**
* Serelaize old and new data arrays before saving
*
* @return $this
*/
protected function _beforeSave()
{
$newData = $this->getNewData(false);
$this->setNewData(serialize($newData));
if (!$this->hasCreatedAt()) {
$this->setCreatedAt($this->dateTime->formatDate(time(), true));
}
return parent::_beforeSave();
}
示例8: _beforeSave
/**
* Stop saving process if file with same report date, account ID and last modified date was already ferched
*
* @return \Magento\Framework\Model\AbstractModel
*/
protected function _beforeSave()
{
$this->_dataSaveAllowed = true;
if ($this->getId()) {
if ($this->getLastModified() == $this->getReportLastModified()) {
$this->_dataSaveAllowed = false;
}
}
$this->setLastModified($this->getReportLastModified());
return parent::_beforeSave();
}
示例9: _beforeSave
/**
* Validate data before save data
*
* @throws \Magento\Framework\Model\Exception
* @return $this
*/
protected function _beforeSave()
{
if (!$this->getTypeId()) {
throw new \Magento\Framework\Model\Exception(__('Invalid form type.'));
}
if (!$this->getStoreId() && $this->getLabel()) {
$this->setStoreLabel($this->getStoreId(), $this->getLabel());
}
return parent::_beforeSave();
}
示例10: _beforeSave
/**
* Verify data required for saving
*
* @return $this
*/
protected function _beforeSave()
{
// set parent id
$this->_verifyPaymentObject();
if (!$this->getId()) {
// We need to set order and payment ids only for new transactions
if (null !== $this->_paymentObject) {
$this->setPaymentId($this->_paymentObject->getId());
}
if (null !== $this->_order) {
$this->setOrderId($this->_order->getId());
}
$this->setCreatedAt($this->_dateFactory->create()->gmtDate());
}
return parent::_beforeSave();
}
示例11: _beforeSave
/**
* Processing object before save data
*
* @return $this
*/
protected function _beforeSave()
{
if ($this->getContentHeight() == 0) {
$this->setContentHeight('');
//converting zero Content-Height
}
if ($this->getContentHeight() && !preg_match('/(' . implode("|", $this->allowedCssUnits) . ')/', $this->getContentHeight())) {
$contentHeight = $this->getContentHeight() . 'px';
//setting default units for Content-Height
$this->setContentHeight($contentHeight);
}
return parent::_beforeSave();
}
示例12: _beforeSave
/**
* Before Event save process
*
* @return $this
*/
protected function _beforeSave()
{
$date = $this->_dateFactory->create();
$this->setLoggedAt($date->gmtDate());
return parent::_beforeSave();
}
示例13: _beforeSave
/**
* Before save unlock attributes
*
* @return \Magento\Catalog\Model\AbstractModel
*/
protected function _beforeSave()
{
$this->unlockAttributes();
return parent::_beforeSave();
}
示例14: _beforeSave
/**
* Prepare customer/visitor, store data before save
*
* @return $this
*/
protected function _beforeSave()
{
parent::_beforeSave();
if (!$this->hasVisitorId()) {
$this->setVisitorId($this->getVisitorId());
}
if (!$this->hasCustomerId()) {
$this->setCustomerId($this->getCustomerId());
}
if (!$this->hasStoreId()) {
$this->setStoreId($this->getStoreId());
}
if (!$this->hasAddedAt()) {
$this->setAddedAt($this->dateTime->now());
}
return $this;
}
示例15: _beforeSave
/**
* Prepare data before save
*
* @return $this
*/
protected function _beforeSave()
{
$this->_prepareData();
return parent::_beforeSave();
}