Inventory API not decreasing uc_stocklevels

Posts: 17
Joined: 08/22/2007
Bug Finder

I have Übercart 5.x-1.0-alpha7b working.

I'm trying to use the module Inventory API + Simple Stock Levels.

This inventory control system correctly prevents too many items from being added to the cart...great, so far so good... Smiling

However, it does not decrease the number of items in the uc_stocklevels table following the sale.

I have looked at the code in both modules, and I think I understand what it's trying to do, but it doesn't do it.

Is this behavior a bug that is being worked on? Or does somebody else have the API and manager working who might be able to help me?

Thanks,

Jim L.

P.S. Sorry...new here...should this have gone in the Issue Tracker?

Posts: 8
Joined: 08/08/2007

I reported this problem also, right before the big crash. CpILL said he was too busy to look at it then... maybe he's had time by now? Sure hope so, since my client sells one of a kind items!

Posts: 17
Joined: 08/22/2007
Bug Finder

I have continued playing with uc_inventory_api.module.

It looks like function uc_inventory_api_order is suppose to check to make sure stock is still available upon submitting the order, and decrease the stock levels by the amount ordered.

But it seems like the function uc_inventory_api_order never gets called by function uc_cart_checkout_review_form_submit.

Still trying to figure it out Sad

Jim L.

Posts: 17
Joined: 08/22/2007
Bug Finder

The purpose of this post is twofold.

First, it's a shameless bump (this issue is the only thing standing in my way of deploying an new web project that would primarily sell "one-of" items).

Second, and most importantly, I am looking for guidance on how hook_order is supposed to work with modules like uc_inventory_api.module.

Specifically, I assume function uc_inventory_api_order (line 246 of uc_inventory_api.module) is supposed to get called when function uc_cart_checkout_review_form_submit (line 1345 of uc_cart.module) is executed.

However, my testing leads me to believe that function uc_inventory_api_order is never actually getting called.

How is function uc_inventory_api_order supposed to get called by uc_cart.module? Puzzled

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

THis module does nothing fancy (No support for product attributes .. blah.. blah..)

I put this online before crash.. So here it is again

AttachmentSize
uc_simpleinventory.tar.gz4.34 KB
Posts: 17
Joined: 08/22/2007
Bug Finder

Well, I just finished testing the uc_simpleinventory module, and it does not decrease stock in the uc_simpleinventory table upon ordering.

Looking through the module, I believe I understand how it's supposed to work (just like I think I understand how the Inventory API module is supposed to work).

Again, it appears that the function uc_simpleinventory_order is not getting called by hook_order when the cart is finally submitted. But I can't figure out why.

I assume you use simpleinventory for http://www.vingowine.com ???

Puzzled

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

I need to check what exactly happened there.

I was just told by my manager it is not decreasing the inventory.

Posts: 17
Joined: 08/22/2007
Bug Finder

Whew! I thought I was goin' crazy...

BTW, nice wine site. But I assume we are in the same boat...that sometimes you only have a few bottles (maybe even just one) of a particular vintage available.

Does anybody have a functioning inventory control system working with Übercart?

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

This is what the problem i see. uc_order was updated and i suppose there is no more a hook_ordre for submit.

Ryan , someone needs to get into this issue. It seems the hook_order does not work for submit.

Whether it is uc_simpleinventory or uc_inventory both end up with the same problem.

I shd be able to come with a solution in a couple of hours

http://www.vingowine.com

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

Let me take my words back

I was looking at a different repo.

So here is the problem and also iam attaching the module. Works on PHP5 and drupal with latest ubercart.

Probably there was an update on the hook and we never took care of it. Its a simple change. Anyway iam reattaching the module

AttachmentSize
uc_simpleinventory.tar.gz4.38 KB
Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

Also time for me to get a beer. I had some anxious moments there, because for us the inventory is a damn big deal. The vintage and also not getting those rare wines..

Regards
cosmo

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

Removed some stupid Stuff..

AttachmentSize
uc_simpleinventory.tar.gz4.35 KB
Posts: 17
Joined: 08/22/2007
Bug Finder

Now I'm getting the following error:

Fatal error: Cannot pass parameter 3 by reference in /home/lafflamc/public_html/testing/modules/ubercart/uc_order/uc_order.module on line 2352

Following advice from an earlier post, I changed the NULL on line 2353 of the uc_order.module to $null.

The error went away, but the stock level did not decrease following an order.

I am using:

PHP 4.4.4
MySQL 4.1.22-standard-log
Übercart bazaar

Is PHP4 the problem?

I will make the changes necessary to run PHP5 and give that a try...I'll let you know how it goes.

Posts: 17
Joined: 08/22/2007
Bug Finder

Well, PHP5 doesn't seem to make any difference.

Which version of Übercart are you using with your updated uc_simpleinventory? And (perhaps a stupid question) I assume you have verified that your stock levels are actually decreasing in the uc_simpleinventory table when ordering? I assume the decrease is supposed to occur when you click the last "submit" button...right before being taken to PayPal?

P.S. I'm currently trying the bazaar version of Übercart.

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

I really dont know which is called first

in uc_credit.module module_invoke_all('order','submit' ..) is called. Its called both by paypal, uc_credit and uc_simpleinventory. I dont know the order how it is processed. Did u complete the whole transaction. I would check for the inventory for the whole transaction to be completed

http://www.vingowine.com

Posts: 17
Joined: 08/22/2007
Bug Finder

Yes, I've done both actually.

I have tried completing the order all the way through PayPal until I am taken back to my site, and then "shipped the item", and then even run cron.

I have also tried just "submitting" the order, and then checked inventory in the uc_simpleinventory table after the first PayPal page loads up. (As far as I can tell by looking at the source, this should be sufficient to decrease the inventory.)

Perhaps I should revert back from the bazaar version to the 5.x-1.0-alpha7b version?

Perhaps I should restart with a fresh Drupal install with PHP5 as default?

Can you tell me which version of Drupal and Übercart you have working with your most recent version of uc_simpleinventory? And I assume you have tested an order submission and your stock level actually decreased upon submitting the order? I can then set mine up just like yours. Smiling

Posts: 110
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

Mine is not exactly a bazaar ubercart. I think iam on 296 revision of bazaar. I need to update , but i have some own customizations, so it takes time to fix them.

I will give u an update , whether its working on the latest cart or not. Give me an hour or so. If it is not i will try to fix it soon.

Regards
cosmo83

http://www.vingowine.com

Posts: 17
Joined: 08/22/2007
Bug Finder

No rush, my friend. With the long weekend ahead, I might just do a fresh install on a test server and play around with hook_order et al to see what makes it tick.

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Ok, here's an unforeseen problem. hook_order() gets invoked w/ the 'submit' $op in the submit function for the checkout review page. If any hook function returns a failure, then the cart won't let the customer check out (example: in the credit module, if a store charges cards at checkout and the card doesn't process, it fails out). So, if you're using a payment method or gateway that bypasses the normal review screen (like PayPal Express Checkout or Website Payments Standard), it won't get fired off. Shocked

I see this as a problem... but I also see this as a necessary place for this particular $op to be passed. I'm up for brainstorming on ways to fix it. Or perhaps you should consider using a different $op. For example, you could use 'update' and check the order's status... when it gets updated to

<?php
  uc_get_order_status_id
('in_checkout');
?>

from

<?php
  uc_get_order_status_id
('post_checkout');
?>

you could decrement the inventory level. This wouldn't work for all cases, like when an administrator adds a product to an order from the backend. So you may even consider using the 'save' $op and logging when an order's items have been removed from inventory... Just a thought.

Posts: 17
Joined: 08/22/2007
Bug Finder

Thank you, Ryan, for the information. It was helpful. I think I understand the problem much better now. I hope to have some time over the long weekend to try a few hacks to see what might work for PayPal. My intention will be to play around with other payment methods, too, to see if I can come up with a blanket approach.

Idea (?): After an order is finished, the cart is emptied at some point. I mean, if the customer returns to the site and checks his cart after completing an order, the cart is empty. I have not had time to look into the code for this yet, but perhaps whatever trigger empties the cart could decrement inventory first. Just thinking out loud...we'll see what I can figure out. Smiling

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

Hey, did you find a solution to this? I'm back in the saddle again after a 3 week holiday and wil have to tackle this problem at some point.

Looking at this documentation http://www.ubercart.org/docs/api/hook_order (I'm assuming its up-to-date, Ryan?), more order states need to be taken into consideration such as 'delete' should increment the stocklevels for each of the items in the order (or perhaps it should be an option on the admin form?)

I'm still fuzzy about the best place to change the stocklevel value.
1. Do you do it as soon as the order is received and before payment is confirmed?
2. only after payment?
3. After the order has been shipped?

I think I had these questions when designing the API and thats when I decided that the API should be apart from the business logic as most shop setups will have their own rules they would like to implement.

The simple inventory manager that comes with the API was supposed to be a guide to others writing their own inventory rules not cover all situations.

Still this needs to be cleared up

--

suffering from too much information

Posts: 17
Joined: 08/22/2007
Bug Finder

Sorry it has taken so long for me to get back to this issue. It was consuming a lot of time, and I had to get another project off my plate. Now, back to this.

Sorry this post is so long. Most of it is just me thinking out loud again. Do I come up with any solutions? Sadly, no. But I'm hoping for an epiphany.

I did set up a test server with a fresh, new installation of Drupal, a few modules (Ubercart, TinyMCE, IMCE), clean URLs...I think that's it. I killed the PayPal payment method so I can test an internally controlled payment method, such as Checks. Paying by check works. The inventory decrements upon final submission of the order. So, I understood Ryan's last post correctly.

Now, to decide whether or not that is the best time to decrement the inventory...by what Ryan and CpILL said, it looks like this has been on their minds too.

One test I performed...I initiated a purchase by putting a "one-of-a-kind" item in my cart, then started to checkout. But before clicking "Review", I logged into the back end database and manually decremented the stock level to 0. This should simulate another customer who put the same item in his cart, but the other guy "Submitted" his order before me. Then I went back and "Reviewed" and "Submitted" my order. Unfortunately but predictably, Ubercart allowed me to complete my purchase. Then I checked the database and found my stock level at -1. Again, this seems to be a symptom of "when do we check/change inventory level."

OK, so let's think about this...

Lets say I sell one-of-a-kind autographed t-shirts. I need to prevent two customers from putting the same t-shirt in their carts.

Let's say I had a brick-and-mortar store. Let's say Ryan takes an autographed ABBA t-shirt off the shelf, puts it in his cart, and continues shopping. (I didn't know Ryan was an ABBA fan, did you? Eye-wink ) If CpILL went to the shelf after Ryan, there would be no ABBA shirt for him to take. I guess CpILL would just have to go find a different t-shirt.

In Ubercart, could we/should we decrement the stock level when the item is actually placed in the cart?

Hmmm...let's keep going with the example.

Let's say Ryan changes his mind about buying the ABBA t-shirt. He leaves the cart in the back corner of the store somewhere and leaves. Several more customers go and check the shelf for that shirt, but it's still in Ryan's cart, so I miss several opportunities to sell it. Ok, this isn't good.

In my brick-and-mortar store, the shirt doesn't get put back on the shelf until I walk my around the store to clean up. But in Ubercart, couldn't we use "cart duration" to help us out? If the cart sits there with a t-shirt in it for more than 4 hours (or whatever duration), don't just delete the cart...instead, increment the stock levels first, then delete the cart (I think CpILL said that in his last post too, but I don't know how hard that would be to implement).

Using this method, you might still miss out on sales opportunities due to carts being abandoned all over the store, but at least the customer's perception of your inventory is accurate at the time they try to put something in their cart. Heh, it would really suck though if someone wrote a script to shop your entire store, putting ALL your inventory into carts, and then just left them there.

Another option would be to decrement stock levels when "Reviewing" the order, before "Submitting". That way, we get around the problem of NOT decrementing when using PayPal. But we still have the problem of carts lying around with inventory in them. We also still have the problem with multiple customers walking around with the same item in their carts. If the Ryan and CpILL both put that ABBA t-shirt in their carts, but CpILL "Reviews" his order first, what happens to the Ryan's shopping experience when he "Reviews" his order and learns that his ABBA t-shirt was bought out from under him. That's not good.

I think I'm leaning towards decrementing stock levels upon putting the item in the cart, and using cart duration and delete to put the items back into inventory.

One thing I might not understand is what CpILL meant when he said I decided that the API should be apart from the business logic as most shop setups will have their own rules they would like to implement. Is my example above too much "business logic"?

So what does everybody think so far?

EDIT: BTW, if the store had dozens of each shirt available, and I could still get more from my suppliers, then decrementing stock levels when the item is placed in the cart should not adversely affect the customer's shopping experience, nor should it affect the opportunity for the store to make the sales. It would only come into play when stock levels are low and NEED to be tracked accurately due to supply.

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I think you've done a good job summarizing the issues but don't know that I'll have any epiphanies for you. Eye-wink The stock issue is tricky, and I like your idea of just implementing a short cart duration for all users and using that to keep your products open for sale while not hosing any customers in checkout.

To go with your idea further (and beyond the scope of the current code), what if you implemented your own hook_cron in an inventory module with an extra cart product timer. For limited items, or even for all stocked items if you wish, set up the inventory decrement when an item goes in a user's cart but apply a timer. Have the cron periodically scan carts and simply remove any items in the table uc_cart_products that have been in carts for more than the designated duration. The easiest thing to do would be to give all products the same duration. This way you can handle inventory items separately from say a site membership... so you could leave that in a cart indefinitely if you while restocking the shelves with ABBA shirts more often. Eye-wink

Of course, I don't know that this gives you any advantage on a site that only carries inventory controlled items.

And I will add in an $op for hook_cart_item that will let modules act on items as they're being destroyed from users' carts. Right now that's not possible. Simple fix in the morning. Smiling

Posts: 15
Joined: 08/07/2007

I think my vote would be to have the inventory get decremented AFTER the sale was made, thus it would be after the final submission. This way only actual sales have affected your inventory count. I would also prefer to capture the sales lead even if I didn't have the stock available as I might be able to offer a substitute or still close the sale (after ordering more of the item). I'm not sure how we could capture the sales lead, maybe institute some form of back order processing? Or provide some way to let the customer know when the product would be back in stock (automatic email)?

I also would vote for having at least 24 hour cart durations (maybe even as long as 2-3 days). I often times start to place an order online and get distracted with something else and then need to come back to the site to finish my order. If I come back and my cart is empty, I'm much less likely to fill it all back up!

Maybe we could make these options user configurable?

Jeff

Posts: 17
Joined: 08/22/2007
Bug Finder

The stock level is already currently decremented upon final "Submission" for payment methods handled by Übercart. But, if the payment is handed off to a third-party process, such as PayPal, the logic that decrements inventory is bypassed, and the inventory level is not decremented (that's what started this whole thread in the first place). Plus, even if we do figure out how to decrement inventory levels after final "Submission", the customer could still abandon the sale after getting to the PayPal site.

I understand the argument against decrementing inventory when somebody puts an item in their cart. If a bunch of customers go shopping and all abandon their carts, then you have less inventory to sell to the next customer. I understand that we need to minimize those "lost revenue opportunities". And I understand that if two customers want the same one-of-a-kind item, well "first come first served"...that seems fair.

But we also need to take into consideration the shopping experience from the point of view of the customer. I would be pissed if I put that one-of-a-kind autographed ABBA t-shirt in my cart, then spent an hour browsing the rest of the inventory, only to have Ryan come in and put the same ABBA shirt in his cart thereby stealing it from me just because he got to the check-out counter first (Ryan must REALLY like ABBA Laughing out loud).

Cart durations are already customizable. You can even have different cart durations for anonymous shoppers and registered shoppers (ah, the value of membership Smiling ). It should be relatively easy, then, to implement a cron job that would periodically take the items out of the abandoned carts and put the items back into inventory. The customers would still get a "first come first served" experience...we minimize abandoned cart/lost revenue opportunities by customizing cart durations.

I like your idea of making the timing of decrement user configurable, but I'm sure that makes the module a bit more complex to execute. If you write a patch, I'd love to see it Eye-wink

As for the sales lead idea...this is outside the scope of the inventory module (IMHO). But, if generating the lead is important to you, then you could simply require customers to register on the site prior to making a purchase. You would have all the sales lead information you desired at the expense of losing those customers who prefer to shop "anonymously".

I'm looking forward to CpILL's input to my previous post. And I like some of the ideas offered by Ryan (no epiphany, but it's something to chew on...mmm mmm good).

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

lafflam,
As you can see there are probably dozens of ways to do the stock tracking and they are based on the type of product (one off ABBA shirts or a more advances third party fulfillment system that can check with the manufacturer and see if the car part is still being manufactured or not and then order more as needed, etc). We did have a long debate on these forums, before the server went down, and I came to the conclusion that it was impossible to cover all the bases so instead I would make an API and a simple stock level tracing system that worked pretty much as 'cobrasound' outlined it above (and I thought it did work this way up until I got back from holidays this week, I'll try and fix the bug). That is stock is decremented when purchase is confirmed.

An immediate argument against the decrement when adding to cart is that say you have a site with 5000+ visits a day and 10% put the most popular t-shirt in their cart (of which you have only 300 in stock) and then only 10 of the 500 actually want to by that t-shirt. On a bad day they have a less than a 1/50 chance of actually getting a hold of that shirt. The more poplar the site the less likely some one can make a purchase, which isn't what you want.

Really, the merchants don't care about the 'fairness' of who gets the 'right to buy', they only care about selling in my experience. Last minute bidding on eBay has never disgruntled the people who get out bid at the last minute as everyone knows the rules and there is a level playing field and thats the best you can hope for. I'm sure if speedier checkouts is the result the merchant isn't going to be complaining.

Anyway, the option is there for you to write your own inventory manager that does it the way you like it while sharing the reusable part of the code, the API, which will get stronger the more people plug their managers into it.

Paypal, and all payment methods, should return a 'yes' or 'no' from the payment process, correct? I guess, decrement, when someone goes into Paypal, and then if it returns 'no' increment the stock again, if the orders state stays in 'pending' (i.e. when the customer is in the process of paying) indefinitely then the order system should ether time it out or it should be done manually by the order admin. This should happen for _all payment processes_, no?

So, I guess I will try and decrement the stock when the purchase phase is started, i.e. immediately after the 'review' screen, and increment if payment was declined. Is this possible Ryan?

--

suffering from too much information

Posts: 17
Joined: 08/22/2007
Bug Finder

I'm starting to see that all situations cannot be covered by one inventory module. I'm also starting to appreciate the fact that the inventory API is separate from the stock level manager (very insightful).

I only consider myself a hack when it comes to PHP, but I have already started to rework the stock level manager for my purposes (just like you and Ryan have suggested). So far, I can decrement inventory just the way I would like it...but I'm still working on re-incrementing inventory when items are put back on the shelf or when carts are abandoned.

Of course, if I come up with a useful stock level manager, I will definitetly contribute it back for anybody else who might find it useful.

Thanks to everybody who has participated in this thread. Smiling

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

@CpILL - To act on something once payment is initiated will be a little tricky. You can do one of a few things... probably the thing to do would be to use the submit $op for hook_order(). The problem is that for redirected payment services, you won't necessarily receive a confirmation. For example, someone could get all the way through checkout, go to PayPal to pay, and then just never complete payment. I suppose this is where the cron hook would do the clean up of carts in checkout.

@lafflam - I was looking at what it will require to add the code for removing items from the cart and it's more than a 2 minute fix. Otherwise I'd do it right now. As it is, I really want to get Alpha 7c out the door. Once I get it out, I'll add in a call to hook_cart_item() when a cart is emptied automatically, an item is removed through the update form, or a cart expires. I forgot I'd have to deal with it in all three places. Eye-wink

Posts: 5
Joined: 08/12/2007

The example of a "one-of-a-kind" autographed product is perfect.... I am thinking about what happens when I am buying tickets for a sporting event online -- specifically, I will use stub-hub or the SF Giants "Double Play" ecommerce site to search for seats/tickets, since these are one-of-a-kind, the assumption is made (by the system) that when I select a seat(s) that I am going to buy them, however, I am given a warning "you must purchase these seats in the next 10 minutes...."

Where I am going with this -- a possible solution would be to have a class that is "unique item" and has an admin option to "remove from cart after nn minutes" ...
OR
Have a function that 'checks inventory levels' upon 'add to cart', if inventory=1, then display a notification : "This is the last one, buy it in the next 30 minutes or the [product_name] will be returned to the store inventory"

Meanwhile the product does get 'locked' so someone who clicked "add to cart" one millisecond after the other buyer added it to the cart, would get a message, "We're sorry, we are out of stock on this item....(or someone just added the last one to their cart, click here if you want to be notified if they do not complete the purchase"....

Just thinking out loud too....

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

@lafflam - if you get it cranking send it over and I'll package it as part of the API as well as any changes to the API you think would make it more universal. The trouble with only doing one Manager is that sometimes you can't tell if your bending the API too much to your specific case or not.

@Ryan - For redirected payment services I was suggesting that the order stats go into something like 'payment pending' and then you can have a cron job scan for orders that have been in this state for X period of time (configurable via the admin on a per payment method basis to 'X minutes' or 'manual'). I guess to clean up the checkout process more 'states' need to be added to model clearly whats going on, which shouldn't be too difficult, more statements around discreet code blocks relating to state changes like:

<?php
if(module_invoke_all('cart_state_enter_payment_pending'))
{
   
// default state behavior...

   
if(module_invoke_all('cart_state_exit_payment_pending'))
    {
       
// some action on success...
   
}
}
?>

Perhaps even a global (ugly but procedural) state object (nice OOP) that you can pass around and that has the above code in a change state method so all state functions are hooks, which would keep it consistent and modular. But maybe I'm being too OO...

@dougdagaz - The example of a "one-of-a-kind" autographed product is only perfect for those types of items. I wouldn't say its even typical if you take the number of rag trade shops online where they basiclly have X number of the same item (the industrial revolution for ya). What IS interesting about that case is that you might want different inventory managers for different kinds (classes) of products! aH! This would be the next extension to the Inventory API where you set the default manager in the admin settings but then have the option on a per-product basis to choose an manager.

note: This will need to integrate with the import/export.

--

suffering from too much information

Posts: 10
Joined: 09/19/2007

hi Lafflam
About the number of items in the uc_stocklevels table following a sale!
I'm trying to do just that, for... an autograph store of all things. Its for a charity . Did you ever come up with a solution?
I'm not a programmer, and Ive been trying to figure out why the items weren't decreasing or even being removed from the cart. Now reading this thread Ive realized why! If you have any insight into this, I'd be really grateful.
Thanks
Hoon

Posts: 17
Joined: 08/22/2007
Bug Finder

Before this inventory problem, I would have considered myself a Drupal/PHP hack. Now, I'm learning more about PHP, and Drupal techniques specifically.

The client who wanted this went looking for a different solution, so I am no longer in a rush to just "mash" something together. Instead, I am trying to do this right. My intention is to use the API as written, but write a couple of backend managers for different situations. Or, better yet, if possible, one configurable manager.

Anyway, as soon as I come up with something that is even remotely useful, I will release it here.

Posts: 10
Joined: 09/19/2007

Oh!
I see...
A hack would do! or just a few hints to where to start, as you said you had got it to work!
Otherwise I don't know what to do!
Thanks
Hoon

Posts: 8
Joined: 08/08/2007

CpILL, any progress on this? I am definitely getting a confirmed message from Paypal. The order is marked payment received. But the item, which was a one of a kind item, stock of 1, is still available for sale and the stock level hasn't been decremented.

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

Ya, I thought I addressed it in the recent version v1.8? Have you tried it yet?

--

suffering from too much information

Posts: 8
Joined: 08/08/2007

I'm using Inventory API 1.9 with Simple Stock Levels 1.4. Thanks for anything you can do. Let me know if there are any tests that would be useful.

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

What was the question again?

--

suffering from too much information

Posts: 8
Joined: 08/08/2007

I guess the question is how can I get Inventory API and Simple Stock Levels to subtract an item when it gets sold and confirmed by Paypal. The module keeps one person from buying two of these one of a kind items, but once the sale is complete and the cart empties, the item is still in the stock of the store.

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

There was some confusion about this when I wrote it and I don't think I ever got it cleared up by Ryan. The inventory manager hooks into the Order module via hook_order and looks for the 'submit' operation, i.e. "When a sale is being completed and the customer has clicked the Submit order button from the checkout screen". At this point I check to see if the quantity is not too much and then let it happen if its OK.

I then assume it went OK and tell the inventory manager the purchase is confirmed. There is no way for me to tell weather PayPal has confirmed the purchase or not...(Ryan?)

I have tested with "Check or money order" payment gateway and its working. You have to have tracking checked for the given item. Having said this I have not tested for products without attribute options. The tracking is SKU based and so shouldn't make a difference to the logic, unless the SKU is not getting passed on correctly for some reason...?

--

suffering from too much information

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

CpILL wrote:
I then assume it went OK and tell the inventory manager the purchase is confirmed. There is no way for me to tell weather PayPal has confirmed the purchase or not...(Ryan?)

Yeah, PayPal may be independent of Ubercart checkout depending on which service you're using... trying to accommodate third party payment systems like Website Payments Standard might just not be feasible. I would just assume it goes ok.

Posts: 8
Joined: 08/08/2007

I am using Website Payments Standard. And I get the IPN notification so that the order shows Payment received. What happens at the point that the IPN is received so that the order status is changed? Why can't something happen to the stock level at that point?

Are you saying that even though that system seems to integrate beautifully, there's no way to subtract the items that were sold from stock? Does anyone have any suggestions as to how I might force/trick this into working? I've got a system all ready to go for this gal and she sells fairly expensive one of a kind items. I guess I'd rather the system assume the sale goes okay and remove the item from stock and let her manually re-add it, than allow double sales of these items and force her to refund money. Both of those options are pretty lame; surely the ubercool Ubercart can do better.

Any suggestions would be appreciated. Leaving aside the matter of getting paid, I've recommended a Drupal/Ubercart solution and had this lady waiting for months...

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Hall, in the latest code I've taken out that order status change b/c it was hard coded. Instead, I think what really needs to happen (and this will most likely be the only way to accommodate all the inventory needs) is for the PayPal module and inventory (whether it's CpILL's or something else) needs to be integrated with Workflow-ng. This way store owners can decide when to change order statuses and when to adjust stock levels. Trying to accommodate everyone in the code just won't work, I don't think.

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

Fair enough, so what hooks should I implement to expose the "remove form stock" action in the inventory module? I had a quick look at workflow-ng and I'm assuming that if I expose some function to it then they can be setup to trigger at certain order state changes...?

--

suffering from too much information

Posts: 3744
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Well... I'm still trying to figure out how it should best be integrated w/ Workflow, but that's the gist of it. You actually have to use a Workflow-ng hook to declare an action and write its function. I'm not knowledgeable enough to explain the process more than just to point to our existing *_workflow.inc files.

Problem is, how many points of integration does it need. Also, the action can only receive arguments of entities that have been defined... the pre-existing one is the order entity which will pass the whole order object. In which case you'd need to just have a single "decrement stock" action that would do it for any stock controlled item on an order.

I thought about it a little after posting that and realized it would take more thinking. Sticking out tongue

Posts: 2
Joined: 02/27/2008

So sadly it will never work with Paypal Standart then, will it ?

Could you at least post the solution where Inventory increments when costumer proceeds to the Paypal Payment Page.

I think most people will still use this solution even thought it is not the ideal solution.

Posts: 17
Joined: 04/09/2008

Has anyone found a solution or a hack to decrease the 'quantity' field in 'uc_stocklevels' table when using PayPal website payments standard or is it time to look for a different ecommerce solution? The uc_stock module is decreasing the 'stock' field in the 'uc_product_stock' table so couldn't i add an extra line of code when it executes to decrease the value in the 'quantity' field from the 'uc_stocklevels' table?

Posts: 659
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

The uc_stocklevels table and the uc_product_stock table are created and managed by two separate stock modules. The first, by Inventory API, the second by the core Stock module. You can't run both modules at the same time. Pick one or the other. uc_stocklevels will decrement properly iff you have the Inventory API enabled and configured properly and the Stock module turned off.

--

<tr>.

Posts: 17
Joined: 04/09/2008

Thanks for the reply TR, someone told me in a previous thread that it should work if i use both modules so i tried that and couldn't get it to work. Then i tried disabling uc_stock module and leaving it up to Inventory API to handle it but this did not work either. Is Workflow-ng supposed to be handling the decreasing of stock?

Posts: 165
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

ya, I guess the
Status: Abandoned
at the top of the 'Inventory API' contribution page is a bit miss leading. It means that the module is no longer maintained and so any changes to the UC API will not be supported. Since UC is in Beta still this is sure to happen.

--

suffering from too much information

Posts: 7
Joined: 05/10/2008

Yeah...it's really irritating, especially to a new user of Ubercart. In this thread I see a lot of hand-waving and lofty ideas about what could be done in some imaginary dreamland, instead of actual action to fix something technically minor that everyone NEEDS to work. uc_stock doesn't prevent users from ordering more than the inventory holds, making it USELESS. uc_inventory_api and Simple Stock doesn't decrement stock via PayPal IPN like uc_stock does. You can't use both, you can't use either...how is anyone without PHP knowledge ever going to use Ubercart?

My point is that yes, there IS a quick hack to make this work, and I'm stunned that none of these intellectuals in this thread have pointed it out yet.

Simple. You want to add an action to your Workflow-ng "Update order status on full payment" configuration, which is executed when PayPal IPN reports success. Add an action, choose "Execute custom PHP code", and insert (in plaintext or source mode, beware TinyMCE users):

foreach($order->products as $product)
_uc_inventory_api_purchace_confirmed($product->model, $product->qty);

No, "purchace" is the right function to use, that's not my spelling error.

I could have overlooked some huge negative effect caused by this hack, please jump on it, I'm by no means an expert in Ubercart or PHP.

Forgive my crankiness but I just see huge glaring holes in this whole setup. Just be glad I'm sticking around to use Ubercart and contribute to the community, instead of jump ship to another commerce solution.

Posts: 7
Joined: 05/10/2008

Also, uc_stocklevels tried to be nice by incremented the stock when you delete an order. However, this sucked when deleting orders that never got a payment confirmation...the customer went to PayPal and decided not to continue, or some other part of the payment process failed. But if you delete the order, the stock is incremented anyway, although it was never decremented. So we have the opposite problem of stock mysteriously appearing on the shelves. Solved, at least in my case, with

case 'delete':


if ($order->order_status == 'completed' || $order->order_status == 'payment_received') {
foreach($order->products as $product)
uc_stocklevels_adjust_stock($product->model, $product->qty);
}

break;

in the uc_stocklevels_order function in uc_stocklevels.module.

Posts: 10
Joined: 12/26/2007

uc_stocklevels has been marked as abandoned for quite some time, and Ryan and others have said that it may not continue to work. I'm still using it, and it works for my purposes, but your mileage may vary. As I get time I'll update my client's site to use uc_stock. uc_stocklevels is somewhat of a "dead horse" at this point.

My point is that no one is updating the module. You seem pretty proficient with PHP and Ubercart. Maybe you'd like to take over uc_stocklevels and incorporate your changes? This thread http://www.ubercart.org/contrib/132 implies that it needs some love...

Posts: 7
Joined: 05/10/2008

uc_stock doesn't do the things that people require an online store to do regarding stock. The whole point of tracking stock levels is not to replace someone's inventory system entirely, but to simply prevent users from buying more of something than you actually have. uc_stocklevels may be considered abandoned, but it's not irrelevant. It at least tries to do the things people need, so with a few small hacks and spelling corrections it's usable.

I certainly can't take over maintenance of this module. If using PHP every couple months and 3 days of Ubercart usage count as pretty proficient on the scale of developers here, that's scary.

Posts: 7
Joined: 05/10/2008

Just to add to my growing list of tricks to get my store doing things right, I wanted customers to see my current stock level. It cuts down on questions when they can't buy a product. I added this to my node.tpl.php file, at the place I wanted to show stock (after content):

<?php if ($node->type == 'product') { ?>
<br><b>In Stock: </b>
<?php print _uc_inventory_api_get_quantity($node->model);
     }
?>

Posts: 31
Joined: 01/20/2008
Bug Finder

I certainly can't take over maintenance of this module. If using PHP every couple months and 3 days of Ubercart usage count as pretty proficient on the scale of developers here, that's scary.

If possible, could you add your changes to the existing module. It would make things easier for code newbies (like me)! ^_^

Just to add to my growing list of tricks to get my store doing things right, I wanted customers to see my current stock level. It cuts down on questions when they can't buy a product. I added this to my node.tpl.php file, at the place I wanted to show stock (after content):
That's a very handy script. Is there anyway to make it list if the individual attributes of a product are in stock?

Posts: 52
Joined: 08/23/2007

This thread is very interesting. A client (who doesn't use PayPal) uses Inventory API & Simple Stock Levels and it works fine. Except for the problem mentioned above where the module decreases stock when it's added to the cart, *not* when it's purchased. This is leading to incorrect stock levels.

I see someone above mentioned the idea of hooking into the final submit order action. I'm unclear if this was ever added to the module before it was abandoned? If someone could clarify this for me (and perhaps provide a link), that would be great!

Thanks,

Jim

--

(Drupal^Ubercart) * (Design^Development^Hosting) = Sundays Energy

Posts: 1
Joined: 06/04/2008

Hi,

I've made some changes to uc_stocklevels_order to detect Order status changes and increment/decrement stock.

Now it works for me with paypal payements.

Know bugs:

  • It can't detect if we remove a product from an Order product list. But it works well if we change qty or if we remove the complete order.
  • I do some test with credit card test gateway. And wen a customer completes an order the order status changes from "Complete" to "pending" and the stock gets decremented in the first change but it not decrement in the s