我需要獲得中某個特定產品在相關產品中列出的所有產品的產品。 所以我會嘗試刪除主要產品後,從購物車中刪除不必要的物品。獲取特定於產品涉及
是否有simplier方式,然後循環的所有車中的項目?
感謝您的諮詢。
我需要獲得中某個特定產品在相關產品中列出的所有產品的產品。 所以我會嘗試刪除主要產品後,從購物車中刪除不必要的物品。獲取特定於產品涉及
是否有simplier方式,然後循環的所有車中的項目?
感謝您的諮詢。
只有兩個方法,我能想到的是:
由於產品似乎是如此緊密相關,並依賴於主要產品,你可能要考慮創建bundle products代替。它也可能會產生混淆,以在他們的購物車3個項目的客戶,並刪除其中的1(主產品),現在他們的車是空的,不知什麼原因,他們仍然希望2個相關產品(你自動刪除)。
正如您上面提到 - 在您的購物車就刪除遍歷所有產品(見下面的代碼)
創建應用程序/本地/ RWS/AutoDeleteRelatedCartProducts的/ etc/config.xml中
<config>
<global>
<models>
<autodeleterelatedcartproducts>
<class>RWS_AutoDeleteRelatedCartProducts_Model</class>
</autodeleterelatedcartproducts>
</models>
</global>
<frontend>
<events>
<sales_quote_remove_item>
<observers>
<autodeleterelatedcartproducts>
<type>singleton</type>
<class>autodeleterelatedcartproducts/observer</class>
<method>removeQuoteItem</method>
</autodeleterelatedcartproducts>
</observers>
</sales_quote_remove_item>
</events>
</frontend>
</config>
創建應用程序/本地/ RWS/AutoDeleteRelatedCartProducts /型號/ Observer.php
<?php
class RWS_AutoDeleteRelatedCartProducts_Model_Observer
{
public function removeQuoteItem(Varien_Event_Observer $observer)
{
//get deleted product
$delete_product = $observer->getQuoteItem()->getProduct();
// Get all related products
$related_products = $delete_product->getRelatedProductCollection();
// get all related product id and save in array
$related_product_ids = array();
foreach($related_products as $product){
$related_product_ids[] = $product->getId(); // double check to make sure this product_id
}
foreach(Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item)
{
// if getId is a related product remove it
if(in_array($item->getId(), $related_product_ids))
Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
}
}
}
?>
更多@
Observer for removed items in the cart
Help with Magento and related products
Magento - How to check if a product has already been removed from the cart
,如果我是你,我可能不會增加產品擺在首位,而是使用一個觀察員checkout_cart_product_add_after事件。 根據您的預期產品檢查產品。使用R.S.的方法。以處理報價並檢查購物車中產品的數量。 爲產品添加自定義選項,讓客戶知道他是否有免費的好東西。 這可能是合適的Magento - Quote/order product item attribute based on user input
然後添加一個觀察員到這個事件sales_convert_quote_to_order。 此觀察者可以檢查的數量和適應這樣的事情,賦予產品給客戶Skip Checkout in Magento for a downloadable product 你只得到單身人士和觀察家使用所以這種方法比很多增加和在車過程中去除的便宜得多。也會看起來更好。如果你想我會盡力實現它,但使用你的網站和數據庫的副本,因爲我懶得設立產品
。
ps。也許你需要觀察這一事件也checkout_cart_update_items_before
PS。 PS。也許我應該檢查之前,我評論哈哈。大聲笑讓你從這裏被禁止?
謝謝。不幸的是它不可能使用捆綁包。在我的情況下,如果您訂購的產品多於十倍,您將獲得一些相關產品。這應該是對客戶的特別優惠。你的第二種方式是我目前的做法。其他一些想法? – bukart
客戶得到的相關物品,它是否改變了訂單總金額(通過增加運輸成本等)? –
不,它們是免費的(額外下載,如果你的購物車中的主要產品超過十倍) – bukart