/** * {@inheritdoc} */ public function getMatchingProductIds() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getMatchingProductIds'); if (!$pluginInfo) { return parent::getMatchingProductIds(); } else { return $this->___callPlugins('getMatchingProductIds', func_get_args(), $pluginInfo); } }
/** * @dataProvider dataProviderCallbackValidateProduct * @param bool $validate */ public function testCallbackValidateProduct($validate) { $args['product'] = $this->productModel; $args['attributes'] = []; $args['idx'] = 0; $args['row'] = ['entity_id' => '1', 'entity_type_id' => '4', 'attribute_set_id' => '4', 'type_id' => 'simple', 'sku' => 'Product', 'has_options' => '0', 'required_options' => '0', 'created_at' => '2014-06-25 13:14:30', 'updated_at' => '2014-06-25 14:37:15']; $this->storeManager->expects($this->any())->method('getWebsites')->with(true)->will($this->returnValue([$this->websiteModel, $this->websiteModel])); $this->websiteModel->expects($this->at(0))->method('getId')->will($this->returnValue('1')); $this->websiteModel->expects($this->at(2))->method('getId')->will($this->returnValue('2')); $this->websiteModel->expects($this->any())->method('getDefaultStore')->will($this->returnValue($this->storeModel)); $this->storeModel->expects($this->at(0))->method('getId')->will($this->returnValue('1')); $this->storeModel->expects($this->at(1))->method('getId')->will($this->returnValue('2')); $this->combineFactory->expects($this->any())->method('create')->will($this->returnValue($this->condition)); $this->condition->expects($this->any())->method('validate')->will($this->returnValue($validate)); $this->condition->expects($this->any())->method('setRule')->will($this->returnSelf()); $this->productModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->rule->callbackValidateProduct($args); $matchingProducts = $this->rule->getMatchingProductIds(); foreach ($matchingProducts['1'] as $matchingRules) { $this->assertEquals($validate, $matchingRules); } }
/** * @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; }