Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Combine.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  protected $productFactory;
17 
21  protected $elementName = 'parameters';
22 
26  private $excludedAttributes;
27 
34  public function __construct(
35  \Magento\Rule\Model\Condition\Context $context,
36  \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory,
37  array $data = [],
38  array $excludedAttributes = []
39  ) {
40  $this->productFactory = $conditionFactory;
41  parent::__construct($context, $data);
42  $this->setType(\Magento\CatalogWidget\Model\Rule\Condition\Combine::class);
43  $this->excludedAttributes = $excludedAttributes;
44  }
45 
49  public function getNewChildSelectOptions()
50  {
51  $productAttributes = $this->productFactory->create()->loadAttributeOptions()->getAttributeOption();
52  $attributes = [];
53  foreach ($productAttributes as $code => $label) {
54  if (!in_array($code, $this->excludedAttributes)) {
55  $attributes[] = [
56  'value' => Product::class . '|' . $code,
57  'label' => $label,
58  ];
59  }
60  }
61  $conditions = parent::getNewChildSelectOptions();
62  $conditions = array_merge_recursive(
63  $conditions,
64  [
65  [
66  'value' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
67  'label' => __('Conditions Combination'),
68  ],
69  ['label' => __('Product Attribute'), 'value' => $attributes]
70  ]
71  );
72  return $conditions;
73  }
74 
82  {
83  foreach ($this->getConditions() as $condition) {
84  $condition->collectValidatedAttributes($productCollection);
85  }
86  return $this;
87  }
88 }
__construct(\Magento\Rule\Model\Condition\Context $context, \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory, array $data=[], array $excludedAttributes=[])
Definition: Combine.php:34
__()
Definition: __.php:13
$label
Definition: details.phtml:21
$attributes
Definition: matrix.phtml:13
$code
Definition: info.phtml:12