Jump to content

Need help with new hook on product page


Recommended Posts

Hi,

 

In my store (PS v. 1.4.7.3) I use free module AgileSoldCounter who is default hooked into productActions but I'd like to hook it next to the product price.

 

I made some changes, created new hook called "soldCounterPrice" etc. and counter works fine, but on home page and all other pages (except product page) I can see this message:

 

Notice: Undefined index: id_product in /....../modules/agilesoldcounter/agilesoldcounter.php on line 83

 

 

This message disappear when I turned off error display in config file. But I'd like eliminate this issue forever.

 

I think that I need call only to the hook on product page, but I don't know how to do that. Can you give me some advice what is wrong?

 

Now my agilesoldcounter.php file looks like that:

 

<?php
/*
 * @module Agile Sold Counter 1.0
 * @author Alvin Jiang <[email protected]>
 * @copyright AgileService.Com
 * @version 1.0
*/

if (!defined('_CAN_LOAD_FILES_') AND _PS_VERSION_ > '1.3.2')
exit;

class AgileSoldCounter extends Module
{
function __construct()
{
$this->name = 'agilesoldcounter';
if(_PS_VERSION_ > '1.4')
{
  $this->tab = 'pricing & promotion';
  $this->author = 'addons-modules.com';
	}	
else $this->tab = 'Blocks';
$this->version = '1.0';

parent::__construct();

$this->displayName = $this->l('Agile Product Sold Counter');
$this->description = $this->l('Displaying sold count of products');
}


function install()
{
  $id_hook = Hook::get('agilesoldcounter');
  if(!$id_hook)
  {
   $hook = new Hook();
   $hook->name = 'agilesoldcounter';
   $hook->save();
  }
if (!parent::install())
  return false;
if(!$this->registerHook('agilesoldcounter'))
  return false;
if(!$this->registerHook('productActions') OR !$this->registerHook('soldCounterPrice'))
  return false;
	if (!$this->registerHook('header')) return false;
return true;
}

public function postProcess()
{
global $currentIndex;

$errors = false;
if ($errors)
echo $this->displayError($errors);
}

function hookSoldCounterPrice($params)
{
if(!$this->active)return;
  return $this->hookAgileSoldCounter($params);
}

function hookProductActions($params)
{
  if(!$this->active)return;
  return $this->hookAgileSoldCounter($params);
}

/**
* Returns module content
*
* @param array $params Parameters
* @return string Content
*/
function hookAgileSoldCounter($params)
{
  if(!$this->active)return;

	global $smarty;
$id_product = isset($_GET['id_product'])? $_GET['id_product']:intval($params['id_product']);
	///$sql = 'SELECT SUM(product_quantity) as agile_product_sold FROM `'._DB_PREFIX_.'order_detail` where product_id = ' . $_GET['id_product'];
$sql = 'SELECT SUM(product_quantity) as agile_product_sold FROM `'._DB_PREFIX_.'order_detail` where product_id = ' . $id_product;
	$agile_product_sold = Db::getInstance()->getRow($sql);
	$counter = 0;
	if($agile_product_sold['agile_product_sold'])$counter =  $agile_product_sold['agile_product_sold'];
	$smarty->assign('agile_product_sold', $counter);

return $this->display(__FILE__, 'agilesoldcounter.tpl');
}

public function hookHeader()
{
  global $smarty;

if(!$this->active)return;
@session_start();

	$smarty->assign(array(
   'is_agilesoldcount_installed' => 1
	));
}
}

?>

Edited by Artus2000 (see edit history)
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...