2 replies [Last post]
rjlang's picture
Offline
Joined: 02/06/2012
Juice: 7
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: 7
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