Getting products position while using flat tables
-
16-10-2019 - |
Pergunta
Regarding the answer from Vinai here https://magento.stackexchange.com/a/5775/199 I have one follow-up question:
How can I get the ProductPosition array when I use flat category tables?
In my system configuration I use these settings:
Catalog -> Frontend -> Use Flat Catalog Category = yes
Catalog -> Frontend -> Use Flat Catalog Product = yes
When I use getProductsPosition()
I receive the following:
Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat::getProductsPosition() in [...]/app/code/core/Mage/Catalog/Model/Category.php on line 318
Any ideas?
Thanks in advance :)
Solução
This should work.
$categoryId = '46'; //replace with your own
$category = Mage::getModel('catalog/category')->load($categoryId);
$positions = Mage::getResourceModel('catalog/category')->getProductsPosition($category);
This ignores the 'Flat categories' flag. It goes directly to the category resource model.
You can even skip the category loading for performance. and just pass as parameter an object that has an id
parameter.
$categoryId = '46'; //replace with your own
$category = new Varien_Object(array('id'=>$categoryId));
$positions = Mage::getResourceModel('catalog/category')->getProductsPosition($category);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange