/**
  * Invalidate catalog price rule indexer
  *
  * @param Import $subject
  * @param bool $result
  * @return bool
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterImportSource(Import $subject, $result)
 {
     if (!$this->ruleProductProcessor->isIndexerScheduled()) {
         $this->ruleProductProcessor->markIndexerAsInvalid();
     }
     return $result;
 }
Example #2
0
 /**
  * Dispatch event "catalogrule_apply_all" and set success or error message depends on result
  *
  * @return \Magento\CatalogRule\Model\Rule\Job
  */
 public function applyAll()
 {
     try {
         $this->ruleProcessor->markIndexerAsInvalid();
         $this->setSuccess(__('Updated rules applied.'));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->setError($e->getMessage());
     }
     return $this;
 }
Example #3
0
 /**
  * Test after update action
  *
  * @return void
  */
 public function testAfterUpdate()
 {
     $this->rule->isObjectNew(false);
     $indexer = $this->getMock('\\Magento\\Indexer\\Model\\IndexerInterface');
     $indexer->expects($this->once())->method('invalidate');
     $this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));
     $this->rule->afterSave();
 }
Example #4
0
 /**
  * Test isRuleBehaviorChanged action
  *
  * @dataProvider isRuleBehaviorChangedDataProvider
  *
  * @param array $dataArray
  * @param array $originDataArray
  * @param bool $isObjectNew
  * @param bool $result
  *
  * @return void
  */
 public function testIsRuleBehaviorChanged($dataArray, $originDataArray, $isObjectNew, $result)
 {
     $this->rule->setData('website_ids', []);
     $this->rule->isObjectNew($isObjectNew);
     $indexer = $this->getMock('\\Magento\\Framework\\Indexer\\IndexerInterface');
     $indexer->expects($this->any())->method('invalidate');
     $this->_ruleProductProcessor->expects($this->any())->method('getIndexer')->will($this->returnValue($indexer));
     foreach ($dataArray as $data) {
         $this->rule->setData($data);
     }
     $this->rule->afterSave();
     foreach ($originDataArray as $data) {
         $this->rule->setOrigData($data);
     }
     $this->assertEquals($result, $this->rule->isRuleBehaviorChanged());
 }
Example #5
0
 /**
  * Check rules that contains affected attribute
  * If rules were found they will be set to inactive and notice will be add to admin session
  *
  * @param string $attributeCode
  * @return $this
  */
 protected function checkCatalogRulesAvailability($attributeCode)
 {
     /* @var $collection RuleCollectionFactory */
     $collection = $this->ruleCollectionFactory->create()->addAttributeInConditionFilter($attributeCode);
     $disabledRulesCount = 0;
     foreach ($collection as $rule) {
         /* @var $rule Rule */
         $rule->setIsActive(0);
         /* @var $rule->getConditions() Combine */
         $this->removeAttributeFromConditions($rule->getConditions(), $attributeCode);
         $rule->save();
         $disabledRulesCount++;
     }
     if ($disabledRulesCount) {
         $this->ruleProductProcessor->markIndexerAsInvalid();
         $this->messageManager->addWarning(__('You disabled %1 Catalog Price Rules based on "%2" attribute.', $disabledRulesCount, $attributeCode));
     }
     return $this;
 }
 public function testAfterDelete()
 {
     $this->ruleProductProcessor->expects($this->once())->method('markIndexerAsInvalid');
     $this->assertEquals($this->subject, $this->plugin->afterDelete($this->subject, $this->subject));
 }
 public function testAfterImportSource()
 {
     $result = true;
     $this->ruleProductProcessor->expects($this->once())->method('markIndexerAsInvalid');
     $this->assertEquals($result, $this->plugin->afterImportSource($this->subject, $result));
 }
 /**
  * Daily update catalog price rule by cron
  * Update include interval 3 days - current day - 1 days before + 1 days after
  * This method is called from cron process, cron is working in UTC time and
  * we should generate data for interval -1 day ... +1 day
  *
  * @return void
  */
 public function execute()
 {
     $this->ruleProductProcessor->markIndexerAsInvalid();
 }
 /**
  * @param Group $subject
  * @param Group $result
  * @return Group
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDelete(Group $subject, Group $result)
 {
     $this->ruleProductProcessor->markIndexerAsInvalid();
     return $result;
 }
 public function testDailyCatalogUpdate()
 {
     $this->ruleProductProcessor->expects($this->once())->method('markIndexerAsInvalid');
     $this->cron->execute();
 }
Example #11
0
 /**
  * Invalidate catalog price rule indexer
  *
  * @param \Magento\Store\Model\Website $subject
  * @param \Magento\Store\Model\Website $result
  * @return \Magento\Store\Model\Website
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDelete(\Magento\Store\Model\Website $subject, \Magento\Store\Model\Website $result)
 {
     $this->ruleProductProcessor->markIndexerAsInvalid();
     return $result;
 }