Jump to content

Add carrier compare to CMS page


5haun

Recommended Posts

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

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());
	}

  • Like 1
Link to comment
Share on other sites

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 390

Notice: 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

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

  • Like 1
Link to comment
Share on other sites

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

×
×
  • Create New...