VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sscheidegger on May 30, 2022, 17:43:24 PM

Title: Invoice randomly shows 0 instead of Payment Name
Post by: sscheidegger on May 30, 2022, 17:43:24 PM
Dear VirtueMart dev team,

the invoice sent to our customers usually looks as expected. However, about once a month or less, there is simply a 0 instead of the Payment Method Name. It hapens usually when customers use PayPal.

We tracked down the problem and found the bug in administrator/components/com_virtuemart/plugins/vmpsplugin.php in the getOrderMethodNamebyOrderId() method:


$q = 'SELECT * FROM `' . $this->_tablename . '` '
                        . 'WHERE `virtuemart_order_id` = ' . (int)$virtuemart_order_id;


In our tests, this select statement returns two rows for one OrderId. The first row contains a payment_name and all other information. The second row has most columns including payment_name set to 0, but column paypal_fullresponse contains some information.
As the above select statement contains no ORDER BY clause, the order in which the two rows are returned is not determined. In some cases, the row with payment_name 0 is returned first causing the bug.

Our suggested solution:

$q = 'SELECT * FROM `' . $this->_tablename . '` '
                        . 'WHERE `virtuemart_order_id` = ' . (int)$virtuemart_order_id
                        . ' ORDER BY `id` LIMIT 1';


In a quick test in our environment this resolved the problem.

Thanks a lot, have a great day,
Stefan


Joomla: 3.9.27
VritueMart: 3.8.8 10427
PHP: 8.0.19

Title: Re: Invoice randomly shows 0 instead of Payment Name
Post by: Milbo on May 29, 2023, 21:04:54 PM
Nice one, yes I an add that. But there will be a new paypal plugin soon, anyway.