示例#1
0
 protected function _beforeSave()
 {
     if ((int) $this->getId() > 3) {
         $this->_getResource()->loadLabelProductImage($this);
         $this->_getResource()->loadLabelCategoryImage($this);
     }
     parent::_beforeSave();
 }
示例#2
0
 public function applyAllRulesToProduct($product, $force = false)
 {
     if ($force) {
         return parent::applyAllRulesToProduct($product);
     } else {
         return $this;
     }
 }
示例#3
0
 public function __construct()
 {
     parent::__construct();
     $this->_joinedAttributes = array();
 }
示例#4
0
 /**
  * Apply catalog rule to product
  *
  * @param Mage_CatalogRule_Model_Rule $rule
  * @param Mage_Catalog_Model_Product $product
  * @param array $websiteIds
  *
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function applyToProduct($rule, $product, $websiteIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $write->delete($this->getTable('onsale/rule_product'), array($write->quoteInto('rule_id=?', $ruleId), $write->quoteInto('product_id=?', $productId)));
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $rows = array();
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = array('rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'sort_order' => $sortOrder);
                 if (count($rows) == 1000) {
                     $write->insertMultiple($this->getTable('onsale/rule_product'), $rows);
                     $rows = array();
                 }
             }
         }
         if (!empty($rows)) {
             $write->insertMultiple($this->getTable('onsale/rule_product'), $rows);
         }
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     $this->applyAllRulesForDateRange(null, null, $product);
     $write->commit();
     return $this;
 }
示例#5
0
 protected function _construct()
 {
     parent::_construct();
     $this->_init('urapidflow/catalogRule');
     $this->setIdFieldName('rule_id');
 }
示例#6
0
 /**
  * Apply catalog rule to product
  * 
  * @param Mage_CatalogRule_Model_Rule $rule
  * @param Mage_Catalog_Model_Product $product
  * @param array $websiteIds
  * @param array $storeIds
  * 
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function applyToProduct2($rule, $product, $websiteIds, $storeIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $helper = $this->getStorePricingHelper();
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $write->delete($this->getTable('catalogrule/rule_product'), array($write->quoteInto('rule_id=?', $ruleId), $write->quoteInto('product_id=?', $productId)));
     if (!$rule->getConditions()->validate($product)) {
         $write->delete($this->getTable('catalogrule/rule_product_price'), array($write->quoteInto('product_id=?', $productId)));
         $write->commit();
         return $this;
     }
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionStop = $rule->getStopRulesProcessing();
     if ($this->getVersionHelper()->isGe1700()) {
         $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     }
     $rows = array();
     if (!$this->getVersionHelper()->isGe1600()) {
         $header = 'replace into ' . $this->getTable('catalogrule/rule_product') . ' (
             rule_id,
             from_time,
             to_time,
             website_id,
             store_id,
             customer_group_id,
             product_id,
             action_operator,
             action_amount,
             action_stop,
             sort_order
         ) values ';
     }
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($helper->getStoreIdsByWebsiteId($websiteId) as $storeId) {
                 if (in_array($storeId, $storeIds)) {
                     foreach ($customerGroupIds as $customerGroupId) {
                         $discountAmount = $rule->getDiscountAmount();
                         if ($this->getVersionHelper()->isGe1600()) {
                             $row = array('rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'store_id' => $storeId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $discountAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder);
                             if ($this->getVersionHelper()->isGe1700()) {
                                 $subDiscountAmount = $rule->getSubDiscountAmount();
                                 $row['sub_simple_action'] = $subActionOperator;
                                 $row['sub_discount_amount'] = $subDiscountAmount;
                             }
                             $rows[] = $row;
                             if (count($rows) == 1000) {
                                 $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
                                 $rows = array();
                             }
                         } else {
                             $rows[] = "(\n                                    '{$ruleId}',\n                                    '{$fromTime}',\n                                    '{$toTime}',\n                                    '{$websiteId}',\n                                    '{$storeId}',\n                                    '{$customerGroupId}',\n                                    '{$productId}',\n                                    '{$actionOperator}',\n                                    '{$discountAmount}',\n                                    '{$actionStop}',\n                                    '{$sortOrder}'\n                                )";
                             if (sizeof($rows) == 100) {
                                 $sql = $header . join(',', $rows);
                                 $write->query($sql);
                                 $rows = array();
                             }
                         }
                     }
                 }
             }
         }
         if ($this->getVersionHelper()->isGe1600()) {
             if (!empty($rows)) {
                 $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
             }
         } else {
             if (!empty($rows)) {
                 $sql = $header . join(',', $rows);
                 $write->query($sql);
             }
         }
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     $this->applyAllRulesForDateRange(null, null, $product);
     $write->commit();
     return $this;
 }
示例#7
0
 public function _construct()
 {
     parent::_construct();
 }
示例#8
0
文件: Rule.php 项目: rajarshc/Rooja
 /**
  * Change label for current store
  */
 protected function _afterLoad()
 {
     $store = Mage::app()->getStore();
     // Not admin
     if ($store->getId() != 0) {
         // Save original name
         $this->setOriginalName($this->getName());
         $label = Mage::getModel('rewards/catalogrule_label')->getRuleLabelsAsArray($this);
         // Load the label for this store
         if (isset($label[$store->getId()])) {
             $this->setName($label[$store->getId()]);
         } elseif (isset($label[0])) {
             $this->setName($label[0]);
         }
     }
     return parent::_afterLoad();
 }
