11

I'm getting an strange issue in Magento 2.2.7.

Some of the orders are duplicating despite us only receiving one payment.

It is the exact same order information except for the order number (which increments by 1 every time) and the time (about 5 - 10 seconds between each order) which I think might indicate someone pushing the "Place Order" button multiple times.

This seems to be happening at random and doesn't seem to be confined to a single product or payment method.

I was wondering if there was a way to resolve this error and stop us receiving multiple versions of the same order.

9
  • 3
    you will have to debug this and provide us more information. we can't help you like this Commented Feb 11, 2019 at 12:55
  • Hi. I'm quite new to Magento are there any instructions about how to debug a problem like this?
    – CJNotts
    Commented Feb 11, 2019 at 13:15
  • @CJNotts i have recently solve this type error in magento1 this issue is start your custom extension place order event or controller Commented Feb 14, 2019 at 9:43
  • Your all order status is pending right? if yes then check payment method and try to place order with that payment method you can see error in checkout Commented Feb 14, 2019 at 9:43
  • do tthis 2 orders have the same invoices? Commented Feb 14, 2019 at 10:27

2 Answers 2

1
+50

I found a solution over GIT :

Create an observer sales_order_place_before as below:

app/code/TB/FixDuplicateOrder/Observer/OrderPlacebefore.php

<?php
namespace TB\FixDuplicateOrder\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class OrderPlacebefore implements ObserverInterface
{
protected $_responseFactory;
protected $_url;


public function __construct(
    \Magento\Framework\App\ResponseFactory $responseFactory,
    \Magento\Framework\UrlInterface $url
) {
    $this->_responseFactory = $responseFactory;
    $this->_url = $url;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();

    $order = $observer->getEvent()->getOrder();
    $quoteID = $order->getQuoteId();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
    $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    $connection = $resource->getConnection();
    $tableName = $resource->getTableName('sales_order');
    $selectedTime = date('Y-m-d h:i:s');
    $endTime = strtotime("-15 seconds", strtotime($selectedTime));
    $last15Sec = date('Y-m-d h:i:s', $endTime);

    echo $sql = "SELECT * FROM `".$tableName."` WHERE `quote_id` = ".$quoteID." and `created_at` >= '$last15Sec'";
    if($result = $connection->fetchRow($sql)){
        $customerBeforeAuthUrl = $this->_url->getUrl('checkout');
        $this->_responseFactory->create()->setRedirect($customerBeforeAuthUrl)->sendResponse();
        exit();
    }
    //var_dump($result);
    //echo  "Hello Testing ";
    //die();
}

Reference URL : https://github.com/magento/magento2/issues/13952

1
  • Thanks, just dealing with another issue at the moment but I'll give that a go once I can and see if it resolves the issue.
    – CJNotts
    Commented Feb 19, 2019 at 9:32
1

I have a suggestion for you.

If there are no errors from Magento logs (var/log/...), we need to check the web server log.

For example, for apache log

We can use tail command to check live error log:

tail -f /var/log/apache2/error.log -n 100

In the past, I faced with the email error. The order was created before sending the email. That caused the duplicate info Orders:

cat /var/log/apache2/error.log | grep "mail"

vendor/magento/module-sales/Model/Order/Email/Sender.php

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.