-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added get variant stock event #1516
Conversation
Thanks Samuel, please give me some time to look through all this. |
Hey @lukeholder, any thoughts on the get variant stock event? |
Sorry I am away from keyboard at the moment and was actually going to write a reply about the event when back. Give me a couple hours. From mobile. |
Didn't realise my commit closed this pull request |
@lukeholder no problem :) |
I have added 2 events to help with knowing when a line item was added and removed from the order in a clearer way with commit 7baba4a We don't want Putting an event in the getter doesn't really make sense in the case of our basic stock counter being deducted when items are purchased. If you are hitting an external API to get the stock, probably best to set the stock to unlimited and add a custom field that manages your own stock (You can even add your own validator to the line item to check that stock). If your plugin/module wants to add stock to a product, best to do something like this: // Add 9999 stock to a variant.
Craft::$app->getDb()->createCommand()->update(
Table::VARIANTS,
['stock' => new Expression('stock + :qty', [':qty' => 9999])],
['id' => $variant->id]
)->execute(); If you want to explain your use-case more, happy to talk more about it here. Thanks. |
Thanks @lukeholder. I'm writing a inventory management plugin at the moment which does manage the stock separately. I'm needing a way to check that stock when for a line item is added/edited but also for admin orders in the variant element picker. if i set everything to unlimited then in admin orders it would all be available but i still need to be able to say which is and which isn't available. Is there a solution for this? |
Thanks for this pull request, I made a custom stock system as well and it's per "store" (think about it like in a restaurant) One Question: Any plans to trigger those functions, when an Order is deleted? |
This will allow the ability for plugins to say how much stock is available for a variant. We can achieve negative stock/back ordering/etc using this.
I've added the EVENT_AFTER_REMOVE_LINE_ITEM to the_saveLineItems function in the Order element.