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 
13 {
19  protected $_eventManager = null;
20 
24  protected $_conditionAddress;
25 
32  public function __construct(
33  \Magento\Rule\Model\Condition\Context $context,
34  \Magento\Framework\Event\ManagerInterface $eventManager,
35  \Magento\SalesRule\Model\Rule\Condition\Address $conditionAddress,
36  array $data = []
37  ) {
38  $this->_eventManager = $eventManager;
39  $this->_conditionAddress = $conditionAddress;
40  parent::__construct($context, $data);
41  $this->setType(\Magento\SalesRule\Model\Rule\Condition\Combine::class);
42  }
43 
49  public function getNewChildSelectOptions()
50  {
51  $addressAttributes = $this->_conditionAddress->loadAttributeOptions()->getAttributeOption();
52  $attributes = [];
53  foreach ($addressAttributes as $code => $label) {
54  $attributes[] = [
55  'value' => 'Magento\SalesRule\Model\Rule\Condition\Address|' . $code,
56  'label' => $label,
57  ];
58  }
59 
60  $conditions = parent::getNewChildSelectOptions();
61  $conditions = array_merge_recursive(
62  $conditions,
63  [
64  [
65  'value' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
66  'label' => __('Product attribute combination'),
67  ],
68  [
69  'value' => \Magento\SalesRule\Model\Rule\Condition\Product\Subselect::class,
70  'label' => __('Products subselection')
71  ],
72  [
73  'value' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
74  'label' => __('Conditions combination')
75  ],
76  ['label' => __('Cart Attribute'), 'value' => $attributes]
77  ]
78  );
79 
80  $additional = new \Magento\Framework\DataObject();
81  $this->_eventManager->dispatch('salesrule_rule_condition_combine', ['additional' => $additional]);
82  $additionalConditions = $additional->getConditions();
83  if ($additionalConditions) {
84  $conditions = array_merge_recursive($conditions, $additionalConditions);
85  }
86 
87  return $conditions;
88  }
89 }
$addressAttributes
Definition: register.phtml:117
__()
Definition: __.php:13
$label
Definition: details.phtml:21
__construct(\Magento\Rule\Model\Condition\Context $context, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\SalesRule\Model\Rule\Condition\Address $conditionAddress, array $data=[])
Definition: Combine.php:32
$attributes
Definition: matrix.phtml:13
$code
Definition: info.phtml:12