本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::beforeSave方法的具体用法?PHP Attribute::beforeSave怎么用?PHP Attribute::beforeSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute
的用法示例。
在下文中一共展示了Attribute::beforeSave方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* Processing object before save data
*
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Eav\Exception
*/
public function beforeSave()
{
try {
$this->attrLockValidator->validate($this);
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
throw new \Magento\Eav\Exception(__($exception->getMessage()));
}
$this->setData('modulePrefix', self::MODULE_NAME);
return parent::beforeSave();
}
示例2: beforeSave
/**
* Processing object before save data
*
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeSave()
{
$this->setData('modulePrefix', self::MODULE_NAME);
if (isset($this->_origData[self::KEY_IS_GLOBAL])) {
if (!isset($this->_data[self::KEY_IS_GLOBAL])) {
$this->_data[self::KEY_IS_GLOBAL] = self::SCOPE_GLOBAL;
}
if ($this->_data[self::KEY_IS_GLOBAL] != $this->_origData[self::KEY_IS_GLOBAL]) {
try {
$this->attrLockValidator->validate($this);
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
throw new \Magento\Framework\Exception\LocalizedException(__('Do not change the scope. %1', $exception->getMessage()));
}
}
}
if ($this->getFrontendInput() == 'price') {
if (!$this->getBackendModel()) {
$this->setBackendModel('Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Price');
}
}
if ($this->getFrontendInput() == 'textarea') {
if ($this->getIsWysiwygEnabled()) {
$this->setIsHtmlAllowedOnFront(1);
}
}
if (!$this->getIsSearchable()) {
$this->setIsVisibleInAdvancedSearch(false);
}
return parent::beforeSave();
}