public function validate() { $request = Mage::app()->getFrontController()->getRequest(); if ((bool) Mage::helper('gomage_checkout')->getConfigData('general/enabled') && $request->getModulename() != "admin") { $errors = array(); $helper = Mage::helper('customer'); $this->implodeStreetAddress(); foreach ($this->required_fields as $fieldName => $method) { if ($fieldName == 'region' && intval(Mage::getStoreConfig('gomage_checkout/address_fields/country_id')) > 0) { if ($this->getCountryModel()->getRegionCollection()->getSize() && !Zend_Validate::is($this->getRegionId(), 'NotEmpty')) { $errors[] = $helper->__('Please enter the state/province.'); } } elseif ($fieldName == 'postcode' && Mage::helper('gomage_checkout')->getIsAnymoreVersion(1, 4)) { $_havingOptionalZip = Mage::helper('directory')->getCountriesWithOptionalZip(); if (!in_array($this->getCountryId(), $_havingOptionalZip) && !Zend_Validate::is($this->getPostcode(), 'NotEmpty')) { $errors[] = $helper->__('Please enter the zip/postal code.'); } } else { if (!Zend_Validate::is($this->getData($fieldName), $method[0])) { $errors[] = $helper->__($method[1]); } } } if (empty($errors) || $this->getShouldIgnoreValidation()) { return true; } return $errors; } else { return parent::validate(); } }
protected function _validate() { $errors = array(); if ($this->helperCompatibility()->isEnabledDsdataNoState()) { // we need to instantiate without Mage::getModel, cause no model is defined for NoState if (class_exists('Dsdata_NoState_Model_Quote_Address')) { $address = new Dsdata_NoState_Model_Quote_Address($this->getData()); $errors = $address->validate(); } } elseif ($this->helperCompatibility()->isEnabledDhlAccount()) { /** * @var $address Dhl_Account_Model_Quote_Address */ $address = Mage::getModel('dhlaccount/quote_address', $this->getData()); $errors = $address->validate(); } elseif ($this->helperCompatibility()->isEnabledGoMageLightCheckout()) { /** * @var $address GoMage_Checkout_Model_Quote_Address */ $address = Mage::getModel('gomage_checkout/quote_address', $this->getData()); $errors = $address->validate(); } else { $errors = parent::validate(); } return $errors; }
/** * Validates the address. AvaTax validation is invoked if the this is a ship-to address. * Returns true on success and an array with an error on failure. * * @return true|array */ public function validate() { if (!Mage::helper('avatax')->fullStopOnError()) { return true; } $result = parent::validate(); //if base validation fails, don't bother with additional validation if ($result !== true) { return $result; } //if ship-to address, do AvaTax validation $data = Mage::app()->getRequest()->getPost('billing', array()); $useForShipping = isset($data['use_for_shipping']) ? (int) $data['use_for_shipping'] : 0; if ($this->getAddressType() == self::TYPE_SHIPPING || $this->getUseForShipping() || $useForShipping) { if (!isset(self::$_validationResult[$this->getAddressId()])) { if (!$this->getAvataxValidator()) { $validator = Mage::getModel('avatax/avatax_address')->setAddress($this); $this->setAvataxValidator($validator); } self::$_validationResult[$this->getAddressId()] = $this->getAvataxValidator()->validate(); } return self::$_validationResult[$this->getAddressId()]; } return $result; }
/** * validates the address * * @return boolean | array true if validation is passed, otherwise the error messages */ public function validate() { $errors = parent::validate(); if (true === $errors) { $errors = array(); } if ($this->getAddressType() == self::TYPE_BILLING) { if (preg_match('/pac?k(et)?station/i', $this->getStreetFull())) { $errors[] = Mage::helper('customer')->__('No parcel pick up machines are allowed in billing address. To send to a parcel pick up machine you should enter it as shipping address.'); } } if ($this->getAddressType() == self::TYPE_SHIPPING) { if (!is_null($this->getShipToPackstation()) && $this->getShipToPackstation() == Dhl_Account_Model_Config::SHIP_TO_PACKSTATION) { if (Mage::getModel('dhlaccount/config')->isPackstationEnabled() && !preg_match('/^(packstation\\s){0,1}\\d{3,3}$/i', trim($this->getStreetFull()))) { $errors[] = Mage::helper('customer')->__('Only 3 digits are allowed for packstations.'); } if ((Mage::getModel('dhlaccount/config')->isPackstationEnabled() || Mage::getModel('dhlaccount/config')->isPreferredDeliveryDateEnabled()) && 0 < strlen(trim($this->getDhlaccount())) && !preg_match('/^\\d{6,10}$/i', trim($this->getDhlaccount()))) { $errors[] = Mage::helper('customer')->__('Only 6 to 10 digits are allowed for DHL account number') . ' ' . $this->getDhlaccount() . '.'; } } if (Mage::getModel('dhlaccount/config')->isPackstationEnabled() && !is_null($this->getQuote()) && !is_null($this->getQuote()->getBillingAddress()) && !is_null($this->getQuote()->getBillingAddress()->getDhlaccount()) && 0 < strlen($this->getQuote()->getBillingAddress()->getDhlaccount())) { if (false === $this->addressesAreEqual($this, $this->getQuote()->getBillingAddress())) { $errorMessage = Mage::helper('customer')->__('If a different shipping address is used, the parcel announcement will be skipped.'); if (0 == count($errors)) { $errorMessage = array('message' => Mage::helper('customer')->__('If a different shipping address is used, the parcel announcement will be skipped.') . ' ' . Mage::helper('customer')->__("Click 'OK' to skip the parcel announcement, click 'cancel' to edit your shipping address."), 'showConfirm' => 1); } $errors[] = $errorMessage; } } } if (empty($errors) || $this->getShouldIgnoreValidation()) { return true; } return $errors; }
public function validate() { $billData = Mage::app()->getFrontController()->getRequest()->getPost('billing', array()); $result = parent::validate(); // Perform default magento validation if ($result !== true) { return $result; } else { if ($this->getAddressType() == self::TYPE_SHIPPING || $this->getAddressType() == self::TYPE_BILLING && isset($billData['use_for_shipping']) && (int) $billData['use_for_shipping']) { return $this->_getATValidator()->validate(); } } return $result; }
/** * Validates the address. AvaTax validation is invoked if the this is a ship-to address. * Returns true on success and an array with an error on failure. * * @return true|array */ public function validate() { if (!$this->_getConfigHelper()->fullStopOnError($this->getQuote()->getStoreId())) { return true; } $result = parent::validate(); //if base validation fails, don't bother with additional validation if ($result !== true) { return $result; } //if ship-to address, do AvaTax validation $data = Mage::app()->getRequest()->getPost('billing', array()); $useForShipping = isset($data['use_for_shipping']) ? (int) $data['use_for_shipping'] : 0; if ($this->getAddressType() == self::TYPE_SHIPPING || $this->getUseForShipping() || $useForShipping) { return Mage::getModel('avatax/action_validator')->validate($this); } return $result; }
public function validate() { if (Mage::helper('onestepcheckout')->enabledOnestepcheckout()) { $errors = array(); $helper = Mage::helper('customer'); $this->implodeStreetAddress(); if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) { $errors[] = $helper->__('Please enter the first name.'); } if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) { $errors[] = $helper->__('Please enter the last name.'); } if (!Zend_Validate::is($this->getStreet(1), 'NotEmpty')) { $errors[] = $helper->__('Please enter the street.'); } } else { return parent::validate(); } }
/** * Validate address attribute values * * @return bool */ public function validate() { $active = Mage::getStoreConfig('nopobox/option/active'); if ($active) { $errors = array(); $allowcountry = Mage::getStoreConfig('nopobox/option/allowspecific'); $flag = true; if ($allowcountry) { $specificcountry = Mage::getStoreConfig('nopobox/option/specificcountry'); $specificcountry = explode(',', $specificcountry); if (!in_array($this->getCountryId(), $specificcountry)) { $flag = false; $_error = Mage::helper('core')->__(Mage::getStoreConfig('nopobox/option/cerror')); } } else { $flag = false; } //add filter for P.O. Box if (!$flag) { $re = "/p\\.* *o\\.* *box/i"; if (preg_match($re, $this->getStreet(1)) || preg_match($re, $this->getStreet(2))) { if (isset($_error)) { $errors[] = $_error; } else { $errors[] = Mage::helper('core')->__(Mage::getStoreConfig('nopobox/option/aerror')); } } } $_errors = parent::validate(); if (empty($errors) && $_errors === true || $this->getShouldIgnoreValidation()) { return true; } if ($_errors && is_array($_errors)) { $errors = array_merge($_errors, $errors); } return $errors; } else { return parent::validate(); } }