我想覆盖一个抽象的magento类。即Mage_Customer_Model_Address_Abstract
。我的目的是摆脱电话号码验证。
我尝试复制app / code / core /Mage/Customer/Model/Address/Abstract.php
要
应用程序/代码/ 本地 /Telephone/Customer/Model/Address/Abstract.php
试图用新代码覆盖函数validate()。
public function validate()
{
$errors = array();
$this->implodeStreetAddress();
if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the first name.');
}
if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the last name.');
}
if (!Zend_Validate::is($this->getStreet(1), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the street.');
}
if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the city.');
}
/* if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the phone number.');
} */
$_havingOptionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
if (!in_array($this->getCountryId(), $_havingOptionalZip)
&& !Zend_Validate::is($this->getPostcode(), 'NotEmpty')
) {
$errors[] = Mage::helper('customer')->__('Please enter the zip/postal code.');
}
if (!Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the country.');
}
if ($this->getCountryModel()->getRegionCollection()->getSize()
&& !Zend_Validate::is($this->getRegionId(), 'NotEmpty')
&& Mage::helper('directory')->isRegionRequired($this->getCountryId())
) {
$errors[] = Mage::helper('customer')->__('Please enter the state/province.');
}
if (empty($errors) || $this->getShouldIgnoreValidation()) {
return true;
}
return $errors;
}
但是,我不能让它发挥作用!
我能做到的唯一方法就是将文件完全复制到本地文件夹。即
应用程序/代码/的核心/法师 /Customer/Model/Address/Abstract.php
要
应用程序/代码/ 本地/法师 /Customer/Model/Address/Abstract.php
和app / code / local / Customer / etc /中的config.xml是..
<?xml version="1.0"?>
<config>
<modules>
<Telephone_Customer>
<version>0.0.1</version>
</Telephone_Customer>
</modules>
<global>
<models>
<telephone_customer>
<class>Telephone_Customer_Model</class>
</telephone_customer>
<customer>
<rewrite>
<customer>Telephone_Customer_Model_Customer</customer>
</rewrite>
<customer>
</models>
</global>
</config>
但是这里不允许bcz这不是正确的方法。
我们可以覆盖这个抽象类,就像我们在别处做的那样。?
请帮忙。
答案 0 :(得分:-1)
最后得到它。
我可以访问
function validate()
重写派生类,例如Address.php。
即覆盖
应用程序/代码/核心/法师/客户/ Address.php
我们可以像上面的代码中描述的那样使用相同的原则来覆盖文件。