VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: welrachid on March 03, 2017, 13:13:41 PM

Title: [Solved]orderModel->getOrder($an_order_id_that_does_not_exists) creates new ordr
Post by: welrachid on March 03, 2017, 13:13:41 PM
Hi guys.
I've have made a component that will help a customer to "scan" printed orders so that they auto-change status, print out a shipping label AND capture payment.


      $input = JFactory::getApplication()->input;
      $virtuemart_order_id = $input->getVar('virtuemart_order_id');
      if (!class_exists ('shopFunctionsF'))
         require(VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
      if(!class_exists('VirtueMartControllerInvoice')) require( VMPATH_SITE.DS.'controllers'.DS.'invoice.php' );
      $controller = new VirtueMartControllerInvoice( array(
         'model_path' => VMPATH_SITE.DS.'models',
         'view_path' => VMPATH_SITE.DS.'views'
      ));

      $orderModel=VmModel::getModel('orders');
      $order_data = $orderModel->getOrder($virtuemart_order_id);

Using this code i apparently are creating a new order if for some reason someone TYPES in a wrong vm_order_id that does not exist.

since there is no documentation for VM3 i have seen into the VM2 docs:

https://docs.virtuemart.net/api-vm2/de/dee/administrator_2components_2com__virtuemart_2models_2orders_8php_source.html

Then i've looked into the file on line 213
public function getOrder($virtuemart_order_id, $userlang=false)

is has no mention of insert into.. onyl selects..
not sure if this is a bug?

VM 3.0.14 on J!3.6.5
Title: Re: orderModel->getOrder($an_order_id_that_does_not_exists) creates new order
Post by: Milbo on March 03, 2017, 23:10:31 PM
First, I do not understand for what you use the controller. Yes, getOrder should not write an order. I think something else is going on in the background
Title: Re: orderModel->getOrder($an_order_id_that_does_not_exists) creates new order
Post by: welrachid on March 06, 2017, 10:32:55 AM
I've found the error.
It is in my own code.
Somewhere after this i had a missing check, after which made $orderModel->updateStatusForOneOrder
and this is where a new order creation is triggered.
if($data->store())....