Skip to content

Instantly share code, notes, and snippets.

Ismael Celis ismasan

Block or report user

Report or block ismasan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View parametric_nullable_types.rb
Parametric.policy(:nullable_integer) do
PARAMETRIC_INT_EXP = /^\d+$/.freeze
coerce do |value, _key, _context|
if value.to_s =~ PARAMETRIC_INT_EXP
value.to_i
else
nil
end
end
@ismasan
ismasan / validations_for.rb
Created Jun 26, 2019
Declarative AM validations depending on arbitrary attributes
View validations_for.rb
# class Page
# include ValidationsFor
#
# validations_for page_type: 'offer' do
# validates :amount, presence: true
# end
#
# validations_for page_type: 'page' do
# validates :title, presence: true
# end
View inventory_control.mkd

Bodegas default

Para integrar ecommerce <-> inventario.

  • world
  • ecommerce
  • sales
done evento Bootic Transferencia de inventario
View _unit_price.html
{% if product.has_multiple_prices or product.price.positive %}
<span class="bootic-price">{{ product.price.format }}</span>
<span class="bootic-price-comparison-box" style="display: {% if product.has_price_comparison %}inline-block{% else %}none{% endif %}">
<span class="bootic-price-comparison-label">{{ 'products.price_comparison_label' | t }}</span>
<strike class="bootic-price-comparison">
{% if product.has_price_comparison %}
{{ product.price_comparison.format }}
{% endif %}
</strike>
View crea_o_actualiza_variante.rb
# 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 Sep 28, 2018
Download all product images for a Bootic shop
View images.rb
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)
View object_mapper.js
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 Mar 8, 2018
Importa imágenes desde una directorio a productos con el mismo nombre
View bootic_images_upload.rb
# 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
View csv_import_example.mkd

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
View ioc_container.rb
# 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
You can’t perform that action at this time.