Jump to content

Changing carrier delay from within shipping module


Recommended Posts

Hi

 

I am writing a customised shipping module for PrestaShop 1.4

 

The module is already working, but i wanted it to dinamically change the shipping delay, from whithin the shipping module. Can this be done? How?

 

I was looking at getDeliveryOptionList and HOOK_BEFORECARRIER, but I don't know how to do it. Any help would be welcome.

 

Thanks

Link to comment
Share on other sites

  • 1 month later...

I did it for presta 1.5 and it should work with multi shipping also. I did not tested it extensively though

 

in install function of your module:

$this->registerHook('displayBeforeCarrier')

 

then implement the hook making sure to replace YOUR_MODULE_ID with your module carrier id! (not your actual module id but carrier id that you use)

 

public function hookDisplayBeforeCarrier($params) {
 global $appended_text;

 $delivery_option_list = $params['delivery_option_list'];
 foreach($delivery_option_list as $id_address => $carrier_list_raw) {
  $appended_text = 'tetsting appended text';
  foreach($carrier_list_raw as $key => $carrier_list) {
foreach($carrier_list['carrier_list'] as $id_carrier => $carrier) {
 if($id_carrier != YOUR_MODULE_ID) {
  continue;
 }
 $delay = &$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance']->delay;
 $delay = array_map(function ($item) {global $appended_text; return $item.$appended_text;}, $delay);
}
  }
 }

 // overwrite the list of shipping options
 $this->context->smarty->assign('delivery_option_list', $delivery_option_list);
}

Link to comment
Share on other sites

  • 5 months later...

Hi, it returns:

 

Parse error: syntax error, unexpected T_FUNCTION, expecting ')'

 

in this line:

 

$delay = array_map(function ($item) {global $appended_text; return $item.$appended_text;}, $delay);

 

I'm also trying to change delay message, once it changes every time. But I think that I must act directly on order_carrier.tpl file in order to make it work the way as I need.

Link to comment
Share on other sites

  • 1 year later...

I am also trying to change the shipping delay text to reflect the API response from the shipping company which is stored the MySQL database in prestashop.  although i can't figure out in which class/method to override the default delay text.  any help would be apreciated.

 

I'm using the canada post shipping module from a 3rd party and prestashop 1.6.0.14

Link to comment
Share on other sites

  • 2 years later...

this worked for me on prestashop 1.6
    public function hookDisplayBeforeCarrier($params) {
        global $appended_text;
        $delivery_option_list = $params['delivery_option_list'];
        foreach($delivery_option_list as $id_address => $carrier_list_raw) {
           $appended_text = "Custom text";
           foreach($carrier_list_raw as $key => $carrier_list) {
                foreach($carrier_list['carrier_list'] as $id_carrier => $carrier) {
                     if($id_carrier != YOUR_CARRIER_ID) {
                      continue;
                     }
                     $delay = $delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance']->delay;
                     $delay = array_map(function ($item) {global $appended_text; return $appended_text;}, $delay);
                     $delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance']->delay=$delay;
                    
                }
           }
        }
        // overwrite the list of shipping options
        $this->context->smarty->tpl_vars["delivery_option_list"]->value=$delivery_option_list;
    }

Link to comment
Share on other sites

×
×
  • Create New...