Created
October 2, 2018 13:43
-
-
Save ismasan/58457ee5debf3b8cd0a1f07d48b52474 to your computer and use it in GitHub Desktop.
This file contains 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
# 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