80 parent::__construct(
$data);
89 $options = $this->getOperatorOptions();
103 if (
null === $this->_defaultOperatorInputByType) {
104 $this->_defaultOperatorInputByType = [
105 'string' => [
'==',
'!=',
'>=',
'>',
'<=',
'<',
'{}',
'!{}',
'()',
'!()'],
106 'numeric' => [
'==',
'!=',
'>=',
'>',
'<=',
'<',
'()',
'!()'],
107 'date' => [
'==',
'>=',
'<='],
108 'select' => [
'==',
'!='],
109 'boolean' => [
'==',
'!='],
110 'multiselect' => [
'{}',
'!{}',
'()',
'!()'],
111 'grid' => [
'()',
'!()'],
113 $this->_arrayInputTypes = [
'multiselect',
'grid'];
126 if (
null === $this->_defaultOperatorOptions) {
127 $this->_defaultOperatorOptions = [
129 '!=' =>
__(
'is not'),
130 '>=' =>
__(
'equals or greater than'),
131 '<=' =>
__(
'equals or less than'),
132 '>' =>
__(
'greater than'),
133 '<' =>
__(
'less than'),
134 '{}' =>
__(
'contains'),
135 '!{}' =>
__(
'does not contain'),
136 '()' =>
__(
'is one of'),
137 '!()' =>
__(
'is not one of'),
148 return $this->getRule()->getForm();
156 public function asArray(array $arrAttributes = [])
159 'type' => $this->getType(),
160 'attribute' => $this->getAttribute(),
161 'operator' => $this->getOperator(),
163 'is_value_processed' => $this->getIsValueParsed(),
194 return $this->getAttribute();
206 $this->getAttribute() .
209 $this->getOperator() .
223 $this->setType($arr[
'type']);
224 $this->setAttribute(isset($arr[
'attribute']) ? $arr[
'attribute'] :
false);
225 $this->setOperator(isset($arr[
'operator']) ? $arr[
'operator'] :
false);
226 $this->setValue(isset($arr[
'value']) ? $arr[
'value'] :
false);
227 $this->setIsValueParsed(isset($arr[
'is_value_parsed']) ? $arr[
'is_value_parsed'] :
false);
237 if (is_string($xml)) {
238 $xml = simplexml_load_string($xml);
266 foreach ($this->getAttributeOption() as $key =>
$value) {
267 $opt[] = [
'value' => $key,
'label' =>
$value];
277 return $this->getAttributeOption($this->getAttribute());
309 $operatorByType = $this->getOperatorByInputType();
310 foreach ($this->getOperatorOption() as $key =>
$value) {
311 if (!$operatorByType || in_array($key, $operatorByType[
$type])) {
312 $opt[] = [
'value' => $key,
'label' =>
$value];
323 return $this->getOperatorOption($this->getOperator());
331 $this->setValueOption([]);
341 if ($this->hasValueOption()) {
342 foreach ((array)$this->getValueOption() as $key =>
$value) {
343 $opt[] = [
'value' => $key,
'label' =>
$value];
356 if (!$this->hasValueParsed()) {
362 $value = preg_split(
'#\s*[,;]\s*#',
$value,
null, PREG_SPLIT_NO_EMPTY);
364 $this->setValueParsed(
$value);
366 return $this->
getData(
'value_parsed');
378 $operator = $this->getOperator();
379 return $operator ===
'()' || $operator ===
'!()' || in_array($this->
getInputType(), $this->_arrayInputTypes);
387 if ($this->
getInputType() ==
'date' && !$this->getIsValueParsed()) {
390 (
new \DateTime($this->
getData(
'value')))->format(
'Y-m-d H:i:s')
392 $this->setIsValueParsed(
true);
394 return $this->
getData(
'value');
414 $valueArr[] =
$option[
'label'];
417 if (is_array(
$option[
'value'])) {
430 if (!empty($valueArr)) {
431 $value = implode(
', ', $valueArr);
445 return [[
'value' =>
'',
'label' =>
__(
'Please choose a condition to add.')]];
482 return $this->
getForm()->addField(
483 $this->getPrefix() .
'__' . $this->getId() .
'__type',
486 'name' => $this->elementName .
'[' . $this->getPrefix() .
'][' . $this->getId() .
'][type]',
487 'value' => $this->getType(),
490 'data-form-part' => $this->getFormName()
508 if (
null === $this->getAttribute()) {
509 $options = $this->getAttributeOption();
515 return $this->
getForm()->addField(
516 $this->getPrefix() .
'__' . $this->getId() .
'__attribute',
519 'name' => $this->elementName .
'[' . $this->getPrefix() .
'][' . $this->getId() .
'][attribute]',
521 'value' => $this->getAttribute(),
523 'data-form-part' => $this->getFormName()
526 $this->_layout->getBlockSingleton(\
Magento\Rule\Block\Editable::class)
547 if ($this->getOperator() ===
null) {
549 $this->setOperator(
$option[
'value']);
552 $elementId = sprintf(
'%s__%s__operator', $this->getPrefix(), $this->getId());
553 $elementName = sprintf($this->elementName .
'[%s][%s][operator]', $this->getPrefix(), $this->getId());
560 'value' => $this->getOperator(),
562 'data-form-part' => $this->getFormName()
565 $element->setRenderer($this->_layout->getBlockSingleton(\
Magento\Rule\Block\Editable::class));
597 return $this->_layout->getBlockSingleton(\
Magento\Rule\Block\Editable::class);
606 'name' => $this->elementName .
'[' . $this->getPrefix() .
'][' . $this->getId() .
'][value]',
610 'after_element_html' => $this->getValueAfterElementHtml(),
611 'explicit_apply' => $this->getExplicitApply(),
612 'data-form-part' => $this->getFormName()
619 return $this->
getForm()->addField(
620 $this->getPrefix() .
'__' . $this->getId() .
'__value',
641 $src = $this->_assetRepo->getUrl(
'images/rule_component_add.gif');
642 return '<img src="' . $src .
'" class="rule-param-add v-middle" alt="" title="' .
__(
'Add') .
'"/>';
650 $src = $this->_assetRepo->getUrl(
'images/rule_component_remove.gif');
651 $html =
' <span class="rule-param"><a href="javascript:void(0)" class="rule-param-remove" title="' .
__(
653 ) .
'"><img src="' . $src .
'" alt="" class="v-middle" /></a></span>';
662 $url = $this->getValueElementChooserUrl();
663 return $url ?
'<div class="rule-chooser" url="' .
$url .
'"></div>' :
'';
682 return str_pad(
'', $level * 3,
' ', STR_PAD_LEFT) . $this->
asString();
696 if (is_object($validatedValue)) {
721 if (!is_array($validatedValue)) {
726 if (is_array($validatedValue)) {
727 $result = count($validatedValue) == 1 && array_shift($validatedValue) ==
$value;
736 if (!is_scalar($validatedValue)) {
744 if (!is_scalar($validatedValue)) {
752 if (is_scalar($validatedValue) && is_array(
$value)) {
754 if (stripos($validatedValue, (
string)
$item) !==
false) {
760 if (!is_array($validatedValue)) {
766 if (is_array($validatedValue)) {
776 if (is_array($validatedValue)) {
777 $result = count(array_intersect($validatedValue, (array)
$value)) > 0;
807 if ($strict && is_numeric($validatedValue) && is_numeric(
$value)) {
808 return $validatedValue ==
$value;
811 $validatePattern = preg_quote($validatedValue,
'~');
813 $validatePattern =
'^' . $validatePattern .
'$';
815 return (
bool)preg_match(
'~' . $validatePattern .
'~iu',
$value);
824 if (!
$model->hasData($this->getAttribute())) {
827 $attributeValue =
$model->getData($this->getAttribute());
839 return $this->getOperator();
validateAttribute($validatedValue)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
getNewChildSelectOptions()
__construct(Context $context, array $data=[])
asArray(array $arrAttributes=[])
getAttributeElementHtml()
getDefaultOperatorOptions()
asStringRecursive($level=0)
getOperatorSelectOptions()
getChooserContainerHtml()
getAttributeSelectOptions()
getValueElementRenderer()
$_defaultOperatorInputByType
const DATE_INTERNAL_FORMAT
validate(\Magento\Framework\Model\AbstractModel $model)
_compareValues($validatedValue, $value, $strict=true)
getDefaultOperatorInputByType()