Created
November 25, 2021 19:18
-
-
Save juque/e1567d8bf22e710701eb7d3ca630c62e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shop = root.shops.first | |
# Buscamos el producto por su slug | |
product = shop.product(id: 'shinola') | |
# Se configura | |
payload = { | |
name: "Descuento para #{product.title}", | |
discount_type: 'percentage', | |
tiers: [ | |
{from: 5, to: 9, value: 5}, | |
{from: 9, to: 15, value: 8} | |
] | |
} | |
# Se crea el descuento por volumen | |
res = shop.create_volume_discount(payload) | |
# Hubo problemas, mostramos errores | |
if res.has?(:errors) | |
puts res.to_hash | |
# Todo bien: ahora asociamos el descuento al producto | |
else | |
product.update_product(volume_discount_id: res.id) | |
puts "done" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment