Jump to content

Recommended Posts

Posted

Hi,

 

In a plugin i have below code

 public function getEvents() {
        return array(
            array(
                'event' => "Services.add",
                'callback' => array("this", "myAction")
            )
              
        );
    }


    public function myAction($event) {
        $params = $event->getParams();

        echo "<pre>"; print_r($params);
    }

This code is calling when a new   service is added.  $params do have many details like service id and many other info.

I need package details too here.  When adding a package i am giving few informations under module options, but i can't see that in $params . How i can get those package details in the function   myAction?

Posted

From the Services.add section in the page  http://docs.blesta.com/display/dev/Event+Handlers

it has below information

  • configoptions - An array of key/value pairs of package options where the key is the package option ID and the value is the option value
  • (any other service field data passed to the module)

 

But that part is missing in the $params. Everything else is there.  everything else is there.

Posted

configoptions are only included if they are given when the service is created. The same is true for other fields as well. You shouldn't assume that every field will be given.

 

  • vars - An array of input data which may include:
  • ...
  • configoptions - An array of key/value pairs of package options where the key is the package option ID and the value is the option value
  • (any other service field data passed to the module)
  • ...
Posted

I got what  i want now :)

      $params = $event->getParams();
      $service_id = (int) $params['service_id'];
      Loader::loadModels($this, array("Services", "Packages"));
      $details = $this->Services->get( $service_id);  
      $package_id = (int) $details->package->id;
      $p_details = $this->Packages->get($package_id);
      $meta_array = array();
      $meta_array =  $p_details->meta;
  • 1 year later...
Posted
  On 6/11/2015 at 6:34 PM, AllToolKits.com said:

I got what  i want now :)

      $params = $event->getParams();
      $service_id = (int) $params['service_id'];
      Loader::loadModels($this, array("Services", "Packages"));
      $details = $this->Services->get( $service_id);  
      $package_id = (int) $details->package->id;
      $p_details = $this->Packages->get($package_id);
      $meta_array = array();
      $meta_array =  $p_details->meta;
Expand  

Thank you AllToolKits.com, I have got a big solution from your code. Blesta doesn't give package id in Invoice. i go to service class then get package id.

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...