Search adjustment for Chilean pharmacies in jumpseller

Alejandro Troncoso
2025-01-29T22:30:41Z

gistfile1.txt

| # 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.
|
| ---
|
| ## 1. Add Custom Fields to Products
|
| First, you need to **manually add a custom field** to each product:
| - **Label:** `bioequivalent`
| - **Value:** A comma-separated list of **permalinks** for bioequivalent products, **ordered from cheapest to most expensive**.
|
| ### Example:
| For an expensive **brand-name drug**, set:
| - **Custom Field (`bioequivalent`) → Value:** `generic-med1, generic-med2, generic-med3`
|
| This way, when someone searches for the brand-name drug, we **sneak in the cheaper options first** before showing the expensive one.
|
| ---
|
| ## 2. Modify the Search Results Template
|
| Now comes the fun part: **hacking Jumpseller’s Liquid template** to make this work.
|
| The logic:
| 1. Go through **each product in the search results**.
| 2. If a product has the `bioequivalent` field, grab its **cheaper alternative products** and **display them first**.
| 3. Then, and **only then**, show the original product.
| 4. Move on to the next product and repeat.
|
| ### Updated Liquid Code:
| ```liquid
| {% for product in search.results %}
| {% assign bioequivalents = "" | split: "," %}
|
|
| {% for field in product.custom_fields %}
| {% if field[0] == "bioequivalent" %}
| {% for custom_field_value in field[1] %}
| {% assign bioequivalents = custom_field_value.value | split: ',' %}
| {% endfor %}
| {% endif %}
| {% endfor %}
|
|
| {% for bioequ in bioequivalents %}
| {% assign bio_product = products.product[bioequ] %}
| {% if bio_product %}
|
| {{ bio_product.name }}
| Price: {{ bio_product.price | money }}
| View Product
|
| {% endif %}
| {% endfor %}
|
|
|
| {{ product.name }}
| Price: {{ product.price | money }}
| View Product
|
| {% endfor %}