Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我们如何覆盖Magento中的抽象类?_Php_Magento_Overriding_Abstract Class - Fatal编程技术网

Php 我们如何覆盖Magento中的抽象类?

Php 我们如何覆盖Magento中的抽象类?,php,magento,overriding,abstract-class,Php,Magento,Overriding,Abstract Class,我想重写magento的一个抽象类。ie图像、客户、模型、地址、摘要。我的意图是消除电话号码验证 我试图复制app/code/core/Mage/Customer/Model/Address/Abstract.php 到 app/code/local/Telephone/Customer/Model/Address/Abstract.php 试图用新代码覆盖函数validate public function validate() { $errors = array();

我想重写magento的一个抽象类。ie图像、客户、模型、地址、摘要。我的意图是消除电话号码验证

我试图复制app/code/core/Mage/Customer/Model/Address/Abstract.php

app/code/local/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;
    }
但是,我不能让它工作

我唯一能做的就是将文件精确地复制到本地文件夹。即

app/code/core/Mage/Customer/Model/Address/Abstract.php

app/code/local/Mage/Customer/Model/Address/Abstract.php

app/code/local/Customer/etc/is中的my 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>
但是这里是不允许的,因为这不是正确的方法

我们可以像在其他地方那样重写这个抽象类吗

请帮忙。

终于拿到了

我可以访问

功能验证

重写诸如Address.php之类的派生类

超越

app/code/core/Mage/Customer/Address.php


正如我在上面的代码中所描述的,我们可以使用相同的原则来覆盖该文件。

class SomeClass扩展了Abstract{…?我已经尝试过了。class Telephone\u Customer\u Model\u Address\u Abstract扩展了Mage\u Customer\u Model\u Address\u Abstract{}但它不起作用…:这不是一个好方法。请使用观察器或基于配置的类重写来完成此操作,否则您将拥有大量不相关的代码并使升级工作流复杂化。