Jump to content

stock_available.quantity and stock_available.physical_quantity difference


bedford

Recommended Posts

Hi,

I'm looking to a way to only decrease stock when the order is really paid (too many customers reserve some items and they aren't available for buying by other in the meantime, and most orders aren't paid). So as far as I understand the way it works, I've updated the function updatePhysicalProductQuantity in StockManager to check if order is paid before executing code:

public function updatePhysicalProductQuantity($shopId, $errorState, $cancellationState, $idProduct = null, $idOrder = null)
    {
            //GG START 16/4/20 only deduct when status changes from unpaid to paid
            if($idOrder == null)
                    return;
            $order = new Order((int) $idOrder);
            if($order->hasBeenPaid()){
                //GG END
                    $this->updateReservedProductQuantity($shopId, $errorState, $cancellationState, $idProduct, $idOrder);

                    $updatePhysicalQuantityQuery = '
                            UPDATE {table_prefix}stock_available sa
                            SET sa.physical_quantity = sa.quantity + sa.reserved_quantity
                            WHERE sa.id_shop = ' . (int) $shopId . '
                    ';

                    if ($idProduct) {
                            $updatePhysicalQuantityQuery .= ' AND sa.id_product = ' . (int) $idProduct;
                    }

                    $updatePhysicalQuantityQuery = str_replace('{table_prefix}', _DB_PREFIX_, $updatePhysicalQuantityQuery);

                    return Db::getInstance()->execute($updatePhysicalQuantityQuery);
            } //GG 16/4/20
        }

When I make an order, the field stock_available.physical_quantity isn't decreased nor the stock_available.reserved_quantity is increased, but I see the field stock_available.quantity is decreased.

Could someone tell me what is the difference between stock_available.physical_quantity and stock_available.quantity ? The backend still show full stock quantity as expected since the order hasn't been paid, but what this stock_available.quantity is ? I see in this function that "sa.physical_quantity = sa.quantity + sa.reserved_quantity". But since is't a calculated information, based on 2 fields in the same table, why it is in a database (redundant information) ?

Also if somebody could tell me if such kind of information exists somewhere, so I can try to find without asking.

Thank you for help !

Link to comment
Share on other sites

  • 3 months later...

I am interested to understand this concept.

By reserved do you mean you offer customers this option? Or does reserved simply happen when a customer has items in their basket and/or are going through the checkout process?

Presumably there is some kind of automated release of the reserved stock if the customer does not order?

Link to comment
Share on other sites

56 minutes ago, Jezza said:

I am interested to understand this concept.

By reserved do you mean you offer customers this option? Or does reserved simply happen when a customer has items in their basket and/or are going through the checkout process?

Presumably there is some kind of automated release of the reserved stock if the customer does not order?

Hi Jezza, in my store I don't reserve items for unpaid orders. For me the stock must be decreased when the payment is done, not when the order is done. This is because many people and some concurrent make orders and never pay, so the items aren't on available for other customers but in fact they are.

Unfortunately Prestashop decreases stock when you make order, not when you pay it. So I checked around and found some weird things in code (redundant information on database and/or an unused field). So I needed help to understand what are those fields for and why the information is recorded in different places. Still haven't found the information.

In backend there is a feature to restock unpaid orders after X days, so the stock number is set back to initial value, but this is not the way I want it to work.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...