示例#9
0
 /**
  * Apply catalog rule to product
  *
  * @param   Mage_CatalogRule_Model_Rule $rule
  * @param   Mage_Catalog_Model_Product $product
  * @param   array $websiteIds
  * @return  Mage_CatalogRule_Model_Mysql4_Rule
  */
 public function applyToProduct($rule, $product, $websiteIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $write->delete($this->getTable('catalogrule/rule_product'), array($write->quoteInto('rule_id=?', $ruleId), $write->quoteInto('product_id=?', $productId)));
     if (!$rule->getConditions()->validate($product)) {
         $write->delete($this->getTable('catalogrule/rule_product_price'), array($write->quoteInto('product_id=?', $productId)));
         $write->commit();
         return $this;
     }
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = array();
     $header = 'replace into ' . $this->getTable('catalogrule/rule_product') . ' (
             rule_id,
             from_time,
             to_time,
             website_id,
             customer_group_id,
             product_id,
             action_operator,
             action_amount,
             action_stop,
             sort_order
         ) values ';
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = "(\n                        '{$ruleId}',\n                        '{$fromTime}',\n                        '{$toTime}',\n                        '{$websiteId}',\n                        '{$customerGroupId}',\n                        '{$productId}',\n                        '{$actionOperator}',\n                        '{$actionAmount}',\n                        '{$actionStop}',\n                        '{$sortOrder}'\n                    )";
                 if (sizeof($rows) == 100) {
                     $sql = $header . join(',', $rows);
                     $write->query($sql);
                     $rows = array();
                 }
             }
         }
         if (!empty($rows)) {
             $sql = $header . join(',', $rows);
             $write->query($sql);
         }
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     $this->applyAllRulesForDateRange(null, null, $product);
     $write->commit();
     return $this;
 }
 public function _construct()
 {
     parent::_construct();
     $this->_init('zblocks/condition');
 }
