1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_SalesRule
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: class Mage_SalesRule_Model_Rule_Condition_Product_Found
29: extends Mage_SalesRule_Model_Rule_Condition_Product_Combine
30: {
31: public function __construct()
32: {
33: parent::__construct();
34: $this->setType('salesrule/rule_condition_product_found');
35: }
36:
37: /**
38: * Load value options
39: *
40: * @return Mage_SalesRule_Model_Rule_Condition_Product_Found
41: */
42: public function loadValueOptions()
43: {
44: $this->setValueOption(array(
45: 1 => Mage::helper('salesrule')->__('FOUND'),
46: 0 => Mage::helper('salesrule')->__('NOT FOUND')
47: ));
48: return $this;
49: }
50:
51: public function asHtml()
52: {
53: $html = $this->getTypeElement()->getHtml() . Mage::helper('salesrule')->__("If an item is %s in the cart with %s of these conditions true:", $this->getValueElement()->getHtml(), $this->getAggregatorElement()->getHtml());
54: if ($this->getId() != '1') {
55: $html.= $this->getRemoveLinkHtml();
56: }
57: return $html;
58: }
59:
60: /**
61: * validate
62: *
63: * @param Varien_Object $object Quote
64: * @return boolean
65: */
66: public function validate(Varien_Object $object)
67: {
68: $all = $this->getAggregator()==='all';
69: $true = (bool)$this->getValue();
70: $found = false;
71: foreach ($object->getAllItems() as $item) {
72: $found = $all;
73: foreach ($this->getConditions() as $cond) {
74: $validated = $cond->validate($item);
75: if (($all && !$validated) || (!$all && $validated)) {
76: $found = $validated;
77: break;
78: }
79: }
80: if (($found && $true) || (!$true && $found)) {
81: break;
82: }
83: }
84: // found an item and we're looking for existing one
85: if ($found && $true) {
86: return true;
87: }
88: // not found and we're making sure it doesn't exist
89: elseif (!$found && !$true) {
90: return true;
91: }
92: return false;
93: }
94: }
95: