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 :)
Sorry for the chaotic formatting :-/
– Celldweller Sep 16 '13 at 15:10Mage_Catalog_Model_Resource_Category::_saveCategoryProductsis protected and cannot be called from anywhere. But you can create your own class that extendsMage_Catalog_Model_Resource_Categoryadd a method to it that is a wrapper for_saveCategoryProductsand call the wrapper method in your code. where there's a will there's a way – Marius Sep 16 '13 at 15:43Mage_Catalog_Model_Resource_Category::_saveCategoryProductsis the key here. My approach is that you use thesetPostedProductsmethod on a category object and then usesave(). Like I said before it already worked. But unfortunately it only works when not using flat category setting. I just tried and checked whenMage_Catalog_Model_Resource_Category::_saveCategoryProductsis called. It is only called when not using flat categories so overwriting would not work or am I missing something? – Celldweller Sep 16 '13 at 15:52SomeClass sxtends Mage_Catalog_Model_Resource_Categorywith a method:public function saveProductRelation($category){return $this->_saveCategoryProducts($category)}. $now you can save the products like this:$category = new Varien_Object(array('id'=>$categoryId)); $category->setPostedProducts($positions); $category->setProdyctsPosition($oldPositions);//set the old positions $myClass = new SomeClass(); $myClass->saveProductRelation($category);Sorry for the code format. – Marius Sep 16 '13 at 16:00Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));. But I'm almost sure there is more to this. – Marius Sep 17 '13 at 07:56