I need to have stock value for Product display which has multiple Product variations. When some of the variations are bought then it takes certain amount of stock away from product display.
I have Product display where is custom field called Stock (field_stock). This field holds stock value (integer) for Product.
In Product display I have Product Variations. Variations has custom field called Stock Value (field_stock_value).
When adding new Product display and setting field Stock to value 10. And then adding first Variation and setting field Stock Value to 6. And to second Variation field Stock Value to 4.
I need to have rules which decreases Stock field from Product display. So it is simple: take value from Stock Value field and reduce that amount from Stock field.
I have created a new Rule where Event: Completing the checkout process. But I have not managed to have field_stock to Actions. Because I cant set Condition: Node Content is of type - and that is because I have used checkout Event?
I have not succeeded to make working rules so any help needed. Thanks!
Comments
Comment #1
guy_schneerson commentedCompleting the checkout process may be difficult as you will need to get from the order through the line item to the product and then the product display.
You can try and instead use the "After updating an existing commerce product" event this will allow you to compare the stock value to the unchanged stock value. However you may still have a problem getting from the product to its display. Maybe you can find info or even a contrib that lets you do this otherwise you may need to write code.
Comment #2
studio-days commentedHey, excited that I made a breakthrough with this issue without using code, only using Views. My situation: I have a Product Display, which references 5 Product Entities, each with their own stock count, and I needed to know when the SUM of the stock of all entities hit ZERO, and be able display it on the Product Display page.
Here's what I did. It ALMOST solves your issue (but not quite - maybe someone can finish it off):
- In Views create a block (or whatever) for content type Product Display
- Add relationship: "Content: Product Reference"
- Add field: "Commerce Product: Stock" and set the relationship to Product
- Set Use Aggregation to Yes.
- Set the Aggregation settings for the field to SUM, group column by Value.
- Done
For some reason this displays DOUBLE the sum of the stock of the product entities. However this suited me fine, as I just needed to know when it hit zero (and 2 x 0 = 0). As I say, maybe someone can shed some light as to why it could be doubling (I've already tried messing with Distinct and Pure Distinct but moved on quickly).
PS: this way you also don't need your stock field on the Product Display content type.
Comment #3
guy_schneerson commentedShould be not do difficult to write a replacement module for simple stock called something like "product display stock".
If you are interested in such functionality do comment on this issue as with interest comes code :)
Comment #4
nguyendav commentedHello, i'm really interested by the fonctionnality "product display stock" , tried to manage that with rules but didn't succed....need help :-)
Thanks
Comment #5
WillsCreative commentedI'm also interested in this functionality. I'd imagine it being a common issue as well, surprised it's not already implemented
Comment #6
cedric_aHi, I need this too
Comment #7
guy_schneerson commented@nguyendav, @WillsCreative &cedric_a are you all using version 1?
I have closed version 1 for new features but can update the issue for V2 if applicable?
Comment #8
WillsCreative commented@guy_schneerson I'm using V2. Please update it :)
Comment #9
guy_schneerson commentedUpdated to Version 2.
While this may not be an easy feature to add to V2. I think I can do a quick tutorial on how to set this up. will try and do this soon.
Comment #10
cedric_aI'm using v2 too and would love to read your tutorial ;-)
Comment #11
benjarlett commentedI also need this. Can it be done?
Comment #12
benjarlett commentedI had to sell out when I'd sold 80 of any of the line items attached to the product display. I had three variations. So I had to sell out when the sum of remaining line items went below 160 (ie 80 less than (variations)*80(stock) I hope that makes sense)
I got round this by making a second content type (product display stock controller) that referenced the product display. Then I created a block that showed a link to it's referenced product display (using contextual filter to get the nid of the page being displayed, then a relationship to the product display referenced in that node). then a second relationship that referenced the line items related to that product display. then using aggregation I created a filter that summed the commerce product stock of the line items onlu if it was greater than or equal to a figure which I set to 160. This was a bit bespoke cos I only had one product to do this with so if I had more I'd need to create a new block for each product.
Might help someone in the same boat.. but a product display stock would be better.