示例#11
0
 /**
  * Apply catalog rule to product
  *
  * @param Mage_CatalogRule_Model_Rule $rule
  * @param Mage_Catalog_Model_Product $product
  * @param array $websiteIds
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function applyToProduct($rule, $product, $websiteIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = array();
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = array('rules_id' => $ruleId, 'product_id' => $productId);
                 if (count($rows) == 1000) {
                     $write->insertMultiple($this->getTable('prolabels/index'), $rows);
                     $rows = array();
                 }
             }
         }
         if (!empty($rows)) {
             $write->insertMultiple($this->getTable('prolabels/index'), $rows);
         }
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     $this->applyAllRulesForDateRange(null, null, $product);
     $write->commit();
     return $this;
 }
示例#12
0
文件: Rule.php 项目: rajarshc/Rooja
 /**
  * Safe method of checking if a rule is a points rule.
  * @param TBT_Rewards_Model_Salesrule_Rule|TBT_Rewards_Model_Catalogrule_Rule|Mage_CatalogRule_Model_Rule|Mage_SalesRule_Model_Rule $rule
  */
 public function isPointsRule($rule)
 {
     if ($rule instanceof TBT_Rewards_Model_Salesrule_Rule || $rule instanceof TBT_Rewards_Model_Catalogrule_Rule) {
         return $rule->isPointsRule();
     }
     if ($rule instanceof Mage_CatalogRule_Model_Rule) {
         $rule = Mage::helper('rewards/rule')->getCatalogrule($rule->getId());
         return $rule->isPointsRule();
     }
     if ($rule instanceof Mage_SalesRule_Model_Rule) {
         $rule = Mage::helper('rewards/rule')->getSalesRule($rule->getId());
         return $rule->isPointsRule();
     }
     Mage::logException(new Exception("Reached Helper_Rule::isPointsRule() with parameter that is not a catalog rule or cart or catalog rule."));
 }
示例#13
0
 /**
  * Process rule related data after rule save
  *
  * @return Innoexts_StorePricing_Model_Catalogrule_Rule
  */
 protected function _afterSave()
 {
     if ($this->getVersionHelper()->isGe1700()) {
         parent::_afterSave();
     } else {
         Mage_Core_Model_Abstract::_afterSave();
         $this->_getResource()->updateRuleProductData($this);
     }
     return $this;
 }
