Jump to content
  • 0

Problem z instalacją modułu


mati010

Question

Witam, mam problem mianowicie chciałem zainstalować blok komentarzy na stronie głównej. 

Wcześniej był potem został usunięty, więc przekopiowałem pliki z kopii jaką miałem.

Podczas instalacj modułu:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TRUNCATE TABLE ps_block_coment_home_config; INSERT INTO ps_block_coment_home' at line 2CREATE TABLE IF NOT EXISTS ps_block_coment_home_config (name char(255),value char(255),id_shop int(11)); TRUNCATE TABLE ps_block_coment_home_config; INSERT INTO ps_block_coment_home_config VALUES ('hook_left','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_right','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_home','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_left_count','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_right_count','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_home_count','1',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_left_time','3',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_right_time','3',0); INSERT INTO ps_block_coment_home_config VALUES ('hook_home_time','3',0); INSERT INTO ps_block_coment_home_config VALUES ('product_name','1',0); INSERT INTO ps_block_coment_home_config VALUES ('product_foto','1',0); INSERT INTO ps_block_coment_home_config VALUES ('comment','1',0); INSERT INTO ps_block_coment_home_config VALUES ('date','1',0); INSERT INTO ps_block_coment_home_config VALUES ('name','1',0); INSERT INTO ps_block_coment_home_config VALUES ('surname','1',0); 

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Szczerze nie wiem, miałem poprawić klika drobiazgów znajomemu co ma dwa sklepy na preście i to miał.

Blok komentarzy na stronie głównej

Stworzone przez :prestahelp.com

Wersja :0.5 

 

Stara presta: 1.5.3.1

Link to comment
Share on other sites

  • 0

Pewnie tutaj cały kod nie przerobiony (czysty jaki był skopiowany):

<?php
if (!defined('_PS_VERSION_'))
	exit;

	require_once(dirname(__FILE__).'/../productcomments/ProductComment.php');
	
class BlockComentHome extends Module
{
	private $_html = '';
	private $_postErrors = array();
	private $configuration;
	private $pc=NULL;
	private $shop=NULL;

	public function __construct()
	{
		$this->name = 'blockcomenthome';
		$this->tab = 'front_office_features';
		$this->version = 0.5;
		$this->author = 'prestahelp.com';
		$this->need_instance = 0;
		$this->configuration = null;
		parent::__construct();
		
		$this->displayName = $this->l('Block coments Home');
		$this->description = $this->l('View comments');
	}
	
