2017-10-06 118 views
0

我是新來的shopify。現在我想用shopify API來創建一個價格規則,這是我在這裏的源代碼 我用導軌5.1.4,shopify_app 8.1.0Shopify如何通過API創建價格規則

shop_url = "https://api_key:[email protected]/admin" 
ShopifyAPI::Base.site = shop_url 
prerequisite_saved_search_ids = [53677883419] 
price_rule = ShopifyAPI::PriceRule.new 
price_rule.title = "demodemo" 
price_rule.target_name = "line_item" 
price_rule.target_selection = "all" 
price_rule.allocation_method = "across" 
price_rule.value_type = "fixed_amount" 
price_rule.value = "-10.0" 
price_rule.customer_selection = "prerequisite" 
price_rule.prerequisite_saved_search_ids = prerequisite_saved_search_ids 
price_rule.start_at = Time.now.iso8601 
res = price_rule.save 
puts res 

然而,它總是返回我的假。如果有人有這個想法?太感謝了!

回答

0

請檢查此API以創建價格規則(Shopify Api)。我在php中使用了這個Api,它對我來說工作得很好。

我已經創建了應用程序,然後使用Api密鑰和密鑰來生成價格規則。

感謝

0

對於那些來到這個問題,我們可以取價規則,每shopify_app創業板的Rails應用程序爲:

首先讓你的應用程序訪問讀取初始化/ shopify /寫權限。 RB文件:

config.scope = "read_products, write_products, read_price_rules, write_price_rules" 

之後,你可以取價規則:

@price_rules = ShopifyAPI::PriceRule.find(:all, params:{id: '4171201931'}) 

而且還可以創建一個標價規定爲:

@create_price_rule = ShopifyAPI::PriceRule.new(
    price_rule: { 
     title: "FREESHIPPING2", 
     target_type: "shipping_line", 
     target_selection: "all", 
     allocation_method: "each", 
     value_type: "percentage", 
     value: "-100.0", 
     usage_limit: 20, 
     customer_selection: "all", 
     prerequisite_subtotal_range: { 
      greater_than_or_equal_to: "50.0" 
     }, 
     starts_at: "2017-11-19T17:59:10Z" 
    } 
) 
@create_price_rule.save 

有參與驗證。櫃面要檢查的響應,可以檢查它像@create_price_rule.inspect

甚至可以刪除PriceRule爲:

@price_rules = ShopifyAPI::PriceRule.find(:all).first 
@price_rules.destroy 
@last_price_rule = ShopifyAPI::PriceRule.find(4171860875)