/**
  * {@inheritdoc}
  */
 public function validate(\Magento\Framework\DataObject $object)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'validate');
     if (!$pluginInfo) {
         return parent::validate($object);
     } else {
         return $this->___callPlugins('validate', func_get_args(), $pluginInfo);
     }
 }
Exemple #2
0
 /**
  * @param Rule $rule
  * @param Product $product
  * @return $this
  * @throws \Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function applyRule(Rule $rule, $product)
 {
     $ruleId = $rule->getId();
     $productEntityId = $product->getId();
     $websiteIds = array_intersect($product->getWebsiteIds(), $rule->getWebsiteIds());
     if (!$rule->validate($product)) {
         return $this;
     }
     $this->connection->delete($this->resource->getTableName('catalogrule_product'), [$this->connection->quoteInto('rule_id = ?', $ruleId), $this->connection->quoteInto('product_id = ?', $productEntityId)]);
     $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 = [];
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = ['rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productEntityId, '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->resource->getTableName('catalogrule_product'), $rows);
         }
     } catch (\Exception $e) {
         throw $e;
     }
     $this->applyAllRules($product);
     return $this;
 }