2017-04-06 62 views
0

我试图列出我的一些产品从一个PHP脚本,我需要得到一些属性的值。对于为例我想是这样的,从产品集合店::magento:加入具有属性值的产品

Mage::app(); 
Mage::app()->setCurrentStore(1); 
$collection = Mage::getModel('catalog/product')->getCollection() 
    ->addAttributeToSelect('computer_type') 
    ->joinAttribute('computer_type_value', 'eav/entity_attribute_option', "computer_type", null, 'left', 0) 

"computer_type"这是在eav_attribute_option_valueoption_id领域找到一个id:

+----------+-----------+----------+--------+ 
| value_id | option_id | store_id | value | 
+----------+-----------+----------+--------+ 
|  3738 |  14 |  0 | server | 
+----------+-----------+----------+--------+ 

我想加盟此表与我的集合的结果,以便显示值“服务器”而不是ID“3738”,但我这样做的方式是行不通的,尽管我所有的搜索。

我没有找到如何在只有一个查询中实现。可能吗 ?

+0

你是如何_using_的数据? Magento有一种特殊的方式,使用属性模型的“前端”渲染器访问前端模板中的选择属性值。如果这是你正在做的事情,那么你应该效仿。如果是用于数据馈送或其他/自定义逻辑,请继续:D –

+0

@RobbieAverill:感谢您的评论,它确实在前端实例之外使用,这就是为什么我使用纯php库 – ehretf

回答

-1

请使用如下代码加入产品属性:

$mageFilename = 'app/Mage.php'; 
require_once $mageFilename; 
umask(0); 
Mage::app('admin'); 
Mage::register('isSecureArea', 1); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
$collection = Mage::getModel('catalog/product') 
     ->getCollection() 
     ->addAttributeToSelect('*') 
    ->addAttributeToFilter('computer_type',array('neq'=>0)) 
    ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) 
     ->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); 
+0

感谢您的建议,我可能会以错误的方式使用它,但实际上它是否与包含属性值的表连接,我只从目录/产品中获取'computer_type',就像我已经拥有的那样。 – ehretf

相关问题