VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Kuubs on September 26, 2022, 15:37:33 PM

Title: Plugin to automatically change order status, what method should I override?
Post by: Kuubs on September 26, 2022, 15:37:33 PM
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");
}
}
}

}






}
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: Kuubs on September 28, 2022, 20:57:40 PM
Nobody knows the answer? Maybe some of the devs can answer?
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: 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
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: Kuubs on October 04, 2022, 10:13:32 AM
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.
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: 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);
}
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: Milbo on October 05, 2022, 22:52:17 PM
Even better with a category
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: Kuubs on October 19, 2022, 09:31:37 AM
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?
Title: Re: Plugin to automatically change order status, what method should I override?
Post by: GJC Web Design on October 19, 2022, 12:30:54 PM
either edit it and update each version update or copy it. rename it, change it and use it