Public Member Functions | |
getConditionsInstance () | |
_resetConditions ($conditions=null) | |
setConditions ($conditions) | |
getConditions () | |
getActionsInstance () | |
_resetActions ($actions=null) | |
setActions ($actions) | |
getActions () | |
getForm () | |
asString ($format='') | |
asHtml () | |
loadPost (array $rule) | |
asArray (array $arrAttributes=array()) | |
validate (Varien_Object $object) | |
afterLoad () | |
isDeleteable () | |
setIsDeleteable ($flag) | |
isReadonly () | |
setIsReadonly ($value) | |
Protected Member Functions | |
_construct () | |
_convertFlatToRecursive (array $rule) | |
_afterLoad () | |
_beforeSave () | |
Protected Attributes | |
$_conditions | |
$_actions | |
$_form | |
$_isDeleteable = true | |
$_isReadonly = false |
Definition at line 27 of file Rule.php.
_afterLoad | ( | ) | [protected] |
Processing object after load data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 234 of file Rule.php.
00235 { 00236 parent::_afterLoad(); 00237 $conditionsArr = unserialize($this->getConditionsSerialized()); 00238 if (!empty($conditionsArr) && is_array($conditionsArr)) { 00239 $this->getConditions()->loadArray($conditionsArr); 00240 } 00241 00242 $actionsArr = unserialize($this->getActionsSerialized()); 00243 if (!empty($actionsArr) && is_array($actionsArr)) { 00244 $this->getActions()->loadArray($actionsArr); 00245 } 00246 00247 $this->setWebsiteIds(explode(',',$this->getWebsiteIds())); 00248 $groupIds = $this->getCustomerGroupIds(); 00249 if (is_string($groupIds)) { 00250 $this->setCustomerGroupIds(explode(',',$groupIds)); 00251 } 00252 }
_beforeSave | ( | ) | [protected] |
Processing object before save data
Reimplemented from Mage_Core_Model_Abstract.
Reimplemented in Mage_SalesRule_Model_Rule.
Definition at line 254 of file Rule.php.
00255 { 00256 // check if discount amount > 0 00257 if ((int)$this->getDiscountAmount() < 0) { 00258 Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.')); 00259 } 00260 00261 00262 if ($this->getConditions()) { 00263 $this->setConditionsSerialized(serialize($this->getConditions()->asArray())); 00264 $this->unsConditions(); 00265 } 00266 if ($this->getActions()) { 00267 $this->setActionsSerialized(serialize($this->getActions()->asArray())); 00268 $this->unsActions(); 00269 } 00270 if (is_array($this->getWebsiteIds())) { 00271 $this->setWebsiteIds(join(',', $this->getWebsiteIds())); 00272 } 00273 if (is_array($this->getCustomerGroupIds())) { 00274 $this->setCustomerGroupIds(join(',', $this->getCustomerGroupIds())); 00275 } 00276 parent::_beforeSave(); 00277 }
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Reimplemented in Mage_CatalogRule_Model_Rule, and Mage_SalesRule_Model_Rule.
Definition at line 48 of file Rule.php.
00049 { 00050 $this->_init('rule/rule'); 00051 parent::_construct(); 00052 }
_convertFlatToRecursive | ( | array $ | rule | ) | [protected] |
convert dates into Zend_Date
Definition at line 162 of file Rule.php.
00163 { 00164 $arr = array(); 00165 foreach ($rule as $key=>$value) { 00166 if (($key==='conditions' || $key==='actions') && is_array($value)) { 00167 foreach ($value as $id=>$data) { 00168 $path = explode('--', $id); 00169 $node =& $arr; 00170 for ($i=0, $l=sizeof($path); $i<$l; $i++) { 00171 if (!isset($node[$key][$path[$i]])) { 00172 $node[$key][$path[$i]] = array(); 00173 } 00174 $node =& $node[$key][$path[$i]]; 00175 } 00176 foreach ($data as $k=>$v) { 00177 $node[$k] = $v; 00178 } 00179 } 00180 } else { 00181 /** 00182 * convert dates into Zend_Date 00183 */ 00184 if (in_array($key, array('from_date', 'to_date')) && $value) { 00185 $value = Mage::app()->getLocale()->date( 00186 $value, 00187 Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 00188 null, 00189 false 00190 ); 00191 } 00192 $this->setData($key, $value); 00193 } 00194 } 00195 return $arr; 00196 }
_resetActions | ( | $ | actions = null |
) |
Definition at line 94 of file Rule.php.
00095 { 00096 if (is_null($actions)) { 00097 $actions = $this->getActionsInstance(); 00098 } 00099 $actions->setRule($this)->setId('1')->setPrefix('actions'); 00100 $this->setActions($actions); 00101 00102 return $this; 00103 }
_resetConditions | ( | $ | conditions = null |
) |
Definition at line 59 of file Rule.php.
00060 { 00061 if (is_null($conditions)) { 00062 $conditions = $this->getConditionsInstance(); 00063 } 00064 $conditions->setRule($this)->setId('1')->setPrefix('conditions'); 00065 $this->setConditions($conditions); 00066 00067 return $this; 00068 }
afterLoad | ( | ) |
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 229 of file Rule.php.
00230 { 00231 $this->_afterLoad(); 00232 }
Returns rule as an array for admin interface
Output example: array( 'name'=>'Example rule', 'conditions'=>{condition_combine.asArray} 'actions'=>{action_collection.asArray} )
Definition at line 210 of file Rule.php.
00211 { 00212 $out = array( 00213 'name'=>$this->getName(), 00214 'start_at'=>$this->getStartAt(), 00215 'expire_at'=>$this->getExpireAt(), 00216 'description'=>$this->getDescription(), 00217 'conditions'=>$this->getConditions()->asArray(), 00218 'actions'=>$this->getActions()->asArray(), 00219 ); 00220 00221 return $out; 00222 }
asHtml | ( | ) |
Definition at line 138 of file Rule.php.
00139 { 00140 $str = Mage::helper('rule')->__("Name: %s", $this->getName()) ."<br/>" 00141 . Mage::helper('rule')->__("Start at: %s", $this->getStartAt()) ."<br/>" 00142 . Mage::helper('rule')->__("Expire at: %s", $this->getExpireAt()) ."<br/>" 00143 . Mage::helper('rule')->__("Description: %s", $this->getDescription()) .'<br/>' 00144 . '<ul class="rule-conditions">'.$this->getConditions()->asHtmlRecursive().'</ul>' 00145 . '<ul class="rule-actions">'.$this->getActions()->asHtmlRecursive()."</ul>"; 00146 return $str; 00147 }
asString | ( | $ | format = '' |
) |
Definition at line 127 of file Rule.php.
00128 { 00129 $str = Mage::helper('rule')->__("Name: %s", $this->getName()) ."\n" 00130 . Mage::helper('rule')->__("Start at: %s", $this->getStartAt()) ."\n" 00131 . Mage::helper('rule')->__("Expire at: %s", $this->getExpireAt()) ."\n" 00132 . Mage::helper('rule')->__("Description: %s", $this->getDescription()) ."\n\n" 00133 . $this->getConditions()->asStringRecursive() ."\n\n" 00134 . $this->getActions()->asStringRecursive() ."\n\n"; 00135 return $str; 00136 }
getActions | ( | ) |
Definition at line 111 of file Rule.php.
00112 { 00113 if (!$this->_actions) { 00114 $this->_resetActions(); 00115 } 00116 return $this->_actions; 00117 }
getActionsInstance | ( | ) |
Reimplemented in Mage_CatalogRule_Model_Rule, and Mage_SalesRule_Model_Rule.
Definition at line 89 of file Rule.php.
00090 { 00091 return Mage::getModel('rule/action_collection'); 00092 }
getConditions | ( | ) |
Retrieve Condition model
Definition at line 81 of file Rule.php.
00082 { 00083 if (empty($this->_conditions)) { 00084 $this->_resetConditions(); 00085 } 00086 return $this->_conditions; 00087 }
getConditionsInstance | ( | ) |
Reimplemented in Mage_CatalogRule_Model_Rule, and Mage_SalesRule_Model_Rule.
Definition at line 54 of file Rule.php.
00055 { 00056 return Mage::getModel('rule/condition_combine'); 00057 }
getForm | ( | ) |
Definition at line 119 of file Rule.php.
00120 { 00121 if (!$this->_form) { 00122 $this->_form = new Varien_Data_Form(); 00123 } 00124 return $this->_form; 00125 }
isDeleteable | ( | ) |
isReadonly | ( | ) |
loadPost | ( | array $ | rule | ) |
Reimplemented in Mage_SalesRule_Model_Rule.
Definition at line 149 of file Rule.php.
00150 { 00151 $arr = $this->_convertFlatToRecursive($rule); 00152 if (isset($arr['conditions'])) { 00153 $this->getConditions()->loadArray($arr['conditions'][1]); 00154 } 00155 if (isset($arr['actions'])) { 00156 $this->getActions()->loadArray($arr['actions'][1]); 00157 } 00158 00159 return $this; 00160 }
setActions | ( | $ | actions | ) |
setConditions | ( | $ | conditions | ) |
setIsDeleteable | ( | $ | flag | ) |
Set is deleteable flag
boolean | $flag |
Definition at line 295 of file Rule.php.
setIsReadonly | ( | $ | value | ) |
Set is readonly flag
boolean | $value |
Definition at line 318 of file Rule.php.
validate | ( | Varien_Object $ | object | ) |
Definition at line 224 of file Rule.php.
00225 { 00226 return $this->getConditions()->validate($object); 00227 }