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
Bootic.require([ 'Util' ], function(util){ | |
var ajax = util.ajax, | |
buttonAsyncProducts = document.querySelector('.load-async-products'), | |
target = document.querySelector('.async-list > div'); | |
buttonAsyncProducts.addEventListener('click', function(e){ | |
var res = ajax('get', '/partials/custom-list-products', e.target.dataset, function(code, body){ |
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
... | |
payload = { | |
name: "Descuento para #{product.title}", | |
discount_type: 'fixed', | |
tiers: [ | |
{from: 5, to: 9, value: 1900}, | |
{from: 9, to: nil, value: 2500} | |
] | |
} | |
... |
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
shop = root.shops.first | |
# Buscamos el producto por su slug | |
product = shop.product(id: 'shinola') | |
# Se configura | |
payload = { | |
name: "Descuento para #{product.title}", | |
discount_type: 'percentage', | |
tiers: [ |
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
{ | |
"_actions": { | |
"search": { | |
"fields": [ | |
{ | |
"name": "page", | |
"options": null, | |
"prompt": "page number", | |
"value": null | |
}, |
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
Rails.application.routes.draw do | |
match '/auth/:provider/callback', to: 'session#create', via: [:get, :post] | |
get '/auth/logout', to: 'session#destroy', as: :logout | |
get '/dashboard', to: 'dashboard#index' | |
get 'session/create' | |
get 'dashboard/index' | |
get 'welcome/index' | |
root to: 'welcome#index' |
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
<h1>Dashboard#index</h1> | |
<p><a title="Salir" href="/auth/logout">Logout</a></p> | |
<h2>Pedidos recientes</h2> | |
<ul class="orders_list"> | |
<% @orders.each do |order| %> | |
<li class="order status_<%= order.status %>"> | |
<h3><%= order.code %></h3> | |
<span class="total"><%= order.net_total %></span> |
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
<h1>Welcome#index</h1> | |
<p><a href="/auth/bootic">Login</a></p> |
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
class DashboardController < ApplicationController | |
before_action :login_required | |
def index | |
@orders = if current_shop.has?(:orders) | |
current_shop.orders(sort: 'updated_on.desc') | |
else | |
[] | |
end | |
end |
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
class SessionController < ApplicationController | |
def create | |
session[:access_token] = request.env['omniauth.auth']['credentials']['token'] | |
session[:user_name] = request.env['omniauth.auth']['info']['name'] | |
flash[:notice] = "Welcome!" | |
redirect_to dashboard_index_url | |
end | |
def destroy | |
session.delete :access_token |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery with: :exception | |
def logged_in? | |
session[:access_token].present? | |
end | |
def bootic_client | |
@bootic_client ||= BooticClient.client(:authorized, access_token: session[:access_token]) do |new_token| | |
Rails.logger.info "Renewed access token" |