检查具有特定属性名称的产品的Magento购物车

检查具有特定属性名称的产品的Magento购物车,magento,Magento,在Magento结帐/购物车中,我想检查是否将来自六个特定属性集的产品添加到Magento购物车中 我已经创建了下面的函数来检查productview页面中的这些属性名称,但是如何对checkout/cart中的项目进行相同的检查呢 $attribute_set = Mage::getModel('eav/entity_attribute_set')->load( $_product->getAttributeSetId() ); $attributeset_name = $att

在Magento结帐/购物车中,我想检查是否将来自六个特定属性集的产品添加到Magento购物车中

我已经创建了下面的函数来检查productview页面中的这些属性名称,但是如何对checkout/cart中的项目进行相同的检查呢

$attribute_set = Mage::getModel('eav/entity_attribute_set')->load( $_product->getAttributeSetId() ); 
$attributeset_name = $attribute_set->getAttributeSetName();
if ($attributeset_name =="Sko" or $attributeset_name =="beklaedning" or $attributeset_name =="Banz_solhat" or $attributeset_name =="Soltoj" or $attributeset_name =="solhat" or $attributeset_name =="fodtoj") { 
    echo "<b>Fragt</b>: <span style='color:red'>Fri Fragt p&aring; varen samt resten af ordren</span><br>"; 
}
致以最良好的祝愿, 小丑

或者

使用属性集ID而不是名称。这将避免任何潜在的措辞问题,也会清理一点代码

$attributeSetIds = array(1, 2, 3, 4, 5, 6);

$quote = Mage::getSingleton('checkout/session')->getQuote();
$itemCollection = Mage::getModel('sales/quote_item')->getCollection();
$itemCollection->getSelect()
    ->joinLeft( 
        array('cp' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 
        'cp.entity_id = main_table.product_id', 
        array('cp.attribute_set_id'))
;
$itemCollection->setQuote($quote);

foreach($itemCollection as $item) {
    if (in_array($item->getData('attribute_set_id'), $attributeSetIds)) {
       //... Match
    }
}
或者

使用属性集ID而不是名称。这将避免任何潜在的措辞问题,也会清理一点代码

$attributeSetIds = array(1, 2, 3, 4, 5, 6);

$quote = Mage::getSingleton('checkout/session')->getQuote();
$itemCollection = Mage::getModel('sales/quote_item')->getCollection();
$itemCollection->getSelect()
    ->joinLeft( 
        array('cp' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 
        'cp.entity_id = main_table.product_id', 
        array('cp.attribute_set_id'))
;
$itemCollection->setQuote($quote);

foreach($itemCollection as $item) {
    if (in_array($item->getData('attribute_set_id'), $attributeSetIds)) {
       //... Match
    }
}

您好Drew,非常感谢您的回复:-您能帮我剪一个代码,检查某个购物车规则id是否符合订单的要求吗?如果符合,那么echo…您好Drew,非常感谢您的回复:-请您也帮我用一个代码剪报来检查某个购物车规则id是否符合订单,如果符合,然后回显。。。