예제 #1
0
 /**
  * Save status labels per store
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->hasStoreLabels()) {
         $labels = $object->getStoreLabels();
         $this->getConnection()->delete($this->labelsTable, ['status = ?' => $object->getStatus()]);
         $data = [];
         foreach ($labels as $storeId => $label) {
             if (empty($label)) {
                 continue;
             }
             $data[] = ['status' => $object->getStatus(), 'store_id' => $storeId, 'label' => $label];
         }
         if (!empty($data)) {
             $this->getConnection()->insertMultiple($this->labelsTable, $data);
         }
     }
     return parent::_afterSave($object);
 }
예제 #2
0
파일: Rule.php 프로젝트: rafaelstz/magento2
 /**
  * Bind sales rule to customer group(s) and website(s).
  * Save rule's associated store labels.
  * Save product attributes used in rule.
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(AbstractModel $object)
 {
     if ($object->hasStoreLabels()) {
         $this->saveStoreLabels($object->getId(), $object->getStoreLabels());
     }
     // Save product attributes used in rule
     $ruleProductAttributes = array_merge($this->getProductAttributes(serialize($object->getConditions()->asArray())), $this->getProductAttributes(serialize($object->getActions()->asArray())));
     if (count($ruleProductAttributes)) {
         $this->setActualProductAttributes($object, $ruleProductAttributes);
     }
     // Update auto geterated specific coupons if exists
     if ($object->getUseAutoGeneration() && $object->hasDataChanges()) {
         $this->_resourceCoupon->updateSpecificCoupons($object);
     }
     return parent::_afterSave($object);
 }
예제 #3
0
 /**
  * Bind sales rule to customer group(s) and website(s).
  * Save rule's associated store labels.
  * Save product attributes used in rule.
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(AbstractModel $object)
 {
     if ($object->hasStoreLabels()) {
         $this->saveStoreLabels($object->getId(), $object->getStoreLabels());
     }
     if ($object->hasWebsiteIds()) {
         $websiteIds = $object->getWebsiteIds();
         if (!is_array($websiteIds)) {
             $websiteIds = explode(',', (string) $websiteIds);
         }
         $this->bindRuleToEntity($object->getId(), $websiteIds, 'website');
     }
     if ($object->hasCustomerGroupIds()) {
         $customerGroupIds = $object->getCustomerGroupIds();
         if (!is_array($customerGroupIds)) {
             $customerGroupIds = explode(',', (string) $customerGroupIds);
         }
         $this->bindRuleToEntity($object->getId(), $customerGroupIds, 'customer_group');
     }
     // Save product attributes used in rule
     $ruleProductAttributes = array_merge($this->getProductAttributes(serialize($object->getConditions()->asArray())), $this->getProductAttributes(serialize($object->getActions()->asArray())));
     if (count($ruleProductAttributes)) {
         $this->setActualProductAttributes($object, $ruleProductAttributes);
     }
     // Update auto geterated specific coupons if exists
     if ($object->getUseAutoGeneration() && $object->hasDataChanges()) {
         $this->_resourceCoupon->updateSpecificCoupons($object);
     }
     return parent::_afterSave($object);
 }