$attributeSetNames = array('Sko', 'beklaedning', 'Banz_solhat', 'Soltoj', 'solhat', 'fodtoj');
$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'))
->joinLeft(
array('eas' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_set')),
'cp.attribute_set_id = eas.attribute_set_id',
array('eas.attribute_set_name'))
;
$itemCollection->setQuote($quote);
foreach($itemCollection as $item) {
if (in_array($item->getData('attribute_set_name'), $attributeSetNames)) {
//... 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
}
}