Skip to content

Instantly share code, notes, and snippets.

@juque
Created November 25, 2021 19:18
Show Gist options
  • Save juque/e1567d8bf22e710701eb7d3ca630c62e to your computer and use it in GitHub Desktop.
Save juque/e1567d8bf22e710701eb7d3ca630c62e to your computer and use it in GitHub Desktop.
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