2

マゼンタの宝石を使おうとしています。ドキュメントは非常に弱いです。呼び出しに成功しました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 に答える