magento使用product id获取产品

magento使用product id获取产品,magento,attributes,product,Magento,Attributes,Product,我试图获得magento的功能产品,我在每个变量中正确地获得所有产品ID,但它在循环中不起作用,并显示重复的产品 这是我的密码 $storeId = Mage::app()->getStore()->getId(); $categoryId = $this->getRequest()->getParam('id', false); $resource = Mage::getSingleton('core/resource'); $read = $resource-&

我试图获得magento的功能产品,我在每个变量中正确地获得所有产品ID,但它在循环中不起作用,并显示重复的产品

这是我的密码

$storeId = Mage::app()->getStore()->getId();   
$categoryId = $this->getRequest()->getParam('id', false);
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$categoryProductTable = $resource->getTableName('catalog/category_product');
//$productEntityIntTable = $resource->getTableName('catalog/product_entity_int'); // doesn't work :(
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');

$select = $read->select()
    ->from(array('cp'=>$categoryProductTable))
    ->join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
    ->joinNatural(array('ea'=>$eavAttributeTable))
    ->where('pei.value=1')
    ->where('ea.attribute_code="featured"');            

$_product = $read->fetchAll($select);
$total_product= count($_product);
当我打印r($\产品)时,它会显示产品的多个id,这些id都是功能,因此它是正确的

但在for循环内部,当我尝试使用id获取产品名称时,它会显示重复的产品名称,下面是代码

$obj = Mage::getModel('catalog/product');
for($cp=0;$cp <= $total_product; $cp++):
    $_product= $obj->load($_product[$cp]['product_id']);
    echo $_product->getName();
endfor;
$obj=Mage::getModel('catalog/product');
对于($cp=0;$cp加载($_产品[$cp]['product_id']);
echo$_product->getName();
endfor;

将$obj放入下面的循环中

for($cp=0;$cp <= $total_product; $cp++):
 $obj = Mage::getModel('catalog/product');
 $_product= $obj->load($_product[$cp]['product_id']);
 echo $_product->getName();

endfor;
for($cp=0;$cp加载($\u产品[$cp]['product\u id']);
echo$_product->getName();
endfor;
试试这个

for($cp=0;$cp <= $total_product; $cp++):
 $obj = Mage::getModel('catalog/product');
 $_productnew= $obj->load($_product[$cp]['product_id']);
echo $_productnew->getName();
endfor;
for($cp=0;$cp加载($\u产品[$cp]['product\u id']);
echo$\u productnew->getName();
endfor;

您好,谢谢您的回复,我尝试过了,但现在它只显示一个产品,我有18个产品的计数($\u产品)值。另外,当我打印($\u产品)时,它会显示所有id。您犯了一个错误…您正在重新分配$\u产品数组,因此它只给您一个产品,因此请将$\u产品更改为$\u productnew in for loop…检查我的code@vishal:有时会发生:)