[英]Magento cart items check
如何檢查所有購物車商品是否都具有我的自定義屬性? 並且,如果所有具有自定義屬性的項目都顯示一條消息,但是如果購物車中的一項沒有自定義屬性,則它在結帳時顯示一條錯誤消息?
請嘗試以下代碼
<?php
$productModel = Mage::getModel('catalog/product');
$cart = Mage::getModel('checkout/cart')->getQuote();
$error = "";
foreach ($cart->getAllItems() as $item) {
$product = $productModel->load($item->getProduct()->getId());
if($product->getData('your_attribute_code')){
$message = "your message for items have attribute";
$error = 0;
}else{
$message = "your message for items have no attributes";
$error = 1;
break;
}
}
if($error == 1){
Mage::getSingleton('core/session')->addError($message);
}else{
Mage::getSingleton('core/session')->addSuccess($message);
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.