<p>Sounds like a fun project. :) My thoughts:</p>

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

<p>– 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.</p>

<p>– 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 <code>craft.commerce.products</code> directly), that extends the element criteria to add your custom stock availability to it (see <a href="https://blog.tighten.co/craft-cms-building-complex-queries-by-extending-the-elementcriteriamodel" rel="nofollow">this article</a>, or my <a href="https://github.com/aelvan/Similar-Craft" rel="nofollow">Similar plugin</a> for examples).</p>

<p>– I'd listen for some Commerce events (<code>commerce_orders.beforeOrderComplete</code> and <code>commerce_variants.onOrderVariant</code>) to update the stock level when an order is placed (see the <a href="https://github.com/pixelandtonic/CommerceStockNotifier" rel="nofollow">Stock Notifier plugin</a> from P&amp;T for examples)</p>

<p>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.</p>

<p>Anyways, that's my initial thoughts. :)</p>

CC BY-SA 3.0
2016-10-30T20:52:31.060Z
2016-10-30T20:52:31.060Z
André Elvan
<p>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.</p>

<p>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.</p>

<p>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!</p>

<p>Thanks in advance!!</p>

<plugin-development><plugin-craftcommerce>
Commerce: Calendar to Product Quantity
# Commerce: Calendar to Product Quantity

(Asked by: username_0 on 2016-10-29)

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!!

**Tags:** plugin-development, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-10-30. Score: 4 | Accepted answer

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](https://blog.tighten.co/craft-cms-building-complex-queries-by-extending-the-elementcriteriamodel), or my [Similar plugin](https://github.com/aelvan/Similar-Craft) 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](https://github.com/pixelandtonic/CommerceStockNotifier) 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. :)


---

