如何使用Magentor gem

时间:2012-11-05 18:53:05

标签: ruby magento

我正在尝试使用Magentor宝石。文档非常薄弱。我成功地打电话给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)

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

1 个答案:

答案 0 :(得分:1)

我联系了宝石开发者,得到了以下回复。一个好人。


山姆,

对于稀疏文档感到抱歉。我们很快就创建了这个库,并且只在我们正在开发的项目中使用了一小部分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)

我还会提交一个修复github,正确地获取parent_id。

谢谢, -preston