/** * Get the shipping address for the request * * @param OnePica_AvaTax_Model_Sales_Quote_Address $address * @return OnePica\AvaTax16\Document\Part\Location\Address */ protected function _getDestinationAddress($address) { $street1 = $address->getStreet(1); $street2 = $address->getStreet(2); $city = (string) $address->getCity(); $zip = $address->getPostcode(); $state = Mage::getModel('directory/region')->load($address->getRegionId())->getCode(); $country = $address->getCountry(); $address = $this->_newAddress($street1, $street2, $city, $state, $zip, $country); return $address; }
/** * Validates the address with the AvaTax validation API. * Returns true on success and an array with an error on failure. * * @return array|bool * @throws OnePica_AvaTax_Model_Avatax_Address_Exception */ public function validate() { if (!$this->_mageAddress) { throw new OnePica_AvaTax_Model_Avatax_Address_Exception($this->__('An address must be set before validation.')); } /** @var Mage_Sales_Model_Quote $quote */ $quote = $this->_mageAddress->getQuote(); $isAddressValidationOn = $this->_getDataHelper()->isAddressValidationOn($this->_mageAddress, $this->_storeId); $isAddressNormalizationOn = $this->_getDataHelper()->isAddressNormalizationOn($this->_mageAddress, $this->_storeId); $isAddressActionable = $this->_getDataHelper()->isAddressActionable($this->_mageAddress, $quote->getStoreId(), OnePica_AvaTax_Model_Config::REGIONFILTER_ALL, true); //if there is no use cases for AvaTax services, return address as valid without doing a lookup if (!$isAddressValidationOn && !$isAddressNormalizationOn && !$isAddressActionable) { return true; } //lookup in AvaTax (with caching) $key = $this->_mageAddress->getCacheHashKey(); if (array_key_exists($key, $this->_cache)) { $result = unserialize($this->_cache[$key]); } elseif ($this->_mageAddress->getPostcode() && $this->_mageAddress->getPostcode() != '-') { $checkFieldsResult = $this->_checkFields(); if ($checkFieldsResult) { return $checkFieldsResult; } $result = $this->_sendAddressValidationRequest(); $this->_cache[$key] = serialize($result); } else { $errors = array(); $errors[] = $this->__('Invalid ZIP/Postal Code.'); return $errors; } $this->_addressNormalization($isAddressNormalizationOn, $result); $addressValidationResult = $this->_addressValidation($isAddressValidationOn, $isAddressActionable, $result); if ($addressValidationResult) { return $addressValidationResult; } return true; }