Skip to content

Instantly share code, notes, and snippets.

View tiagomatos's full-sized avatar

Tiago Matos tiagomatos

View GitHub Profile
@tiagomatos
tiagomatos / shipping_methods_according_order.js
Created June 4, 2018 18:40
Hide/Show Jumpseller Shipping Methods according to the Order Amount.
var shipping_methods_ids = []; // 10441, 19855, 26703, 26704, 27216, 63580
// select usable shipping methods
switch(event.target.value){
case "75995":
if({{order.total}} >= 50000)
shipping_methods_ids = ['10441', '19855', '27216'];
else
@tiagomatos
tiagomatos / dhl_label.rb
Created May 3, 2018 15:51
Create DHL eCommerce Label
require 'byebug'
require 'awesome_print'
require 'httparty'
username = 'elite.track'
password = 'axwdavgo'
client_id = 35318
pickup = 1000000047
response = HTTParty.get("https://api.dhlglobalmail.com/v2/auth/access_token?username=#{username}&password=#{password}")
@tiagomatos
tiagomatos / webhooks_verification.php
Created March 28, 2018 20:13
Verify Webhooks Secret
<?php
define('HOOKS_TOKEN', 'XXXXX'); // get your token at Admin Panel > Config > Notifications / Webhooks.
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, HOOKS_TOKEN, true));
return ($hmac_header == $calculated_hmac);
}
@tiagomatos
tiagomatos / create_jsapp.rb
Created March 13, 2018 15:33
Create Javascript App in a Jumpseller App
# after the App is Authorized, the /callback route is requested.
# on the App itself, the /callback controller will:
# 1. confirm the App is authorized
# 2. save the Authorization tokens on the Database
# 3. create the Javascript App on the Store.
app.get '/callback' do
halt 403, 'Authorization denied' if authorization_denied? // App Authorization
store = find_or_create_app(
klass: model_name,
@tiagomatos
tiagomatos / post_create_product.sh
Created March 12, 2018 15:54
Create a Jumpseller Product with a Description (via API with CURL)
curl -X POST -d '{ "product" : {"name": "My new Product!", "price": 100, "description": "<p>Articulo en preventa</p><p>No depende del idioma.<p>Trepidante! Porque todos los jugadores intentan encajar las piezas en su plantilla simultaneamente"} }' "https://api.jumpseller.com/v1/products.json?login=87cf9e6326e83bfed88b8dad4fae5b41&authtoken=5c7e86d7318ba2f10b9b2b0e6291ff30" -H "Content-Type:application/json"
@tiagomatos
tiagomatos / wines_from_same_vineyard.liquid
Created March 2, 2018 16:16
Products from the same Product's Sub-Category
{% for vina_cat in store.category['vinas'].subcategories %}
{% for product_cat in product.categories %}
{% if vina_cat.id == product_cat.id %} // identify the vina category (monos)
{% assign cat = vina_cat %}
{% endif %}
{% end %}
<h2>{% t 'Wines from the same vineyard' %}</h2>
@tiagomatos
tiagomatos / centry_requests.rb
Last active February 25, 2018 12:32
Centry - Jumpseller Integration
def do_request_login(method, resource, data)
url = "#{ENV['JUMPSELLER_API_BASE_URL']}#{resource}?#{{login: integration_config.login, authtoken: integration_config.authtoken}.to_query}"
for i in 1..10 do
perform_request(method, url, data)
if resp.code >= 200 and resp.code < 300 or resp.code == 404
return resp
elsif resp.nil? or resp.code == 403 # and message "Rate Limit Exceeded"?
sleep 1.0
else
raise "Error #{resp.code}: #{resp.inspect}"
@tiagomatos
tiagomatos / select_variant_with_stock.liquid
Created February 20, 2018 12:16
Select first variant with stock
$(document).ready(function() {
var parentId;
var parentOptionCounter = 0;
$.each($(".prod-options option"), function( index, option ) {
var stock = $(option).data("variant-stock");
if(index == 0 || parentId !== $(option).parent().attr('id')){
parentId = $(option).parent().attr('id');
parentOptionCounter = 0;
}
<script type="text/javascript">
var Fn = {
// Valida el rut con su cadena completa "XXXXXXXX-X"
validaRut : function (rutCompleto) {
if (!/^[0-9]+[-|‐]{1}[0-9kK]{1}$/.test( rutCompleto ))
return false;
var tmp = rutCompleto.split('-');
var digv = tmp[1];
var rut = tmp[0];
@tiagomatos
tiagomatos / setQuantityOne.checkout.js
Created January 10, 2018 11:34
On the Jumpseller's Checkout or Cart Page, update all of each product's quantity to one.
var setQuantityOne = function(data){
$.each(data.products, function(index, item) {
//console.log(item);
Jumpseller.updateCart(item.id, 1, {});
});
};
Jumpseller.getCart({callback: setQuantityOne})