我有一个产品ID列表,并根据该产品ID我想获得产品名称,但由于catalog_product_entity表不包含产品名称只有sku,我被困。
请检查我的代码,我尝试过左右加入,但没有得到名称
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->getSelect()->joinRight(
array('table_alias'=>'my_table'),
'entity_id = table_alias.product_id',
array('table_alias.*')
);
$result = null;
foreach ($collection as $temp) {
$result[] = array(
'name' => $temp->getCustomer_name(),
);
}
答案 0 :(得分:0)
如果您希望您的收藏集加载产品名称,那么代码的第一部分是正确的。这是一个简化版本:
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('name');
$result = array();
foreach ($collection as $temp) {
$result[] = array('name' => $temp->getName());
}
答案 1 :(得分:0)
这就是我解决它的方式
$resource = Mage::getSingleton('core/resource');
$readResource = $resource->getConnection('core_read');
$tableName = $resource->getTableName('myTable');
$results = $readResource->select('table_alias.*')
->from($tableName)
->joinLeft(
array('table_alias'=>'catalog_product_flat_1'),
'product_id = table_alias.entity_id',
array('table_alias.*')
)->where('customer_id=?',$customerId);
$products=$readResource->fetchAll($results);
$dataList = array();
foreach($products as $row)
{
$dataList[] = array('productName'=>$row['name'],'price'=> $row['price'],'status'=>$row['status'],'myTable_id'=>$row['myTable_id']);
}