Skip to content

Instantly share code, notes, and snippets.

View ismasan's full-sized avatar

Ismael Celis ismasan

View GitHub Profile
# 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’],
@ismasan
ismasan / images.rb
Last active September 28, 2018 14:09
Download all product images for a Bootic shop
require 'open-uri'
require 'fileutils'
## USAGE
# S=<subdominio> bootic runner images.rb
#
subdomain = ENV.fetch('S')
s = root.all_shops(subdomains: subdomain).first
prs = s.products(status: 'all').full_set
shop_dir = File.join(".", subdomain)
var sys = require('util');
function value (obj, path) {
var segments = path.split('/')
if(segments[0] == '') segments = segments.slice(1)
return segments.reduce(function (memo, segment) {
return (typeof memo == 'object') ? memo[segment] : {}
}, obj)
}
@ismasan
ismasan / bootic_images_upload.rb
Last active March 8, 2018 16:04
Importa imágenes desde una directorio a productos con el mismo nombre
# asume un directorio ./imgs/ junto a este script
# correr con
# SUBDOMAIN=acme bootic runner bootic_images_upload.rb
# sólo importa a productos con este tag
TAG = 'import20171115'.freeze
def errors(errs)
errs.map{|e| [e.field, e.messages.first].join(': ')}
end

Planilla productos.xlxs

title                | vendor      | price   | price_comparison  | weight_in_grams  | status   | product_type   | variant     | sku | stock | available_if_no_stock
---------------------|-------------|---------|-------------------|------------------|----------|----------------|-------------|-----|-------|------------------
Zapatillas de fútbol | Adidas      | 1000    | 1200              | 300              | visible  | Calzado        | 39          | ABC | 10    | true
# Simple thread-safe IoC container
# Example
#
# DEPS = Container.new
# # db singleton is lazily initialized if needed
# DEPS.register(:db) do
# require 'sequel'
# Sequel.connect ENV.fetch('DATABASE_URL')
# end
# database-backed repo depends on :db
require 'typhoeus'
require 'json'
require 'base64'
require 'fileutils'
# theme = GithubTheme.new(
# repo_url: "https://api.github.com/repos/bootic/theme_gallery/contents/snap",
# credentials: "user:token"
# )
# puts 'TEMPLATES'
order_code = 'ABCXXX'
variant_id = 123
variant_units = 3 # unidades a agregar
# encuentra pedido existente
order = shop.order(id: order_code) # si no existe, creamos una nueva
# construimos un array de line_items
# a partir de los items del pedido existente
# si es que la variante que queremos agregar
@ismasan
ismasan / bootic_product_conflict_resolution.rb
Last active November 1, 2017 12:15
Ejemplo resolviendo conflicto de nombres al crear producto en API Bootic
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)
FROM ruby:2.3.1
MAINTAINER Ismael Celis "ismael@bootic.net"
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev apt-transport-https apt-utils
RUN apt-get install -y mysql-client
# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev
# for a JS runtime
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -