示例#1
0
文件: Rule.php 项目: rcclaudrey/dev
 protected function _afterSave()
 {
     if (is_array($this->getSchedule())) {
         $scheduleCollection = Mage::getModel('amacart/schedule')->getCollection();
         $scheduleCollection->addFilter('rule_id', $this->getId());
         $scheduleDbData = $scheduleCollection->getItems();
         $schedule = $this->getSchedule();
         $saveData = array();
         foreach ($schedule['row_index'] as $order) {
             if ($order != '_rowIdx_') {
                 //skip first template row
                 $days = intval($schedule['days'][$order]);
                 $hours = intval($schedule['hours'][$order]);
                 $minutes = intval($schedule['minutes'][$order]);
                 $rowIndex = intval($schedule['row_index'][$order]);
                 $email_template_id = $schedule['email_templates'][$order];
                 $delayed_start = $this->_toSeconds($days, $hours, $minutes);
                 $saveItem = array();
                 if (intval($schedule['use_rule'][$order]) == 1) {
                     $saveItem = array("use_rule" => 1, "sales_rule_id" => $schedule['rule_id'][$order], 'delayed_start' => $delayed_start, 'email_template_id' => empty($email_template_id) ? NULL : $email_template_id);
                 } else {
                     $coupon_type = $schedule['coupon_type'][$order];
                     $discount_amount = intval($schedule['discount_amount'][$order]);
                     $expired_in_days = intval($schedule['expired_in_days'][$order]);
                     $discount_qty = $schedule['discount_qty'][$order];
                     $discount_step = $schedule['discount_step'][$order];
                     $promo_sku = $schedule['promo_sku'][$order];
                     $ampromo_type = $schedule['ampromo_type'][$order];
                     $subtotal_greater_than = $schedule['subtotal_greater_than'][$order];
                     $saveItem = array('email_template_id' => empty($email_template_id) ? NULL : $email_template_id, 'delayed_start' => $delayed_start, 'coupon_type' => empty($coupon_type) ? NULL : $coupon_type, 'discount_amount' => $discount_amount, 'expired_in_days' => $expired_in_days, 'discount_qty' => $discount_qty, 'discount_step' => $discount_step, 'promo_sku' => $promo_sku, 'ampromo_type' => $ampromo_type, 'use_rule' => 0, 'subtotal_greater_than' => empty($subtotal_greater_than) ? NULL : $subtotal_greater_than);
                 }
                 $saveData[$order] = $saveItem;
             }
         }
         foreach ($scheduleDbData as $scheduleDbItem) {
             $delayed_start = $scheduleDbItem->getDelayedStart();
             if (array_key_exists($delayed_start, $saveData)) {
                 //                    $scheduleDbItem->setEmailTemplateId($saveData[$delayed_start]);
                 $scheduleDbItem->addData($saveData[$delayed_start]);
                 $scheduleDbItem->save();
                 unset($saveData[$delayed_start]);
             } else {
                 $scheduleDbItem->delete();
             }
         }
         foreach ($saveData as $delayed_start => $config) {
             $schedule = Mage::getModel('amacart/schedule');
             $schedule->setData(array_merge(array('rule_id' => $this->getId(), 'email_template_id' => $email_template_id), $config));
             $schedule->save();
         }
     }
     //Saving attributes used in rule
     $ruleProductAttributes = array_merge($this->_getUsedAttributes($this->getConditionsSerialized()), $this->_getUsedAttributes($this->getActionsSerialized()));
     if (count($ruleProductAttributes)) {
         $this->getResource()->saveAttributes($this->getId(), $ruleProductAttributes);
     }
     return parent::_afterSave();
 }
示例#2
0
 protected function _afterSave()
 {
     //Saving attributes used in rule
     $ruleProductAttributes = array_merge($this->_getUsedAttributes($this->getConditionsSerialized()), $this->_getUsedAttributes($this->getActionsSerialized()));
     if (count($ruleProductAttributes)) {
         $this->getResource()->saveAttributes($this->getId(), $ruleProductAttributes);
     }
     return parent::_afterSave();
 }
 protected function _afterSave()
 {
     if (is_array($this->getSchedule())) {
         $scheduleCollection = Mage::getModel('amacart/schedule')->getCollection();
         $scheduleCollection->addFilter('rule_id', $this->getId());
         $scheduleDbData = $scheduleCollection->getItems();
         $schedule = $this->getSchedule();
         $saveData = array();
         foreach ($schedule['email_templates'] as $order => $email_template_id) {
             if ($order > 0) {
                 //skip first template row
                 $days = intval($schedule['days'][$order]);
                 $hours = intval($schedule['hours'][$order]);
                 $minutes = intval($schedule['minutes'][$order]);
                 $coupon_type = $schedule['coupon_type'][$order];
                 $discount_amount = intval($schedule['discount_amount'][$order]);
                 $expired_in_days = intval($schedule['expired_in_days'][$order]);
                 $subtotal_greater_than = $schedule['subtotal_greater_than'][$order];
                 //                    var_dump($subtotal_greater_than);
                 //                    exit(1);
                 $delayed_start = $this->_toSeconds($days, $hours, $minutes);
                 $saveData[$this->_toSeconds($days, $hours, $minutes)] = array('delayed_start' => $delayed_start, 'email_template_id' => empty($email_template_id) ? NULL : $email_template_id, 'coupon_type' => empty($coupon_type) ? NULL : $coupon_type, 'discount_amount' => $discount_amount, 'expired_in_days' => $expired_in_days, 'subtotal_greater_than' => empty($subtotal_greater_than) ? NULL : $subtotal_greater_than);
             }
         }
         foreach ($scheduleDbData as $scheduleDbItem) {
             $delayed_start = $scheduleDbItem->getDelayedStart();
             if (array_key_exists($delayed_start, $saveData)) {
                 //                    $scheduleDbItem->setEmailTemplateId($saveData[$delayed_start]);
                 $scheduleDbItem->addData($saveData[$delayed_start]);
                 $scheduleDbItem->save();
                 unset($saveData[$delayed_start]);
             } else {
                 $scheduleDbItem->delete();
             }
         }
         foreach ($saveData as $delayed_start => $config) {
             $schedule = Mage::getModel('amacart/schedule');
             $schedule->setData(array_merge(array('rule_id' => $this->getId(), 'email_template_id' => $email_template_id), $config));
             $schedule->save();
         }
     }
     //Saving attributes used in rule
     $ruleProductAttributes = array_merge($this->_getUsedAttributes($this->getConditionsSerialized()), $this->_getUsedAttributes($this->getActionsSerialized()));
     if (count($ruleProductAttributes)) {
         $this->getResource()->saveAttributes($this->getId(), $ruleProductAttributes);
     }
     return parent::_afterSave();
 }
示例#4
0
 protected function _afterSave()
 {
     if ($storeId = $this->getStoreId()) {
         $storeAttributes = $this->getStoreAttributes();
         foreach ($storeAttributes as $attribute) {
             $attributeValue = Mage::getModel('affiliateplusprogram/value')->loadAttributeValue($this->getId(), $storeId, $attribute);
             if ($this->getData($attribute . '_in_store')) {
                 try {
                     $attributeValue->setValue($this->getData($attribute . '_value'))->save();
                 } catch (Exception $e) {
                 }
             } elseif ($attributeValue && $attributeValue->getId()) {
                 try {
                     $attributeValue->delete();
                 } catch (Exception $e) {
                 }
             }
         }
     }
     if (is_string($this->getData('tier_commission'))) {
         $this->setData('tier_commission', unserialize($this->getData('tier_commission')));
     }
     if (is_string($this->getData('sec_tier_commission'))) {
         $this->setData('sec_tier_commission', unserialize($this->getData('sec_tier_commission')));
     }
     return parent::_afterSave();
 }
 /**
  * Process rule related data after rule save
  *
  * @return Mage_CatalogRule_Model_Rule
  */
 protected function _afterSave()
 {
     $this->_getResource()->updateRuleProductData($this);
     parent::_afterSave();
 }
示例#6
0
 /**
  * Save rule labels after rule save and process product attributes used in actions and conditions
  *
  * @return Mage_SalesRule_Model_Rule
  */
 protected function _afterSave()
 {
     if ($this->hasStoreLabels()) {
         $this->_getResource()->saveStoreLabels($this->getId(), $this->getStoreLabels());
     }
     $couponCode = trim($this->getCouponCode());
     if ($couponCode && $this->getCouponType() == self::COUPON_TYPE_SPECIFIC) {
         $this->getPrimaryCoupon()->setCode($couponCode)->setUsageLimit($this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null)->setUsagePerCustomer($this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null)->setExpirationDate($this->getToDate())->save();
     } else {
         $this->getPrimaryCoupon()->delete();
     }
     //Saving attributes used in rule
     $ruleProductAttributes = array_merge($this->_getUsedAttributes($this->getConditionsSerialized()), $this->_getUsedAttributes($this->getActionsSerialized()));
     if (count($ruleProductAttributes)) {
         $this->getResource()->setActualProductAttributes($this, $ruleProductAttributes);
     }
     return parent::_afterSave();
 }
示例#7
0
 protected function _afterSave()
 {
     parent::_afterSave();
 }
 /**
  * Save rula labels after rule save
  *
  * @return Mage_SalesRule_Model_Rule
  */
 protected function _afterSave()
 {
     if ($this->hasStoreLabels()) {
         $this->_getResource()->saveStoreLabels($this->getId(), $this->getStoreLabels());
     }
     return parent::_afterSave();
 }
 protected function _afterSave()
 {
     if ($storeId = $this->getStoreId()) {
         $storeAttributes = $this->getStoreAttributes();
         foreach ($storeAttributes as $attribute) {
             $attributeValue = Mage::getModel('rewardpointsreferfriends/rewardpointsspecialrefervalue')->loadAttributeValue($this->getId(), $storeId, $attribute);
             if ($this->getData($attribute . '_in_store')) {
                 try {
                     $attributeValue->setValue($this->getData($attribute . '_value'))->save();
                 } catch (Exception $e) {
                 }
             } elseif ($attributeValue && $attributeValue->getId()) {
                 try {
                     $attributeValue->delete();
                 } catch (Exception $e) {
                 }
             }
         }
     }
     return parent::_afterSave();
 }