当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractDb::_beforeSave方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\Resource\Db\AbstractDb::_beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractDb::_beforeSave方法的具体用法?PHP AbstractDb::_beforeSave怎么用?PHP AbstractDb::_beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\Resource\Db\AbstractDb的用法示例。


在下文中一共展示了AbstractDb::_beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($date = $object->getDateFrom()) {
         $object->setDateFrom($this->dateTime->formatDate($date));
     } else {
         $object->setDateFrom(null);
     }
     if ($date = $object->getDateTo()) {
         $object->setDateTo($this->dateTime->formatDate($date));
     } else {
         $object->setDateTo(null);
     }
     if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && (new \DateTime($object->getDateFrom()))->getTimestamp() > (new \DateTime($object->getDateTo()))->getTimestamp()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The start date can\'t follow the end date.'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The date range for this design change overlaps another design change for the specified store.'));
     }
     if ($object->getDateFrom() === null) {
         $object->setDateFrom(new \Zend_Db_Expr('null'));
     }
     if ($object->getDateTo() === null) {
         $object->setDateTo(new \Zend_Db_Expr('null'));
     }
     parent::_beforeSave($object);
 }
开发者ID:nja78,项目名称:magento2,代码行数:34,代码来源:Design.php

示例2: _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:nja78,项目名称:magento2,代码行数:14,代码来源:Website.php

示例3: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return \Magento\Framework\Model\Resource\Db\AbstractDb
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getSortOrder()) {
         $object->setSortOrder($this->_getMaxSortOrder($object) + 1);
     }
     return parent::_beforeSave($object);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Group.php

