本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getCode方法的具体用法?PHP AbstractModel::getCode怎么用?PHP AbstractModel::getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* Validate website code before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) {
throw new \Magento\Framework\Exception\LocalizedException(__('Website code may only contain letters (a-z), numbers (0-9) or underscore (_),' . ' and the first character must be a letter.'));
}
return parent::_beforeSave($object);
}
示例2: _beforeDelete
/**
* Check if group uses as default
*
* @param \Magento\Framework\Model\AbstractModel $group
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
protected function _beforeDelete(\Magento\Framework\Model\AbstractModel $group)
{
if ($group->usesAsDefault()) {
throw new \Magento\Framework\Model\Exception(__('The group "%1" cannot be deleted', $group->getCode()));
}
return parent::_beforeDelete($group);
}
示例3: _beforeSave
/**
* Process post data before saving
*
* @param \Smart2Pay\GlobalPay\Model\Country $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getCode()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please provide country code.'));
}
if (!$object->getName()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please provide country name.'));
}
if ($this->checkCode($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Country code already exists in database.'));
}
return parent::_beforeSave($object);
}
示例4: _beforeSave
/**
* {@inheritdoc}
*/
protected function _beforeSave(AbstractModel $object)
{
$reindexRequired = false;
if ($object->hasData('attributes') && is_array($object->getData('attributes'))) {
$serialized = serialize($object->getData('attributes'));
if ($object->getData('attributes_serialized') != $serialized) {
$reindexRequired = true;
}
$object->setData('attributes_serialized', $serialized);
}
if ($object->hasData('properties') && is_array($object->getData('properties'))) {
$serialized = serialize($object->getData('properties'));
if ($object->getData('properties_serialized') != $serialized) {
$reindexRequired = true;
}
$object->setData('properties_serialized', $serialized);
}
if ($reindexRequired && !$object->dataHasChangedFor('status')) {
$object->setStatus(Config::INDEX_STATUS_INVALID);
}
$object->setCode($object->getCode());
return $this;
}
示例5: _beforeSave
/**
* Prepare data before save
*
* @param \Magento\Framework\Model\AbstractModel $group
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $group)
{
/** @var \Magento\Customer\Model\Group $group */
$group->setCode(substr($group->getCode(), 0, $group::GROUP_CODE_MAX_LENGTH));
return parent::_beforeSave($group);
}