overwrite Mage_Sales_Model_Quote_Address
<?xml version="1.0"?>
<config>
<modules>
<Empire_Sales>
<version>1.0.0.0.0</version>
</Empire_Sales>
</modules>
<global>
<models>
<sales>
<rewrite>
<quote_address>Empire_Sales_Model_Quote_Address</quote_address>
</rewrite>
</sales>
</models>
</global>
</config>
File: /app/code/local/Empire/Sales/Model/Quote/Address.php
<?php
class Empire_Sales_Model_Quote_Address extends Mage_Sales_Model_Quote_Address
{
/**
* Validate address attribute values
*
* @return bool
*/
public function validate()
{
$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->getStreet(1), 'NotEmpty')) {
$errors[] = $helper->__('Please enter the street.');
}
if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) {
$errors[] = $helper->__('Please enter the city.');
}
if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
//$errors[] = $helper->__('Please enter the telephone number.');
}
$_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.');
}
if (!Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
$errors[] = $helper->__('Please enter the country.');
}
if ($this->getCountryModel()->getRegionCollection()->getSize()
&& !Zend_Validate::is($this->getRegionId(), 'NotEmpty')) {
$errors[] = $helper->__('Please enter the state/province.');
}
if (empty($errors) || $this->getShouldIgnoreValidation()) {
return true;
}
return $errors;
}
}

本文介绍了一个Magento扩展,用于增强订单地址验证功能。该扩展通过覆盖默认的地址验证方法,确保客户在结账过程中输入完整且有效的地址信息。

被折叠的 条评论
为什么被折叠?



