Active
Project:
Commerce Stock
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Jul 2012 at 13:20 UTC
Updated:
21 May 2016 at 14:36 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
guy_schneerson commented@philipz Would be a cool feature not sure how simple it will be to implement with attributes may be possible to do in the hook_form_alter(), if i get a chance will play around with it, but will welcome both patches and ideas about how it should be implemented.
It should be done in the main commerce_stock module, i have a real issue with how i have implemented the relationship of the main module and simple stock as stock should hide the implementation of the SS module, however the triggering of the checks (rules events) is performed by the main commerce_stock module so you should be fine, if you manage to get most of it working but have problems integrating into rules i can help.
Comment #2
iaugur commentedOne approach would be to use a rule to make out of stock items disabled (status=0)
and then they wouldn't appear in the list!
A companion rule could set them back enabled when stock is back > 0
It would be nice too to have the last product unpublish the display when it goes out of stock
Comment #3
philipz commentedI'm looking through 7.x-2.0-alpha2. I see that changing selected dropdown element triggers rules event that sets the cart form state based on the product stock level. If we had only available products in the drop down we wouldn't need to validate stock at this point as it gets validated on add to cart anyway.
So first I'm going to remove the
commerce_stock_cart_state_validate_optionsand replace it with a function that checks products one by one and filtering them out if stock is 0. This new function could maybe reuse rules already in the module or do the filtering without rules at all. The second approach is simpler for me and might be faster performance wise I think.It's late so I'll start tommorow and I'll appriciate a lot any thoughts from you @guy_schneerson.
@iAugur making a rule that sets out of stock items disabled seems like great idea.
Comment #4
guy_schneerson commented@philipz if its for your own site than go for what ever works for you. If this was to be made a feature of stock it would need to be a configurable option probably per product bundle and respect the stock override also the stock check on change gives a better UI for when pages are open for a long time and stock has run out meanwhile.
@iAugur i think this is probably the best generic approach as it allows users to customize the rules if they need to, would make a great sub module. Same as above will need to check stock enabled for the bundle and the override but should be easy to implement.
Comment #5
philipz commentedI would like it to be a feature of stock and as you described it I agree completely. But first I have to make it work on my own site and I'm starting simple. I'll let you know if I have something to show. I will not remove checking the stock on change but maybe this could be an option too.
Comment #6
srgk commentedthis feature is just what i need, good luck with it
subscribing
Comment #7
philipz commentedThis is basic functionality patch. It removes out of stock products from add to cart dropdown. Next I'll:
1. Make this into an option per product type.
2. Respect stock override.
Comment #8
guy_schneerson commentedHi philipz nice work,
other things to consider :
Integration with rules for checking
How to handle products that use attributes
configuration should be on the commerce_stock not the ss
the above may be difficult at the moment, i am planning on a new version of stock soon (a major upgrade of 2 or a 3 brunch) that will be a more object oriented API that will allow the stock module to make stock queries without knowing about the implantation.
for now i think that the approach in #2 may be more practical as it is fully rule based, however if you need this changes do post a patch so others can use it and ill be happy to add it in as a feature if you do manage to fully integrate it.
note that this will be easier on the version 1 as it has no sub module architecture.
Comment #9
philipz commentedFixed two mistakes in patch #7.
Comment #10
philipz commented@guy_schneerson thanks! :)
I have no experience in regard of products with attributes. Do they have separate stock field per attribute combination? I remember I did some coding for attributes and stock in Ubercart a year ago and I had some good results with it.
Do you have any timeline on 3.x roadmap you could share? I feel that the next branch will be as awsome as the whole commerce and what you probably wanted it to be from the start :) I'll try to finish my approach as described in #7 but now I have less motivation to do it.
Comment #11
guy_schneerson commented@philipz products with attributes are controlled by the configuration of product properties its just a different way of formatting the output, instead of a single drop-down you get one for each attribute like colour and size.
time line for the next major upgrade is probably after DrupalCon Munich (will try and organize a bof if you are around)
Don't wont to discourage you just trying to be transparent and i think that this discussion and your work will improve both of our knowledge of Drupal Commerce and produce a better stock module.
Comment #12
srgk commentedhi!
is there any progress on the out of stock products with attributes?
i'm not a very experienced Drupal user, but i have tried a different approach, and i think that it's working...
i added the following function to my module, to make sure that each time a commerce product is saved it's in stock (the field 'commerce_stock'), and if not - the product is disabled (and thus disappears from the product displays).
i have also checked if saving with entity_metadata_wrapper (like in the Simple Stock Rules) triggers the hook_entity_presave, and it looks like all is ok.
please feel free to correct me if anything
Comment #13
guy_schneerson commentedHi @srgk your approach is the same as #2 proposed by @ iAugur only uses code instead of rules
Comment #14
guy_schneerson commentedFor this to make it into the module we need to create a new stock event and action something like
Event "Stock add to cart preprocess product"
Action - Hide product
test if this can be used with both attributes and options, action can also be used to add the out of stock that existed in version 1.
I am assigning to myself as i think this is an important upgrade (so its easy to find), but patches are welcome
Comment #15
akalata commentedA different approach, but here's an exported rule that seems to be working fine. It fires on entity_presave, so it captures administrator actions as well as stock decrements.
Comment #16
kirie commentedThanks @akalata!
Here is the accompanying rule which activates a product once it is back in stock :)
Comment #17
gynekolog commentedAnd is there any way to unpublish product display if all referenced products are sold out (or are disabled)?
edit: http://drupal.org/node/1461442#comment-5675126
my bad
Comment #18
kirie commentedYeah, I was about to say views :) I just used views to not show product displays if it didn't have a active or in-stock product attached to it. I did not want to unpublish the product displays just in case a customer wanted to view a purchased product (or had a product display bookmarked).
Comment #19
mrackham commentedwhen I import either of the rules from #15 and #16 I get the error:
Integrity check for the imported configuration failed. Error message: Data selector commerce-product:commerce-stock for parameter data is invalid
Is there something that I am doing incorrectly? I am using the default install of Drupal Commerce Kickstart v2
Comment #20
gillisig commentedI guess I got the same error when I first tried it, I can't remember exactly what I did to fix it though, I think the token module was not activated or something so make sure to check that all the needed modules are active.
Comment #21
mrackham commentedthe error did not recur when I installed commerce_stock v2
however, the same error does occur if you install commerce_stock v2 and you have not yet enabled stock management for any products yet as detailed here: http://drupal.org/node/1462952
Thank you s2sz for your reply
Comment #22
summit commentedHi,
And how about updates through feeds? Are they also covered if a feed update makes the stock 0?
Thanks a lot in advance for your reply!
Greetings, Martijn
Comment #23
lsolesen commentedTrying to import rule from #15 I get
Comment #24
guy_schneerson commentedJust removing the assigned to me as you guys are doing all the work on this issue :)
Comment #25
Yuri commentedAnyone already using a working solution?