Monday, January 2, 2012

Export Categories Magento

 <?php
  //Export Categories Magento
//Upload this file in root and access from url.
//Exported file will be stored in var/import

    define('MAGENTO', realpath(dirname(__FILE__)));
    require_once MAGENTO . '/app/Mage.php';
    Mage::app();

    $category = Mage::getModel ( 'catalog/category' );
    $tree = $category->getTreeModel ();
    $tree->load ();

    $ids = $tree->getCollection ()->getAllIds ();

    if ($ids) {
        $file = "var/import/catwithid.csv";
        file_put_contents($file,"catId, catName\n");
        foreach ( $ids as $id ) {
          $string = $id . ', ' .$category->load($id)->getName() . "\n";
            file_put_contents($file,$string,FILE_APPEND);
        }
    }
   
    ?>

21 comments:

  1. category_id , i can't get it.because i create Category Import / Export Extension module.

    public function setcategoryid($row)
    {
    $collection = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('level');
    $collection = $this->addAttributesToSelect($collection);
    $collection->getSelect()->order('level');

    $Ids = $collection->getAllIds();
    foreach ($Ids as $id)
    {

    }
    return implode('/',$Ids );


    }

    above code at foreach, i cant know how get category_id to write to csv file.
    can you help me?

    ReplyDelete
    Replies
    1. Hi truongngoc,
      if you wish i can provide you complete module for categories export and import.
      for this you can put your request here with your email id .
      Thanks

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. my email :phongdevelopers@gmail.com thank alot Afroz Alam

    ReplyDelete
    Replies
    1. I have sent you my categories import/export module by mail. Please revert back if you have any issue.

      Delete
  4. thanks for replying, Afroz Alam. this is my gmail address : truongvietngocl@gmail.com . Please send to me your complete module import/export.thank you vary much, Afroz Alam. I am nice to know you! good luck, wish best for you,Afroz Alam.

    ReplyDelete
    Replies
    1. I have sent you my categories import/export module by mail to your email id. Please revert back if you have any issue.

      Delete
    2. hi Afroz Alam, thank you for sending your module to me. but now i have another issue, can you help me, in import/export product by csv file. with category_ids attribute must input is its ID, but i want to input path of category, not category_ids. so you can suggest to me that issue. you have seen that issue before?
      thank you in advance, Afroz Alam!

      Delete
  5. hello Afroz, can you please send me the module to my email? saziine@hotmail.com

    ReplyDelete
    Replies
    1. I have sent you the required module. Please check your mail.

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hi Afroz, can you please send me the module to my email? alexrunner1@gmail.com
      Thanks

      Delete
  7. Hi Afroz, can you please send me the module to my email? alexrunner1@gmail.com...Thanks

    ReplyDelete
  8. Hi Afroz, can you please send me the module also to my email? verkoop88@live.nl..........Many thanks

    ReplyDelete
  9. can you send me this module?:) reganck@o2.pl :) Thanks!

    ReplyDelete
  10. hello
    i have to import category in magento
    its in tree structure
    eg:
    Clothing & Accessories/Baby/Baby Boys/Bodysuits
    Clothing & Accessories/Baby/Baby Boys/Bottoms/Shorts

    help mee

    ReplyDelete
    Replies
    1. Hi Shweta
      Can you provide your email so i can assist better.

      Delete
  11. HI Afroz
    can u send me that extension please.

    ReplyDelete
  12. my email ID vaibhav16singh@gmail.com

    ReplyDelete
  13. The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
    magento development company in bangalore 

    ReplyDelete