Author Topic: Set order status via URL - possible?  (Read 6340 times)

gba

  • Jr. Member
  • **
  • Posts: 227
Set order status via URL - possible?
« on: April 15, 2015, 17:40:03 pm »
Hi community!

In BE view of an order you can manually update the order status.
Is there a possibility to update the status via an URL?
Like i.e.:
http://myshop.com/index.php?option=com_virtuemart&view=orders&task=updatestatus&order_status=S&order_number=a73e031&order_pass=p_958d6

Any useful hints are very welcome!

Kind regards,
Gerald

EDIT:
Of course on updating the status via URL everything shall work like having it manually done in BE (update status in DB, send e-mails according to configuration, etc.)

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #1 on: April 15, 2015, 21:32:13 pm »
Hi VM development team!

I seem to be on a good path.
I created a component 'com_updateorderstatus' having following code in FE:
Code: [Select]
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');

$data = vRequest::getRequest();
$model = VmModel::getModel('orders');
$virtuemart_order_id = $model->getOrderIdByOrderPass($data['order_number'],$data['order_pass']);
$order = array();
$order[$virtuemart_order_id] = ($data);
$result = $model->updateOrderStatus($order);

The URL I use is:
http://myshop.com/index.php?option=com_updateorderstatus&order_number=150415105101&order_pass=C2gVIMHH&order_status=U

But $data needs to contain some information more, than just my own parameters.
The main work seems to be done in function updateStatusForOneOrder() in file /administrator/components/com_virtuemart/models/orders.php, right?

Could you, please, give me a hint, what parameters exactly are needed to update the order status and to run all necessary triggers?
I'd be very grateful for any help!

Kind regards,
Gerald

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7637
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Set order status via URL - possible?
« Reply #2 on: April 15, 2015, 22:12:12 pm »
Your basically imitating what the response part of any payment plugin does

perhaps a comp is a bit over kill - you could probably do it as a dummy payment plugin and use the std. response url (pm is the payment method id)
you could set its filter to some extra high cart amount so it doesn't show on the frontend

index.php?option=com_virtuemart&view=vmplg&task=pluginresponsereceived&on=5555555&pm=6&order_status=U&order_pass=xxxxx

in the plugin is
function plgVmOnPaymentResponseReceived (&$html) {
      
      
      if (!class_exists ('VirtueMartModelOrders')) {
         require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
      }
      $jinput = JFactory::getApplication()->input;
      $return = $jinput->getArray(array( 'on' => '', 'pm' => '', 'order_status' => '', 'order_pass' => ''));

                $model = VmModel::getModel('orders');
              $virtuemart_order_id = $model->getOrderIdByOrderPass($return['on'],$return['order_pass']);
               $order = $model->getOrder($virtuemart_order_id);

                 result = $model->updateStatusForOneOrder ($virtuemart_order_id, $order, TRUE);
}

might work

if you look at a simple payment plugin










GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #3 on: April 20, 2015, 15:02:57 pm »
Hello!

Thank you very much for your hint.
This approach makes for sure, that calling this URL all triggers will be run like if I would update the order status in backend manually?

Kind regards,
Gerald

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7637
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Set order status via URL - possible?
« Reply #4 on: April 20, 2015, 22:16:41 pm »
exactly
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #5 on: April 21, 2015, 13:36:32 pm »
Hello!

I really tried hard to implement your example, but it seems as if the parameters are not completely right:
The function plgVmOnPaymentResponseReceived() in my "payment" plugin seems not to be triggered.
There is no place in the VM source code, where the parameter 'task' can is checked for value 'pluginresponsereceived'.

BTW: What difference is between view=vmplg and view=pluginresponse?

Kind regards,
Gerald

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7637
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Set order status via URL - possible?
« Reply #6 on: April 21, 2015, 15:15:46 pm »
components\com_virtuemart\controllers\vmplg.php
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #7 on: April 21, 2015, 16:34:53 pm »
Thank you very much for your help!
I decided to stick to a tiny component.

In the site part I have following code:
Code: [Select]
<?php
// no direct access
defined'_JEXEC' ) or die( 'Restricted access' );

