コード例 #1
0
ファイル: IndexBuilder.php プロジェクト: koliaGI/magento2
 /**
  * @param Rule $rule
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function updateRuleProductData(Rule $rule)
 {
     $ruleId = $rule->getId();
     if ($rule->getProductsFilter()) {
         $this->connection->delete($this->getTable('catalogrule_product'), ['rule_id=?' => $ruleId, 'product_id IN (?)' => $rule->getProductsFilter()]);
     } else {
         $this->connection->delete($this->getTable('catalogrule_product'), $this->connection->quoteInto('rule_id=?', $ruleId));
     }
     if (!$rule->getIsActive()) {
         return $this;
     }
     $websiteIds = $rule->getWebsiteIds();
     if (!is_array($websiteIds)) {
         $websiteIds = explode(',', $websiteIds);
     }
     if (empty($websiteIds)) {
         return $this;
     }
     \Magento\Framework\Profiler::start('__MATCH_PRODUCTS__');
     $productIds = $rule->getMatchingProductIds();
     \Magento\Framework\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();
     $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     $subActionAmount = $rule->getSubDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = [];
     foreach ($productIds as $productId => $validationByWebsite) {
         foreach ($websiteIds as $websiteId) {
             if (empty($validationByWebsite[$websiteId])) {
                 continue;
             }
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = ['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) == $this->batchCount) {
                     $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
                     $rows = [];
                 }
             }
         }
     }
     if (!empty($rows)) {
         $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
     }
     return $this;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getWebsiteIds()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getWebsiteIds');
     if (!$pluginInfo) {
         return parent::getWebsiteIds();
     } else {
         return $this->___callPlugins('getWebsiteIds', func_get_args(), $pluginInfo);
     }
 }