本文整理汇总了PHP中Mage_Customer_Model_Address_Abstract::setAddressValidated方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Customer_Model_Address_Abstract::setAddressValidated方法的具体用法?PHP Mage_Customer_Model_Address_Abstract::setAddressValidated怎么用?PHP Mage_Customer_Model_Address_Abstract::setAddressValidated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Customer_Model_Address_Abstract
的用法示例。
在下文中一共展示了Mage_Customer_Model_Address_Abstract::setAddressValidated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _addressValidation
/**
* Address validation
*
* @param int $isAddressValidationOn
* @param int $isAddressActionable
* @param ValidateResult $result
* @return array|bool|null
*/
protected function _addressValidation($isAddressValidationOn, $isAddressActionable, $result)
{
if ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_PREVENT_ORDER) {
if ($result->getResultCode() == SeverityLevel::$Success) {
$this->_mageAddress->setAddressValidated(true);
return true;
} else {
$errors = array();
foreach ($result->getMessages() as $message) {
$errors[] = $this->__($message->getSummary());
}
return $errors;
}
} elseif ($isAddressValidationOn == OnePica_AvaTax_Model_Source_Addressvalidation::ENABLED_ALLOW_ORDER) {
$this->_mageAddress->setAddressValidated(true);
if ($result->getResultCode() == SeverityLevel::$Success) {
return true;
} else {
if (!$this->_mageAddress->getAddressNotified()) {
$this->_mageAddress->setAddressNotified(true);
foreach ($result->getMessages() as $message) {
Mage::getSingleton('core/session')->addNotice($this->__($message->getSummary()));
}
}
return true;
}
//a valid address isn't required, but Avalara has to say there is
//enough info to drill down to a tax jurisdiction to calc on
} elseif (!$isAddressValidationOn && $isAddressActionable) {
if ($result->isTaxable()) {
$this->_mageAddress->setAddressValidated(true);
return true;
} else {
$errors = array();
foreach ($result->getMessages() as $message) {
$errors[] = $this->__($message->getSummary());
}
return $errors;
}
}
return null;
}
示例2: validate
/**
* 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 OnePica_AvaTax_Model_Config $config */
$config = Mage::getSingleton('avatax/config')->init($this->_storeId);
/** @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());
//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() != '-') {
$session = Mage::getSingleton('checkout/session');
if ($session->getPostType() == 'onepage') {
$requiredFields = explode(",", $this->getHelper()->getFieldRequiredList());
$fieldRules = explode(",", $this->getHelper()->getFieldRule());
foreach ($requiredFields as $field) {
$requiredFlag = 0;
foreach ($fieldRules as $rule) {
if (preg_match("/street\\d/", $field)) {
$field = "street";
}
if ($field == "country") {
$field = "country_id";
}
if ($this->_mageAddress->getData($field) == $rule || !$this->_mageAddress->getData($field)) {
$requiredFlag = 1;
}
}
if ($requiredFlag) {
$errors = array();
$errors[] = $this->__('Invalid ') . $this->__($field);
return $errors;
}
}
}
$client = $config->getAddressConnection();
$request = new ValidateRequest($this->_requestAddress, TextCase::$Mixed, 0);
$request->setTaxability(true);
$result = $client->Validate($request);
$this->_log(OnePica_AvaTax_Model_Source_Logtype::VALIDATE, $request, $result, $this->_storeId, $config->getParams());
$this->_cache[$key] = serialize($result);
} else {
$errors = array();
$errors[] = $this->__('Invalid ZIP/Postal Code.');
return $errors;
}
//normalization
if ($isAddressNormalizationOn && $result->getResultCode() == SeverityLevel::$Success) {
$responseAddress = $result->getValidAddresses();
$responseAddress = array_pop($responseAddress);
if ($responseAddress instanceof ValidAddress) {
$this->_responseAddress = $responseAddress;
$this->_convertResponseAddress();
} else {
throw new OnePica_AvaTax_Model_Avatax_Address_Exception($this->__('Invalid response address type.'));
}
}
//validation
if ($isAddressValidationOn == 1) {
if ($result->getResultCode() == SeverityLevel::$Success) {
$this->_mageAddress->setAddressValidated(true);
return true;
} else {
$errors = array();
foreach ($result->getMessages() as $message) {
$errors[] = $this->__($message->getSummary());
}
return $errors;
}
} elseif ($isAddressValidationOn == 2) {
$this->_mageAddress->setAddressValidated(true);
if ($result->getResultCode() == SeverityLevel::$Success) {
return true;
} else {
if (!$this->_mageAddress->getAddressNotified()) {
$this->_mageAddress->setAddressNotified(true);
foreach ($result->getMessages() as $message) {
Mage::getSingleton('core/session')->addNotice($this->__($message->getSummary()));
}
}
return true;
}
//a valid address isn't required, but Avalara has to say there is
//.........这里部分代码省略.........