1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogWidget\Model\Rule\Condition;
/**
* Combination of product conditions
*/
class Combine extends \Magento\Rule\Model\Condition\Combine
{
/**
* @var \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory
*/
protected $productFactory;
/**
* {@inheritdoc}
*/
protected $elementName = 'parameters';
/**
* @var array
*/
private $excludedAttributes;
/**
* @param \Magento\Rule\Model\Condition\Context $context
* @param \Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory
* @param array $data
* @param array $excludedAttributes
*/
public function __construct(
\Magento\Rule\Model\Condition\Context $context,
\Magento\CatalogWidget\Model\Rule\Condition\ProductFactory $conditionFactory,
array $data = [],
array $excludedAttributes = []
) {
$this->productFactory = $conditionFactory;
parent::__construct($context, $data);
$this->setType(\Magento\CatalogWidget\Model\Rule\Condition\Combine::class);
$this->excludedAttributes = $excludedAttributes;
}
/**
* @return array
*/
public function getNewChildSelectOptions()
{
$productAttributes = $this->productFactory->create()->loadAttributeOptions()->getAttributeOption();
$attributes = [];
foreach ($productAttributes as $code => $label) {
if (!in_array($code, $this->excludedAttributes)) {
$attributes[] = [
'value' => Product::class . '|' . $code,
'label' => $label,
];
}
}
$conditions = parent::getNewChildSelectOptions();
$conditions = array_merge_recursive(
$conditions,
[
[
'value' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
'label' => __('Conditions Combination'),
],
['label' => __('Product Attribute'), 'value' => $attributes]
]
);
return $conditions;
}
/**
* Collect validated attributes for Product Collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
* @return $this
*/
public function collectValidatedAttributes($productCollection)
{
foreach ($this->getConditions() as $condition) {
$condition->collectValidatedAttributes($productCollection);
}
return $this;
}
}