Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Bulk upload category using SQL
 
roots
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-04-23
Dallas, TX
 

Example of category:
Engine (10) > Clutches (~200) > ACT Heavy Duty Clutches(~5000)
Number of category are distributed among the parent category.

I have these categories and the relation with the parent already in the separate database. I am trying to upload these first to persist the category ids and use them for the product upload later. I hope i can concentrate on following tables to achieve this.

catalog_category_entity : Main entity entry
catalog_category_entity_datetime : What is this used for ??
catalog_category_entity_decimal :
catalog_category_entity_int
catalog_category_entity_text
catalog_category_entity_varchar
catalog_category_product : Association with the products

the _entity_decimal , int .. . should have similar convention. If you know such docs please share.

I am looking other posts as well.
I would appreciate any pointer or hints on this topic.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenix
Jr. Member
 
Total Posts:  23
Joined:  2008-02-18
 

Why not use import profiles in admin->system->import/export?

bit slow at the moment but give this a try first I recomend.

 
Magento Community Magento Community
Magento Community
Magento Community
 
roots
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-04-23
Dallas, TX
 

Thanks you,
.. but is it possible to import the category structure from export/import… it has only Product and Customers and requires category id for products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
roots
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-04-23
Dallas, TX
 

The EAV model of the database is understood ..

entity_id - UID
entity_type_id - Type of entity (9 for category) ?? Is there any specs/docs for this ??
attribute_set_id - ???
parent_id - For category hirerarchy
created_at - Time stamp
updated_at - Time stamp
is_active - status
path - 1/3/18/4 ?? What does these 1, 3 , 18 ..
position - Is this ranking ?? how is this used

value_id - UID for value entry
entity_type_id -?? May be it is way of associating with entity .. both share 9 in case of category
attribute_id - Type of attribute in system , Any specs ??
store_id - Used to seperate data between the stores ..
entity_id - Entity it is related to
value - The value

These are my guess .. Any one expert on this, please advise me on this ..

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
roots
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-04-23
Dallas, TX
 

Can some one please clear me on “eav_entity_attribute” table and it’s uses.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
desiboyz
Jr. Member
 
Total Posts:  4
Joined:  2008-03-30
 

Hi,

I have created a backend method of adding Attributes and Categories to Magento. Here is my code for both:

For adding Attributes:

$values = array('Attribute 1''Attribute 2''Attribute 3');
  
  foreach (
$values As $value)
  
{
    $data[] 
= array (
      
'entity_type_id'    =>    '4',
      
'attribute_code'    =>    RemoveSpaceNonCharacters($value), /* NOTE: I would check to see if this value is duplicate or not */
      
'attribute_model'    =>    '',
      
'backend_model'        =>    '',
      
'backend_type'        =>    'text'/* varchar */
      
'backend_table'        =>    '',
      
'frontend_model'    =>    '',
      
'frontend_input'    =>    'textarea'/* text */
      
'frontend_label'    =>    $value,
      
'frontend_class'    =>    '',
      
'source_model'        =>    '',
      
'is_global'            =>    '0',
      
'is_visible'          =>    '1',
      
'is_required'          =>    '0',
      
'is_user_defined'    =>    '1',
      
'default_value'        =>    '',
      
'is_searchable'        =>    '0',
      
'is_filterable'        =>    '0',
      
'is_comparable'        =>    '0',
      
'is_visible_on_front'    =>    '1',
      
'is_unique'            =>    '0',
      
'is_configurable'    =>    '1',
      
'apply_to'            =>    '',
      
'position'            =>    '1',
      
'note'                   =>    '',
      
'is_visible_in_advanced_search'    =>    '1'
    
);
  
}
  
      
foreach ($data As $field => $value)
      
{
        $fields[] 
$field;
        
$values[] "'" .mysql_real_escape_string($value$link) ."'";
      
}
      $fields 
implode(","$fields);
      
$values implode(","$values);
      
      
MYSQL_QUERY("BEGIN");
      
      
$query "INSERT INTO eav_attribute ($fields) VALUES ($values)";
      
$resultmysql_query($query$link);
      
$attributeID mysql_insert_id($link);
      
      
//attribute_group_id is the ID from eav_attribute_group. In this case, I created my own custom attribute group.
      
$query "SELECT MAX(sort_order) AS cnt FROM eav_entity_attribute WHERE attribute_group_id=30";
      
$resultmysql_query($query$link);
      
$cnt intval(@mysql_result($result0'cnt')) + 1;    
      
      
$query "INSERT INTO eav_entity_attribute VALUES 
                (null, 4, 4, 30, 
$attributeID$cnt)";
      
$resultmysql_query($query);
      
      
MYSQL_QUERY("COMMIT");

  function 
RemoveSpaceNonCharacters($oldString)
  
{
      $newString 
strtolower(ereg_replace("[^A-Za-z0-9]""_"$oldString));
  
      return 
$newString;
  
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

For adding Attributes, Magento already provides a method.

Create an instance of Mage_Eav_Model_Entity_Setup class and use its method addAttribute() to add one.

Here is a short snippet:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute($entityTypeId$code$attr);

$attr is an array containing Attribute elements (like frontend and backend model, default value, etc.)

For details look at the sourcecode:

\app\code\core\Mage\Eav\Model\Entity\Setup.php

However, I haven’t been able to find similar method to use for creating categories. Any help would be appriciated.

Sincerely,

Bojan Hrnkas

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

Ok, here is how you can add a category using Magento API:

// initialize magento environment for 'default' store
  require_once 'app/Mage.php';
  
Mage::app('default');

  
//get a new category object
  
$category Mage::getModel('catalog/category');
  
$category->setStoreId(0); //default/all
  
  //if update
  
if ($id{
    $category
->load($id);
  
}
  
  $general[
'name'"Cars";
  
$general['path'"1/3"// 1/3 is root catalog, form can be "1/3/14/23", where 23 is the parent of the new category
  
$general['description'"Great new cars";
  
$general['meta_title'"Cars"//Page title
  
$general['meta_keywords'"car, automobile";
  
$general['meta_description'"Some description to be found by meta search robots.";
  
$general['landing_page'""//has to be created in advance, here comes id
  
$general['display_mode'"PRODUCTS_AND_PAGE"//static block and the products are shown on the page
  
$general['is_active'1;
  
$general['is_anchor'0// What is anchor? I couldn't see any difference when I enable this.
  
$general['url_key'"cars";//url to be used for this category's page by magento.
  
  
  
$category->addData($general);

  try 
{
      $category
->save();
      echo 
"Success! Id: ".$category->getId();
  
}
  
catch (Exception $e){
      
echo $e->getMessage();
  
}

I hope this helps someone…

Greets!

Bojan Hrnkas

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenix
Jr. Member
 
Total Posts:  23
Joined:  2008-02-18
 

Thank you very much!

This solved one of my problems, I have to add many categories. This way wil go much quicker,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

Glad to help!
I think I know now what the ‘Anchor’ setting is. When a category is anchor, all subcategories use the image of the anchor category, instead of its own.
Please correct me if I am wrong.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenix
Jr. Member
 
Total Posts:  23
Joined:  2008-02-18
 
Bojan Hrnkas - 09 May 2008 01:20 AM

Glad to help!
I think I know now what the ‘Anchor’ setting is. When a category is anchor, all subcategories use the image of the anchor category, instead of its own.
Please correct me if I am wrong.

Anchor had to do something with the layered navigation,. But don’t know exactly what.

 
Magento Community Magento Community
Magento Community
Magento Community
 
slinky66
Jr. Member
 
Total Posts:  2
Joined:  2009-10-16
 

This is great! Thanks. Can someone explain what “14” represents in this string?
I understand that: 1/3 = root catalog and that
23 = parent of the new category.
What does 14 represent? Thanks

$general[’path’] = “1/3”; // 1/3 is root catalog, form can be “1/3/14/23”, where 23 is the parent of the new category

Bojan Hrnkas - 08 May 2008 02:09 AM

Ok, here is how you can add a category using Magento API:

// initialize magento environment for 'default' store
  require_once 'app/Mage.php';
  
Mage::app('default');

  
//get a new category object
  
$category Mage::getModel('catalog/category');
  
$category->setStoreId(0); //default/all
  
  //if update
  
if ($id{
    $category
->load($id);
  
}
  
  $general[
'name'"Cars";
  
$general['path'"1/3"// 1/3 is root catalog, form can be "1/3/14/23", where 23 is the parent of the new category
  
$general['description'"Great new cars";
  
$general['meta_title'"Cars"//Page title
  
$general['meta_keywords'"car, automobile";
  
$general['meta_description'"Some description to be found by meta search robots.";
  
$general['landing_page'""//has to be created in advance, here comes id
  
$general['display_mode'"PRODUCTS_AND_PAGE"//static block and the products are shown on the page
  
$general['is_active'1;
  
$general['is_anchor'0// What is anchor? I couldn't see any difference when I enable this.
  
$general['url_key'"cars";//url to be used for this category's page by magento.
  
  
  
$category->addData($general);

  try 
{
      $category
->save();
      echo 
"Success! Id: ".$category->getId();
  
}
  
catch (Exception $e){
      
echo $e->getMessage();
  
}

I hope this helps someone…

Greets!

Bojan Hrnkas
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top