我想顯示彈出當產品第一次添加到購物車在Magento和不想顯示,如果再次或updated.In短加入該產品的彈出式窗口,我想知道這是會在添加產品購物車是第一次出現或沒有?如何檢查Magento產品是否已添加到購物車中?
回答
答案在很大程度上取決於你想如何處理父/子類型的產品(如果需要)。
如果你只用簡單的產品只處理或者您有父/子類型的產品,你需要測試孩子的ID,那麼:或者
$productId = 1;
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (! $quote->hasProductId($productId)) {
// Product is not in the shopping cart so
// go head and show the popup.
}
,如果你面對的父/子類產品而你只想要測試父ID,然後在:
$productId = 1;
$quote = Mage::getSingleton('checkout/session')->getQuote();
$foundInCart = false;
foreach($quote->getAllVisibleItems() as $item) {
if ($item->getData('product_id') == $productId) {
$foundInCart = true;
break;
}
}
編輯
的問題是在評論中詢問爲什麼設置controller_action_predispatch_checkout_cart_add
中的註冊表值無法在cart.phtml中檢索。
基本上註冊表值只能通過一個請求的生命 - 你正在發佈到結帳/購物車/添加,然後被重定向到結帳/購物車/索引 - 所以你的註冊表值丟失。
如果你想持續在這些值,那麼你可以改用會話:
在您的觀察:
Mage::getSingleton('core/session')->setData('your_var', 'your_value');
檢索值
$yourVar = Mage::getSingleton('core/session')->getData('your_var', true);
真正的旗幟傳遞到的getData將從SESS刪除值離子爲你。
爲了檢查該產品是否已在購物車或沒有,你可以簡單地使用下面的代碼:
$productId = $_product->getId(); //or however you want to get product id
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
$isProductInCart = false;
foreach($items as $_item) {
if($_item->getProductId() == $productId){
$isProductInCart = true;
break;
}
}
var_dump($isProductInCart);
希望這有助於!
感謝您的回覆..它是完美的解決方案。我在觀察者中使用了這個邏輯,現在我的問題是如何在購物車頁面上獲得$ isProductInCart值,因爲我希望此值顯示購物車頁面中的彈出窗口。一個phtml文件中的變量值... – Tamanna 2012-07-27 10:27:33
您可以簡單地在產品ID作爲函數參數的某些函數中包裝上述代碼,並且可以從任何地方調用它。 – MagePsycho 2012-07-27 10:33:51
我的回答也被低估了 – 2012-07-27 18:39:39
- 1. Magento - 如何檢查商品已添加到購物車
- 2. Magento:產品添加到購物車
- 3. Codeigniter購物車 - 檢查商品是否已添加到購物車
- 4. Magento - 如何檢查產品是否已從購物車中移除
- 5. Magento Ajax檢查購物車是否已包含產品或者當前產品是否已添加到購物車
- 6. 如何添加產品到購物車?
- 7. 檢查Magento購物車是否有特定AttributeSetName產品
- 8. Android-Magento-如何使用ksop2添加產品到購物車
- 9. 如何將隱藏的產品添加到magento購物車?
- 10. 如何檢查類別產品是否在購物車中
- 11. WordPress的購物車添加動態產品到購物車
- 12. Magento:Nick-naming產品添加到購物車
- 13. 將產品添加到購物車
- 14. Virtuemart:產品不添加到購物車
- 15. 添加產品到購物車Rails
- 16. 產品未添加到購物車
- 17. 將產品添加到購物車WooCommerce?
- 18. Magento產品未加入購物車
- 19. 使用拖放在magento中添加產品到購物車
- 20. Magento Theme在IE(Javascript)中將產品2x添加到購物車
- 21. 跟蹤客戶在Magento中將產品添加到購物車
- 22. Magento附加產品未添加到購物車product_addtocart_form
- 23. Magento的AJAX添加到購物車產品未找到錯誤
- 24. 僅將基礎產品添加到Magento中捆綁產品的購物車中
- 25. 在magento中添加產品時,如何檢查產品是否已被選定?
- 26. Magento從訂購商品中添加可配置產品到購物車
- 27. 阿賈克斯添加到購物車未將產品添加到購物車
- 28. Magento購物車:檢查商品清空購物車
- 29. PHP和SQL的購物車是不是將產品添加到購物車
- 30. magento:無法將產品添加到購物車 - 主鑰匙
我在使用「controller_action_predispatch_checkout_cart_add」獲取產品ID之前,它將其添加到購物車..我使用寄存器變量獲取產品ID在購物車上的phtml頁面......並準備一個函數進行條件檢查。但現在我無法在註冊表頁面上獲得productid ..請幫我解決這個問題.. – Tamanna 2012-07-27 12:37:17
已經更新了答案,以便爲你解釋這個問題 – 2012-07-27 13:17:49
非常感謝你Drew Hunter ..對我來說一個完美的解決方案。謝謝你的幫助...:):) – Tamanna 2012-07-27 13:43:58