如何检查所有购物车商品是否都有我的自定义属性?如果item / items都有自定义属性打印一条消息,但如果其中一个购物车项目/项目没有自定义属性,它会在结帐时打印一条错误消息?
答案 0 :(得分:1)
请尝试以下代码
<?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);
}
?>