Skip to content

Instantly share code, notes, and snippets.

@aatronco
aatronco / gist:11d1e7eb3b9cf3762d26e292db496065
Created January 29, 2025 22:30
Search adjustment for Chilean pharmacies in jumpseller
# Making Pharmacies Smarter in Jumpseller: Custom Fields & Bioequivalents
In Chile, pharmacies are legally required to **show the cheapest bioequivalent medications first** in search results. Makes sense, right? Why push people to pay more when there’s a perfectly good alternative?
Now, **Jumpseller doesn’t do this by default**—but we can fix that using **Custom Fields**. The problem? Well... our custom fields setup is a bit like talking to a robot. Ever seen code like `field[0]`? Yeah, super intuitive. Thanks, past developers.
But don’t worry—I’ll guide you through **how to add bioequivalents** and **make sure they show up first** in search results, while still keeping Jumpseller’s original search logic intact.
---
/*
$(function() {
fetch("/geocoder/ip", {
method: "get"
}).then(function (response) {
if (response.ok) {
return response.json().then(function(json) {
var country_code = json["country_code"];
switch(country_code) {
<script>
$(document).ready(function() {
// Get the variant_id from the parameter
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('variant_id')) {
const variant_id = urlParams.get('variant_id')
console.log('-------> '+variant_id)
var update_function = function(data) {
const coupon = "ABCDEFG"
var coupons = function(){
i("#payments_options input:checked").val() == 362229 ? Jumpseller.addCouponToCart(coupon , {callback: alert("Cupon Agregado")}) : Jumpseller.removeCouponFromCart(coupon, {callback: alert("No hay cupon")}) ;
}
$("#checkout").submit(coupons);
function cleanEstimates() {
// remove all prices and errors
$('#shipping_options li').each(function() {
$(this).children().last().detach();
});
// add empty messages - placeholders
$('#shipping_options li').each(function() {
$(this).append('<span></span>')
});
}
let products = [7966034,7966035]; // Add products IDs here
// This may take a while, so it's better to create a loader
var setLoading = function(par){if(par){console.log("Inicio")}else{console.log("Inicio")}}
setLoading(true);
const addListToCart = (index, quantity) => {
if(index < products.length){
product = products[index];
Jumpseller.addProductToCart(product, quantity, {}, {callback: addListToCart(++index,quantity)})
}
<script>
// Define all codes from many promotions
const coupons = ["cupon1", "cupon2", "cupon3"]
//Callback that returns all coupons in cart
var callback_added = function(data) {
console.log(data.coupons)
}
// Callback that searches intersections between the codes in cart and the promotional codes.
<script>
const shipping_method_id = 1234556 // id of free shipping option
const normal_shipping = 654321 // id of normal shipping option
const municipalities_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
const products_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
var conditions = function() {
// certain product is in the cart and certain municipalities are selected. The work is to construct this function
}
var callbackFunction = function() {
console.log("Coupon " + discount + " added")
}
var add_url_coupon = function() {
queryString = window.location.search;
urlParams = new URLSearchParams(queryString);
if (urlParams.has('discount')) {
discount = urlParams.get('discount')
Jumpseller.addCouponToCart(discount, {
@aatronco
aatronco / open_variant_from_url_parameter.js
Created March 17, 2021 20:05
Chooses al of the options from a product URL containing the variant_id parameter in Jumpseller
$(document).ready(function() {
// Get the variant_id from the parameter
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('variant_id')) {
const variant_id = urlParams.get('variant_id')
var update_function = function(data) {
// Find the variant
active_variant = data.variants.find(item => item.id == variant_id)