From 5d67bcb70b4d44aec11ab4520b80d1d2ef8aa81f Mon Sep 17 00:00:00 2001 From: deepankar Date: Tue, 24 Mar 2015 14:51:23 +0530 Subject: [PATCH 1/4] producttooltip.php updation hey, here i have added one more configuration in this file to show number of people added product on their cart and how many people watching this at that moment . it will be helpful to show product popularity direct to customer . i have mentioned " /*added by me */ " comment whereever i have changed the code. --- producttooltip.php | 61 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/producttooltip.php b/producttooltip.php index 36d374e..e128c12 100644 --- a/producttooltip.php +++ b/producttooltip.php @@ -36,12 +36,14 @@ public function __construct() $this->version = '1.3.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; + $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Product tooltips'); $this->description = $this->l('Shows information on a product page: how many people are viewing it, the last time it was sold and the last time it was added to a cart.'); + $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); } public function install() @@ -55,6 +57,8 @@ public function install() Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', 1); Configuration::updateValue('PS_PTOOLTIP_DAYS', 3); Configuration::updateValue('PS_PTOOLTIP_LIFETIME', 30); + /* added by me */ + Configuration::updateValue('PS_PTOOLTIP_CART_PEOPLE', 1); return $this->registerHook('header') && $this->registerHook('productfooter'); } @@ -66,6 +70,8 @@ public function uninstall() || !Configuration::deleteByName('PS_PTOOLTIP_DATE_ORDER') || !Configuration::deleteByName('PS_PTOOLTIP_DAYS') || !Configuration::deleteByName('PS_PTOOLTIP_LIFETIME') + /* added by me */ + || !Configuration::deleteByName('PS_PTOOLTIP_CART_PEOPLE') || !parent::uninstall() ) return false; @@ -84,6 +90,8 @@ public function getContent() Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', (int)Tools::getValue('PS_PTOOLTIP_DATE_ORDER')); Configuration::updateValue('PS_PTOOLTIP_DAYS', ((int)(Tools::getValue('PS_PTOOLTIP_DAYS') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_DAYS')))); Configuration::updateValue('PS_PTOOLTIP_LIFETIME', ((int)(Tools::getValue('PS_PTOOLTIP_LIFETIME') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_LIFETIME')))); + /* added by me */ + Configuration::updateValue('PS_PTOOLTIP_CART_PEOPLE', (int)Tools::getValue('PS_PTOOLTIP_CART_PEOPLE')); $html .= $this->displayConfirmation($this->l('Settings updated')); } @@ -101,7 +109,14 @@ public function hookHeader($params) public function hookProductFooter($params) { $id_product = (int)$params['product']->id; - + + /* + * $id_cart=array( Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + * SELECT id_cart + FROM '._DB_PREFIX_.'cart_product + WHERE id_product ='.(int)$id_product))); + * $id_customer; + */ /* First we try to display the number of people who are currently watching this product page */ if (Configuration::get('PS_PTOOLTIP_PEOPLE')) { @@ -111,12 +126,24 @@ public function hookProductFooter($params) SELECT COUNT(DISTINCT(id_connections)) nb FROM '._DB_PREFIX_.'page p LEFT JOIN '._DB_PREFIX_.'connections_page cp ON (p.id_page = cp.id_page) - WHERE p.id_page_type = 1 AND p.id_object = '.(int)$id_product.' AND cp.time_start > \''.pSQL($date).'\''); + WHERE p.id_page_type = 3 AND p.id_object = '.(int)$id_product.' AND cp.time_start > \''.pSQL($date).'\''); if (isset($nb_people['nb']) && $nb_people['nb'] > 0) $this->smarty->assign('nb_people', (int)$nb_people['nb']); } + /* No of people added this prodect in cart */ + if (Configuration::get('PS_PTOOLTIP_CART_PEOPLE')) + { + $cart_people = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT SUM(cp.quantity) cq + FROM '._DB_PREFIX_.'cart_product cp + WHERE cp.id_product = '.(int)$id_product); + + if (isset($cart_people['cq']) && $cart_people['cq'] >0) + $this->smarty->assign('cart_people', (int)$cart_people['cq']); + } + /* Then, we try to display last sale */ if (Configuration::get('PS_PTOOLTIP_DATE_ORDER')) { @@ -138,17 +165,19 @@ public function hookProductFooter($params) if (Configuration::get('PS_PTOOLTIP_DATE_CART')) { $cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT cp.date_add + SELECT cp.date_add FROM '._DB_PREFIX_.'cart_product cp WHERE cp.id_product = '.(int)$id_product); - if (isset($cart['date_add']) && Validate::isDateFormat($cart['date_add']) && $cart['date_add'] != '0000-00-00 00:00:00') + if (isset($cart['date_add']) && Validate::isDateFormat($cart['date_addPS_PTOOLTIP_DATE_CART']) && $cart['date_add'] != '0000-00-00 00:00:00') $this->smarty->assign('date_last_cart', $cart['date_add']); } + + } } - if ((isset($nb_people['nb']) && $nb_people['nb'] > 0) || isset($order['date_add']) || isset($cart['date_add'])) + if ((isset($nb_people['nb']) && $nb_people['nb'] > 0) || (isset($cart_people['cq']) && $cart_people['cq'] >0) || isset($order['date_add']) || isset($cart['date_add'])) return $this->display(__FILE__, 'producttooltip.tpl'); } @@ -236,6 +265,27 @@ public function renderForm() ) ), ), + //added by me + array( + 'type' => 'switch', + 'label' => $this->l('People added to a cart'), + 'desc' => $this->l('Display the number of people who added product to a cart.'), + 'name' => 'PS_PTOOLTIP_CART_PEOPLE', + '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('Do not display events older than'), @@ -278,6 +328,7 @@ public function getConfigFieldsValues() 'PS_PTOOLTIP_DATE_ORDER' => Tools::getValue('PS_PTOOLTIP_DATE_ORDER', Configuration::get('PS_PTOOLTIP_DATE_ORDER')), 'PS_PTOOLTIP_DATE_CART' => Tools::getValue('PS_PTOOLTIP_DATE_CART', Configuration::get('PS_PTOOLTIP_DATE_CART')), 'PS_PTOOLTIP_DAYS' => Tools::getValue('PS_PTOOLTIP_DAYS', Configuration::get('PS_PTOOLTIP_DAYS')), + 'PS_PTOOLTIP_CART_PEOPLE' => Tools::getValue('PS_PTOOLTIP_CART_PEOPLE', Configuration::get('PS_PTOOLTIP_CART_PEOPLE')), ); } } From b849bc1fb4d0116c0fa3ba40ec69cb8b92494084 Mon Sep 17 00:00:00 2001 From: deepankar Date: Tue, 12 May 2015 18:48:34 +0530 Subject: [PATCH 2/4] [+] MO : show number of customers who added product to a cart producttooltip now can show number customer who have added particular product in their cart through this updation. Thanks & Regards, Deepankar --- producttooltip.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/producttooltip.php b/producttooltip.php index e128c12..9cb2ca0 100644 --- a/producttooltip.php +++ b/producttooltip.php @@ -90,7 +90,6 @@ public function getContent() Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', (int)Tools::getValue('PS_PTOOLTIP_DATE_ORDER')); Configuration::updateValue('PS_PTOOLTIP_DAYS', ((int)(Tools::getValue('PS_PTOOLTIP_DAYS') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_DAYS')))); Configuration::updateValue('PS_PTOOLTIP_LIFETIME', ((int)(Tools::getValue('PS_PTOOLTIP_LIFETIME') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_LIFETIME')))); - /* added by me */ Configuration::updateValue('PS_PTOOLTIP_CART_PEOPLE', (int)Tools::getValue('PS_PTOOLTIP_CART_PEOPLE')); $html .= $this->displayConfirmation($this->l('Settings updated')); @@ -109,14 +108,7 @@ public function hookHeader($params) public function hookProductFooter($params) { $id_product = (int)$params['product']->id; - - /* - * $id_cart=array( Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - * SELECT id_cart - FROM '._DB_PREFIX_.'cart_product - WHERE id_product ='.(int)$id_product))); - * $id_customer; - */ + /* First we try to display the number of people who are currently watching this product page */ if (Configuration::get('PS_PTOOLTIP_PEOPLE')) { @@ -169,7 +161,7 @@ public function hookProductFooter($params) FROM '._DB_PREFIX_.'cart_product cp WHERE cp.id_product = '.(int)$id_product); - if (isset($cart['date_add']) && Validate::isDateFormat($cart['date_addPS_PTOOLTIP_DATE_CART']) && $cart['date_add'] != '0000-00-00 00:00:00') + if (isset($cart['date_add']) && Validate::isDateFormat($cart['date_add']) && $cart['date_add'] != '0000-00-00 00:00:00') $this->smarty->assign('date_last_cart', $cart['date_add']); } @@ -265,7 +257,6 @@ public function renderForm() ) ), ), - //added by me array( 'type' => 'switch', 'label' => $this->l('People added to a cart'), From e82439f84942b8a9e4b807b33a513aadf0445a46 Mon Sep 17 00:00:00 2001 From: deepankar Date: Wed, 13 May 2015 00:49:23 +0530 Subject: [PATCH 3/4] Update producttooltip.php --- producttooltip.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/producttooltip.php b/producttooltip.php index 9cb2ca0..5c8b479 100644 --- a/producttooltip.php +++ b/producttooltip.php @@ -57,7 +57,6 @@ public function install() Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', 1); Configuration::updateValue('PS_PTOOLTIP_DAYS', 3); Configuration::updateValue('PS_PTOOLTIP_LIFETIME', 30); - /* added by me */ Configuration::updateValue('PS_PTOOLTIP_CART_PEOPLE', 1); return $this->registerHook('header') && $this->registerHook('productfooter'); @@ -70,7 +69,6 @@ public function uninstall() || !Configuration::deleteByName('PS_PTOOLTIP_DATE_ORDER') || !Configuration::deleteByName('PS_PTOOLTIP_DAYS') || !Configuration::deleteByName('PS_PTOOLTIP_LIFETIME') - /* added by me */ || !Configuration::deleteByName('PS_PTOOLTIP_CART_PEOPLE') || !parent::uninstall() ) From 5b11d1a1fc0e06b2b484821a19407400b6f2158c Mon Sep 17 00:00:00 2001 From: deepankar Date: Wed, 13 May 2015 14:11:05 +0530 Subject: [PATCH 4/4] [-] MO : added cart_people element in tpl in producttooltip module we can see number of customers who added product to a cart --- views/templates/hook/producttooltip.tpl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/views/templates/hook/producttooltip.tpl b/views/templates/hook/producttooltip.tpl index 86ae878..a9c6318 100644 --- a/views/templates/hook/producttooltip.tpl +++ b/views/templates/hook/producttooltip.tpl @@ -27,7 +27,11 @@ {if isset($nb_people)} $.growl({ldelim}title: '', message: '{if $nb_people == 1}{l s='%d person is currently watching this product.' sprintf=$nb_people mod='producttooltip' js=1}{else}{l s='%d people are currently watching this product.' sprintf=$nb_people mod='producttooltip' js=1}{/if}'{rdelim}); {/if} - + + {if isset($cart_people)} + $.growl({ldelim}title: '', message: '{if $cart_people == 1}{l s='%d person is added this product to a cart.' sprintf=$cart_people mod='producttooltip' js=1}{else}{l s='%d people are added this product to a cart.' sprintf=$cart_people mod='producttooltip' js=1}{/if}'{rdelim}); + {/if} + {if isset($date_last_order)} $.growl({ldelim}title: '', message: '{l s='Last time this product was bought: ' mod='producttooltip' js=1} {dateFormat date=$date_last_order full=1}'{rdelim}); {/if}