示例#14
0
 public function updateRuleProductData(Mage_CatalogRule_Model_Rule $rule)
 {
     $ruleId = $rule->getId();
     $write = $this->_getWriteAdapter();
     $write->delete($this->getTable('catalogrule/rule_product'), $write->quoteInto('rule_id=?', $ruleId));
     if (!$rule->getIsActive()) {
         return $this;
     }
     $productIds = $rule->getMatchingProductIds();
     $websiteIds = explode(',', $rule->getWebsiteIds());
     $customerGroupIds = explode(',', $rule->getCustomerGroupIds());
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + 86400 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = array();
     $header = 'replace into ' . $this->getTable('catalogrule/rule_product') . ' (rule_id, from_time, to_time, website_id, customer_group_id, product_id, action_operator, action_amount, action_stop, sort_order) values ';
     try {
         $write->beginTransaction();
         foreach ($productIds as $productId) {
             foreach ($websiteIds as $websiteId) {
                 foreach ($customerGroupIds as $customerGroupId) {
                     $rows[] = "('{$ruleId}', '{$fromTime}', '{$toTime}', '{$websiteId}', '{$customerGroupId}', '{$productId}', '{$actionOperator}', '{$actionAmount}', '{$actionStop}', '{$sortOrder}')";
                     if (sizeof($rows) == 100) {
                         $sql = $header . join(',', $rows);
                         $write->query($sql);
                         $rows = array();
                     }
                 }
             }
         }
         if (!empty($rows)) {
             $sql = $header . join(',', $rows);
             $write->query($sql);
         }
         $write->commit();
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     return $this;
 }
示例#15
0
 public function _construct()
 {
     parent::_construct();
     $this->_init('emipro_codpayment/codpayment1');
 }
示例#16
0
 /**
  * Apply catalog rule to product
  *
  * @param Mage_CatalogRule_Model_Rule $rule
  * @param Mage_Catalog_Model_Product $product
  * @param array $websiteIds
  *
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function applyToProduct($rule, $product, $websiteIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $write->delete($this->getTable('catalogrule/rule_product'), array($write->quoteInto('rule_id=?', $ruleId), $write->quoteInto('product_id=?', $productId)));
     if (!$rule->getConditions()->validate($product)) {
         $write->delete($this->getTable('catalogrule/rule_product_price'), array($write->quoteInto('product_id=?', $productId)));
         $write->commit();
         return $this;
     }
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     $subActionAmount = $rule->getSubDiscountAmount();
     $rows = array();
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = array('rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount);
                 if (count($rows) == 1000) {
                     $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
                     $rows = array();
                 }
             }
         }
         if (!empty($rows)) {
             $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
         }
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     $this->applyAllRulesForDateRange(null, null, $product);
     $write->commit();
     return $this;
 }
 /**
  * Process rule related data after rule save
  *
  * @return Mage_CatalogRule_Model_Rule
  */
 protected function _afterSave()
 {
     $this->_getResource()->updateRuleProductData($this);
     parent::_afterSave();
 }
示例#18
0
 /**
  * Apply catalog rule to product
  *
  * @param Mage_CatalogRule_Model_Rule $rule
  * @param Mage_Catalog_Model_Product $product
  * @param array $websiteIds
  *
  * @throws Exception
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function applyToProduct($rule, $product, $websiteIds)
 {
     if (!$rule->getIsActive()) {
         return $this;
     }
     $ruleId = $rule->getId();
     $productId = $product->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     if ($this->_isProductMatchedRule($ruleId, $product)) {
         $this->cleanProductData($ruleId, array($productId));
     }
     if ($this->validateProduct($rule, $product, $websiteIds)) {
         try {
             $this->insertRuleData($rule, $websiteIds, array($productId => array_combine(array_values($websiteIds), array_values($websiteIds))));
         } catch (Exception $e) {
             $write->rollback();
             throw $e;
         }
     } else {
         $write->delete($this->getTable('catalogrule/rule_product_price'), array($write->quoteInto('product_id = ?', $productId)));
     }
     $write->commit();
     return $this;
 }
示例#19
0
 public function updateRuleMultiProductData(Mage_CatalogRule_Model_Rule $rule, $pIds)
 {
     $ruleId = $rule->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     $write->delete($this->getTable('catalogrule/rule_product'), $write->quoteInto('rule_id=?', $ruleId));
     if (!$rule->getIsActive()) {
         $write->commit();
         return $this;
     }
     $websiteIds = $rule->getWebsiteIds();
     if (empty($websiteIds)) {
         $write->commit();
         return $this;
     }
     if (!is_array($websiteIds)) {
         $websiteIds = explode(',', $websiteIds);
     }
     Varien_Profiler::start('__MATCH_PRODUCTS__');
     $productIds = $rule->getMatchingMultiProductIds($pIds);
     Varien_Profiler::stop('__MATCH_PRODUCTS__');
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = array();
     $queryStart = 'INSERT INTO ' . $this->getTable('catalogrule/rule_product') . ' (
             rule_id, from_time, to_time, website_id, customer_group_id, product_id, action_operator,
             action_amount, action_stop, sort_order ) values ';
     $queryEnd = ' ON DUPLICATE KEY UPDATE action_operator=VALUES(action_operator),
         action_amount=VALUES(action_amount), action_stop=VALUES(action_stop)';
     try {
         foreach ($productIds as $productId) {
             foreach ($websiteIds as $websiteId) {
                 foreach ($customerGroupIds as $customerGroupId) {
                     $rows[] = "('" . implode("','", array($ruleId, $fromTime, $toTime, $websiteId, $customerGroupId, $productId, $actionOperator, $actionAmount, $actionStop, $sortOrder)) . "')";
                     /**
                      * Array with 1000 rows contain about 2M data
                      */
                     if (sizeof($rows) == 1000) {
                         $sql = $queryStart . join(',', $rows) . $queryEnd;
                         $write->query($sql);
                         $rows = array();
                     }
                 }
             }
         }
         if (!empty($rows)) {
             $sql = $queryStart . join(',', $rows) . $queryEnd;
             $write->query($sql);
         }
         $write->commit();
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     return $this;
 }