	public function install()
	{	
		if(!Module::isInstalled('ProductComments'))
			return false;
		$sql="CREATE TABLE IF NOT EXISTS "._DB_PREFIX_."block_coment_home_config (name char(255),value char(255),id_shop int(11));
			 TRUNCATE TABLE "._DB_PREFIX_."block_coment_home_config;
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left_count','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right_count','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home_count','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left_time','3',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right_time','3',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home_time','3',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('product_name','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('product_foto','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('comment','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('date','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('name','1',0);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('surname','1',0);
			  ";
		
		if(!Db::getInstance()->execute($sql))
			return false;
		return (parent::install()&&$this->registerHooks());	
	}
	
	public function uninstall()
	{
		$sql="DROP TABLE IF EXISTS "._DB_PREFIX_."block_coment_home_config";
		if(!Db::getInstance()->execute($sql))
			return false;
		return (parent::uninstall()&&$this->ununregisterHooks());		
	}	
	
	public function getConfigurationDb(){	
		$this->shop = Context::getContext()->shop;
		
		$sql="SELECT * FROM "._DB_PREFIX_."block_coment_home_config WHERE id_shop = ".$this->shop->id;
		$result=Db::getInstance()->executeS($sql);		
		
		$resultArray=array();
		foreach($result as $resultItem){
			if($resultItem['name']=="hook_left_time"||$resultItem['name']=="hook_right_time"||$resultItem['name']=="hook_home_time"){
				if($resultItem['value']==0)
					$resultItem=1000;
			}
			$resultArray[$resultItem['name']]=$resultItem['value'];
		}
		
		$sql="SELECT * FROM "._DB_PREFIX_."block_coment_home_config WHERE id_shop = 0";
		$result=Db::getInstance()->executeS($sql);		
		
		foreach($result as $resultItem){		
			if($resultItem['name']=="hook_left_time"||$resultItem['name']=="hook_right_time"||$resultItem['name']=="hook_home_time"){
				if($resultItem['value']==0)
					$resultItem=1;
			}
			if(!isset($resultArray[$resultItem['name']])||$resultArray[$resultItem['name']]=="")
			$resultArray[$resultItem['name']]=$resultItem['value'];
		}		
		return $resultArray;
	}
	
	public function getConfig(){
			global $cookie;
		$id_lang = $cookie->id_lang;		
		
		
	    $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
	    $this->shop = Context::getContext()->shop;
			
		$id_shop=$this->shop->id;
		
	    $fields_form[0]['form'] = array(
	        'legend' => array(
	            'title' => $this->l('Settings'),
	        ),
	        'input' => array(	                
	           array(
					  'type'      => 'radio',
					  'label'     => $this->l('Hook left'),
					  'name'      => 'left',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ), 
	            array(
                	'type' => 'text',
                	'label' => $this->l('Hook left count'),
                	'name' => 'hook_left_count',
                	'size' => 20
					           		         
	            ),	      
	             array(
                	'type' => 'text',
                	'label' => $this->l('Hook left display time'),
                	'name' => 'hook_left_time',
                	'size' => 20
					           		         
	            ),  
	            array(
					  'type'      => 'radio',
					  'label'     => $this->l('Hook home'),
					  'name'      => 'home',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ), 	            	     
	             array(
                	'type' => 'text',
                	'label' => $this->l('Hook home display time'),
                	'name' => 'hook_home_time',
                	'size' => 20					           		         
	            ),
				array(
					  'type'      => 'radio',
					  'label'     => $this->l('Hook right'),
					  'name'      => 'right',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ), 
	            array(
                	'type' => 'text',
                	'label' => $this->l('Hook right count'),
                	'name' => 'hook_right_count',
                	'size' => 20
					           		         
	            ),	      
	             array(
                	'type' => 'text',
                	'label' => $this->l('Hook right display time'),
                	'name' => 'hook_right_time',
                	'size' => 20
					           		         
	            ),  	   
	            array(
					  'type'      => 'radio',
					  'label'     => $this->l('Product name'),
					  'name'      => 'product_name',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ),
				array(
					  'type'      => 'radio',
					  'label'     => $this->l('Product foto'),
					  'name'      => 'product_foto',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ),   
				 array(
					  'type'      => 'radio',
					  'label'     => $this->l('Product comment'),
					  'name'      => 'comment',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ),      	
				 array(
					  'type'      => 'radio',
					  'label'     => $this->l('Date add'),
					  'name'      => 'date',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ),     
				 array(
					  'type'      => 'radio',
					  'label'     => $this->l('Customer name'),
					  'name'      => 'name',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),
					  
				 ),        
				 array(
					  'type'      => 'radio',
					  'label'     => $this->l('Customer surname'),
					  'name'      => 'surname',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),					  
				 ),        
				 array(
					  'type'      => 'radio',
					  'label'     => $this->l('Only confirmed'),
					  'name'      => 'validate',
					  'required'  => true,
					  'class'     => 't',
					  'is_bool'   => true,
					  'values'    => array(
					    	array(
					      		'id'    => 'active_on',
					      		'value' => 1,
					      		'label' => $this->l('Enabled')
					    	),
					    	array(
					      		'id'    => 'active_off',
					      		'value' => 0,
					      		'label' => $this->l('Disabled')
					    	)
					  ),					  
				 ),       
	        ),	                  
	        'submit' => array(
	            'title' => $this->l('Save'),
	            'class' => 'button'
	        )
	    );	   	    	    
		$languages = Language::getLanguages(false);
	  	foreach ($languages as $k => $language)
	   		$languages[$k]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'));
	    
	    $helper = new HelperForm();
	    $helper->languages = $languages;	    
	    // Module, t    oken and currentIndex
	    $helper->module = $this;
	    $helper->name_controller = $this->name;
	    $helper->token = Tools::getValue('token');
	    $helper->currentIndex = AdminController::$currentIndex."&controller=AdminModules&configure=blockcomenthome&tab_module=front_office_features&module_name=blockcomenthome";
	    
	     
	    $helper->default_form_language = $default_lang;
	    $helper->allow_employee_form_lang = $default_lang;
	     
	    $helper->show_toolbar = false;        // false -> remove toolbar
	    $helper->submit_action = 'submit'.$this->name;
	    
	    $helper->toolbar_btn = array(
	        'save' =>
	        array(
	            'desc' => $this->l('Save'),
	            'href' => $helper->currentIndex,
	            '&token='.Tools::getAdminTokenLite('AdminModules'),
	        ),
	        'back' => array(
	            'href' => $helper->currentIndex,
	            'desc' => $this->l('Back to list')
	        )
	    );
	    $this->configuration=$this->getConfigurationDb();
	    $helper->fields_value['hook_left_count'] = $this->configuration['hook_left_count'];
	    $helper->fields_value['hook_left_time'] = $this->configuration['hook_left_time'];
	    $helper->fields_value['validate'] = $this->configuration['hook_home_count'];
	    $helper->fields_value['hook_home_time'] = $this->configuration['hook_home_time'];
	    $helper->fields_value['hook_right_count'] = $this->configuration['hook_right_count'];
	    $helper->fields_value['hook_right_time'] = $this->configuration['hook_right_time'];
	    
	    $helper->fields_value['product_name'] = $this->configuration['product_name'];
	    $helper->fields_value['product_foto'] = $this->configuration['product_foto'];
	    $helper->fields_value['date'] = $this->configuration['date'];
	    $helper->fields_value['comment'] = $this->configuration['comment'];
	    $helper->fields_value['name'] = $this->configuration['name'];
	    $helper->fields_value['surname'] = $this->configuration['surname'];
	    $helper->fields_value['left'] = $this->configuration['hook_left'];
	    $helper->fields_value['home'] = $this->configuration['hook_home'];
	    $helper->fields_value['right'] = $this->configuration['hook_right'];
	    
	    $sql="SELECT * FROM "._DB_PREFIX_."block_coment_home_config";
		$e2sult=Db::getInstance()->executeS($sql);
		
		$esult=$this->configuration;
		$t="";//"<pre>".print_r($esult,true).print_r($e2sult,true)."</pre>";
	    	    
	    return $t.$helper->generateForm($fields_form);	    
	}
	
