5haun Posted August 18, 2014 Share Posted August 18, 2014 HelloI wanted to put the carrier compare module into one of my cms pages. This cms page specifically:http://store.audio-visual.co.za/content/1-shippingCan someone help me through the process? Link to comment Share on other sites More sharing options...
NemoPS Posted August 18, 2014 Share Posted August 18, 2014 Well you need a custom hook, adding it this way: http://blog.arvixe.com/adding-hooks-to-prestashop-1-5-the-new-way/ Then, add the hok method to that module by editing its core file, and making sure that Tools::getValue('id_cms')equals the page you want, otherwise return false (to display it on that page only) 1 Link to comment Share on other sites More sharing options...
5haun Posted August 18, 2014 Author Share Posted August 18, 2014 Erm okay. I'm not very php savvy and I was hoping you could guide me further. I managed to register hook and in carriercompare.php I added: public function hookCustomShippingHook() { return 'hi there!'; } In cms.tpl I added: <div> {if $cms->id == 1} {hook h='customshippinghook'} {/if} </div> I see the 'hi there!'. Link to comment Share on other sites More sharing options...
NemoPS Posted August 18, 2014 Share Posted August 18, 2014 Yes, perfect, that's the way to go! Now you only need to clone the normal hook used by carriercompare (which I forgot). I hope it doesn't use any params variable 1 Link to comment Share on other sites More sharing options...
5haun Posted August 18, 2014 Author Share Posted August 18, 2014 Okay I just copied now I get "Fatal error: Cannot redeclare CarrierCompare::getStatesByIdCountry() in /home/bbhs103/public_html/store/modules/carriercompare/carriercompare.php on line 409"Um check what I did to public function hookCustomShippingHook in the attached file carriercompare.php Link to comment Share on other sites More sharing options...
NemoPS Posted August 19, 2014 Share Posted August 19, 2014 This method is duplicated, get rid of one /* ** Get states by Country id, called by the ajax process ** id_state allow to preselect the selection option */ public function getStatesByIdCountry($id_country, $id_state = '') { $states = State::getStatesByIdCountry($id_country); return (sizeof($states) ? $states : array()); } 1 Link to comment Share on other sites More sharing options...
5haun Posted August 19, 2014 Author Share Posted August 19, 2014 Okay I seem to be getting somewhere. The block shows up but not properly. Also, some errors: Notice: Undefined variable: params in /home/bbhs103/public_html/store/modules/carriercompare/carriercompare.php on line 390Notice: Trying to get property of non-object in /home/bbhs103/public_html/store/modules/carriercompare/carriercompare.php on line 390 Current code: public function hookCustomShippingHook() { if (!$this->isModuleAvailable()) return; if (!isset($this->context->cart) || $this->context->cart->getProducts() == 0) return; $protocol = (Configuration::get('PS_SSL_ENABLED') || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; $endURL = __PS_BASE_URI__.'modules/carriercompare/'; if (method_exists('Tools', 'getShopDomainSsl')) $moduleURL = $protocol.Tools::getShopDomainSsl().$endURL; else $moduleURL = $protocol.$_SERVER['HTTP_HOST'].$endURL; $refresh_method = Configuration::get('SE_RERESH_METHOD'); if(isset($this->context->cookie->id_country) && $this->context->cookie->id_country > 0) $id_country = (int)$this->context->cookie->id_country; if(!isset($id_country)) $id_country = (isset($this->context->customer->geoloc_id_country) ? (int)$this->context->customer->geoloc_id_country : (int)Configuration::get('PS_COUNTRY_DEFAULT')); if (isset($this->context->customer->id) && $this->context->customer->id && isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery) { $address = new Address((int)($this->context->cart->id_address_delivery)); $id_country = (int)$address->id_country; } if(isset($this->context->cookie->id_state) && $this->context->cookie->id_state > 0) $id_state = (int)$this->context->cookie->id_state; if(!isset($id_state)) $id_state = (isset($this->context->customer->geoloc_id_state) ? (int)$this->context->customer->geoloc_id_state : 0); if(isset($this->context->cookie->postcode) && $this->context->cookie->postcode > 0) $zipcode = Tools::safeOutput($this->context->cookie->postcode); if(!isset($zipcode)) $zipcode = (isset($this->context->customer->geoloc_postcode) ? $this->context->customer->geoloc_postcode : ''); $this->smarty->assign(array( 'countries' => Country::getCountries((int)$this->context->cookie->id_lang, true), 'id_carrier' => ($params['cart']->id_carrier ? $params['cart']->id_carrier : Configuration::get('PS_CARRIER_DEFAULT')), 'id_country' => $id_country, 'id_state' => $id_state, 'zipcode' => $zipcode, 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'new_base_dir' => $moduleURL, 'refresh_method' => ($refresh_method === false) ? 0 : $refresh_method )); return $this->display(__FILE__, 'template/carriercompare.tpl'); } Link to comment Share on other sites More sharing options...
5haun Posted August 19, 2014 Author Share Posted August 19, 2014 Okay now I changed public function hookCustomShippingHook() to public function hookCustomShippingHook($params) and the error is gone now. How do I get the block to function properly now? Link to comment Share on other sites More sharing options...
NemoPS Posted August 20, 2014 Share Posted August 20, 2014 I tried it myself while writing my new tut (http://nemops.com/how-to-hooks-prestashop-cms/#.U_RXL_na6r0) it's quite complicated as it needs cart variables, and there was some broken javascript as well. The problem is the params here probably doesn't contain 'cart', can you check with a var_dump($params) ? 1 Link to comment Share on other sites More sharing options...
5haun Posted August 20, 2014 Author Share Posted August 20, 2014 Oh cool it's awesome that you did a tutorial See attached for what I got with var_dump($params) var_dump($params).txt Link to comment Share on other sites More sharing options...
NemoPS Posted August 20, 2014 Share Posted August 20, 2014 Ah, it seems that the cart is set but with null values, did you have anything inside when dumped the variable? 1 Link to comment Share on other sites More sharing options...
5haun Posted August 20, 2014 Author Share Posted August 20, 2014 Oh okay. No, I didn't have anything inside the cart Link to comment Share on other sites More sharing options...
NemoPS Posted August 21, 2014 Share Posted August 21, 2014 ok, just to know. Now, how is the module currently behaving? 1 Link to comment Share on other sites More sharing options...
5haun Posted August 21, 2014 Author Share Posted August 21, 2014 It doesn't seem to be loading the carriers. You can have a look here:http://store.audio-visual.co.za/content/1-shipping Link to comment Share on other sites More sharing options...
NemoPS Posted August 22, 2014 Share Posted August 22, 2014 Same result i got, I think there is a missing variable somewhere... probably related to the customer address.... hm,go and guess which one, gosh 1 Link to comment Share on other sites More sharing options...
5haun Posted August 22, 2014 Author Share Posted August 22, 2014 I don't know been looking at the code and I don't know what to do. As I said I don't really understand PHP all too well.Anyone else on here got some ideas? Link to comment Share on other sites More sharing options...
NemoPS Posted August 23, 2014 Share Posted August 23, 2014 Ok, it seems the ajax call is located in carriercompare.js, I guess you have to always have it hooked to the header...probably, didn't test it 1 Link to comment Share on other sites More sharing options...
5haun Posted August 25, 2014 Author Share Posted August 25, 2014 Okay where exactly is the code that I need to modify? Link to comment Share on other sites More sharing options...
NemoPS Posted August 25, 2014 Share Posted August 25, 2014 This one public function hookHeader($params) { if (!$this->isModuleAvailable() || !isset($this->context->controller->php_self) || $this->context->controller->php_self != 'order') return; if (isset($this->context->controller->step) && $this->context->controller->step == 0) { $this->context->controller->addCSS(($this->_path).'style.css', 'all'); $this->context->controller->addJS(($this->_path).'carriercompare.js'); } } Remove all conditions and only leave addjs and css 1 Link to comment Share on other sites More sharing options...
5haun Posted August 25, 2014 Author Share Posted August 25, 2014 Wow thank you Nemo!Code public function hookHeader($params) { if (!$this->isModuleAvailable()) return; $this->context->controller->addCSS(($this->_path).'style.css', 'all'); $this->context->controller->addJS(($this->_path).'carriercompare.js'); } Works like a charm! Thank you very much for all your help Link to comment Share on other sites More sharing options...
Recommended Posts