4 replies [Last post]
rjlang's picture
Offline
Joined: 02/06/2012
Juice: 26
Was this information Helpful?

In our system, people have the option of sending in paper order forms, which are fulfilled by the administrator entering their orders using the "Create Order" functionality. When he does this, we're finding that the stock is decremented twice for each product: once at the moment that each product is added to the order, then again, later, when the payment is entered for the order (typically a check).

The second decrementing appears to be controlled by the Conditional Action titled "Decrement stock upon order submission" (which is part of the default 2.7 installation). When the administrator applies a payment to the order, this action gets triggered. If we disable that action, the second decrementing goes away. But of course, that action is essential for normal cart checkout.

The original stock decrementing at the time the product is added to the order, doesn't seem to be controlled by a conditional action, so there's no way to affect or prevent it, at least, not that we've found.

The workaround we've found is to modify that Conditional Action, using custom PHP to add a condition to check the roles of $user (not the role of the customer, which is what "check user roles" in CA seems to do) and if that role is that of the administrator (the person authorized to create administrative orders), the CA is not triggered. Doing this results in proper behavior of the stock only being decremented once for administratively created orders, while leaving the proper stock decrementation for ordinary cart/checkout orders by other people.

So, we have a workaround. But it seems like double-decrementing on administrative orders is not the desired behavior, and so my question is: what is the intended behavior? I would think administrative orders should behave like ordinary cart/checkout orders, with decrementing of stock should not happen during order creation, only when the payment is recorded, but would like to know. If this is a bug, then when it's fixed, we'll need to undo our workaround.

Vraja's picture
Offline
Joined: 09/13/2010
Juice: 21
Hi there, I have the exact

Hi there,

I have the exact same issue. Could you post the custom php you used to check the roles? I really need this as my live site takes both customer orders through the cart, and admins create orders done over the phone.

Thanks!

rjlang's picture
Offline
Joined: 02/06/2012
Juice: 26
Re: Hi there, I have the exact

Here's the code (which we're still using). In the conditional action "Decrement stock upon order submission", add a Custom PHP condition with the following code:

global $user; return ! ( in_array( 'store manager', $user->roles ) );

Instead of 'store manager', use the name of whatever Drupal role your admin has assigned.

Robert

sjperetz's picture
Offline
Joined: 03/07/2014
Juice: 7
Same problem...

I am lost when it comes to PHP, can you tell me where to place this code since it apparently is still an issue? Is it in the stocking module?

rjlang's picture
Offline
Joined: 02/06/2012
Juice: 26
Same problem...

Hi sjperetz,

The problem exists in both Ubercart 2 (Drupal 6) and Ubercart 3 (Drupal 7), but the fix depends on which version you're running. My answer above applied to Drupal 6 + Ubercart 2, which used Conditional Actions to implement stock decrementation. The PHP snippet applies to that setup.

If you are using Drupal 6 + Ubercart 2, go to the Conditional Actions interface in the Drupal administration, and find the display of all actions. There's an action called "Decrement stock upon order submission." You want to edit that action.

(I'm sorry that I can't give you the exact path, because I no longer have a D6+UC2 installation running.)

Anyhow, when you find that Conditional Action (CA), you can edit the CA, and in the UI, you'll find the option to add a condition. (CAs consist of triggers, conditions, and actions.) There are different types of conditions you can add; choose "Custom PHP". Copy and paste in the code from comment #2 above. Except you'll have to change 'store manager' to the exact name of the Drupal Role you use for your store manager. Then save the condition.

After you've done that, the CA will fire for everyone else (customers) but not for your store manager. That worked for our store for a couple of years.

Now, if you're on Drupal 7 + Ubercart 3, there's the same issue, but there's a different way to fix it. UC3 uses the Rules module, instead of the UC2-specific Conditional Actions module, but they work the same way. There's a rule that fires that decrements stock in response to customer orders. The stock decrementation for admin orders was hard-coded, but I have written (and posted) a patch that moves the stock actions for admin orders into a Rule, so you can now set conditions on the rule that govern when stock decrementation happens.

Here is a discussion, description, and the patch (see comment #16):

https://drupal.org/node/1034044

The patch has passed the automated testing, and we've been using it successfully for the past 9 months on our store. A slight bother is that it hasn't yet been incorporated into Ubercart proper yet (c'mon guys, it's doesn't break anything and it's a pretty important issue!), so you need to reapply it with each release (until it's adopted, anyhow).

Incidentally, there's another stock-fixing patch you might find useful:

https://drupal.org/node/1398448

Both of these work with Ubercart 3.6. Hopefully they'll get adopted and won't be needed much longer.

Hope this helps,

Robert