Hi !
I’m acutally evaluating a migration from Magento to Shopify, and here’s my first problem.
In a Magento ecosystem, I’ve the ability to create php helpers to do “things”. I’m actually trying to find a way to add pre-order functionnality for products.
I tried many preorder apps, and all have the same problem: apps code occurs after the render of the page. Their behaviour is to change the button label of the “add to cart” button and hide the “buy now” button with Javascript code. The side effect is there’s a short time where “add to cart”/“buy now” are visible and clickable.
In Magento, what I did is modifying the template file by using my own helper with something like that :
if Myhelper::isPreorder(product)
echo “pre order”
else
echo “add to cart”
The important part is that code is executed on the server side.
Another important thing is I don’t want a metafield “is_preorder” with true/false state. I want a metafield “preorder_date” to be a real date. My function should test in real time If a product is a preorder by testing the current date. With that system, I don’t have to change anything the day of the end of the preorder period.
Here, my question is how can I handle that kind of templating ?
If I follow the Liquid “style”, I can imagine the 2 following way, but I didn’t find a way to achieve that :
-
either adding a special filter like: {{ assign isPreorder = product | isPreoder }}
-
or extend the liquid “product” by adding a property, like product.is_preorder (here, my wish is "is_preorder propertiy should be a function/callback/whatever that compare the metafield preorder date with current date)
Is there a way, throught custom app/theme/anything, to achieve something like that ?
Thanks for your anwser !