1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: class Mage_SalesRule_Model_Rule_Condition_Product_Subselect
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_subselect')
35: ->setValue(null);
36: }
37:
38: public function loadArray($arr, $key='conditions')
39: {
40: $this->setAttribute($arr['attribute']);
41: $this->setOperator($arr['operator']);
42: parent::loadArray($arr, $key);
43: return $this;
44: }
45:
46: public function asXml($containerKey='conditions', $itemKey='condition')
47: {
48: $xml = '<attribute>'.$this->getAttribute().'</attribute>'
49: . '<operator>'.$this->getOperator().'</operator>'
50: . parent::asXml($containerKey, $itemKey);
51: return $xml;
52: }
53:
54: public function loadAttributeOptions()
55: {
56: $this->setAttributeOption(array(
57: 'qty' => Mage::helper('salesrule')->__('total quantity'),
58: 'base_row_total' => Mage::helper('salesrule')->__('total amount'),
59: ));
60: return $this;
61: }
62:
63: public function loadValueOptions()
64: {
65: return $this;
66: }
67:
68: public function loadOperatorOptions()
69: {
70: $this->setOperatorOption(array(
71: '==' => Mage::helper('rule')->__('is'),
72: '!=' => Mage::helper('rule')->__('is not'),
73: '>=' => Mage::helper('rule')->__('equals or greater than'),
74: '<=' => Mage::helper('rule')->__('equals or less than'),
75: '>' => Mage::helper('rule')->__('greater than'),
76: '<' => Mage::helper('rule')->__('less than'),
77: '()' => Mage::helper('rule')->__('is one of'),
78: '!()' => Mage::helper('rule')->__('is not one of'),
79: ));
80: return $this;
81: }
82:
83: public function getValueElementType()
84: {
85: return 'text';
86: }
87:
88: public function asHtml()
89: {
90: $html = $this->getTypeElement()->getHtml().
91: Mage::helper('salesrule')->__("If %s %s %s for a subselection of items in cart matching %s of these conditions:", $this->getAttributeElement()->getHtml(), $this->getOperatorElement()->getHtml(), $this->getValueElement()->getHtml(), $this->getAggregatorElement()->getHtml());
92: if ($this->getId() != '1') {
93: $html .= $this->getRemoveLinkHtml();
94: }
95: return $html;
96: }
97:
98: 99: 100: 101: 102: 103:
104: public function validate(Varien_Object $object)
105: {
106: if (!$this->getConditions()) {
107: return false;
108: }
109:
110:
111:
112:
113:
114: $attr = $this->getAttribute();
115: $total = 0;
116: foreach ($object->getQuote()->getAllItems() as $item) {
117: if (parent::validate($item)) {
118: $total += $item->getData($attr);
119: }
120: }
121:
122:
123: return $this->validateAttribute($total);
124: }
125: }
126: