Jump to content

Get Package Details ,in Service Add Event


AllToolKits.com

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
  • ...
Link to comment
Share on other sites

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;
Link to comment
Share on other sites

  • 1 year later...
On 6/12/2015 at 0:34 AM, 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;

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.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...