VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on January 17, 2018, 12:58:53 PM

Title: Cancelled order status and SQL error
Post by: sandomatyas on January 17, 2018, 12:58:53 PM
There are special cases where VM tables are a bit inconsitens because of user or 3rd party software. In my case a simple script modifies the value of #__virtuemart_products.product_sale field. It stores to the product sales of the last 4 weeks. Don't ask, it's a customer's request.
But in special cases if I cancel an order VM wants to set the correct product_sale value wich can lead to an SQL error
This is the SQL error for updateStatusForOneOrder
[query:JDatabaseExceptionExecuting:private] => UPDATE `jos_virtuemart_products` SET `product_in_stock` = `product_in_stock` +10, `product_sales` = `product_sales` -10 WHERE `virtuemart_product_id` = 339
[message:protected] => BIGINT UNSIGNED value is out of range in '(`demo_virtuemart`.`#__virtuemart_products`.`product_sales` - 10)'

This is because the value of product_sales is less than 10.
I can fix it for myself, so it is just a notice if anybody else has the same problem.
I know it isn't because VM but the error occours in VM so maybe a simple check wouldn't hurt.
Title: Re: Cancelled order status and SQL error
Post by: Studio 42 on January 17, 2018, 21:31:01 PM
Add a function  adding the same value in product sales so you never have a negative value.
You can use a simple vmpayment plugin with only 1 function plgVmOnCancelPayment to do this