Jump to content

Cant install my module


Recommended Posts

Hi there, im making my first steps as a module developer and im trying to make a module that will display as Related products, the products that have a similar reference code. 4 first digits will have to match to be exact.
 
When i try to install this i get an error and i cant seem to find the problem.... Any thoughts?

 

<?php

/**
 * Related Products by reference code
 *
 * @ver         1.0
 * @author      Cosmo
 * 
 */

if (!defined('_PS_VERSION_'))
	exit;

class Ref_RelatedProducts extends Module
{
	function __construct() {
 	 	$this->name = 'ref_relatedproducts';
 	 	$this->version = '1.0';
 	 	$this->tab = 'front_office_features';
		$this->author = 'Cosmo';
		parent::__construct();
		
		$this->displayName = $this->l('Related products by reference code');
		$this->description = $this->l('Display related products based on the selected products reference code.');
 	}
	
	public function install() {
		if($this->psversion()==6){
			if (!$this->registerHook('header')) return false;
		}
		$this->registerHook('siliadTabTitle');
		$this->registerHook('siliadTabContent');
		return true;
	}

	public function uninstall()	{
		if (!parent::uninstall() || !$this->unregisterHook('header'))
			return false;
		$this->unregisterHook('siliadTabTitle');
		$this->unregisterHook('siliadTabContent');
		return true;
	}
	
	public function hookSiliadTabTitle($params) {
    	     return ($this->display(__FILE__, 'ref_relatedproducts_tab.tpl'));		
	}
	
	public function hookSiliadTabContent($params) {

		$ref_related_products = array();
                $id_product = intval(Tools::getValue('id_product'));
		$prod= new Product($id_product);
		$product_ref = $prod->reference;
	        $context = Context::getContext();
		$other_products = $this->ref_getProductsRef($product_ref); 
		foreach($other_products as $other_key=>$other_value) {	
			if($other_value['id_product'] != $id_product && !array_key_exists($other_value['id_product'], $ref_related_products)) {
				$other_value['link'] = $context->link->getProductLink($other_value['id_product']);
				$other_value['displayed_price'] = Product::getPriceStatic($other_value['id_product'],true);
				$other_value['image'] = Image::getCover($other_value['id_product']);
				if(is_array($other_value['image'])) {
					$other_value['image']['id_image'] = $other_value['id_product'].'-'.$other_value['image']['id_image'];
					$other_value['image']['link_rewrite'] = $this->ref_LinkRewrite($other_value['id_product']);
				}
				$ref_related_products[$other_value['id_product']] = $other_value;
			}
		}

		
		$this->smarty->assign('refRelatedProducts', $ref_related_products);
		return $this->display(__FILE__, 'ref_relatedproducts.tpl');
		
		
	}

	
	
	public function ref_LinkRewrite($id_product) {
		 $result = Db::getInstance()->ExecuteS('SELECT `link_rewrite` 
												FROM `'._DB_PREFIX_.'product_lang` 
												WHERE `id_product`='.intval($id_product).' AND `id_lang` = '.intval($id_lang));
		 return $result[0]['link_rewrite'];
	}
	
	

	public function ref_getProductsRef( $reference)
	{
		$ref_code = substr($reference, 0,4);		
		return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT pl.id_product FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product'.Shop::addSqlRestrictionOnLang('pl').'
		'.Shop::addSqlAssociation('product', 'p').'WHERE product_shop.active = 1 AND pl.reference LIKE "'.$ref_code.'%" ORDER BY pl.id_product ASC');
	}
	
	public function psversion() {
		$version=_PS_VERSION_;
		$exp=$explode=explode(".",$version);
		return $exp[1];
	}
	
	public function hookHeader($params)
	{
		if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'product')
			return;
		$this->context->controller->addCSS($this->_path.'css/ref_relatedproducts16.css', 'all');
		$this->context->controller->addJqueryPlugin(array('scrollTo', 'serialScroll', 'bxslider'));
	}

}

}
Edited by cosmokrator (see edit history)
Link to comment
Share on other sites

I have turned on the dev mode. The error im getting is "The following module(s) could not be installed properly:

  • ref_relatedproducts :"

    is there anywhere i can see more info about this error to debug it? because i cant find anything
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...