2017-10-06 6 views
0

私は新しいものを購入しました。今、私は価格ルールを作成するshopify APIを使用したい、これは私はそれは常に私がfalseを返すただしレール5.1.4、shopify_app 8.1.0APIを使用して価格ルールを作成する方法を見てください

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

価格ルール(Shopify Api)を作成するには、このApiをチェックしてください。私はPHPでこのApiを使用し、私にとってはうまく動作しています。

私はAppを作成し、価格ルールを生成するためにApiキーと秘密鍵を使用しました。

おかげで、この質問に来るもののため

0

は、一つはRailsアプリケーションのためのshopify_app宝石のとおりと価格ルールを取得できます。

まず、あなたのアプリが初期化子/ 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 

が関与検証があります。あなたが応答を確認したい包み、1は@create_price_rule.inspect

のようにそれを検査することができる、あるいは、あなたはとしてPriceRuleを削除することができます。

@price_rules = ShopifyAPI::PriceRule.find(:all).first 
@price_rules.destroy 
@last_price_rule = ShopifyAPI::PriceRule.find(4171860875) 
関連する問題