2017-04-06 88 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

相關問題