Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Found.php
Go to the documentation of this file.
1 <?php
7 
8 class Found extends \Magento\SalesRule\Model\Rule\Condition\Product\Combine
9 {
15  public function __construct(
16  \Magento\Rule\Model\Condition\Context $context,
17  \Magento\SalesRule\Model\Rule\Condition\Product $ruleConditionProduct,
18  array $data = []
19  ) {
20  parent::__construct($context, $ruleConditionProduct, $data);
21  $this->setType(\Magento\SalesRule\Model\Rule\Condition\Product\Found::class);
22  }
23 
29  public function loadValueOptions()
30  {
31  $this->setValueOption([1 => __('FOUND'), 0 => __('NOT FOUND')]);
32  return $this;
33  }
34 
40  public function asHtml()
41  {
42  $html = $this->getTypeElement()->getHtml() . __(
43  "If an item is %1 in the cart with %2 of these conditions true:",
44  $this->getValueElement()->getHtml(),
45  $this->getAggregatorElement()->getHtml()
46  );
47  if ($this->getId() != '1') {
48  $html .= $this->getRemoveLinkHtml();
49  }
50  return $html;
51  }
52 
60  public function validate(\Magento\Framework\Model\AbstractModel $model)
61  {
62  $all = $this->getAggregator() === 'all';
63  $true = (bool)$this->getValue();
64  $found = false;
65  foreach ($model->getAllItems() as $item) {
66  $found = $all;
67  foreach ($this->getConditions() as $cond) {
68  $validated = $cond->validate($item);
69  if ($all && !$validated || !$all && $validated) {
70  $found = $validated;
71  break;
72  }
73  }
74  if ($found && $true || !$true && $found) {
75  break;
76  }
77  }
78  // found an item and we're looking for existing one
79  if ($found && $true) {
80  return true;
81  } elseif (!$found && !$true) {
82  // not found and we're making sure it doesn't exist
83  return true;
84  }
85  return false;
86  }
87 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
__construct(\Magento\Rule\Model\Condition\Context $context, \Magento\SalesRule\Model\Rule\Condition\Product $ruleConditionProduct, array $data=[])
Definition: Found.php:15
validate(\Magento\Framework\Model\AbstractModel $model)
Definition: Found.php:60