if (!
class_exists'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
VmConfig::setdbLanguageTag();
$jinput JFactory::getApplication()->input;
$rdata $jinput->getArray(array('on'=>'','op'=>'','os'=>''));
$model VmModel::getModel('orders');
$virtuemart_order_id $model->getOrderIdByOrderPass($rdata['on'],$rdata['op']);
$order = array();
$order['order_status'] = $rdata['os'];
$orderstatusForShopperEmail VmConfig::get('email_os_s',array('U','C','S','R','X'));
if(!
is_array($orderstatusForShopperEmail)) $orderstatusForShopperEmail = array($orderstatusForShopperEmail);
$order['customer_notified'] = (in_array($order['order_status'],$orderstatusForShopperEmail)) ? 0;
$order['include_comment'] = 0;
$result $model->updateStatusForOneOrder ($virtuemart_order_id,$order,TRUE);
echo 
$result;

And here is an example URL for using it to update the order status:
http://myshop.com/index.php?option=com_updateorderstatus&on=150415105101&op=C2gVIMHH&os=U&format=raw

This way I get 1 if succeeded, otherwise 0.
What does the VM community think about that?  ;)

Best regards,
Gerald

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9412
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Set order status via URL - possible?
« Reply #8 on: April 21, 2015, 18:49:13 pm »
nice done, check for security
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #9 on: April 21, 2015, 21:02:28 pm »
Thank you  :)
Check for security?
Doesn't function getOrderIdByOrderPass() already check security??

Kind regards,
Gerald

inkomico

  • Beginner
  • *
  • Posts: 17
Re: Set order status via URL - possible?
« Reply #10 on: January 30, 2016, 19:17:35 pm »
Hello gba, can you share this component?

Thanks!

gba

  • Jr. Member
  • **
  • Posts: 227
Re: Set order status via URL - possible?
« Reply #11 on: February 02, 2016, 13:16:07 pm »
Hi!

The question about the security issue mentioned is not ansered, yet.
The code you can find above.

Kind regards,
Gerald

inkomico

  • Beginner
  • *
  • Posts: 17
Re: Set order status via URL - possible?
« Reply #12 on: February 03, 2016, 19:47:58 pm »
Ok, thanks. I'll create the component and try.

Adwans

  • Beginner
  • *
  • Posts: 35
  • Beginner, I do think so
Re: Set order status via URL - possible?
« Reply #13 on: September 05, 2016, 23:01:50 pm »
Hello everybody!
So I decided to prepare a plugin according to your , gba and GJC tips. Dummy payment plugin. With only one php file containing only one function:
Code: [Select]
function plgVmOnPaymentResponseReceived( &$virtuemart_order_id, &$html) {
if (!class_exists ('VirtueMartModelOrders')) {
     require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
      }
     $jinput = JFactory::getApplication()->input;
     $statusy = array( 'P' => 'oczekujący', 'U' => 'potwierdzony przez użytkownika', 'C' => 'potwierdzony', 'S' => 'wysłany','X' => 'anulowany','R' => 'zwrócony');

$return = $jinput->getArray(array( 'on' => '', 'os' => ''));
        $model = VmModel::getModel('orders');
.....
and - URL status change works! Also sends email to me everytime it happens.
BUT :( I missed sth, since PLugin interrupts "VM payments method edit page" - FOR EXAMPLE:
With plugin enabled:
Code: [Select]
/administrator/index.php?option=com_virtuemart&view=paymentmethod&task=edit&cid[]=7is blank.
With plugin disabled - is ok.
What is wrong? Does payment plugin need some another file, config, language? More plugin must-be functions?

@GJC maybe this is the reason:
Quote
you could set its filter to some extra high cart amount so it doesn't show on the frontend
This is my first approach to this topic, since I only desired to manipulate order status - not to have any new payment created .
Regards!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7637
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Set order status via URL - possible?
« Reply #14 on: September 06, 2016, 09:51:47 am »
I guess you should add to the plug the conditions function to stop it being called during the edit

maybe by amount or detect if FE/admin or look for a url var etc .. depends how your using this

e.g. with an amount

protected function checkConditions ($cart, $method, $cart_prices) {
$amount = $this->getCartAmount($cart_prices);
if($amount < 999999999) { return false;}
}
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation