Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created October 2, 2018 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/58457ee5debf3b8cd0a1f07d48b52474 to your computer and use it in GitHub Desktop.
Save ismasan/58457ee5debf3b8cd0a1f07d48b52474 to your computer and use it in GitHub Desktop.
# Carga el producto
product = shop.product(id: variante_bsale[“booticProductId”])
# revisa si ya existe una variante con el nombre
variante_existente = product.variants.find{|v| v.title == nombre_variante }
# si ya existe, actualízala
if variante_existente
variant = variante_existente.update_variant(
sku: variante_bsale[‘code’],
stock: variante_bsale[‘quantityAvailable’],
avaiable_if_no_stock: siempre_disponible
)
# si no, créala
else
variant = product.create_variant(
title: nombre_variante,
sku: variante_bsale[‘code’],
stock: variante_bsale[‘quantityAvailable’],
avaiable_if_no_stock: siempre_disponible
)
end
# revisa errores
if variant.has?(:errors)
# maneja errores
else
# todo bien
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment