/** * Validate rule against the buy_x_get_y * * @author Mohamed Meabed <*****@*****.**> * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { $address = $object; if ('buy_x_get_y' == $this->getAttribute()) { $address->setByXGetY(true); return true; } return parent::validate($address); }
public function validate(Varien_Object $object) { if ($object instanceof Rewardpoints_Model_Quote && !$object->getQuote()) { $object->setQuote($object); } $address = $object; if (!$address instanceof Mage_Sales_Model_Quote_Address) { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } $address->setBaseSubtotalIncTax($address->getBaseSubtotal() + $address->getBaseTaxAmount()); return parent::validate($object); }
/** * Validate Address Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $address = $object; if ($address instanceof Mage_Sales_Model_Quote_Address) { $address = $object->getQuote()->getBillingAddress(); } else { if ($object->getQuote()->isVirtual()) { $address = $object->getQuote()->getBillingAddress(); } else { $address = $object->getQuote()->getShippingAddress(); } } if ('payment_method' == $this->getAttribute() && !$address->hasPaymentMethod()) { $address->setPaymentMethod($object->getQuote()->getPayment()->getMethod()); } return parent::validate($address); }
public function validateAttribute($validatedValue) { if (is_object($validatedValue)) { return false; } /** * Condition attribute value */ $value = $this->getValueParsed(); /** * Comparison operator */ $op = $this->getOperatorForValidate(); // if operator requires array and it is not, or on opposite, return false if ($this->_isArrayOperatorType() xor is_array($value)) { return false; } $result = false; switch ($op) { case '{%': if (!is_scalar($validatedValue)) { return false; } else { $result = substr($validatedValue, 0, strlen($value)) == $value; } break; case '%}': if (!is_scalar($validatedValue)) { return false; } else { $result = substr($validatedValue, -strlen($value)) == $value; } break; default: return parent::validateAttribute($validatedValue); break; } return $result; }
/** * Overwrite parent method to add new operators * * @param mixed $validatedValue * * @return bool */ public function validateAttribute($validatedValue) { if (is_object($validatedValue)) { return false; } /** * Condition attribute value */ $value = $this->getValueParsed(); /** * Comparison operator */ $op = $this->getOperatorForValidate(); // if operator requires array and it is not, or on opposite, return false if ($this->isArrayOperatorType() xor is_array($value)) { return false; } switch ($op) { case '><': case '<>': $explodedValue = explode('-', $value); $result = $validatedValue >= $explodedValue[0] && $validatedValue <= $explodedValue[1]; break; default: return parent::validateAttribute($validatedValue); break; } if ($op == '<>') { $result = !$result; } return $result; }