33 parent::__construct($context,
$data);
35 \
Magento\Rule\Model\Condition\Combine::class
47 $options = $this->getAggregatorOptions();
61 $this->setAggregatorOption([
'all' =>
__(
'ALL'),
'any' =>
__(
'ANY')]);
71 foreach ($this->getAggregatorOption() as $key =>
$value) {
72 $opt[] = [
'value' => $key,
'label' =>
$value];
82 return $this->getAggregatorOption($this->getAggregator());
90 if ($this->getAggregator() ===
null) {
91 $options = $this->getAggregatorOption();
97 return $this->
getForm()->addField(
98 $this->getPrefix() .
'__' . $this->getId() .
'__aggregator',
101 'name' => $this->elementName .
'[' . $this->getPrefix() .
'][' . $this->getId() .
'][aggregator]',
103 'value' => $this->getAggregator(),
105 'data-form-part' => $this->getFormName()
108 $this->_layout->getBlockSingleton(\
Magento\Rule\Block\Editable::class)
119 $this->setValueOption([1 =>
__(
'TRUE'), 0 =>
__(
'FALSE')]);
129 $condition->setRule($this->getRule());
130 $condition->setObject($this->getObject());
131 $condition->setPrefix($this->getPrefix());
134 $conditions[] = $condition;
136 if (!$condition->getId()) {
137 $condition->setId($this->getId() .
'--' .
sizeof($conditions));
140 $this->
setData($this->getPrefix(), $conditions);
171 public function asArray(array $arrAttributes = [])
173 $out = parent::asArray();
174 $out[
'aggregator'] = $this->getAggregator();
177 $out[
'conditions'][] = $condition->asArray();
188 public function asXml($containerKey =
'conditions', $itemKey =
'condition')
190 $xml =
"<aggregator>" .
191 $this->getAggregator() .
198 $xml .=
"<{$itemKey}>" . $condition->asXml() .
"</{$itemKey}>";
200 $xml .=
"</{$containerKey}>";
212 $this->setAggregator(
213 isset($arr[
'aggregator']) ? $arr[
'aggregator'] : (isset($arr[
'attribute']) ? $arr[
'attribute'] :
null)
215 isset($arr[
'value']) ? $arr[
'value'] : (isset($arr[
'operator']) ? $arr[
'operator'] :
null)
218 if (!empty($arr[$key]) && is_array($arr[$key])) {
219 foreach ($arr[$key] as $conditionArr) {
221 $condition = $this->_conditionFactory->create($conditionArr[
'type']);
223 $condition->loadArray($conditionArr, $key);
224 }
catch (\Exception $e) {
225 $this->_logger->critical($e);
238 if (is_string($xml)) {
239 $xml = simplexml_load_string($xml);
241 $arr = parent::loadXml($xml);
242 foreach ($xml->conditions->children() as $condition) {
243 $arr[
'conditions'] = parent::loadXml($condition);
255 'If %1 of these conditions are %2:',
259 if ($this->getId() !=
'1') {
270 return $this->
getForm()->addField(
271 $this->getPrefix() .
'__' . $this->getId() .
'__new_child',
274 'name' => $this->elementName .
'[' . $this->getPrefix() .
'][' . $this->getId() .
'][new_child]',
277 'data-form-part' => $this->getFormName()
280 $this->_layout->getBlockSingleton(\
Magento\Rule\Block\Newchild::class)
294 '__children" class="rule-param-children">';
296 $html .=
'<li>' . $cond->asHtmlRecursive() .
'</li>';
319 $str = parent::asStringRecursive($level);
321 $str .=
"\n" . $cond->asStringRecursive($level + 1);
358 $all = $this->getAggregator() ===
'all';
363 $validated = $cond->validate(
$entity);
365 $validated = $cond->validateByEntityId(
$entity);
367 if ($all && $validated !== $true) {
369 }
elseif (!$all && $validated === $true) {
373 return $all ? true :
false;
382 $this->
setData(
'js_form_object', $form);
384 $condition->setJsFormObject($form);
396 $key = $this->getPrefix() ? $this->getPrefix() :
'conditions';
408 $key = $this->getPrefix() ? $this->getPrefix() :
'conditions';
409 return $this->
setData($key, $conditions);
419 return [
'value' => $this->getType(),
'label' =>
__(
'Conditions Combination')];
asStringRecursive($level=0)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
getNewChildSelectOptions()
__construct(Context $context, array $data=[])
_getRecursiveChildSelectOption()
asXml($containerKey='conditions', $itemKey='condition')
validateByEntityId($entityId)
setConditions($conditions)
validate(\Magento\Framework\Model\AbstractModel $model)
getAggregatorSelectOptions()
setData($key, $value=null)
asArray(array $arrAttributes=[])
loadArray($arr, $key='conditions')