Hi!
Problem : I sell ticket with variation product( member, non-member ) with 2 different price
I need stock, but i need the stock on the whole ticket product. eg: 100
maybe i will sell 99 member ticket and 1 non-member... i dont want split the stock 50/50 on the product attribute
It's is possible?
i also try to install the rules module for a simple decrementation of a field_my_custom_stock on the product but the "paid in full" don't exist anymore. (i know why now)
Suggestion are Welcome!
Ben
Problem/Motivation
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
bensti commentedComment #3
bensti commentedComment #4
bensti commentedComment #5
cayenne commentedFollowing. I have a similar desire.
Comment #6
webmens commentedDid you find a solution for your case? I have the exact same problem.
Comment #7
bensti commented@webmens nope
Comment #8
guy_schneerson commentedHi @bensti,
In commerce 2, Rules is no longer part of the base build so will not work.
Currently, you can not have stock on the product only on the variation.
I think you may be able to solve your problem by having a single variation ticket and having the member and non-member on the order item instead. This may require more work for the pricing.
I think we may already have a feature request to have stock on the product level so if you find it add your use case to it.
Comment #9
cayenne commentedWilling to plunge into this. Is there a hook that responds to changes in stock levels?
Comment #10
brightbold@Cayenne Did you ever get anywhere with this?
Comment #11
cassien commentedI'm interested.
I need to offer subscription products with multiple recurrence periods. If the product is released for the day, it must also be released for the week and the months since it is temporarily unavailable.
Comment #12
mvonfrie commentedI'm interested as well.
I have a voucher product with the value chosen by the user. To make it easier for both the users and companies providing the vouchers, there will be a product X with variations like 10€, 20€ and 50€. There is no separate stock for the different variations but only a total value per product.
Example: Stock for product X is 180€, then this can be:
Comment #13
mvonfrie commentedI installed
commerce_stockas the dev version is D10 compatible now and looked a bit into the code to understand how things work and how to quirk a solution for my example into my site. As I have a deadline for the project I can't wait until this feature is implemented but have to find a custom solution in the meantime.But I have an idea for a concept how to implement this properly. This can't be fully implemented in
commerce_stockthough as it would require changes incommerce/commerce_productwhich then are permanent and would make things even more complicated. So the concept will always require custom code by the site developer.Currently all stock logic is connected to the
PurchasableEntityInterfacewhich basically (only) is the product variation entity (but can be extended by contrib modules to nodes for example). But of course we don't want (and don't need) to make the product entity purchasable in order to let it handle the stock of it's variations.So we need two new interfaces plus traits providing their implementations for commerce products:
Then stock checking and stock processing has to check: The given entity or purchased entity of the given order item
PurchasableEntityInterfacebut notStockableEntityInterface--> use it for stock handlingStockableEntityInterface::getStockedEntity()StockedEntityInterface--> use that entity for stock handlingPurchasableEntityInterfaceStockableEntityInterfacebut notPurchasableEntityInterfaceStockedEntityInterface--> use that entity for stock handlingNULL--> don't handle stock for it.Of course this requires changes to all sub-modules of
commerce_stockand is quite complex. But the same time it is very flexible as it allows to decide whether the product variation or product should handle the stock (or maybe a totally different entity implementingStockedEntityInterfaceand being return byStockableEntityInterface::getStockedEntity()) on a per-bundle basis.The site developer would just need to create custom product and product variation classes implementing the interfaces and registering them properly. This can be done using hooks or more easier with the Bundle Class Annotations module.
It would even be possible to mix this for a product type, for example a book product type with three different variation types
book,ebook(like ePub, PDF, ...) andamazon_kindle_book.bookandebookvariations could handle their stock on product level by implementingStockableEntityInterface(i. e. using local stock) whileamazon_kindle_bookhandles its stock on the variation by using a custom amazon kindle stock implementation.Comment #14
matthieu_collet commentedHello @mvonfrie
Two months later do you think your solution is working ? We have the same need
Comment #15
a.dmitriiev commentedI am trying now to implement this without too much changes. I ended up creating new Stock Service that will return stock of the product whenever the stock of its product variation is requested.
I still had to override couple of classes and one of them needs the patch that is attached. I will write more when I finish.
Comment #16
a.dmitriiev commentedMore places where the changes are needed in a new patch
Comment #17
a.dmitriiev commentedI assume that product stock is using commerce_stock_local module. Here is the module for tracking stock for product and not product variation based on local stock.
What module has:
1. Field storage configs for field_stock_level and commerce_stock_always_in_stock for product entity type.
2. New service to set for product variation here
/admin/commerce/config/stock/settingscalled "Product local stock". It should still be attached to product variation, because of the module architecture, and I didn't want to change it.3. New widget "Simple stock transaction for products" that you should use for field "Stock Level" for product entity type.
4. Overrides for queue worker class and stock level field type (to use new class for computed stock level processor.
After you install the module, go to product type that you want to have stock level management. Add 2 fields "Stock Level" and "Always in stock?" from existing fields (the storages are installed with the module). Set widget "Simple stock transaction for products" that you should use for field "Stock Level" for product entity type. Then you need to set here
/admin/commerce/config/stock/settingsthe service called "Product local stock" for your product variation that corresponds to product type.On product edit form you will now see two new fields. And that is basically it. Stock level will change whenever any variation that belongs to product will be bought, but level will be attached to the product and not to variation.
When checking the availability of the product variation, then the stock level for product will be checked as well.
P.S. Don't forget to apply the patch from #16 to commerce_stock module. Without it the module commerce_stock_product from the comment will not work properly.
P.P.S. For security reasons, the upload has been renamed to commerce_stock_product.tar_.gz, so to unpack the archive please rename it after download to commerce_stock_product.tar.gz .
Comment #18
rsnyd@a.dmitriiev,
Thank you for the patch and module. I'm working on this same challenge. I've updated commerce_stock with the patch from #16, downloaded, unzipped and installed your commerce_stock_product from #17. I've added the two reusable fields to my default product bundle and set the field widget to "Simple stock transaction for products". Finally, I've configured commerce_stock here: /admin/commerce/config/stock/settings to use the "Product local stock" service for both the default service and the Product Variation.
The fields show on my product edit form, but I'm unable to change the value of the stock level. No errors, but if I enter 5 into the field and save, Current stock level: remains at 0. I've also tried adding a stock level field to the product variation type for the default product bundle, but that doesn't seem to work either. Can you please suggest what I may be doing wrong?
Comment #19
uridrupal commented@rsnyd
I couldn't make it work sadly, but you're using the wrong Field Widget. You need to use the proper one, I think it's called "Product stock level". Also, the stock is set at variation if I recall correctly, and then it will show properly.
Comment #20
a.dmitriiev commentedFor product type that should have the stock per product you should have these fields:
Manage form display page has these 2 fields with corresponding widgets:
On Stock configuration page the settings are:
See setting for product variation "Side event".
As stock management is local, you need also to create location here `/admin/commerce/commerce_stock_location` of any type from here `/admin/commerce/config/commerce_stock_location_type`
No settings on product variation type are needed.
Then you can manage stock on product page (not product variation):
And when you fill the field "Stock level adjustment (all languages)" with 10, to increase the stock on 10 items, and save the product, it will be displayed like this afterwards:
With the module from attachment you still need the patch from #16, don't forget about it.
Comment #21
rsnyd@a.dmitriiev/@UriDrupal,
I've followed the screen captures below, installed the fields on the product type, set the configuration for my product variation type, and I've ensured the patch was installed. The field shows on the product edit form, but will not save the value entered. After debugging, I found this error:
Removing the $multiplier variable for now allows me to save the value. I will continue testing. @UriDrupal, does this also help you to get it working?
Comment #22
a.dmitriiev commented@rsnyd, I think multiplier is a leftover of my custom code, as the module was copied from solution where there is also people count and quantity is multiplied in case it is a ticket for couples, family, etc.
Comment #23
kaszarobertRemoving that invalid $multiplier variable fixes the problem and your solution with the attached module from commerce_stock_product.tar_.gz + patch #16 works fine. With needing patch #16 it seems the module is not flexible enough for setting up other entities for stock level management. There are entity_id and entity_type columns in the commerce_stock_transaction database table, so the schema can handle this use case but the module cannot. So it would be good if the module supported not just through purchasable entities but any entities.