2012-12-11 4 views
1

나는 자홍색 추상 클래스를 오버라이드하고 싶습니다. 즉 Mage_Customer_Model_Address_Abstract입니다. 제 의도는 전화 번호 확인을 없애는 것입니다.Magento에서 추상 클래스를 어떻게 재정의 할 수 있습니까?

I 앱/코드/코어를 복사 시도 /Mage/Customer/Model/Address/Abstract.php

으로

응용 프로그램/코드/지역/전화/고객/모델/주소 /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

하려면 응용 프로그램/코드/ 지역/마법사/고객/모델/주소/추상 .PHP

및 응용 프로그램/코드/지역/고객/기타 /입니다 내 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> 

B 유엔 여기에 그것이 올바른 방법이 아니라는 bcz 허용되지 않습니다.

다른 곳에서하는 것처럼이 추상 클래스를 재정의 할 수 있습니까?

도와주세요.

+0

class SomeClass extends Abstract {...? – vodich

+0

나는 이미 그것을 시도했다. 클래스는 Telephone_Customer_Model_Address_Abstract는 Mage_Customer_Model_Address_Abstract { } 를 확장하지만 ... :( –

답변

-2

마지막으로 알 수 있습니다.

I는

검증 함수()와 같은 Address.php 같이 유도 클래스를 무시

액세스 할 수있다.

즉, 오버라이드 (override)

응용 프로그램/코드/코어/마법사/고객/Address.php 내가 파일을 대체 할 위의 내 코드에 설명 된대로 우리가 사용할 수있는

같은 원리.

+0

안 좋은 방법 일을 나던.이 일을 다시 작성 관찰자 또는 설정 기반의 클래스를 사용하여, 그렇지 않으면 당신은 관련이없는 코드 및 복잡하게 많은 소유권을 업그레이드 워크 플로우 – benmarks

관련 문제