Shopify如何通过API创建价格规则
问题描述:
我是新来的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
然而,它总是返回我的假。如果有人有这个想法?太感谢了!
答
对于那些来到这个问题,我们可以取价规则,每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)