예제 #1
0
파일: Design.php 프로젝트: nja78/magento2
 /**
  * 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);
 }
예제 #2
0
파일: Website.php 프로젝트: nja78/magento2
 /**
  * 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);
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
파일: Template.php 프로젝트: nja78/magento2
 /**
  * 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);
 }
예제 #5
0
파일: Data.php 프로젝트: aiesh/magento2
 /**
  * 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);
 }
예제 #6
0
 /**
  * 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);
 }
예제 #7
0
 /**
  * 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);
 }
예제 #8
0
파일: Coupon.php 프로젝트: aiesh/magento2
 /**
  * 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);
 }
 /**
  * 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);
 }
예제 #10
0
 /**
  * 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);
 }
예제 #11
0
 /**
  * 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;
 }
예제 #12
0
 /**
  * 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;
 }
예제 #13
0
파일: Event.php 프로젝트: aiesh/magento2
 /**
  * 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);
 }
예제 #14
0
 /**
  * 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);
 }
예제 #15
0
 /**
  * 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);
 }
예제 #16
0
파일: Template.php 프로젝트: aiesh/magento2
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($this->checkCodeUsage($object)) {
         throw new \Magento\Framework\Model\Exception(__('Duplicate template code'));
     }
     if (!$object->hasTemplateActual()) {
         $object->setTemplateActual(1);
     }
     if (!$object->hasAddedAt()) {
         $object->setAddedAt($this->_date->gmtDate());
     }
     $object->setModifiedAt($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
예제 #17
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
         $object->setIncrementId($this->salesIncrement->getNextValue($object->getStoreId()));
     }
     parent::_beforeSave($object);
     return $this;
 }
예제 #18
0
파일: Group.php 프로젝트: vasuscoin/brand
 /**
  * Process group data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->getConnection();
     $select = $connection->select()->from($this->getTable('ves_brand_group'), 'url_key')->where('url_key = ?', $object->getUrlKey())->where('group_id != ?', $object->getId());
     $result = $connection->fetchCol($select);
     if (count($result) > 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('URL key already exists.' . count($result)));
     }
     return parent::_beforeSave($object);
 }
예제 #19
0
파일: User.php 프로젝트: aiesh/magento2
 /**
  * Set created/modified values before user save
  *
  * @param \Magento\Framework\Model\AbstractModel $user
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $user)
 {
     if ($user->isObjectNew()) {
         $user->setCreated($this->dateTime->formatDate(true));
     }
     $user->setModified($this->dateTime->formatDate(true));
     return parent::_beforeSave($user);
 }
예제 #20
0
파일: Design.php 프로젝트: aiesh/magento2
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 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()) && $this->dateTime->toTimestamp($object->getDateFrom()) > $this->dateTime->toTimestamp($object->getDateTo())) {
         throw new \Magento\Framework\Model\Exception(__('Start date cannot be greater than end date.'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         throw new \Magento\Framework\Model\Exception(__('Your design change for the specified store intersects with another one, please specify another date range.'));
     }
     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);
 }
예제 #21
0
 /**
  * before save callback
  *
  * @param AbstractModel|\Sample\News\Model\Author $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     foreach (['dob'] as $field) {
         $value = !$object->getData($field) ? null : $object->getData($field);
         $object->setData($field, $this->dateTime->formatDate($value));
     }
     $object->setUpdatedAt($this->date->gmtDate());
     if ($object->isObjectNew()) {
         $object->setCreatedAt($this->date->gmtDate());
     }
     $urlKey = $object->getData('url_key');
     if ($urlKey == '') {
         $urlKey = $object->getName();
     }
     $urlKey = $object->formatUrlKey($urlKey);
     $object->setUrlKey($urlKey);
     $validKey = false;
     while (!$validKey) {
         if ($this->getIsUniqueAuthorToStores($object)) {
             $validKey = true;
         } else {
             $parts = explode('-', $urlKey);
             $last = $parts[count($parts) - 1];
             if (!is_numeric($last)) {
                 $urlKey = $urlKey . '-1';
             } else {
                 $suffix = '-' . ($last + 1);
                 unset($parts[count($parts) - 1]);
                 $urlKey = implode('-', $parts) . $suffix;
             }
             $object->setData('url_key', $urlKey);
         }
     }
     return parent::_beforeSave($object);
 }
예제 #22
0
파일: Group.php 프로젝트: shazal/magento2
 /**
  * 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);
 }
예제 #23
0
파일: String.php 프로젝트: aiesh/magento2
 /**
  * Before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable(), 'key_id')->where('string = :string')->where('store_id = :store_id');
     $bind = array('string' => $object->getString(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $object->setId($adapter->fetchOne($select, $bind));
     return parent::_beforeSave($object);
 }
예제 #24
0
 /**
  * Perform actions before object save
  * Perform actions before object save, calculate next sequence value for increment Id
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\AbstractModel $object */
     if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
         $object->setIncrementId($this->sequenceManager->getSequence($object->getEntityType(), $object->getStore()->getGroup()->getDefaultStoreId())->getNextValue());
     }
     parent::_beforeSave($object);
     return $this;
 }
예제 #25
0
파일: Cert.php 프로젝트: nja78/magento2
 /**
  * Set date of last update
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return \Magento\Framework\Model\Resource\Db\AbstractDb
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $object->setUpdatedAt($this->dateTime->formatDate($this->_coreDate->gmtDate()));
     return parent::_beforeSave($object);
 }
예제 #26
0
파일: Brand.php 프로젝트: vasuscoin/brand
 /**
  * Process brand data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $result = $this->checkUrlExits($object);
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime($this->_date->gmtDate());
     }
     $object->setUpdateTime($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }