【问题标题】:How to create in Magento with custom code?如何使用自定义代码在 Magento 中创建?
【发布时间】:2013-10-13 11:56:37
【问题描述】:

我正在使用此代码创建类别和子类别。此代码工作正常,但问题是我无法创建自己的类别代码。我需要它来满足需求。

$category = Mage::getModel('catalog/category');
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId().

//if update
if ($id) {
  $category->load($id);
}

$general['name'] = "My Category";
$general['path'] = "1/3/"; // catalog path here you can add your own ID
$general['description'] = "Great My Category";
$general['meta_title'] = "My Category"; //Page title
$general['meta_keywords'] = "My , Category";
$general['meta_description'] = "Some description to be found by meta search robots. 2";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['page_layout'] = 'two_columns_left';

//$general['url_key'] = "cars";//url to be used for this category's page by magento.
//$general['image'] = "cars.jpg";


$category->addData($general);

try {
    $category->setId(255); // Here you cant set your own entity id
    $category->save();
    echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
    echo $e->getMessage();
}

我试图做这样的事情:

$general['id'] = $myCustomId;

但它不起作用。

【问题讨论】:

    标签: magento import categories


    【解决方案1】:

    key需要映射列头,即entity_id。因此,将 $general['id'] 更改为

    $general['entity_id'] = $myCustomId;

    【讨论】:

      猜你喜欢
      • 2015-05-27
      • 2023-01-18
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      相关资源
      最近更新 更多