2014-01-10 90 views
0

事件只運行一次。我在通過觀察員將產品添加到購物車後添加了自定義價值事件checkout_quote_init 它工作正常,但如果客戶登錄並下了訂單,那麼在第一順序中,值被插入到引用中,但第二次觀察者未運行。觀察者只運行一次

<checkout_quote_init> 
    <observers> 
     <youva_custom> 
      <type>singleton</type> 
      <class>custom/observer</class> 
      <method>setqoutevalue</method> 
     </youva_custom> 
    </observers> 
</checkout_quote_init> 

public function setqoutevalue($observer) { 
    $event = $observer->getEvent(); 
    $_quote = $event->getQuote(); 
    $_quote->setCustomevalue($customevalue); 
    $_quote->save(); 
} 

回答

0

如果你看一看分派事件的代碼使用的是你會看到這個(Mage_Checkout_Model_Session::getQuote()):

 if (!$this->getQuoteId()) { 
      if ($customerSession->isLoggedIn() || $this->_customer) { 
       $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer(); 
       $quote->loadByCustomer($customer); 
       $this->setQuoteId($quote->getId()); 
      } else { 
       $quote->setIsCheckoutCart(true); 
       Mage::dispatchEvent('checkout_quote_init', array('quote'=>$quote)); 
      } 
     } 

這意味着,僅在創建報價分派事件。並且只有在用戶沒有登錄的情況下。這意味着如果會話中已經有一個引用ID,則該事件不會被分派。

您可能想要使用其他事件。例如checkout_cart_product_add_after