News:

Support the VirtueMart project and become a member

Main Menu

Set order status via URL - possible?

Started by gba, April 15, 2015, 17:40:03 PM

Previous topic - Next topic

gba

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

Hi VM development team!

I seem to be on a good path.
I created a component 'com_updateorderstatus' having following code in FE: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

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 https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

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

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

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

components\com_virtuemart\controllers\vmplg.php
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

gba

Thank you very much for your help!
I decided to stick to a tiny component.

In the site part I have following code:<?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

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

gba

#9
Thank you  :)
Check for security?
Doesn't function getOrderIdByOrderPass() already check security??

Kind regards,
Gerald

inkomico

Hello gba, can you share this component?

Thanks!

gba

Hi!

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

Kind regards,
Gerald

inkomico

Ok, thanks. I'll create the component and try.

Adwans

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:
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:
/administrator/index.php?option=com_virtuemart&view=paymentmethod&task=edit&cid[]=7
is 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:
Quoteyou 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

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 https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation