00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_SalesRule_Model_Rule_Condition_Product_Subselect
00029 extends Mage_SalesRule_Model_Rule_Condition_Product_Combine
00030 {
00031 public function __construct()
00032 {
00033 parent::__construct();
00034 $this->setType('salesrule/rule_condition_product_subselect')
00035 ->setValue(null);
00036 }
00037
00038 public function loadArray($arr, $key='conditions')
00039 {
00040 $this->setAttribute($arr['attribute']);
00041 $this->setOperator($arr['operator']);
00042 parent::loadArray($arr, $key);
00043 return $this;
00044 }
00045
00046 public function asXml($containerKey='conditions', $itemKey='condition')
00047 {
00048 $xml .= '<attribute>'.$this->getAttribute().'</attribute>'
00049 .'<operator>'.$this->getOperator().'</operator>'
00050 .parent::asXml($containerKey, $itemKey);
00051 return $xml;
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 public function loadAttributeOptions()
00066 {
00067 $hlp = Mage::helper('salesrule');
00068 $this->setAttributeOption(array(
00069 'qty' => $hlp->__('total quantity'),
00070 'row_total' => $hlp->__('total amount'),
00071 ));
00072 return $this;
00073 }
00074
00075 public function loadOperatorOptions()
00076 {
00077 $this->setOperatorOption(array(
00078 '==' => Mage::helper('rule')->__('is'),
00079 '!=' => Mage::helper('rule')->__('is not'),
00080 '>=' => Mage::helper('rule')->__('equals or greater than'),
00081 '<=' => Mage::helper('rule')->__('equals or less than'),
00082 '>' => Mage::helper('rule')->__('greater than'),
00083 '<' => Mage::helper('rule')->__('less than'),
00084 '()' => Mage::helper('rule')->__('is one of'),
00085 '!()' => Mage::helper('rule')->__('is not one of'),
00086 ));
00087 return $this;
00088 }
00089
00090 public function getValueElementType()
00091 {
00092 return 'text';
00093 }
00094
00095 public function asHtml()
00096 {
00097 $html = $this->getTypeElement()->getHtml().
00098 Mage::helper('salesrule')->__("If %s %s %s for a subselection of items in cart matching %s of these conditions:",
00099 $this->getAttributeElement()->getHtml(),
00100 $this->getOperatorElement()->getHtml(),
00101 $this->getValueElement()->getHtml(),
00102 $this->getAggregatorElement()->getHtml()
00103 );
00104 if ($this->getId()!='1') {
00105 $html.= $this->getRemoveLinkHtml();
00106 }
00107 return $html;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 public function validate(Varien_Object $object)
00117 {
00118 if (!$this->getConditions()) {
00119 return false;
00120 }
00121
00122
00123
00124
00125
00126 $attr = $this->getAttribute();
00127 $total = 0;
00128 foreach ($object->getQuote()->getAllItems() as $item) {
00129 if (parent::validate($item)) {
00130 $total += $item->getData($attr);
00131 }
00132 }
00133
00134
00135 return $this->validateAttribute($total);
00136 }
00137 }