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_Address extends Mage_Rule_Model_Condition_Abstract
00029 {
00030 public function loadAttributeOptions()
00031 {
00032 $attributes = array(
00033 'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'),
00034 'total_qty' => Mage::helper('salesrule')->__('Total Items Quantity'),
00035 'weight' => Mage::helper('salesrule')->__('Total Weight'),
00036 'payment_method' => Mage::helper('salesrule')->__('Payment Method'),
00037 'shipping_method' => Mage::helper('salesrule')->__('Shipping Method'),
00038 'postcode' => Mage::helper('salesrule')->__('Shipping Postcode'),
00039 'region' => Mage::helper('salesrule')->__('Shipping Region'),
00040 'region_id' => Mage::helper('salesrule')->__('Shipping State/Province'),
00041 'country_id' => Mage::helper('salesrule')->__('Shipping Country'),
00042 );
00043
00044 $this->setAttributeOption($attributes);
00045
00046 return $this;
00047 }
00048
00049 public function getAttributeElement()
00050 {
00051 $element = parent::getAttributeElement();
00052 $element->setShowAsText(true);
00053 return $element;
00054 }
00055
00056 public function getInputType()
00057 {
00058 switch ($this->getAttribute()) {
00059 case 'base_subtotal': case 'weight': case 'total_qty':
00060 return 'numeric';
00061
00062 case 'shipping_method': case 'payment_method': case 'country_id': case 'region_id':
00063 return 'select';
00064 }
00065 return 'string';
00066 }
00067
00068 public function getValueElementType()
00069 {
00070 switch ($this->getAttribute()) {
00071 case 'shipping_method': case 'payment_method': case 'country_id': case 'region_id':
00072 return 'select';
00073 }
00074 return 'text';
00075 }
00076
00077 public function getValueSelectOptions()
00078 {
00079 if (!$this->hasData('value_select_options')) {
00080 switch ($this->getAttribute()) {
00081 case 'country_id':
00082 $options = Mage::getModel('adminhtml/system_config_source_country')
00083 ->toOptionArray();
00084 break;
00085
00086 case 'region_id':
00087 $options = Mage::getModel('adminhtml/system_config_source_allregion')
00088 ->toOptionArray();
00089 break;
00090
00091 case 'shipping_method':
00092 $options = Mage::getModel('adminhtml/system_config_source_shipping_allmethods')
00093 ->toOptionArray();
00094 break;
00095
00096 case 'payment_method':
00097 $options = Mage::getModel('adminhtml/system_config_source_payment_allmethods')
00098 ->toOptionArray();
00099 break;
00100
00101 default:
00102 $options = array();
00103 }
00104 $this->setData('value_select_options', $options);
00105 }
00106 return $this->getData('value_select_options');
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 public function validate(Varien_Object $object)
00116 {
00117 $address = $object;
00118 if (!$address instanceof Mage_Sales_Model_Quote_Address) {
00119 if ($object->getQuote()->isVirtual()) {
00120 $address = $object->getQuote()->getBillingAddress();
00121 }
00122 else {
00123 $address = $object->getQuote()->getShippingAddress();
00124 }
00125 }
00126 return parent::validate($address);
00127 }
00128 }