Exemplo n.º 1
0
 /**
  * Bind sales rule to customer group(s) and website(s).
  * Save rule's associated store labels.
  * Save product attributes used in rule.
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return Mage_SalesRule_Model_Resource_Rule
  */
 protected function _afterSave(Mage_Core_Model_Abstract $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()) {
         Mage::getResourceModel('Mage_SalesRule_Model_Resource_Coupon')->updateSpecificCoupons($object);
     }
     return parent::_afterSave($object);
 }
Exemplo n.º 2
0
 /**
  * Bind catalog rule to customer group(s) and website(s).
  * Update products which are matched for rule.
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 protected function _afterSave(Mage_Core_Model_Abstract $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;
 }
 /**
  * Match and save events.
  * Save websites associations.
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return Enterprise_CustomerSegment_Model_Resource_Segment
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $segmentId = $object->getId();
     $this->unbindRuleFromEntity($segmentId, array(), 'event');
     if ($object->hasMatchedEvents()) {
         $matchedEvents = $object->getMatchedEvents();
         if (is_array($matchedEvents) && !empty($matchedEvents)) {
             $this->bindRuleToEntity($segmentId, $matchedEvents, 'event');
         }
     }
     if ($object->hasWebsiteIds()) {
         $websiteIds = $object->getWebsiteIds();
         if (!is_array($websiteIds)) {
             $websiteIds = explode(',', (string) $websiteIds);
         }
         $this->bindRuleToEntity($segmentId, $websiteIds, 'website');
     }
     parent::_afterSave($object);
     return $this;
 }
 /**
  * Clean index
  *
  * @param Mage_Core_Model_Abstract|Enterprise_TargetRule_Model_Rule $object
  *
  * @return Enterprise_TargetRule_Model_Resource_Rule
  */
 protected function _beforeDelete(Mage_Core_Model_Abstract $object)
 {
     Mage::getSingleton('index/indexer')->processEntityAction(new Varien_Object(array('type_id' => $object->getData('apply_to'))), Enterprise_TargetRule_Model_Index::ENTITY_TARGETRULE, Enterprise_TargetRule_Model_Index::EVENT_TYPE_CLEAN_TARGETRULES);
     parent::_beforeDelete($object);
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Bind gift rule to customer group(s) and website(s).
  * Save rule's associated store labels.
  * Save product attributes used in rule.
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return Mage_SalesRule_Model_Resource_Rule
  */
 protected function _afterSave(Mage_Core_Model_Abstract $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');
     }
     if ($object->hasProductIds()) {
         $productIds = $object->getProductIds();
         if (!is_array($productIds)) {
             $productIds = explode(',', (string) $productIds);
         }
         $this->bindRuleToEntity($object->getId(), $productIds, 'product');
     }
     // 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);
     }
     return parent::_afterSave($object);
 }
 /**
  * Bind reminder rule to and website(s).
  * Save store templates data.
  *
  * @param Mage_Core_Model_Abstract $rule
  * @return Enterprise_Reminder_Model_Resource_Rule
  */
 protected function _afterSave(Mage_Core_Model_Abstract $rule)
 {
     if ($rule->hasWebsiteIds()) {
         $websiteIds = $rule->getWebsiteIds();
         if (!is_array($websiteIds)) {
             $websiteIds = explode(',', (string) $websiteIds);
         }
         $this->bindRuleToEntity($rule->getId(), $websiteIds, 'website');
     }
     if ($rule->hasData('store_templates')) {
         $this->_saveStoreData($rule);
     }
     parent::_afterSave($rule);
     return $this;
 }
Exemplo n.º 7
0
 /**
  * Save matched products for current rule and clean index
  *
  * @param Mage_Core_Model_Abstract|Enterprise_TargetRule_Model_Rule $object
  *
  * @return Enterprise_TargetRule_Model_Resource_Rule
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     parent::_afterSave($object);
     $segmentIds = $object->getUseCustomerSegment() ? $object->getCustomerSegmentIds() : array(0);
     $this->saveCustomerSegments($object->getId(), $segmentIds);
     $this->unbindRuleFromEntity($object->getId(), array(), 'product');
     /** @var $catalogFlatHelper Mage_Catalog_Helper_Product_Flat */
     $catalogFlatHelper = Mage::helper('catalog/product_flat');
     $storeView = Mage::app()->getDefaultStoreView();
     if ($storeView) {
         $storeId = $storeView->getId();
     } else {
         $storeId = null;
     }
     if ($catalogFlatHelper->isEnabled() && $catalogFlatHelper->isBuilt($storeId)) {
         $this->_fillProductsByRule($object);
     } else {
         $this->bindRuleToEntity($object->getId(), $object->getMatchingProductIds(), 'product');
     }
     return $this;
 }