Decrease stock quantity only if payment status is PAID

5 days ago
I have just installed the latest version of nopcommerce 4-60
I want stock quantity to be decreased only if order is paid.
Is there any settings for this?
Or how to do it please?
5 days ago
You need to customise to change the way this works - there is no setting
How do the orders get Paid - Pre or Post Order creation i.e. What payment method ?
Do you ever have limited stock - if so there maybe an issue running this way
i.e. Two orders get paid but there is not enogh stock to fill both
5 days ago
Yidna wrote:
You need to customise to change the way this works - there is no setting
How do the orders get Paid - Pre or Post Order creation i.e. What payment method ?
Do you ever have limited stock - if so there maybe an issue running this way
i.e. Two orders get paid but there is not enogh stock to fill both


Thanks for your reply.

I use manual payment method.

First customer places order and then pays it, so it is post order creation.

How can I do it please?

PS. My problem, that I put stock 20 units. Some customers just place order and do not pay it, but other customers who really want to buy does not see stock available... Or I need somehow to auto cancel order if it is not paid in about 5 minutes.
5 days ago
Manual Payment - dont you do the payment ?
So you mean some order and dont enter the correct CC details or ?

Anyway what happens if you get 15 customers and they all order and want to pay for one and you only have 10 ?

Auto cancel order after a set time is probably best - cancelled stock becomes available again after the set time

You can add a scheduled task to run every few hours
For example have a look at src\Libraries\Nop.Services\Gdpr\DeleteInactiveCustomersTask.cs

Here is a simplified version of my code to cancel older orders

        /// <summary>
        /// Executes a task
        /// </summary>
        public async Task ExecuteAsync()
        {
            var orders = await GetAllRecentOrders(2);
            if (orders != null)
            {
                foreach (var order in orders)
                {
                    if (order.PaymentStatus == PaymentStatus.Pending && _orderProcessingService.CanCancelOrder(order))
                    {
                        await _orderProcessingService.CancelOrderAsync(order, true);
                    }
                }
            }
        }

        public async Task<List<Order>> GetAllRecentOrders(int numberOfDays = 0)
        {
            var store = await _storeContext.GetCurrentStoreAsync();

            var records = from o in _orderRepository.Table
                          where o.OrderStatusId != 40 && // Cancelled
                                o.PaymentStatusId != 30 && // Paid
                                o.CreatedOnUtc > DateTime.UtcNow.AddDays(-numberOfDays) &&
                                o.CreatedOnUtc < DateTime.UtcNow.AddDays(-1) &&
                                !o.Deleted
                          select o;

            return records.ToList();
        }