Luca berta Posted October 2 Share Posted October 2 Hello. I would like to use displayCarrierExtraContent in my module. i registered hook: $this->registerHook('displayCarrierExtraContent') then i create this function. public function hookDisplayCarrierExtraContent($params) { return $this->display(__FILE__, 'views/templates/admin/carrier/carrier_extra_content.html.tpl'); } But when i select carrier in checkout the funtion is not work. i suppose the function have to start when the customer click on the carrier in checkout. But it not working. Link to comment Share on other sites More sharing options...
Andrei H Posted October 3 Share Posted October 3 Hello, The displayCarrierExtraContent hook is called only for carrier modules. It does not work for the carriers manually created in the admin panel. You can see that in the following class: DeliveryOptionsFinder.php If you want to display some additional text in the carrier section, you have the following options: 1. Use a general hook like displayBeforeCarrier or displayAfterCarrier - this text will be displayed before/after all carriers, not for each one of them. 2. Create an override for the DeliveryOptionsFinder class. Not really recommended but it can get the job done. 3. Create a carrier module. This will work only if you do not plan on distributing the module, as merchants can have different carriers as well. Link to comment Share on other sites More sharing options...
Luca berta Posted October 3 Author Share Posted October 3 2 hours ago, Andrei H said: Hello, The displayCarrierExtraContent hook is called only for carrier modules. It does not work for the carriers manually created in the admin panel. You can see that in the following class: DeliveryOptionsFinder.php If you want to display some additional text in the carrier section, you have the following options: 1. Use a general hook like displayBeforeCarrier or displayAfterCarrier - this text will be displayed before/after all carriers, not for each one of them. 2. Create an override for the DeliveryOptionsFinder class. Not really recommended but it can get the job done. 3. Create a carrier module. This will work only if you do not plan on distributing the module, as merchants can have different carriers as well. Hi Andrei, thanks for asnwer. I create a carrier module. And i want to show a text when customer click on carrier of my module. So , i set module_external_name in my carriers. And i set displayCarrierExtraContent (see code). But it's not working. i dont' want use displayBeforeCarrier or displayAfterCarrier because the text change when customer choose carrier. I need to use displayCarrierExtraContent , but i don't understand because hook not function. Do you have any idea? Link to comment Share on other sites More sharing options...
ps8modules Posted October 5 Share Posted October 5 (edited) Hi. You need to create your carrier correctly, then everything will work. Example of how the carrier should be created: $carrier = new Carrier(); $carrier->name = $this->l('my new carrier'); $carrier->active = 1; $carrier->deleted = 0; $carrier->shipping_handling = 0; $carrier->range_behavior = 0; $languages = \Language::getLanguages(false); $delays = []; $descriptions = []; foreach ($languages as $language) { $delays[$language['id_lang']] = 'my new carrier'; $descriptions[$language['id_lang']] = 'here is my new carrier'; } $carrier->delay = $delays; $carrier->description = $descriptions; $carrier->shipping_external = 1; $carrier->is_module = 1; $carrier->external_module_name = $this->name; $carrier->need_range = 1; // carrier logo if (file_exists(dirname(__FILE__) . 'logo.jpg')) { copy(dirname(__FILE__) . 'logo.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'); } $db = Db::getInstance(); $groups = Group::getGroups(true); $zones = Zone::getZones(true); $shops = Shop::getShops(true); if ($carrier->add()) { foreach ($groups as $group) { $db->insert( 'carrier_group', array( 'id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group'] ), ); } foreach ($zones as $zone) { $db->insert( 'carrier_zone', array( 'id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone'] ), ); } foreach ($shops as $shop) { $db->insert( 'carrier_shop', array( 'id_carrier' => (int) $carrier->id, 'id_shop' => (int) $shop['id_shop'] ), ); } } and call hook: public function hookDisplayCarrierExtraContent($params) { $myCarrierId = $this->id; if ($params['moduleId'] == $myCarrierId) { return $this->display(__FILE__, 'views/templates/admin/carrier/carrier_extra_content.html.tpl'); } } Edited October 5 by ps8modules (see edit history) Link to comment Share on other sites More sharing options...
Luca berta Posted October 7 Author Share Posted October 7 On 10/5/2024 at 6:17 AM, ps8modules said: Hi. You need to create your carrier correctly, then everything will work. Example of how the carrier should be created: $carrier = new Carrier(); $carrier->name = $this->l('my new carrier'); $carrier->active = 1; $carrier->deleted = 0; $carrier->shipping_handling = 0; $carrier->range_behavior = 0; $languages = \Language::getLanguages(false); $delays = []; $descriptions = []; foreach ($languages as $language) { $delays[$language['id_lang']] = 'my new carrier'; $descriptions[$language['id_lang']] = 'here is my new carrier'; } $carrier->delay = $delays; $carrier->description = $descriptions; $carrier->shipping_external = 1; $carrier->is_module = 1; $carrier->external_module_name = $this->name; $carrier->need_range = 1; // carrier logo if (file_exists(dirname(__FILE__) . 'logo.jpg')) { copy(dirname(__FILE__) . 'logo.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'); } $db = Db::getInstance(); $groups = Group::getGroups(true); $zones = Zone::getZones(true); $shops = Shop::getShops(true); if ($carrier->add()) { foreach ($groups as $group) { $db->insert( 'carrier_group', array( 'id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group'] ), ); } foreach ($zones as $zone) { $db->insert( 'carrier_zone', array( 'id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone'] ), ); } foreach ($shops as $shop) { $db->insert( 'carrier_shop', array( 'id_carrier' => (int) $carrier->id, 'id_shop' => (int) $shop['id_shop'] ), ); } } and call hook: public function hookDisplayCarrierExtraContent($params) { $myCarrierId = $this->id; if ($params['moduleId'] == $myCarrierId) { return $this->display(__FILE__, 'views/templates/admin/carrier/carrier_extra_content.html.tpl'); } } Thanks, i undestand my error. I have to set is_module = 1 and need_range = 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 7 Share Posted October 7 And wouldn't you rather upload the entire module here? Otherwise, we will be arguing about little things here and for several weeks. If you want to make a module, you have to find out in its class what needs to be turned off. For example: you want to create a carrier, so you go to ./classes/Carrier.php And there you will find what is necessary and what is not necessary to fill out. So, if you want custom text in your carrier module, you must have is_module=1. It is only about the logic of thinking. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now