1

I'm working on a Commerce Grocery Store that allows users to select a day to have their order either picked up or delivered. Furthermore, some products will have a set quantity for each day of the week. As an example, Fresh Cinnamon Rolls may have 20 available on Thursday, and only 5 available on Friday. With users being able to make an order and then select 'Pickup on Friday', that would mean Friday's quantity for the product needs to be checked and adjusted.

This kind of thing is going to be a bit of work with a Craft Plugin. I've been struggling to come up with simply a concept/path for how I would go about this quantity-by-calander situation. The client is imagining the 'Quantity' field in variants being a calander, where he can define the quantity for each day of the month.

I know this isn't the most technical question as I'm not providing code. But it would be incredibly helpful to get some insight from some of you Craft/Commerce experts on just how you would go about something like this in a plugin. If you thought of an approach while reading this, I'd love to hear it!

Thanks in advance!!

4

Sounds like a fun project. :) My thoughts:

– I'd ditch using Commerce' stock management, and set all products to have unlimited stock.

– I'd build a plugin that has a field type that attaches to products/variants, that lets the client add stock to certain dates for that product/variant.

– I'd have template variable for getting stock for a given date and product/variant, and use it to show availability in the templates. If you need to show availability in product listings, I'd probably also create a custom template variable for getting products (instead of using craft.commerce.products directly), that extends the element criteria to add your custom stock availability to it (see this article, or my Similar plugin for examples).

– I'd listen for some Commerce events (commerce_orders.beforeOrderComplete and commerce_variants.onOrderVariant) to update the stock level when an order is placed (see the Stock Notifier plugin from P&T for examples)

To be honest, I think the biggest challenge is the second point, making the interface and database structure that lets the client update availability. A real simple solution where they add a date and a number for stock, is easy enough. But making a nicer calendar interface, and adding support for stuff like recurring dates ("we have 20 fresh cinnamon rolls every thursday"), gets pretty complicated pretty fast. But, it all depends on the use case how advanced it needs to be.

Anyways, that's my initial thoughts. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.