Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Contributed modules
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
30 Sep 2010 at 12:45 UTC
Updated:
28 Apr 2011 at 20:31 UTC
Jump to comment: Most recent file
Comments
Comment #1
pieterdcI'm giving it a go.
Will post my findings over here.
Comment #2
rszrama commentedI'm going to have to go over our previous sprint notes, but I believe we've specced this to be a contrib thing until it's mature enough to move to core. It shouldn't need to be in the core for it to accomplish what it needs to accomplish (i.e. entering / tracking / reporting stock levels and integrating itself with the cart and checkout process). My early envisioning had stock being a field that you attached to product types as necessary... didn't get much further than that. ; )
Comment #3
pieterdcAt this point it's a field you can attach to - everything, I guess, based on the number module and reusing some code of it. See attachment.
Do you want me to start this as a commerce_stock module in contrib?
Comment #4
rszrama commentedHey, cool - were you reading my mind or did you start that after I commented? : )
I think ultimately we'll need another project page for it, but we may as well hold off a bit to see how things develop. I need to revisit the old notes and see if Damien or someone from the sprints thus far has thoughts on how to get stock support working toward a future core. At the very least, it would be outlining your approach in a forum thread on drupalcommerce.org so folks can weigh in on the module architecture and integration w/ checkout. My hunch is there should be multiple modules, one that provides the stock field functionality and others for the different types of holds you can place on stock values... it's a tricky subject, and I'm sure there are people who have thought about it more than me. : P
Comment #5
mertskeli commentedGreat idea. A must for a serious business solution.
Comment #6
pieterdc@rszrama I had been reading some discussions on drupalcommerce.org - or: I was mind reading, if you like that explanation better :p
I might add some views integration, but that's about it, for me, for now, as I don't need being able to (de)activate stock level "stuff" per product, nor rules integration.
Comment #7
johnv@PieterDC,
as for your question "should this be a contrib", I would say Yes.
It allows for a sharper interface with commerce-core, and provides a separate development-cycle.
In my case, products can have multiple stock-locations (e.g. at the physical store(s), the warehouse, and my separate web-stock.
(this would then require a separate table product-location-stock)
Comment #8
pieterdcI have a blocking issue ( #932296: Order status entity property definition ) which prevents me from getting further with this issue.
Comment #9
rszrama commentedSaw that come through yesterday and was reminded how poor order status support is right now (i.e. you can't even change the status via the UI). Have been doing a lot of documentation the last couple of days but am getting back on the code. Check these babies out:
http://www.drupalcommerce.org/specification/info-hooks
Comment #10
pieterdcThanks for the patch, I'll give it a try.
Thanks for the documentation!
IMO writing documentation is boring but I'm convinced it's worthwhile ;-)
Comment #11
pieterdcGot a little further, can use the order-status token now.
Would like to use Rule Action Loop Parameter: List: [commerce-order:line-items] to adjust stock value for each line item upon order completion.
But I have a new blocking issue #941324: Call to undefined function commerce_line_item_access()
Comment #12
pieterdcAdding
function commerce_line_item_access() { return TRUE; }in commerce_line_item.module to quickly work around the issue stated in comment #11,and configuring a rule as you can see in the attached screenshot,
stock decreasing works...
Comment #13
rszrama commentedhah, awesome. : D
Comment #14
redben commentedComment #15
rszrama commentedComment #16
arbel commentedHello,
I've added a bit of code to the module:
1. added an indication on the product attribute field that the product is out of stock.
2. added a validation check if you try to add a product that's out of stock
3. renamed and disabled the add-to-cart buton on products that don't have attributes.
I want to add a couple more things but i'm not sure how to approach them (I'm a designer not a developer...)
1. I'd like to add a style to the in the select to the attributes that arn't in stock (gray them out).
2. I'd like to disable to add to cart button when the select box is on a attribute that is out of stock
3. I'd like to add two more stock checks, one when the user reviews the order, and one right before payment, this is to take into account situations when other users purchase the stock before you have a chance to complete the order
4. the stock check doesn't take into account the number of items you already have in your cart...not sure how to access the cart/order info
Thanks
Idan
Comment #17
arbel commentedIgnore the last file...still had a bunch of dpm()s in it....
Comment #18
mthart commentedsubscribe
Comment #19
essbee commentedAt the risk of sounding unappreciative, believe me I really do appreciate the work that has already gone into this, but I think an opportunity to build a far more scalable and robust stock system may be being missed here.
I believe a far more valuable stock system that duplicating the ubercart incarnation would be to have stock levels calculated based on transactions, rather than just utilising a single integer field.
To better explain, rather than having a field to which we subtract or add based on events. It would be far more valuable to have a table holding qntity transaction information. Eg. sku, quantity, entry_date, entry_user, explanation
So for a sale an entry would be added as
'PRDCT111', -5, '13/03/2011 09:00:00', 3, 'SALE'
That would allow in the future the addition for example of a "purchases" type module which wold generate entries such as
'PRDCT111;, +50, '13/03/2011 09:00:00', 1, "PURCHASE"
This would then give full audit capabilities on current stock levels, and accordingly far better tracking and reporting.
Calculating stock on hand then is simply SELECT SUM(quantity) as stock_on_hand WHERE sku='PRDCT111'
I don't believe that performance issues would be a problem, but obviously this information could also be cached in a field if need be.
As I see it this would require three main things to get basic functionality.
1. .install would need to generate an appropriate place to store these transactions
2. commerce_stock_adjust() woud require rewriting to create entries rather than just editing field.
3. a new function eg commerce_stock_retrieve() would be required for use in displays and cart validations etc.
Beyond that obviously the opportunity to create transaction log displays etc is opened up.
I appreciate that it is far easier to write out the concepts than actually generating the code, but I think something of great value is possible here. While I'm a fairly handy code tinkerer, I don't have the understanding of the correct drupal structures and methodologies to be able to put something together, but am happy to lend assistance where ever I can.
Anyway thats my thoughts. Be interested in other's responses.
Comment #20
arbel commentedHi,
I understand what you're saying and it might be a better solution, but unfortunately I have a project that requires stock updates, and the project needs to be launched in less than two weeks, that's why i'm working on this. I'm also really not a developer but rather a designer who knows a bit of php....
Idan
Comment #21
zeezhao commentedI agree with #19. This will also be useful for audit trail when new stock arrives into the store. Hence a new transaction to increase existing stock, which ultimately updates the stock field too.
This can probably be done using a new cck type (at least in D6 thinking...), with rules to affect the product quantity. The transactions can be seen via a views report or somthing.
Comment #22
drcho commented#17: Thank you for your quick and dirty solution. It seems to be enough for of small Shops. But it's very alpha, there are some major and some small problems...
1.
appears many times in you code of "commerce_stock.module". It must be at least:
and you should better use the drupal function field_get_items($entity_type, $entity, $field_name, $language)
2.
If I put 10 units of a product with field_stock=10 into my cart, it works. After that I put 5 units of the same product into my cart, and there comes no error message "Out of stock" - that's false.
3.
The fieldname field_stock ist not variable... no warning at all.
I try to change the small module and I'll upload it here...
Comment #23
arbel commentedThanks, I've actually fixed some of those things, but haven't had a chance to upload them.
I'm a designer with some knowledge of php so this is the best I can do =).
I've also written a rules condition that checks if you have any products that are out of stock in your order, this should be called each time the order is updated -> mainly for the purpose of check your cart in the checkout process.
I'd very much like some help here with creating the JS check each time you load a product option to disable the add to cart.
and create the action for the condition, that will mark the quantity field as an error for each product (red highlight) with the message.
Thanks
Idan
Comment #24
arbel commentedforgot to upload
Comment #25
pcambraYou may consider in creating this as a contrib and work in it as a separate project there :)
Comment #26
xlyz commentedsubscribing
Comment #27
liupascal commentedI went through your code, and I don't know if it will break anything but your last function is called
commmerce_stock_produdct_check_out_of_stock($product_id ,$quantity), while the right name should be
commmerce_stock_product_check_out_of_stock($product_id ,$quantity) i guess ?
Comment #28
zkrebs commented#19 and #21 hit it on the spot. Also, see here.
http://www.drupalcommerce.org/node/66#comment-944
Also, what about Stock Reports, Stock Managers, etc.?
Comment #29
latulipeblanche commentedsubscribing
Comment #30
rfayWell, we can't be building this in zipfiles in an issue.
I created the project http://drupal.org/project/commerce_stock. @arbel, you have VCS write permissions there.
Let's get the concerns in this issue over into that module, and let's get this thing humming.
Thanks all for your efforts! Stock is a big important issue.
Comment #31
arbel commentedSince i'm not really a developer and don't really have the coding chops to maintain or even properly handle a git account, i'm uploading the files here and looking for someone to take over.
Comment #32
rfayThanks, @arbel. Your #31 is already accounted for in the code over at http://drupal.org/project/commerce_stock. I just checked it.
You *are* obviously a developer and your contribution here is valued. It's not at all hard to get going with git, and every Drupal contributor already has git access. There's a quick video introduction at http://vimeo.com/20459209
Comment #33
arbel commentedthanks, i'll take a look.
Comment #34
rfayThink "fixed" is a better status.