ruby - 如何使用 Magentor gem

标签 ruby magento

我正在尝试使用 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)

谁能提供一个调用方法的例子?

最佳答案

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


嗨,山姆,

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

库中的创建调用似乎没有正确传递数据。这是一个解决方法:

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。

谢谢, -普雷斯顿

关于ruby - 如何使用 Magentor gem ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13238453/

相关文章:

ruby-on-rails - 从字符串中删除单词时,正则表达式会比遍历单词列表更快吗?

ruby-on-rails - 无论大小写如何查找所有记录

ruby-on-rails - 在 ubuntu 上安装 Rails - 错误 : Failed to build gem native extension

php - 在 Magento 安装期间哪些文件被更改

php - 如何在 Magento 中翻译产品名称和信息

magento-1.7 - magento 通知 : Array to string conversion lib\Varien\Data\Form\Element\Image. php 第 57 行

ruby - 寻找 "real"使用延续的例子

ruby - 在 Ruby 中,是否有更好的方法来执行 class_eval() 来提取类变量?

php - 在 magento 中更改产品类型

php - Magento 文件夹更改