Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionsToCollectionApplierTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
13 // @codingStandardsIgnoreFile
14 
15 class ConditionsToCollectionApplierTest extends \PHPUnit\Framework\TestCase
16 {
17  private $objectManager;
18 
19  private $productCollectionFactory;
20 
21  private $conditionsToCollectionApplier;
22 
23  private $combinedConditionFactory;
24 
25  private $simpleConditionFactory;
26 
27  private $categoryCollectionFactory;
28 
29  private $setFactory;
30 
31  public function setUp()
32  {
33  $this->objectManager = Bootstrap::getObjectManager();
34 
35  $this->productCollectionFactory = $this->objectManager
36  ->get(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class);
37 
38  $this->conditionsToCollectionApplier = $this->objectManager
39  ->get(\Magento\CatalogRule\Model\ResourceModel\Product\ConditionsToCollectionApplier::class);
40 
41  $this->combinedConditionFactory = $this->objectManager
42  ->get(\Magento\CatalogRule\Model\Rule\Condition\CombineFactory::class);
43 
44  $this->simpleConditionFactory = $this->objectManager
45  ->get(\Magento\CatalogRule\Model\Rule\Condition\ProductFactory::class);
46 
47  $this->categoryCollectionFactory = $this->objectManager
48  ->get(\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class);
49 
50  $this->setFactory = $this->objectManager
51  ->get(\Magento\Eav\Model\Entity\Attribute\SetFactory::class);
52  }
53 
61  public function testVariations()
62  {
63  foreach ($this->conditionProvider() as $variationName => $variationData) {
64  $condition = $variationData['condition'];
65  $expectedSkuList = $variationData['expected-sku'];
66 
67  $productCollection = $this->productCollectionFactory->create();
68  $resultCollection = $this->conditionsToCollectionApplier
69  ->applyConditionsToCollection($condition, $productCollection);
70 
71  $resultSkuList = array_map(
72  function (Product $product) {
73  return $product->getSku();
74  },
75  array_values($resultCollection->getItems())
76  );
77 
78  asort($expectedSkuList);
79  asort($resultSkuList);
80 
81  $this->assertEquals($expectedSkuList, $resultSkuList, sprintf('%s failed', $variationName));
82  }
83  }
84 
92  {
93  $conditions = [
94  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
95  'aggregator' => 'all',
96  'value' => 0,
97  'conditions' => [
98  [
99  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
100  'operator' => '====',
101  'value' => 42,
102  'attribute' => 'attribute_set_id'
103  ]
104  ]
105  ];
106 
107  $combineCondition = $this->getCombineConditionFromArray($conditions);
108 
109  $productCollection = $this->productCollectionFactory->create();
110  $this->conditionsToCollectionApplier
111  ->applyConditionsToCollection($combineCondition, $productCollection);
112  }
113 
121  {
122  $conditions = [
123  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
124  'aggregator' => 'olo-lo',
125  'value' => 0,
126  'conditions' => [
127  [
128  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
129  'operator' => '==',
130  'value' => 42,
131  'attribute' => 'attribute_set_id'
132  ]
133  ]
134  ];
135 
136  $combineCondition = $this->getCombineConditionFromArray($conditions);
137 
138  $productCollection = $this->productCollectionFactory->create();
139  $this->conditionsToCollectionApplier
140  ->applyConditionsToCollection($combineCondition, $productCollection);
141  }
142 
147  private function conditionProvider()
148  {
149  return [
150  // test filter by category without children
151  'variation 1' => [
152  'condition' => $this->getConditionsForVariation1(),
153  'expected-sku' => [
154  'simple-product-1',
155  'simple-product-2',
156  'simple-product-7',
157  'simple-product-8'
158  ]
159  ],
160 
161  // test filter by root category
162  'variation 2' => [
163  'condition' => $this->getConditionsForVariation2(),
164  'expected-sku' => [
165  'simple-product-1',
166  'simple-product-2',
167  'simple-product-3',
168  'simple-product-4',
169  'simple-product-5',
170  'simple-product-6',
171  'simple-product-7',
172  'simple-product-8',
173  'simple-product-9',
174  'simple-product-10',
175  'simple-product-11',
176  'simple-product-12'
177  ]
178  ],
179 
180  // test filter by anchor category with children
181  'variation 3' => [
182  'condition' => $this->getConditionsForVariation3(),
183  'expected-sku' => [
184  'simple-product-1',
185  'simple-product-2',
186  'simple-product-3',
187  'simple-product-4',
188  'simple-product-5',
189  'simple-product-6',
190  'simple-product-9',
191  'simple-product-10',
192  'simple-product-11',
193  'simple-product-12'
194  ]
195  ],
196 
197  // test filter by non existing category
198  'variation 4' => [
199  'condition' => $this->getConditionsForVariation4(),
200  'expected-sku' => []
201  ],
202 
203  // test filter by sku
204  'variation 5' => [
205  'condition' => $this->getConditionsForVariation5(),
206  'expected-sku' => ['simple-product-2']
207  ],
208 
209  // test filter by attribute set
210  'variation 6' => [
211  'condition' => $this->getConditionsForVariation6(),
212  'expected-sku' => [
213  'simple-product-1',
214  'simple-product-4',
215  'simple-product-7',
216  'simple-product-10'
217  ]
218  ],
219 
220  // test filter by product name
221  'variation 7' => [
222  'condition' => $this->getConditionsForVariation7(),
223  'expected-sku' => [
224  'simple-product-1',
225  'simple-product-9',
226  'simple-product-12'
227  ]
228  ],
229 
230  // test filter by not existing attribute
231  'variation 8' => [
232  'condition' => $this->getConditionsForVariation8(),
233  'expected-sku' => [
234  'simple-product-1',
235  'simple-product-2',
236  'simple-product-3',
237  'simple-product-4',
238  'simple-product-5',
239  'simple-product-6',
240  'simple-product-7',
241  'simple-product-8',
242  'simple-product-9',
243  'simple-product-10',
244  'simple-product-11',
245  'simple-product-12'
246  ]
247  ],
248 
249  // test filter by category with empty value
250  'variation 9' => [
251  'condition' => $this->getConditionsForVariation9(),
252  'expected-sku' => []
253  ],
254 
255  // test filter by sku with empty value
256  'variation 10' => [
257  'condition' => $this->getConditionsForVariation10(),
258  'expected-sku' => [
259  'simple-product-1',
260  'simple-product-2',
261  'simple-product-3',
262  'simple-product-4',
263  'simple-product-5',
264  'simple-product-6',
265  'simple-product-7',
266  'simple-product-8',
267  'simple-product-9',
268  'simple-product-10',
269  'simple-product-11',
270  'simple-product-12'
271  ]
272  ],
273 
274  // test filter by name with empty value
275  'variation 11' => [
276  'condition' => $this->getConditionsForVariation11(),
277  'expected-sku' => []
278  ],
279 
280  // test filter by like condition
281  'variation 12' => [
282  'condition' => $this->getConditionsForVariation12(),
283  'expected-sku' => [
284  'simple-product-1',
285  'simple-product-2',
286  'simple-product-3',
287  'simple-product-4',
288  'simple-product-5',
289  'simple-product-6',
290  'simple-product-9',
291  'simple-product-10',
292  'simple-product-11',
293  'simple-product-12'
294  ]
295  ],
296 
297  // test filter with ALL aggregation
298  'variation 13' => [
299  'condition' => $this->getConditionsForVariation13(),
300  'expected-sku' => [
301  'simple-product-7',
302  'simple-product-8'
303  ]
304  ],
305 
306  // test filter with ANY aggregation
307  'variation 14' => [
308  'condition' => $this->getConditionsForVariation14(),
309  'expected-sku' => [
310  'simple-product-1',
311  'simple-product-2',
312  'simple-product-3',
313  'simple-product-4',
314  'simple-product-7',
315  'simple-product-8'
316  ]
317  ],
318 
319  // test filter with array in product condition's value
320  'variation 15' => [
321  'condition' => $this->getConditionsForVariation15(),
322  'expected-sku' => [
323  'simple-product-1',
324  'simple-product-2',
325  'simple-product-3',
326  'simple-product-4',
327  'simple-product-7',
328  'simple-product-8'
329  ]
330  ],
331 
332  // test filter by multiple sku
333  'variation 16' => [
334  'condition' => $this->getConditionsForVariation16(),
335  'expected-sku' => [
336  'simple-product-1',
337  'simple-product-5',
338  'simple-product-11'
339  ]
340  ],
341 
342  // test filter with multiple combined conditions
343  'variation 17' => [
344  'condition' => $this->getConditionsForVariation17(),
345  'expected-sku' => [
346  'simple-product-1',
347  'simple-product-2',
348  'simple-product-4',
349  'simple-product-8',
350  'simple-product-10'
351  ]
352  ],
353 
354  // test filter with multiply levels in conditions
355  'variation 18' => [
356  'condition' => $this->getConditionsForVariation18(),
357  'expected-sku' => [
358  'simple-product-1',
359  'simple-product-2',
360  'simple-product-3',
361  'simple-product-4',
362  'simple-product-5',
363  'simple-product-6',
364  'simple-product-10',
365  'simple-product-11'
366  ]
367  ],
368 
369  // test filter with empty conditions
370  'variation 19' => [
371  'condition' => $this->getConditionsForVariation19(),
372  'expected-sku' => [
373  'simple-product-1',
374  'simple-product-2',
375  'simple-product-3',
376  'simple-product-4',
377  'simple-product-5',
378  'simple-product-6',
379  'simple-product-7',
380  'simple-product-8',
381  'simple-product-9',
382  'simple-product-10',
383  'simple-product-11',
384  'simple-product-12'
385  ]
386  ],
387 
388  // test filter for case "If ALL of these conditions are FALSE"
389  'variation 20' => [
390  'condition' => $this->getConditionsForVariation20(),
391  'expected-sku' => [
392  'simple-product-2',
393  'simple-product-5',
394  'simple-product-8',
395  'simple-product-11'
396  ]
397  ],
398 
399  // test filter for case "If ANY of these conditions are FALSE"
400  'variation 21' => [
401  'condition' => $this->getConditionsForVariation21(),
402  'expected-sku' => [
403  'simple-product-1',
404  'simple-product-2',
405  'simple-product-3',
406  'simple-product-4',
407  'simple-product-5',
408  'simple-product-6',
409  'simple-product-7',
410  'simple-product-8',
411  'simple-product-9',
412  'simple-product-10',
413  'simple-product-11',
414  'simple-product-12'
415  ]
416  ],
417  ];
418  }
419 
420  private function getConditionsForVariation1()
421  {
422  $category2Name = 'Category 2';
423 
424  $category2Id = $this->categoryCollectionFactory
425  ->create()
426  ->addAttributeToFilter('name', $category2Name)
427  ->getAllIds();
428 
429  $conditions = [
430  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
431  'aggregator' => 'any',
432  'value' => 1,
433  'conditions' => [
434  [
435  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
436  'operator' => '==',
437  'value' => implode(',', $category2Id),
438  'attribute' => 'category_ids'
439  ]
440  ]
441  ];
442 
443  return $this->getCombineConditionFromArray($conditions);
444  }
445 
446  private function getConditionsForVariation2()
447  {
448  $categoryName = 'Default Category';
449 
450  $categoryId = $this->categoryCollectionFactory
451  ->create()
452  ->addAttributeToFilter('name', $categoryName)
453  ->getAllIds();
454 
455  $conditions = [
456  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
457  'aggregator' => 'any',
458  'value' => 1,
459  'conditions' => [
460  [
461  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
462  'operator' => '==',
463  'value' => implode(',', $categoryId),
464  'attribute' => 'category_ids'
465  ]
466  ]
467  ];
468 
469  return $this->getCombineConditionFromArray($conditions);
470  }
471 
472  private function getConditionsForVariation3()
473  {
474  $category1Name = 'Category 1';
475 
476  $category1Id = $this->categoryCollectionFactory
477  ->create()
478  ->addAttributeToFilter('name', $category1Name)
479  ->getAllIds();
480 
481  $conditions = [
482  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
483  'aggregator' => 'any',
484  'value' => 1,
485  'conditions' => [
486  [
487  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
488  'operator' => '==',
489  'value' => implode(',', $category1Id),
490  'attribute' => 'category_ids'
491  ]
492  ]
493  ];
494 
495  return $this->getCombineConditionFromArray($conditions);
496  }
497 
498  private function getConditionsForVariation4()
499  {
500  $conditions = [
501  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
502  'aggregator' => 'any',
503  'value' => 1,
504  'conditions' => [
505  [
506  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
507  'operator' => '==',
508  'value' => implode(',', [308567758103]),
509  'attribute' => 'category_ids'
510  ]
511  ]
512  ];
513 
514  return $this->getCombineConditionFromArray($conditions);
515  }
516 
517  private function getConditionsForVariation5()
518  {
519  $conditions = [
520  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
521  'aggregator' => 'any',
522  'value' => 1,
523  'conditions' => [
524  [
525  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
526  'operator' => '{}',
527  'value' => 'product-2',
528  'attribute' => 'sku'
529  ]
530  ]
531  ];
532 
533  return $this->getCombineConditionFromArray($conditions);
534  }
535 
536  private function getConditionsForVariation6()
537  {
538  $attrSet = $this->setFactory->create()
539  ->load('Super Powerful Muffins', 'attribute_set_name');
540 
541  $conditions = [
542  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
543  'aggregator' => 'any',
544  'value' => 1,
545  'conditions' => [
546  [
547  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
548  'operator' => '==',
549  'value' => $attrSet->getId(),
550  'attribute' => 'attribute_set_id'
551  ]
552  ]
553  ];
554 
555  return $this->getCombineConditionFromArray($conditions);
556  }
557 
558  private function getConditionsForVariation7()
559  {
560  $conditions = [
561  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
562  'aggregator' => 'any',
563  'value' => 1,
564  'conditions' => [
565  [
566  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
567  'operator' => '{}',
568  'value' => 'Sale',
569  'attribute' => 'name'
570  ]
571  ]
572  ];
573 
574  return $this->getCombineConditionFromArray($conditions);
575  }
576 
577  private function getConditionsForVariation8()
578  {
579  $conditions = [
580  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
581  'aggregator' => 'any',
582  'value' => 1,
583  'conditions' => [
584  [
585  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
586  'operator' => '==',
587  'value' => 'Sale',
588  'attribute' => 'absolutely_random_attribute_name'
589  ]
590  ]
591  ];
592 
593  return $this->getCombineConditionFromArray($conditions);
594  }
595 
596  private function getConditionsForVariation9()
597  {
598  $conditions = [
599  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
600  'aggregator' => 'any',
601  'value' => 1,
602  'conditions' => [
603  [
604  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
605  'operator' => '==',
606  'value' => '',
607  'attribute' => 'category_ids'
608  ]
609  ]
610  ];
611 
612  return $this->getCombineConditionFromArray($conditions);
613  }
614 
615  private function getConditionsForVariation10()
616  {
617  $conditions = [
618  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
619  'aggregator' => 'any',
620  'value' => 1,
621  'conditions' => [
622  [
623  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
624  'operator' => '==',
625  'value' => '',
626  'attribute' => 'sku'
627  ]
628  ]
629  ];
630 
631  return $this->getCombineConditionFromArray($conditions);
632  }
633 
634  private function getConditionsForVariation11()
635  {
636  $conditions = [
637  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
638  'aggregator' => 'any',
639  'value' => 1,
640  'conditions' => [
641  [
642  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
643  'operator' => '==',
644  'value' => '',
645  'attribute' => 'name'
646  ]
647  ]
648  ];
649 
650  return $this->getCombineConditionFromArray($conditions);
651  }
652 
653  private function getConditionsForVariation12()
654  {
655  $category1Name = 'Category 1';
656 
657  $category1Id = $this->categoryCollectionFactory
658  ->create()
659  ->addAttributeToFilter('name', $category1Name)
660  ->getAllIds();
661 
662  $conditions = [
663  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
664  'aggregator' => 'any',
665  'value' => 1,
666  'conditions' => [
667  [
668  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
669  'operator' => '{}',
670  'value' => implode(',', $category1Id),
671  'attribute' => 'category_ids'
672  ]
673  ]
674  ];
675 
676  return $this->getCombineConditionFromArray($conditions);
677  }
678 
679  private function getConditionsForVariation13()
680  {
681  $category3Name = 'Category 3';
682 
683  $category3Id = $this->categoryCollectionFactory
684  ->create()
685  ->addAttributeToFilter('name', $category3Name)
686  ->getAllIds();
687 
688  $category2Name = 'Category 2';
689 
690  $category2Id = $this->categoryCollectionFactory
691  ->create()
692  ->addAttributeToFilter('name', $category2Name)
693  ->getAllIds();
694 
695  $conditions = [
696  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
697  'aggregator' => 'all',
698  'value' => 1,
699  'conditions' => [
700  [
701  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
702  'operator' => '{}',
703  'value' => implode(',', $category3Id),
704  'attribute' => 'category_ids'
705  ],
706  [
707  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
708  'operator' => '==',
709  'value' => implode(',', $category2Id),
710  'attribute' => 'category_ids'
711  ]
712  ]
713  ];
714 
715  return $this->getCombineConditionFromArray($conditions);
716  }
717 
718  private function getConditionsForVariation14()
719  {
720  $category3Name = 'Category 3';
721 
722  $category3Id = $this->categoryCollectionFactory
723  ->create()
724  ->addAttributeToFilter('name', $category3Name)
725  ->getAllIds();
726 
727  $category2Name = 'Category 2';
728 
729  $category2Id = $this->categoryCollectionFactory
730  ->create()
731  ->addAttributeToFilter('name', $category2Name)
732  ->getAllIds();
733 
734  $conditions = [
735  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
736  'aggregator' => 'any',
737  'value' => 1,
738  'conditions' => [
739  [
740  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
741  'operator' => '{}',
742  'value' => implode(',', $category3Id),
743  'attribute' => 'category_ids'
744  ],
745  [
746  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
747  'operator' => '==',
748  'value' => implode(',', $category2Id),
749  'attribute' => 'category_ids'
750  ]
751  ]
752  ];
753 
754  return $this->getCombineConditionFromArray($conditions);
755  }
756 
757  private function getConditionsForVariation15()
758  {
759  $category3Name = 'Category 3';
760 
761  $category3Id = $this->categoryCollectionFactory
762  ->create()
763  ->addAttributeToFilter('name', $category3Name)
764  ->getAllIds();
765 
766  $category2Name = 'Category 2';
767 
768  $category2Id = $this->categoryCollectionFactory
769  ->create()
770  ->addAttributeToFilter('name', $category2Name)
771  ->getAllIds();
772 
773  $conditions = [
774  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
775  'aggregator' => 'all',
776  'value' => 1,
777  'conditions' => [
778  [
779  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
780  'operator' => '{}',
781  'value' => [$category3Id[0], $category2Id[0]],
782  'attribute' => 'category_ids'
783  ]
784  ]
785  ];
786 
787  return $this->getCombineConditionFromArray($conditions);
788  }
789 
790  private function getConditionsForVariation16()
791  {
792  $conditions = [
793  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
794  'aggregator' => 'any',
795  'value' => 1,
796  'conditions' => [
797  [
798  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
799  'operator' => '()',
800  'value' => 'simple-product-1,simple-product-5,simple-product-11',
801  'attribute' => 'sku'
802  ]
803  ]
804  ];
805 
806  return $this->getCombineConditionFromArray($conditions);
807  }
808 
809  private function getConditionsForVariation17()
810  {
811  $category1Name = 'Category 1';
812 
813  $category1Id = $this->categoryCollectionFactory
814  ->create()
815  ->addAttributeToFilter('name', $category1Name)
816  ->getAllIds();
817 
818  $category2Name = 'Category 2';
819 
820  $category2Id = $this->categoryCollectionFactory
821  ->create()
822  ->addAttributeToFilter('name', $category2Name)
823  ->getAllIds();
824 
825  $attributeSetMuffins = $this->setFactory->create()
826  ->load('Super Powerful Muffins', 'attribute_set_name');
827 
828  $attributeSetRangers = $this->setFactory->create()
829  ->load('Banana Rangers', 'attribute_set_name');
830 
831  $conditions = [
832  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
833  'aggregator' => 'any',
834  'value' => 1,
835  'conditions' => [
836  [
837  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
838  'aggregator' => 'all',
839  'value' => 1,
840  'conditions' => [
841  [
842  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
843  'operator' => '==',
844  'value' => implode(',', $category1Id),
845  'attribute' => 'category_ids'
846  ],
847  [
848  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
849  'operator' => '==',
850  'value' => $attributeSetMuffins->getId(),
851  'attribute' => 'attribute_set_id'
852  ]
853  ]
854  ],
855  [
856  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
857  'aggregator' => 'all',
858  'value' => 1,
859  'conditions' => [
860  [
861  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
862  'operator' => '==',
863  'value' => implode(',', $category2Id),
864  'attribute' => 'category_ids'
865  ],
866  [
867  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
868  'operator' => '==',
869  'value' => $attributeSetRangers->getId(),
870  'attribute' => 'attribute_set_id'
871  ]
872  ]
873  ]
874  ]
875  ];
876 
877  return $this->getCombineConditionFromArray($conditions);
878  }
879 
880  private function getConditionsForVariation18()
881  {
882  $category1Name = 'Category 1';
883 
884  $category1Id = $this->categoryCollectionFactory
885  ->create()
886  ->addAttributeToFilter('name', $category1Name)
887  ->getAllIds();
888 
889  $attributeSetMuffins = $this->setFactory->create()
890  ->load('Super Powerful Muffins', 'attribute_set_name');
891 
892  $conditions = [
893  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
894  'aggregator' => 'any',
895  'value' => 1,
896  'conditions' => [
897  [
898  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
899  'aggregator' => 'all',
900  'value' => 1,
901  'conditions' => [
902  [
903  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
904  'operator' => '==',
905  'value' => implode(',', $category1Id),
906  'attribute' => 'category_ids'
907  ],
908  [
909  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
910  'aggregator' => 'any',
911  'value' => 1,
912  'conditions' => [
913  [
914  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
915  'operator' => '!{}',
916  'value' => '(Sale)',
917  'attribute' => 'name'
918  ],
919  [
920  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
921  'operator' => '==',
922  'value' => $attributeSetMuffins->getId(),
923  'attribute' => 'attribute_set_id'
924  ],
925  ]
926  ]
927  ]
928  ]
929  ]
930  ];
931 
932  return $this->getCombineConditionFromArray($conditions);
933  }
934 
935  private function getConditionsForVariation19()
936  {
937  $conditions = [
938  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
939  'aggregator' => 'all',
940  'value' => 0,
941  'conditions' => []
942  ];
943 
944  return $this->getCombineConditionFromArray($conditions);
945  }
946 
947  private function getConditionsForVariation20()
948  {
949  $attributeSetMuffins = $this->setFactory->create()
950  ->load('Super Powerful Muffins', 'attribute_set_name');
951 
952  $attributeSetGuardians = $this->setFactory->create()
953  ->load('Guardians of the Refrigerator', 'attribute_set_name');
954 
955  $conditions = [
956  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
957  'aggregator' => 'all',
958  'value' => 0,
959  'conditions' => [
960  [
961  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
962  'operator' => '==',
963  'value' => $attributeSetMuffins->getId(),
964  'attribute' => 'attribute_set_id'
965  ],
966  [
967  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
968  'operator' => '==',
969  'value' => $attributeSetGuardians->getId(),
970  'attribute' => 'attribute_set_id'
971  ]
972  ]
973  ];
974 
975  return $this->getCombineConditionFromArray($conditions);
976  }
977 
978  private function getConditionsForVariation21()
979  {
980  $attributeSetMuffins = $this->setFactory->create()
981  ->load('Super Powerful Muffins', 'attribute_set_name');
982 
983  $attributeSetGuardians = $this->setFactory->create()
984  ->load('Guardians of the Refrigerator', 'attribute_set_name');
985 
986  $conditions = [
987  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
988  'aggregator' => 'any',
989  'value' => 0,
990  'conditions' => [
991  [
992  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
993  'operator' => '==',
994  'value' => $attributeSetMuffins->getId(),
995  'attribute' => 'attribute_set_id'
996  ],
997  [
998  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
999  'operator' => '==',
1000  'value' => $attributeSetGuardians->getId(),
1001  'attribute' => 'attribute_set_id'
1002  ]
1003  ]
1004  ];
1005 
1006  return $this->getCombineConditionFromArray($conditions);
1007  }
1008 
1009  private function getCombineConditionFromArray(array $data)
1010  {
1011  $combinedCondition = $this->combinedConditionFactory->create();
1012  $combinedCondition->setPrefix('conditions');
1013  $combinedCondition->loadArray($data);
1014 
1015  return $combinedCondition;
1016  }
1017 }
$attributeSetGuardians
Definition: products.php:16
$attributeSetRangers
Definition: products.php:14
$attributeSetMuffins
Definition: products.php:12