2012-02-02 101 views
1

Magento版本是1.6.2.0。如果設置了desiger選項,我已經覆蓋Mage_Sales_Order_Quoteapp/code/local不僅僅是增加數量。我有一個設計系統,用戶可以點擊產品視圖中的鏈接,然後將它們帶到我們製作的設計師手中,然後將產品實用添加到購物車。當Mage_Sales_Order_Quote被覆蓋時登錄時,購物車從購物車消失不到

我改變了getItemByProduct以下:

public function getItemByProduct($product) 
{ 
    $_options = unserialize($product->getCustomOption('info_buyRequest')->getValue()); 
    $_designs = $_options['options']['designer']; 
    foreach ($this->getAllItems() as $item) { 
     if ($item->representProduct($product)) { 
      $_itemOptions = unserialize($item->getProduct()->getCustomOption('info_buyRequest')->getValue()); 
      if (!empty($_designs) && !empty($_itemOptions['options']['designer'])) { // consider detecting if this was a re-design 
       return false; 
      } else { 
       return $item; 
      } 
     } 
    } 
    return false; 
} 

現在,功能按預期工作,除了一個事實,即如果我註銷,並在購物車,物品,當我登錄的物品再次合併爲默認功能,而不是我的重寫。我還會在哪裏去除這個?我有「保存購物車到數據庫」設置啓用,以保持購物車持久性,以防相關。

回答

1

創建監聽事件sales_quote_merge_before,並清除了客戶的保存購物車觀察員:

/app/code/local/{namespace}/{yourmodule}/Model/Observer.php

<?php 
class <namespace>_<modulename>_Model_Observer 
{ 
    public function preventMerge(Varien_Event_Observer $observer) 
    { 
    // Clear the customer's cart 
    } 

創建一個觀察者類。然後,添加以下到/應用/代碼/本地/{namespace}/{yourmodule}/etc/config.xml該模塊的文件:

<config> 
    ... 
    <frontend> 
    ... 
    <events> 
     <sales_quote_merge_before> 
     <observers> 
      <sales_quote_merge_before_event> 
      <class>{modulename}/observer</class> 
      <method>preventMerge</method> 
      </sales_quote_merge_before_event> 
     </observers> 
     </sales_quote_merge_before> 
    </events> 
    ... 
    </frontend> 
    ... 
</config>