model = Bootstrap::getObjectManager()->create(Builder::class); } /** * @return void */ public function testAttachConditionToCollection(): void { /** @var ProductCollectionFactory $collectionFactory */ $collectionFactory = Bootstrap::getObjectManager()->create(ProductCollectionFactory::class); $collection = $collectionFactory->create(); /** @var RuleFactory $ruleFactory */ $ruleFactory = Bootstrap::getObjectManager()->create(RuleFactory::class); $rule = $ruleFactory->create(); $ruleConditionArray = [ 'conditions' => [ '1' => [ 'type' => CombineCondition::class, 'aggregator' => 'all', 'value' => '1', 'new_child' => '', ], '1--1' => [ 'type' => ProductCondition::class, 'attribute' => 'category_ids', 'operator' => '==', 'value' => '3', ], '1--2' => [ 'type' => ProductCondition::class, 'attribute' => 'special_to_date', 'operator' => '==', 'value' => '2017-09-15', ], ], ]; $rule->loadPost($ruleConditionArray); $this->model->attachConditionToCollection($collection, $rule->getConditions()); $whereString = "/\(category_id IN \('3'\).+\(IFNULL\(`e`\.`entity_id`,.+\) = '2017-09-15'\)/"; $this->assertNotFalse(preg_match($whereString, $collection->getSelectSql(true))); } }