I am well-versed in CraftCMS and am finally able to use Craft Commerce 3 for the first time on a project (first time for any version of Commerce, actually) and it's to build a platform for a butcher shop to take orders for pick-up and delivery.
One challenge is that this shop will have multiple types of quantity. For example, some products will be based on total pounds available (15 lbs. of ground beef), some on pre-created packages (more traditional item count), and others based on the length of cuts (i.e. 12" total available).
I believe I will be able to use the default Quantity field for each of these scenarios and show the type of quantity on the front end with a simple radio field.
Something I am now trying to figure out is the best way to handle products with options that could change the final product price.
For example: Pork Shank - $8.00
Options:
- Skin-on (+$0.00)
- Skin-off (+$1.00)
In this example, the quantity is based on total pounds available, let's say 8.
My first instinct was to use variants, but this won't work as each variant has its own quantity field and these products will each have only one main quantity field.
I decided a good way to handle this might be a Matrix field that includes an option title and a table to enter the option label and associate cost increase.
This brings me to my main question: after ready through a variety of sources (many on Stack Exchange), it's clear that there is no way to manipulate the Commerce product/line-item price directly via the Twig templates.
This post gave me the idea that creating a custom plugin to update the product line-item price is probably the way to go. Unfortunately, it seems that this was written in reference to an older version of Commerce.
In addition, I am not confident in how I would actually trigger a custom plugin (assuming I would use the populateLineItem
event, but also looking for guidance on this) via the Twig template.
I would really appreciate any guidance on how I might create a custom plugin for this particular scenario, or if there is a better way to approach this than the one I am thinking of. Thanks!