本文整理汇总了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
/**
* BeforeSave actions
*
* @return $this
*/
public function beforeSave()
{
$this->setUpdatedAt(time());
$this->validate();
parent::beforeSave();
return $this;
}
示例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
*/
public function beforeSave()
{
parent::beforeSave();
if ($this->getAddress()) {
$this->setAddressId($this->getAddress()->getId());
}
return $this;
}
示例4: beforeSave
/**
* Prevent blocks recursion
*
* @return AbstractModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeSave()
{
$needle = 'block_id="' . $this->getId() . '"';
if (false == strstr($this->getContent(), $needle)) {
return parent::beforeSave();
}
throw new \Magento\Framework\Exception\LocalizedException(__('Make sure that static block content does not reference the block itself.'));
}
示例5: beforeSave
/**
* Prepare data to be saved to database
*
* @return $this
*/
public function beforeSave()
{
parent::beforeSave();
if ($this->isObjectNew()) {
$this->setCreatedAt($this->_dateTime->formatDate(true));
}
$this->setUpdatedAt($this->_dateTime->formatDate(true));
return $this;
}
示例6: beforeSave
/**
* Prepare data to be saved to database.
*
* @return $this
* @codingStandardsIgnoreStart
*/
public function beforeSave()
{
//@codingStandardsIgnoreEnd
parent::beforeSave();
if ($this->isObjectNew()) {
$this->setCreatedAt($this->dateTime->formatDate(true));
}
$this->setUpdatedAt($this->dateTime->formatDate(true));
return $this;
}
示例7: beforeSave
public function beforeSave()
{
parent::beforeSave();
if ($this->isObjectNew()) {
$this->setCreatedAt(time());
} else {
$this->setUpdatedAt(time());
}
$this->setCondition(serialize($this->getCondition()));
$this->setWebsiteIds(implode(',', $this->getWebsiteIds()));
return $this;
}
示例8: beforeSave
/**
* Processing object before save data
*
* @return $this
*/
public 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();
}
示例9: beforeSave
/**
* Prepare customer/visitor, store data before save
*
* @return $this
*/
public 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((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
}
return $this;
}
示例10: beforeSave
public function beforeSave()
{
if ($this->getStoreViewId()) {
$defaultStore = $this->_bannerFactory->create()->setStoreViewId(null)->load($this->getId());
$storeAttributes = $this->getStoreAttributes();
$data = $this->getData();
foreach ($storeAttributes as $attribute) {
if (isset($data['use_default']) && isset($data['use_default'][$attribute])) {
$this->setData($attribute . '_in_store', false);
} else {
$this->setData($attribute . '_in_store', true);
$this->setData($attribute . '_value', $this->getData($attribute));
}
$this->setData($attribute, $defaultStore->getData($attribute));
}
}
return parent::beforeSave();
}
示例11: beforeSave
/**
* Prepare data before saving
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeSave()
{
// Check if discount amount not negative
if ($this->hasDiscountAmount()) {
if ((int) $this->getDiscountAmount() < 0) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please choose a valid discount amount.'));
}
}
// Serialize conditions
if ($this->getConditions()) {
$this->setConditionsSerialized(serialize($this->getConditions()->asArray()));
$this->unsConditions();
}
// Serialize actions
if ($this->getActions()) {
$this->setActionsSerialized(serialize($this->getActions()->asArray()));
$this->unsActions();
}
/**
* Prepare website Ids if applicable and if they were set as string in comma separated format.
* Backwards compatibility.
*/
if ($this->hasWebsiteIds()) {
$websiteIds = $this->getWebsiteIds();
if (is_string($websiteIds) && !empty($websiteIds)) {
$this->setWebsiteIds(explode(',', $websiteIds));
}
}
/**
* Prepare customer group Ids if applicable and if they were set as string in comma separated format.
* Backwards compatibility.
*/
if ($this->hasCustomerGroupIds()) {
$groupIds = $this->getCustomerGroupIds();
if (is_string($groupIds) && !empty($groupIds)) {
$this->setCustomerGroupIds(explode(',', $groupIds));
}
}
parent::beforeSave();
return $this;
}
示例12: beforeSave
/**
* Before theme save
*
* @return $this
*/
public function beforeSave()
{
$this->_validate();
return parent::beforeSave();
}
示例13: beforeSave
/**
* Stop saving process if file with same report date, account ID and last modified date was already ferched
*
* @return \Magento\Framework\Model\AbstractModel
*/
public function beforeSave()
{
$this->_dataSaveAllowed = true;
if ($this->getId()) {
if ($this->getLastModified() == $this->getReportLastModified()) {
$this->_dataSaveAllowed = false;
}
}
$this->setLastModified($this->getReportLastModified());
return parent::beforeSave();
}
示例14: beforeSave
/**
* Prepare file before it will be saved
*
* @return $this
*/
public function beforeSave()
{
$fileService = $this->getCustomizationService();
$fileService->prepareFile($this);
$fileService->save($this);
return parent::beforeSave();
}
示例15: beforeSave
/**
* Serialize info for Resource Model to save
* For new model check and set available cookie key
*
* @return $this
*/
public function beforeSave()
{
parent::beforeSave();
// Setting info
$info = [];
foreach ($this->getData() as $index => $value) {
if (!in_array($index, $this->_unserializableFields)) {
$info[$index] = $value;
}
}
$this->setInfo($this->jsonHelper->jsonEncode($info));
if ($this->isObjectNew()) {
$this->setWebsiteId($this->_storeManager->getStore()->getWebsiteId());
// Setting cookie key
do {
$this->setKey($this->mathRandom->getRandomString(self::KEY_LENGTH));
} while (!$this->getResource()->isKeyAllowed($this->getKey()));
}
return $this;
}