VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Kuubs on November 24, 2023, 22:02:45 PM

Title: Shipment plugin, which method before storing the order?
Post by: Kuubs on November 24, 2023, 22:02:45 PM
I have a custom shipment plugin which saves order data. Now I want to check if that is filled in before i store the order.. But plgVmConfirmedOrder the order is already stored. How can I prevent the order save if a specific data is not set??
Title: Re: Shipment plugin, which method before storing the order?
Post by: Kuubs on November 27, 2023, 10:30:38 AM
Does nobody knows this?

I dislike the lack of documentation, and the unwillingness for other experienced developers to help other people. This should be an easy answer for the peolpe that know Virtuemart. But nobody knows??
Title: Re: Shipment plugin, which method before storing the order?
Post by: hazael on November 27, 2023, 10:48:09 AM
For example, I totally don't understand what you wrote, so I don't even bother with this post  ;D
Title: Re: Shipment plugin, which method before storing the order?
Post by: Kuubs on November 27, 2023, 11:00:31 AM
Quote from: hazael on November 27, 2023, 10:48:09 AM
For example, I totally don't understand what you wrote, so I don't even bother with this post  ;D

What do you mean you don't know what I wrote?

When an order is made there are probably a couple of methods that are being run (validating etc) before actually storing the order. So which method is that? That is the only thing I ask? What's so hard about that?

I want to check whether or not an order has all the requirements I need for my shipment. When a field is empty it should redirect back to the cart page and show an error.
Title: Re: Shipment plugin, which method before storing the order?
Post by: Jumbo! on November 28, 2023, 07:05:26 AM
VirtueMart triggers the "plgVmConfirmedOrder" event after saving the order in the "Pending" state. It passes two arguments to the event. The first is in the cart object, and the second is the order object. Therefore, you can not stop order creation when this event is called.

To check if the cart object has valid data and trigger an error before the order is saved, you must use the "plgVmOnCheckoutCheckDataShipment" event.

Example:

<?php

  
public function plgVmOnCheckoutCheckDataShipment($cart) {
    
// Do data validations here
    
$isValid false;

    
// If data is invalid
    
if (!$isValid) {
      
// Show the error message.
      
JFactory::getApplication()->enqueueMessage('Please fill up the required data.''error');

      
// Return false to stop order processing
      
return false;
    }

    
// Return true to allow order processing
    
return true;
  }
Title: Re: Shipment plugin, which method before storing the order?
Post by: Kuubs on November 28, 2023, 13:39:15 PM
Quote from: Jumbo! on November 28, 2023, 07:05:26 AM
VirtueMart triggers the "plgVmConfirmedOrder" event after saving the order in the "Pending" state. It passes two arguments to the event. The first is in the cart object, and the second is the order object. Therefore, you can not stop order creation when this event is called.

To check if the cart object has valid data and trigger an error before the order is saved, you must use the "plgVmOnCheckoutCheckDataShipment" event.

Example:

<?php

  
public function plgVmOnCheckoutCheckDataShipment($cart) {
    
// Do data validations here
    
$isValid false;

    
// If data is invalid
    
if (!$isValid) {
      
// Show the error message.
      
JFactory::getApplication()->enqueueMessage('Please fill up the required data.''error');

      
// Return false to stop order processing
      
return false;
    }

    
// Return true to allow order processing
    
return true;
  }


Thank you! This is great advice and help. Thanks again.