2

Now this is the sort of problem I would help others with but I am flummoxed. I am creating new categories in an import routine, e.g.

$this->magObject = Mage::getModel("catalog/category");
$this->magObject->setName($item["name"]);
$this->magObject->setData("agilityId",$item["id"]);
$this->magObject->setIsActive($this->isActive);
$this->magObject->setIsAnchor($this->isAnchor);
$this->magObject->setPageLayout($this->pageLayout);
$this->magObject->setStoreId(Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID)); 
//$this->magObject->setPath ("1/2/6") ); //actually got by getting path of specific required parent
$this->magObject->save();

Without the setPath it saves fine, but with the wrong path (obviously). When the setPath is included, nothing happens. I know that there are devious magento elements at work that prevent writing to _entity tables unless certain circumstances are met but I thought I was meeting them . I am already performing the usual

define("ADMIN_STORE_ID",1);
//...
Mage::app();
Mage::setIsDeveloperMode(true);
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

at the start but in this instance it just is not working. I have similar scripts on other sites that do work. Only difference with this site is that there are multiple store fronts

3 UK
7 Spanish
5 German
6 French
1 Default Store View

Anyone spot something obvious that I am missing, whilst I still have some hair left?

Oh this is using Magento 1.9.1.1.

  • Oddly though, I can set the attributeSetId....which works and is still in the entity table – Jon Holland Jul 31 '15 at 9:00
  • ->setParentId(6) does not work either. – Jon Holland Jul 31 '15 at 9:18
1

You are not supposed to set the path. This is calculated based on the parent. Same goes for the level.
Instead you should set the parent id.

So you can do this:

$this->magObject = Mage::getModel("catalog/category");
$this->magObject->setName($item["name"]);
$this->magObject->setData("agilityId",$item["id"]);
$this->magObject->setIsActive($this->isActive);
$this->magObject->setIsAnchor($this->isAnchor);
$this->magObject->setPageLayout($this->pageLayout);
$this->magObject->setStoreId(Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID)); 
$this->magObject->setParentId(2);
$this->magObject->save();
  • I have tried setParentId(6) and that has the same non effect, it comes out as 0 and the path is just the id of the new cat – Jon Holland Jul 31 '15 at 9:07
  • on other sites I have successfully used ->setPath(#PARENT PATH#) but they were version 1.9.0.1 - wonder if there is a difference there – Jon Holland Jul 31 '15 at 9:13
  • I have managed to get around the problem my doing $this->magObject->move(6,null); but that doesn't really explain why it doesn't work in the first place – Jon Holland Jul 31 '15 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.