	public function saveConfiguration(){
		if(Tools::isSubmit('submitblockcomenthome')){			
			$left=(int)Tools::getValue('left');
			$right=(int)Tools::getValue('right',1);
			$home=(int)Tools::getValue('home',1);
			$left_count=(int)Tools::getValue('hook_left_count',1);
			$right_count=(int)Tools::getValue('hook_right_count',1);
			$home_count=(int)Tools::getValue('hook_home_count',1);
			$left_time=(int)Tools::getValue('hook_left_time',1);
			$right_time=(int)Tools::getValue('hook_right_time',1);
			$home_time=(int)Tools::getValue('hook_home_time',1);
			$product_name=(int)Tools::getValue('product_name',1);
			$comment=(int)Tools::getValue('comment',1);
			$date=(int)Tools::getValue('date',1);
			$name=(int)Tools::getValue('name',1);
			$surname=(int)Tools::getValue('surname',1);
			$product_foto=(int)Tools::getValue('product_foto',1);
			$validate=(int)Tools::getValue('validate',1);
		
			//if($this->shop==null)
			$this->shop = Context::getContext()->shop;
			
			$id_shop=$this->shop->id;
		
			
		
			 $sql="DELETE FROM "._DB_PREFIX_."block_coment_home_config WHERE id_shop=$id_shop;
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left','$left',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right','$right',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home','$home',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left_count','$left_count',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right_count','$right_count',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home_count','$validate',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_left_time','$left_time',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_right_time','$right_time',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('hook_home_time','$home_time',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('product_name','$product_name',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('product_foto','$product_foto',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('comment','$comment',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('date','$date',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('name','$name',$id_shop);
			 INSERT INTO "._DB_PREFIX_."block_coment_home_config VALUES ('surname','$surname',$id_shop);";
 			 Db::getInstance()->execute($sql);			 
			 $this->configuration=$this->getConfigurationDb();			
			 if($left==0)
			 	$this->unregisterHook('leftColumn');
			 else
			 	$this->registerHook('leftColumn');
			 if($right==0)
			 	$this->unregisterHook('rightColumn');
			 else
			 	$this->registerHook('rightColumn');
			 if($home==0)
			 	$this->unregisterHook('home');
			 else
			 	$this->registerHook('home');			
		}
	}
	
	public function getContent()
	{
		$this->saveConfiguration();
		$this->_display = 'index';
		return $this->getConfig();
	}
	
	private function registerHooks(){
		return ($this->registerHook('leftColumn') && $this->registerHook('rightColumn') && $this->registerHook('home')&&$this->registerHook('header'));
	}
	
	public function ununregisterHooks(){
		return ($this->unregisterHook('leftColumn') && $this->unregisterHook('rightColumn') && $this->unregisterHook('home') && $this->registerHook('header'));
	}
	
	public function getComment($s=100){
		$v=$this->getConfigurationDb();
		$validate=$v['hook_home_count'];
		
		if($validate==1)
			$validate="AND pc.validate=1";
		else 
			$validate="";
		global $cookie;
		if($this->shop==null)
				$this->shop = Context::getContext()->shop;
		$c=(Db::getInstance()->executeS('
		SELECT pc.`id_product_comment`, prod.id_shop_default, pc.`id_product`, pc.validate, c.`firstname`,c.`lastname`, pc.customer_name customer_name, pc.`content`, pc.`title` , pc.`grade`, pc.`date_add`, pl.`name` AS pname
		FROM `'._DB_PREFIX_.'product_comment` pc
		JOIN `'._DB_PREFIX_.'product` prod on prod.id_product=pc.id_product
		LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`)
		LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Shop::addSqlRestrictionOnLang('pl').')
		WHERE prod.id_shop_default = '.$this->shop->id.' '.$validate.' ORDER BY RAND()'));
		$arr=array();
		foreach($c as $item){
			$id=$item['id_product'];			
			$p=new Product($id,true, $cookie->id_lang,$this->shop->id);
			$item['link']=$p->getLink();			
			$item['images']=Product::getCover($id);
			$item['link_rewrite']=$p->link_rewrite;
			if($item['customer_name']!="")
				$item['name']=$item['customer_name'];
			if(strlen($item['content'])>100)
				$item['content']=substr($item['content'], 0,$s)."...";
			$arr[]=$item;
		}
		$this->pc=$arr;
	}
	
	public function hookLeftColumn(){
		if(!Module::isInstalled('ProductComments'))
			return false;
		$this->getComment();	
		$this->smarty->assign('comments',$this->pc);
		$this->smarty->assign('configuration_blockcomenthome',$this->getConfigurationDb());					
		return $this->display(__FILE__, 'home_column.tpl');
	}

	public function hookRightColumn(){
		if(!Module::isInstalled('ProductComments'))
			return false;
		$this->getComment();
		$this->smarty->assign('comments',$this->pc);					
		$this->smarty->assign('configuration_blockcomenthome',$this->getConfigurationDb());
		return $this->display(__FILE__, 'home_column.tpl');
	}
	
	public function hookHome(){
		if(!Module::isInstalled('ProductComments'))
			return false;
		$this->getComment(40);
		$this->smarty->assign('comments',$this->pc);		
		$this->smarty->assign('configuration_blockcomenthome',$this->getConfigurationDb());			
		return $this->display(__FILE__, 'home_column.tpl');
	}
	
	public function hookHeader($params)
	{
		$this->context->controller->addCSS(($this->_path).'css/blockcomenthome.css', 'all');
	}
}

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...