2012-11-05 58 views
2

我正在嘗試使用Magentor寶石。文檔非常薄弱。我成功地致電Magento::Category.info(1)如何使用Magentor寶石

但我沒有打電話給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) 

誰能提供調用該方法的一個例子嗎?

+0

看起來像一個有趣的項目。生成的rdoc實際上看起來比我預期的要好得多。 – pguardiario

回答

1

我聯繫了寶石開發人員,並得到了以下回復。一個好人。


薩姆嗨,

對不起稀疏文件。我們很快創建了這個庫,只在我們正在開發的項目中使用了一小部分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。

感謝, -preston