當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AbstractModel::getCode方法代碼示例

本文整理匯總了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);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:Website.php

示例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);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:14,代碼來源:Group.php

示例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);
 }
開發者ID:smart2pay,項目名稱:magento20,代碼行數:20,代碼來源:Country.php

示例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;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:26,代碼來源:Index.php

示例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);
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:12,代碼來源:Group.php


注:本文中的Magento\Framework\Model\AbstractModel::getCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。