コード例 #1
0
ファイル: Rule.php プロジェクト: zhangjiachao/magento2
 /**
  * Bind catalog rule to customer group(s) and website(s).
  * Update products which are matched for rule.
  *
  * @param AbstractModel $object
  * @return $this
  */
 protected function _afterSave(AbstractModel $object)
 {
     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');
     }
     parent::_afterSave($object);
     return $this;
 }
コード例 #2
0
ファイル: Rule.php プロジェクト: shabbirvividads/magento2
 /**
  * @param \Magento\Framework\Model\AbstractModel $rule
  * @return $this
  */
 protected function _afterDelete(\Magento\Framework\Model\AbstractModel $rule)
 {
     $write = $this->_getWriteAdapter();
     $write->delete($this->getTable('catalogrule_product'), ['rule_id=?' => $rule->getId()]);
     $write->delete($this->getTable('catalogrule_customer_group'), ['rule_id=?' => $rule->getId()]);
     $write->delete($this->getTable('catalogrule_group_website'), ['rule_id=?' => $rule->getId()]);
     return parent::_afterDelete($rule);
 }
コード例 #3
0
ファイル: Rule.php プロジェクト: shabbirvividads/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());
     }
     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);
 }