[Solved]orderModel->getOrder($an_order_id_that_does_not_exists) creates new ordr

Started by welrachid, March 03, 2017, 13:13:41 PM

Previous topic - Next topic

welrachid

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
Best regards,
Wel

Milbo

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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

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())....

Best regards,
Wel