/** * 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); }
public function getStoreLabels() { if (!isset($this->_storeLabels)) { $this->_storeLabels = unserialize(parent::getStoreLabels()); } return $this->_storeLabels; }
protected function _afterSave(Mage_Core_Model_Abstract $object) { if ($object->hasStoreLabels()) { $labels = $object->getStoreLabels(); $this->_getWriteAdapter()->delete($this->_labelsTable, array('status = ?' => $object->getStatus())); $data = array(); foreach ($labels as $storeId => $label) { if (empty($label)) { continue; } $data[] = array('status' => $object->getStatus(), 'store_id' => $storeId, 'label' => $label); } if (!empty($data)) { $this->_getWriteAdapter()->insertMultiple($this->_labelsTable, $data); } } return parent::_afterSave($object); }
/** * 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); }
/** * Save store labels * * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object * @return Mage_Eav_Model_Resource_Entity_Attribute */ protected function _saveStoreLabels(Mage_Core_Model_Abstract $object) { $storeLabels = $object->getStoreLabels(); if (is_array($storeLabels)) { $adapter = $this->_getWriteAdapter(); if ($object->getId()) { $condition = array('attribute_id =?' => $object->getId()); $adapter->delete($this->getTable('eav_attribute_label'), $condition); } foreach ($storeLabels as $storeId => $label) { if ($storeId == 0 || !strlen($label)) { continue; } $bind = array('attribute_id' => $object->getId(), 'store_id' => $storeId, 'value' => $label); $adapter->insert($this->getTable('eav_attribute_label'), $bind); } } return $this; }
protected function _afterSave(Mage_Core_Model_Abstract $object) { $this->saveStoreLabels($object->getId(), $object->getStoreLabels()); $this->saveStoreTemplates($object->getId(), $object->getStoreTemplates()); }