News:

Looking for documentation? Take a look on our wiki

Main Menu

Plugin to automatically change order status, what method should I override?

Started by Kuubs, September 26, 2022, 15:37:33 PM

Previous topic - Next topic

Kuubs

Hello,

I'd like to build a plugin that automatically changes order status based on product id. I now use the following method:

plgVmOnUpdateOrderPayment

But this gets called before the actual order is set (so that the confirmed status isn't actually sending emails etc) my plugin catches this before, so it changes the order status but it doesn't sent the confirmed emails to vendor and shopper. Does anyone know if I have to use another method to override?

So I got the following code, but the problem is is that the customer gets notified twice... In the backend at hte order status overview for that specific order is also 2 times the sent order status with one time not notifying customer, and one time it does. But it gets sent twice.

function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
$app = JFactory::getApplication();
$go = false;
if (!$app->isAdmin()){
#return true;
}
$id_product = $this->params->get('id_product', '');
$id_product_array = explode(',',$id_product);

$fromOrderStatus = $this->params->get('from_order_status', 'C');
$fromOrderStatusArray = explode(',',$fromOrderStatus);

$toOrderStatus = $this->params->get('to_order_status', 'S');

$shipmentId = $this->params->get("id_shipment", 6);
$sid_array = explode(',',$shipmentId);

$productid = $debug = $this->params->get('id_product', 0);

if(in_array($data->virtuemart_shipmentmethod_id, $sid_array)){

if($old_order_status == "P"){

$modelOrder = VmModel::getModel ('orders');
$data->order_status = "C";
if($modelOrder->updateStatusForOneOrder($order->virtuemart_order_id, (array)$data, true)){
if(in_array($data->order_status, $fromOrderStatusArray)){




$order = $data;
$result = $this->plgVmCustomAutochange($data, $old_order_status, $toOrderStatus,  "orderchange");

if($result == 'saved'){

} else {
#print 'Debug Line odersave.php '.__LINE__.' $result <pre>'; print_r ($result); print "</pre><br />\n";
#die();
vmInfo("Automatic order change didn't work :( ");
}
} else {
//vmInfo("Not in array");
}
}
}

}






}

Kuubs


Milbo

From my point of view, you try to use it irregular and the good code prevents it.

I just wonder, what you really want to achieve with this idea. Leave the workaround beside and just tell the real idea. Then I may find a simpler way
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Kuubs

Quote from: Milbo on October 02, 2022, 23:27:42 PM
From my point of view, you try to use it irregular and the good code prevents it.

I just wonder, what you really want to achieve with this idea. Leave the workaround beside and just tell the real idea. Then I may find a simpler way

I basically have a product that gets handled at another location. When the confirmed email is sent to the vendor, it also gets sent to the other location. They will handle the order. I want it to go straight to Shipped so that the stock gets handled correctly and the customer gets a shipped email. Basically changing the order status automatically to Shipped, after the order has been confirmed.

GJC Web Design

would it not be simpler to extend what ever payment plugins you are using?

e.g. Standard Payment plugin    function plgVmConfirmedOrder ($cart, $order)



if (virtuemart_product_id == x) {
     $order['order_status'] = 'S';
}else{
    $order['order_status'] = $this->getNewStatus ($method);
}
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

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/

Kuubs

Quote from: GJC Web Design on October 04, 2022, 19:42:48 PM
would it not be simpler to extend what ever payment plugins you are using?

e.g. Standard Payment plugin    function plgVmConfirmedOrder ($cart, $order)



if (virtuemart_product_id == x) {
     $order['order_status'] = 'S';
}else{
    $order['order_status'] = $this->getNewStatus ($method);
}

How can I extend a plugin?

GJC Web Design

either edit it and update each version update or copy it. rename it, change it and use it
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