cancel
Showing results for 
Search instead for 
Did you mean: 

Cheking item quantity just before pay.

Cheking item quantity just before pay.

Hi to all!

First, excuse me if my question not in the correct forum group, but let me ask!

As payment module developer, I am curious about the following case:

a customer add an item into the Cart and go to the checkout page. Select a provider and click on the "pay" button. But in same moment someone else get the last item. Do Magento system care for this case, for example preserve some minimal item quantity or the the payment plugin must care?

If non care it happens the client go to some redirect payment page and pay, then return to the shop site and see the message like "Your item is no more available". At the end the money are gone and an Order is not made, but Cart is active.

If my plugin must made last check for item quantity, what is the best approach to do it? Checking quantity for a simple product is not a problem, but when I tried to check the quantity of variable product (by color) I failed.

 

Thanks!

5 REPLIES 5

Re: Cheking item quantity just before pay.

Hello @mpstoevgmaea24 

 

To handle the scenario where a customer's payment is processed, but the item they purchased is no longer available in Magento 2, please follow the steps below:

  • Please create a custom observer that listens to the "sales_order_place_after" event. This event is triggered after an order is placed.
  • In the observer, check if the purchased item is still available. You can do this by checking the product's stock status or any other relevant conditions.
  • If the item is no longer available, you can create a custom message and add it to the customer's order comments. You can use the following code to add the comment:
    php
    $order = $observer->getEvent()->getOrder();
    $comment = "Your item is no longer available.";
    $order->addStatusHistoryComment($comment)->setIsCustomerNotified(false);
    $order->save();
  • This will add a custom message to the order comments and prevent the customer from being notified.
  • You can also create a custom email template that is sent to the customer informing them that the item they purchased is no longer available. You can use the following code to send the email:
    php
    $emailTemplate = $this->_transportBuilder
        ->setTemplateIdentifier('custom_email_template')
        ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
        ->setTemplateVars(['order' => $order])
        ->setFrom($sender)
        ->addTo($customerEmail)
        ->getTransport();
    $emailTemplate->sendMessage();
  • Please replace custom_email_template with the identifier of your custom email template.
  • By following these steps, you can handle the scenario where a customer's payment is processed, but the item they purchased is no longer available in Magento 2.

 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9

Re: Cheking item quantity just before pay.

Hi!

 

Thanks for the advice, but this observers fires too late. I need this check to be done after I click on pay button, but before submit the checkout form.

After the order is saved is too late to check if the product is available, because the money are gone Smiley Wink

If someone else can recommend the me the best Magento method to check for product quantity I have a place to call it.

 

Regards!

Re: Cheking item quantity just before pay.

It is always a good practice to check the item quantity before making a payment to avoid any discrepancies or overcharges. This is especially important when dealing with top cyber security companies in Dubai, as they may have complex pricing structures or offer additional services that could impact the final amount due. By double-checking the number of items being purchased, you can ensure that you are paying the correct amount and avoid any potential billing issues. Additionally, it is recommended to review the invoice or receipt provided by the company to confirm that all charges are accurate and accounted for.

Re: Cheking item quantity just before pay.


@mpstoevgmaea24 wrote:

Hi to all!

First, excuse me if my question not in the correct forum group, but let me ask!

As payment module developer, I am curious about the following case:

a customer add an item into the Cart and go to the checkout page. Select a provider and click on the "pay" button. But in same moment someone else get the last item. Do Magento system care for this case, for example preserve some minimal item quantity or the the payment plugin must care?

If non care it happens the client go to some redirect payment page and pay, then return to the shop site and see the message like "Your item is no more available". At the end the money are gone and an Order is not made, but Cart is active.

If my plugin must made last check for item quantity, what is the best approach to do it? Checking quantity for a simple product is not a problem, but when I tried to check the quantity of variable product (by color) I failed.

 

Thanks!


Because of these issue sometime i want to delete my website from Magento CMS. Many issues faced and solution also not found easily. I got issue in my website same type of issue in https://realtimeapk.com/gta-5-apk/ my website.

Re: Cheking item quantity just before pay.

In Magento, you can check the item quantity just before payment by implementing a custom solution or using available extensions or plugins that offer this functionality. This feature ensures that the items in the customer's shopping cart are still in stock before they proceed with the payment process.

 

One way to achieve this is by utilizing event observers or customizing the checkout process. By hooking into the appropriate events, you can intercept the payment process and verify the item quantities against your inventory. If the quantities are insufficient, you can prevent the payment from being processed and notify the customer about the unavailability of certain items.

 

Keep in mind that the exact implementation may vary depending on your Magento version and the specific requirements of your E-commerce store. It's recommended to consult with Magento developers or E-commerce solution services that specialize in Magento to ensure a seamless integration and optimal user experience. Additionally, you may find ready-made extensions in the Magento Marketplace that offer this feature, saving you development time and effort.