Created
January 29, 2025 22:30
-
-
Save aatronco/11d1e7eb3b9cf3762d26e292db496065 to your computer and use it in GitHub Desktop.
Search adjustment for Chilean pharmacies in jumpseller
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
# 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: "," %} | |
<!-- Oh look, here comes the clunky custom field structure --> | |
{% 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 %} | |
<!-- Show Bioequivalent Products First --> | |
{% for bioequ in bioequivalents %} | |
{% assign bio_product = products.product[bioequ] %} | |
{% if bio_product %} | |
<div class="product"> | |
<h2>{{ bio_product.name }}</h2> | |
<p>Price: {{ bio_product.price | money }}</p> | |
<a href="{{ bio_product.url }}">View Product</a> | |
</div> | |
{% endif %} | |
{% endfor %} | |
<!-- Now, show the original product (because we HAVE to) --> | |
<div class="product"> | |
<h2>{{ product.name }}</h2> | |
<p>Price: {{ product.price | money }}</p> | |
<a href="{{ product.url }}">View Product</a> | |
</div> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment