2

我正在尝试使用Magentor gem。文档非常薄弱。我成功调用了Magento::Category.info(1)

但我没有打电话Magento::Category.create(args)

方法定义如下。

  # catalog_category.create
  # Create new category and return its id.
  # 
  # Return: int
  # 
  # Arguments:
  # 
  # int $parentId - ID of parent category
  # array $categoryData - category data ( array(’attribute_code’⇒‘attribute_value’ )
  # mixed $storeView - store view ID or code (optional)
  def create(attributes)
    id = commit("create", attributes)
    record = new(attributes)
    record.id = id
    record
  end

这是我尝试过的。(父ID为1)

args = [1, {:name => 'Cars', :description => 'Great Cars', :is_active => '1', :url_key => 'cars'}]
category_id = Magento::Category.create(args)

exception: 1 -> SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

任何人都可以提供调用该方法的示例吗?

4

1 回答 1

1

我联系了 gem 开发人员并得到了以下回复。一个好人。


你好山姆,

对稀疏的文档感到抱歉。我们很快就创建了这个库,并且在我们正在处理的项目中只使用了一小部分 api。

看起来库中的 create 调用没有正确传递数据。这是一种解决方法:

parent_id = 1
attributes =  {
  :url_key=>"cars", 
  :description=>"Great Cars", 
  :name=>"Cars", 
  :is_active=>"1", 
  :available_sort_by => "Name", 
  :default_sort_by => "Name",
  :include_in_menu => '1'
}
category_id = Magento::Category.commit("create", parent_id, attributes)

我还将对正确使用 parent_id 的 github 进行修复。

谢谢,-普雷斯顿

于 2012-11-05T23:37:33.323 回答