_conditionFactory = $context->getConditionFactory();
$this->_logger = $context->getLogger();
parent::__construct($context, $data);
$this->setType(
\Magento\Rule\Model\Condition\Combine::class
)->setAggregator(
'all'
)->setValue(
true
)->setConditions(
[]
)->setActions(
[]
);
$this->loadAggregatorOptions();
$options = $this->getAggregatorOptions();
if ($options) {
reset($options);
$this->setAggregator(key($options));
}
}
/* start aggregator methods */
/**
* @return $this
*/
public function loadAggregatorOptions()
{
$this->setAggregatorOption(['all' => __('ALL'), 'any' => __('ANY')]);
return $this;
}
/**
* @return array
*/
public function getAggregatorSelectOptions()
{
$opt = [];
foreach ($this->getAggregatorOption() as $key => $value) {
$opt[] = ['value' => $key, 'label' => $value];
}
return $opt;
}
/**
* @return string
*/
public function getAggregatorName()
{
return $this->getAggregatorOption($this->getAggregator());
}
/**
* @return object
*/
public function getAggregatorElement()
{
if ($this->getAggregator() === null) {
$options = $this->getAggregatorOption();
if ($options) {
reset($options);
$this->setAggregator(key($options));
}
}
return $this->getForm()->addField(
$this->getPrefix() . '__' . $this->getId() . '__aggregator',
'select',
[
'name' => $this->elementName . '[' . $this->getPrefix() . '][' . $this->getId() . '][aggregator]',
'values' => $this->getAggregatorSelectOptions(),
'value' => $this->getAggregator(),
'value_name' => $this->getAggregatorName(),
'data-form-part' => $this->getFormName()
]
)->setRenderer(
$this->_layout->getBlockSingleton(\Magento\Rule\Block\Editable::class)
);
}
/* end aggregator methods */
/**
* @return $this
*/
public function loadValueOptions()
{
$this->setValueOption([1 => __('TRUE'), 0 => __('FALSE')]);
return $this;
}
/**
* @param object $condition
* @return $this
*/
public function addCondition($condition)
{
$condition->setRule($this->getRule());
$condition->setObject($this->getObject());
$condition->setPrefix($this->getPrefix());
$conditions = $this->getConditions();
$conditions[] = $condition;
if (!$condition->getId()) {
$condition->setId($this->getId() . '--' . sizeof($conditions));
}
$this->setData($this->getPrefix(), $conditions);
return $this;
}
/**
* @return string
*/
public function getValueElementType()
{
return 'select';
}
/**
* Returns array containing conditions in the collection
*
* Output example:
* array(
* 'type'=>'combine',
* 'operator'=>'ALL',
* 'value'=>'TRUE',
* 'conditions'=>array(
* {condition::asArray},
* {combine::asArray},
* {quote_item_combine::asArray}
* )
* )
*
* @param array $arrAttributes
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function asArray(array $arrAttributes = [])
{
$out = parent::asArray();
$out['aggregator'] = $this->getAggregator();
foreach ($this->getConditions() as $condition) {
$out['conditions'][] = $condition->asArray();
}
return $out;
}
/**
* @param string $containerKey
* @param string $itemKey
* @return string
*/
public function asXml($containerKey = 'conditions', $itemKey = 'condition')
{
$xml = "