Last active
November 1, 2017 12:15
-
-
Save ismasan/310d8846e4b9543f397abf1d4157d5fe to your computer and use it in GitHub Desktop.
Ejemplo resolviendo conflicto de nombres al crear producto en API Bootic
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
datos = shop.create_product( | |
title: ‘un nombre que ya existe’, | |
price: 1234, | |
_policies: { | |
ensure_unique: ‘title’ | |
} | |
) | |
if datos.has?(:errors) | |
if datos.has?(:current_entity) | |
# hubo un conflicto con el título. datos.current_entity es el producto existente en Bootic | |
actualizar_bsale(datos.current_entity) | |
# current_entity es un producto completo, incluyendo el link #update_product() | |
# se puede usar para actualizar el producto existente en Bootic | |
datos = datos.current_entity.update_product(price: 1234) | |
else | |
# hubo algún otro tipo de error (validaciones, variantes, etc) | |
end | |
else | |
# todo bien aquí. El producto fue creado sin conflictos. | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment