Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:56:34+00:00 2026-06-11T09:56:34+00:00

I actually can add a category via setup script, the thing is for some

  • 0

I actually can add a category via setup script, the thing is for some reason some of the fields doesn’t get set properly. Here’s is my code

$this->startSetup();
Mage::register('isSecureArea', 1);

$category = Mage::getModel('catalog/category');
$category->setPath('1/2') // set parent to be root category
    ->setName('Category Name')
    ->setUrlKey('category-name')
    ->setIsActive(0)
    ->setIncludeInMenu(1)
    ->setInfinitescroll(1)
    ->setDisplayMode('PAGE')
    ->setLandingPage($idToCmsBlock)
    ->setPageLayout('anotherLayoutThanDefault')
    ->setCustomUseParentSettings(0)
    ->setCustomLayoutUpdate('<reference name="head"><action method="addCss"><stylesheet>css/somecss.css</stylesheet></action></reference>')
->save();
$this->endSetup();

After running this script, I have a category created with all my value set in the EAVs table.
However the Flat table will be missing displayMode, landingPage, pageLayout, customLayoutUpdate even if I re-index the flat table.

The weird thing is that if I go in the admin, I can see all those fields properly set but if I go in my frontend most of those fields are ignored. I will have to go to the admin, unset those value and reset them for each of them to work properly.

Also let say I use setEnabled(1), my category will be “enable” in the admin but not show up in the frontend.

PS: I have Flat Category activated, if I disable it seems to work fine but if I re-index it still not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:56:35+00:00Added an answer on June 11, 2026 at 9:56 am

    I finally found it, I’m not sure why but those fields are not showing up properly because they were inserted for the default store (storeId=1) because my script is running in an update script. You need to use the storeId 0.

    With this information you would think that the solution would be something like :

    $this->startSetup();
    Mage::register('isSecureArea', 1);
    
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    
    $category = Mage::getModel('catalog/category');
    $category->setPath('1/2') // set parent to be root category
        ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
        ->setName('Category Name')
        ...
        ->save();
    $this->endSetup();
    

    But this code doesn’t work either. Indeed after looking into Mage::app() (Mage_Core_Model_App Line 804) I noticed a IF condition that would always return the default store if you’re in a setup script.

    The trick is to fake that you’re not in a setup script, my working solution is:

    $this->startSetup();
    Mage::register('isSecureArea', 1);
    
    // Force the store to be admin
    Mage::app()->setUpdateMode(false);
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    
    $category = Mage::getModel('catalog/category');
    $category->setPath('1/2') // set parent to be root category
        ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
        ->setName('Category Name')
        ...
        ->save();
    $this->endSetup();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually my problem is sometimes i can get the location and sometimes i can't
In Google Sheets, you can add some scripting functionality. I'm adding something for the
I am wanting to know if I can add some style to strings used
I don't think I can actually add a field (column) to an existing IEnumerable.
Actually I can save it in swf and in avi formats. Is there any
I'd like to limit what organizational items users can actually see in the CM
I want to show up only words with minimum 4 Characters, actually I can
I've recently come across this website. Now, is there any way I can actually
If my understanding is correct, you can't actually look at messages in the rabbit
I can't believe this - someone actually created two accounts on my social networking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.