2013-06-10 4 views
0

체크 아웃 모델 saveBilling() 함수를 Mage/Checkout/Model/Type/Onepage.php에 포함 된 이벤트를 추가하는 맞춤 모듈을 만들었습니다. 모듈Magento : 모듈 기능 재 지정 -> 재정의 된 기능에 액세스 할 수있는 항목은 무엇입니까?

Notice: Undefined property: Fla_Checkout_Model_Type_Onepage::$_customerEmailExistsMessage 
in /home/magento/public_html/app/code/local/Fla/Checkout/Model/Type/Onepage.php 
on line 154 

타당한 비트 공용 기능 saveBilling의 코드() 정확히 젠토 코어 옆으로 동일하다 : 제외 제대로이 호출마다 소성 이벤트에서, 모듈은 지금 때때로 에러가 발생 dispatchEvent() 행 및 그 이전의 주석. 오류를 던지는 섹션 :

<?php 
class Fla_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage { 
    public function saveBilling($data, $customerAddressId) { 

     /* much code removed here as not relevant to question */ 

     /* This section throws error because $this->_customerEmailExistsMessage not found */ 


     if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) { 
      if ($this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) { 
       return array('error' => 1, 'message' => $this->_customerEmailExistsMessage); 
      } 
     } 


     /* much code removed here as not relevant to question, below code works as intended*/ 

     /* Fiascolabs added event for exporting billing data */ 
     Mage::dispatchEvent('fla_billing_export', array('quote'=>$this->getQuote())); 

     return array(); 
    } 
} 

나는 젠토의 핵심 코드를 참조

, 상단에, 내가 함수 덮어 쓰기에 액세스 할 수 없습니다 것 같다 선언 몇 가지 항목이있다.
  1. 상수공공 기능 __construct 있습니까() 내 모듈을 사용할 수?

  2. 신고 된 개인 항목 만 복제하면 되나요?

문제의 코드

은 다음과 같습니다 : 그들은 처음에는 부두처럼 보일 때문에

/** 
* Checkout types: Checkout as Guest, Register, Logged In Customer 
*/ 
const METHOD_GUEST = 'guest'; 
const METHOD_REGISTER = 'register'; 
const METHOD_CUSTOMER = 'customer'; 

/** 
* Error message of "customer already exists" 
* 
* @var string 
*/ 
private $_customerEmailExistsMessage = ''; 

/** 
* Class constructor 
* Set customer already exists message 
*/ 
public function __construct() 
{ 
    $this->_helper = Mage::helper('checkout'); 
    $this->_customerEmailExistsMessage = $this->_helper->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.'); 
    $this->_checkoutSession = Mage::getSingleton('checkout/session'); 
    $this->_customerSession = Mage::getSingleton('customer/session'); 
} 

답변

2

그것은, 난처하게하고 젠토의 클래스 재 작성에 의해 신비화하기가 쉽습니다. 그러나 "다른 클래스 대신이 클래스를 인스턴스화"기능을 제외한 클래스 재 작성은 표준 PHP OOP 일 뿐이며 모든 표준 PHP OOP 규칙이 적용됩니다. 클래스가 다른 클래스를 확장하는 경우

특히, 그것은 개인 특성의 기본 클래스/객체의에 액세스 할 수 없습니다.

private $_customerEmailExistsMessage = ''; 

보호 된 공개 속성 및 방법에 액세스 할 수 있습니다. 당신이

public function __construct() 
{   
    //do the stuff in the parent consturctor 
    parent::__construct(); 

    //do my new stuff 
}  

당신은 parent::__construct()를 호출 할 필요는 없습니다를 원한다면 당신은 __constructor 메소드를 재정의 할 수 있지만, 당신은 이유가되지 않음을하지 않는 한 항상이 작업을 수행하는 것이 좋습니다. parent::methodName() 구문은 다른 방법으로 작동 할뿐만 아니라

public function getCheckout() 
{ 
    $parent_results = parent::getCheckout(); 

    //do my stuff 

    return $parent_results; 
} 

상수는 약간 난이도가 있습니다. 상수는 멤버 함수 및 변수와 같은 액세스 규칙이 없지만 PHP 버전 (5.2 대 5.3 이상)에 따라 PHP의 "Late Static Bindings" behavior은 특수 '자체', '부모'및 '정적'키워드가 상호 작용하는 방식을 변경합니다 상수와. 상수 내가하는 경향이 한

echo Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER 

를 참조, 당신은, 동일한 작업을 수행하는 것이 좋습니다 때 일반적으로, 마 젠토 코드베이스는 전체 클래스 이름을 사용합니다.

+0

나는 여기에 뭉칠만한 것들이있어, 설명 해줘서 고마워! –