示例4: _beforeSave

 /**
  * Set template type, added at and modified at time
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     if ($object->isObjectNew()) {
         $object->setAddedAt($this->dateTime->formatDate(true));
     }
     $object->setModifiedAt($this->dateTime->formatDate(true));
     $object->setTemplateType((int) $object->getTemplateType());
     return parent::_beforeSave($object);
 }
开发者ID:nja78,项目名称:magento2,代码行数:15,代码来源:Template.php

示例5: _beforeSave

 /**
  * Convert array to comma separated value
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId()) {
         $this->_checkUnique($object);
     }
     if (is_array($object->getValue())) {
         $object->setValue(join(',', $object->getValue()));
     }
     return parent::_beforeSave($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:16,代码来源:Data.php

示例6: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param AbstractModel $object
  * @return $this
  */
 public function _beforeSave(AbstractModel $object)
 {
     if (!$object->getExpirationDate()) {
         $object->setExpirationDate(null);
     } elseif ($object->getExpirationDate() instanceof \DateTimeInterface) {
         $object->setExpirationDate($object->getExpirationDate()->format('Y-m-d H:i:s'));
     }
     // maintain single primary coupon per rule
     $object->setIsPrimary($object->getIsPrimary() ? 1 : null);
     return parent::_beforeSave($object);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Coupon.php

示例7: _beforeSave

 /**
  * Serialize additional information, if any
  *
  * @param \Magento\Framework\Model\AbstractModel $transaction
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
 {
     $txnId = $transaction->getData('txn_id');
     $idFieldName = $this->getIdFieldName();
     // make sure unique key won't cause trouble
     if ($transaction->isFailsafe()) {
         $autoincrementId = (int) $this->_lookupByTxnId($txnId, $idFieldName);
         if ($autoincrementId) {
             $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false);
         }
     }
     return parent::_beforeSave($transaction);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:20,代码来源:Transaction.php

示例8: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param AbstractModel $object
  * @return $this
  */
 public function _beforeSave(AbstractModel $object)
 {
     if (!$object->getExpirationDate()) {
         $object->setExpirationDate(null);
     } else {
         if ($object->getExpirationDate() instanceof \Zend_Date) {
             $object->setExpirationDate($object->getExpirationDate()->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
         }
     }
     // maintain single primary coupon per rule
     $object->setIsPrimary($object->getIsPrimary() ? 1 : null);
     return parent::_beforeSave($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:19,代码来源:Coupon.php

示例9: _beforeSave

 /**
  * Process post data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$this->isValidPostUrlKey($object)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The post URL key contains capital letters or disallowed symbols.'));
     }
     if ($this->isNumericPostUrlKey($object)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The post URL key cannot be made of only numbers.'));
     }
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime($this->_date->gmtDate());
     }
     $object->setUpdateTime($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
开发者ID:andrew-smart,项目名称:magento2-blog-module-tutorial,代码行数:21,代码来源:Post.php

示例10: _beforeSave

 /**
  * Method to run before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     // format height
     $height = $object->getContentHeight();
     $height = $this->filterManager->stripTags($height);
     if (!$height) {
         $height = '';
     }
     if ($height && preg_match('/[0-9]$/', $height)) {
         $height .= 'px';
     }
     $object->setContentHeight($height);
     return parent::_beforeSave($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:20,代码来源:Agreement.php

示例11: _beforeSave

 /**
  * Prepare rule's active "from" and "to" dates
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $fromDate = $object->getFromDate();
     if ($fromDate instanceof \Zend_Date) {
         $object->setFromDate($fromDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
     } elseif (!is_string($fromDate) || empty($fromDate)) {
         $object->setFromDate(null);
     }
     $toDate = $object->getToDate();
     if ($toDate instanceof \Zend_Date) {
         $object->setToDate($toDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
     } elseif (!is_string($toDate) || empty($toDate)) {
         $object->setToDate(null);
     }
     parent::_beforeSave($object);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:23,代码来源:AbstractResource.php

示例12: _beforeSave

 /**
  * Prepare rule's active "from" and "to" dates
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $fromDate = $object->getFromDate();
     if ($fromDate instanceof \DateTime) {
         $object->setFromDate($fromDate->format('Y-m-d H:i:s'));
     } elseif (!is_string($fromDate) || empty($fromDate)) {
         $object->setFromDate(null);
     }
     $toDate = $object->getToDate();
     if ($toDate instanceof \DateTime) {
         $object->setToDate($toDate->format('Y-m-d H:i:s'));
     } elseif (!is_string($toDate) || empty($toDate)) {
         $object->setToDate(null);
     }
     parent::_beforeSave($object);
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:AbstractResource.php

示例13: _beforeSave

 /**
  * Check if semilar event exist before start saving data
  *
  * @param AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     /**
      * Check if event already exist and merge previous data
      */
     if (!$object->getId()) {
         $select = $this->_getReadAdapter()->select()->from($this->getMainTable())->where('type=?', $object->getType())->where('entity=?', $object->getEntity());
         if ($object->hasEntityPk()) {
             $select->where('entity_pk=?', $object->getEntityPk());
         }
         $data = $this->_getWriteAdapter()->fetchRow($select);
         if ($data) {
             $object->mergePreviousData($data);
         }
     }
     $object->cleanNewData();
     return parent::_beforeSave($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:24,代码来源:Event.php

示例14: _beforeSave

 /**
  * Validate attribute data before save
  *
  * @param EntityAttribute|AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(AbstractModel $object)
 {
     $frontendLabel = $object->getFrontendLabel();
     if (is_array($frontendLabel)) {
         if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
             throw new \Magento\Framework\Model\Exception(__('Frontend label is not defined'));
         }
         $object->setFrontendLabel($frontendLabel[0])->setStoreLabels($frontendLabel);
     }
     /**
      * @todo need use default source model of entity type !!!
      */
     if (!$object->getId()) {
         if ($object->getFrontendInput() == 'select') {
             $object->setSourceModel('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table');
         }
     }
     return parent::_beforeSave($object);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:26,代码来源:Attribute.php

示例15: _beforeSave

 /**
  * Process page data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /*
      * For two attributes which represent timestamp data in DB
      * we should make converting such as:
      * If they are empty we need to convert them into DB
      * type NULL so in DB they will be empty and not some default value
      */
     foreach (array('custom_theme_from', 'custom_theme_to') as $field) {
         $value = !$object->getData($field) ? null : $object->getData($field);
         $object->setData($field, $this->dateTime->formatDate($value));
     }
     if (!$object->getData('identifier')) {
         $object->setData('identifier', $this->filter->translitUrl($object->getData('title')));
     }
     if (!$this->getIsUniquePageToStores($object)) {
         throw new \Magento\Framework\Model\Exception(__('A page URL key for specified store already exists.'));
     }
     if (!$this->isValidPageIdentifier($object)) {
         throw new \Magento\Framework\Model\Exception(__('The page URL key contains capital letters or disallowed symbols.'));
     }
     if ($this->isNumericPageIdentifier($object)) {
         throw new \Magento\Framework\Model\Exception(__('The page URL key cannot be made of only numbers.'));
     }
     // modify create / update dates
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime($this->_date->gmtDate());
     }
     $object->setUpdateTime($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:38,代码来源:Page.php


注:本文中的Magento\Framework\Model\Resource\Db\AbstractDb::_beforeSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。