Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into development

This commit is contained in:
gRoussac committed 2013-07-04 16:48:14 +02:00
commit c360e841b3
11 files changed
+270 -201

No files matched your search

-1
View File
@@ -1 +0,0 @@
* text=auto
+3 -4
View File
@@ -538,11 +538,10 @@ class TabCore extends ObjectModel
foreach($tab->attributes() as $key => $value) foreach($tab->attributes() as $key => $value)
if ($key == 'display_type') if ($key == 'display_type')
$display_type = (string)$value; $display_type = (string)$value;
foreach ($tab->children() as $module) foreach ($tab->children() as $module)
foreach ($module->attributes() as $k => $v) $modules_list[$display_type][(int)$module['position']] = (string)$module['name'];
if ($k == 'name') ksort($modules_list[$display_type]);
$modules_list[$display_type][] = (string)$v;
} }
} }
+4 -3
View File
@@ -1534,7 +1534,6 @@ class AdminControllerCore extends Controller
public function renderModulesList() public function renderModulesList()
{ {
if ($this->getModulesList($this->filter_modules_list)) if ($this->getModulesList($this->filter_modules_list))
{ {
$helper = new Helper(); $helper = new Helper();
@@ -2233,7 +2232,7 @@ class AdminControllerCore extends Controller
$all_modules = Module::getModulesOnDisk(true); $all_modules = Module::getModulesOnDisk(true);
$this->modules_list = array(); $this->modules_list = array();
foreach($all_modules as $module) foreach ($all_modules as $module)
{ {
$perm = true; $perm = true;
if ($module->id) if ($module->id)
@@ -2249,9 +2248,11 @@ class AdminControllerCore extends Controller
if (in_array($module->name, $filter_modules_list) && $perm) if (in_array($module->name, $filter_modules_list) && $perm)
{ {
$this->fillModuleData($module, 'select'); $this->fillModuleData($module, 'select');
$this->modules_list[] = $module; $this->modules_list[array_search($module->name, $filter_modules_list)] = $module;
} }
} }
ksort($this->modules_list);
if (count($this->modules_list)) if (count($this->modules_list))
return true; return true;
-1
View File
@@ -351,7 +351,6 @@ class HelperCore
public function renderModulesList($modules_list) public function renderModulesList($modules_list)
{ {
$this->tpl_vars = array('modules_list' => $modules_list); $this->tpl_vars = array('modules_list' => $modules_list);
$tpl = $this->createTemplate('helpers/modules_list/list.tpl'); $tpl = $this->createTemplate('helpers/modules_list/list.tpl');
$tpl->assign($this->tpl_vars); $tpl->assign($this->tpl_vars);
+18 -3
View File
@@ -47,6 +47,8 @@ class WebserviceOutputBuilderCore
protected $virtualFields = array(); protected $virtualFields = array();
protected $statusInt; protected $statusInt;
protected $wsParamOverrides; protected $wsParamOverrides;
protected static $_cache_ws_parameters = array();
// Header properties // Header properties
protected $headerParams = array( protected $headerParams = array(
@@ -359,7 +361,11 @@ class WebserviceOutputBuilderCore
$type_of_view = self::VIEW_DETAILS; $type_of_view = self::VIEW_DETAILS;
} }
$ws_params = $objects['empty']->getWebserviceParameters(); $class = get_class($objects['empty']);
if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $objects['empty']->getWebserviceParameters();
$ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
foreach ($this->wsParamOverrides AS $p) foreach ($this->wsParamOverrides AS $p)
{ {
$object = $p['object']; $object = $p['object'];
@@ -406,7 +412,11 @@ class WebserviceOutputBuilderCore
*/ */
public function renderEntityMinimum($object, $depth) public function renderEntityMinimum($object, $depth)
{ {
$ws_params = $object->getWebserviceParameters(); $class = get_class($object);
if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $object->getWebserviceParameters();
$ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
$more_attr['id'] = $object->id; $more_attr['id'] = $object->id;
$more_attr['xlink_resource'] = $this->wsUrl.$ws_params['objectsNodeName'].'/'.$object->id; $more_attr['xlink_resource'] = $this->wsUrl.$ws_params['objectsNodeName'].'/'.$object->id;
$output = $this->setIndent($depth).$this->objectRender->renderNodeHeader($ws_params['objectNodeName'], $ws_params, $more_attr, false); $output = $this->setIndent($depth).$this->objectRender->renderNodeHeader($ws_params['objectNodeName'], $ws_params, $more_attr, false);
@@ -446,7 +456,12 @@ class WebserviceOutputBuilderCore
public function renderEntity($object, $depth) public function renderEntity($object, $depth)
{ {
$output = ''; $output = '';
$ws_params = $object->getWebserviceParameters();
$class = get_class($object);
if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $object->getWebserviceParameters();
$ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
foreach ($this->wsParamOverrides AS $p) foreach ($this->wsParamOverrides AS $p)
{ {
$o = $p['object']; $o = $p['object'];
+10 -10
View File
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<module> <module>
<name>crossselling</name> <name>crossselling</name>
<displayName><![CDATA[Cross Selling]]></displayName> <displayName><![CDATA[Cross Selling]]></displayName>
<version><![CDATA[0.1]]></version> <version><![CDATA[0.7]]></version>
<description><![CDATA[Customers who bought this product also bought:]]></description> <description><![CDATA[Customers who bought this product also bought:]]></description>
<author><![CDATA[PrestaShop]]></author> <author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab> <tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable> <is_configurable>1</is_configurable>
<need_instance>0</need_instance> <need_instance>0</need_instance>
<limited_countries></limited_countries> <limited_countries></limited_countries>
</module> </module>
+113 -101
View File
@@ -35,7 +35,7 @@ class CrossSelling extends Module
{ {
$this->name = 'crossselling'; $this->name = 'crossselling';
$this->tab = 'front_office_features'; $this->tab = 'front_office_features';
$this->version = 0.1; $this->version = 0.7;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
@@ -54,18 +54,18 @@ class CrossSelling extends Module
!$this->registerHook('productFooter') OR !$this->registerHook('productFooter') OR
!$this->registerHook('header') OR !$this->registerHook('header') OR
!$this->registerHook('shoppingCart') OR !$this->registerHook('shoppingCart') OR
!$this->registerHook('actionOrderStatusPostUpdate') OR
!Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', 0) OR !Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', 0) OR
!Configuration::updateValue('CROSSSELLING_NBR', 10)) !Configuration::updateValue('CROSSSELLING_NBR', 10))
return false; return false;
$this->_clearCache('crossselling.tpl');
return true; return true;
} }
public function uninstall() public function uninstall()
{ {
$this->_clearCache('crossselling.tpl');
if (!parent::uninstall() OR if (!parent::uninstall() OR
!$this->unregisterHook('productFooter') OR
!$this->unregisterHook('header') OR
!$this->unregisterHook('shoppingCart') OR
!Configuration::deleteByName('CROSSSELLING_DISPLAY_PRICE') OR !Configuration::deleteByName('CROSSSELLING_DISPLAY_PRICE') OR
!Configuration::deleteByName('CROSSSELLING_NBR')) !Configuration::deleteByName('CROSSSELLING_NBR'))
return false; return false;
@@ -88,6 +88,7 @@ class CrossSelling extends Module
{ {
Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice')); Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice'));
Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr')); Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr'));
$this->_clearCache('crossselling.tpl');
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully')); $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
} }
} }
@@ -126,66 +127,69 @@ class CrossSelling extends Module
if (!$params['products']) if (!$params['products'])
return; return;
$qOrders = 'SELECT o.id_order $cache_id = 'crossselling|shoppingcart|'.(int)$params['products'];
FROM '._DB_PREFIX_.'orders o if (!$this->isCached('crossselling.tpl', $this->getCacheId($cache_id)))
LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
WHERE o.valid = 1 AND (';
$nProducts = count($params['products']);
$i = 1;
$pIds = array();
foreach ($params['products'] as $product)
{ {
$qOrders .= 'od.product_id = '.(int)$product['id_product']; $qOrders = 'SELECT o.id_order
if ($i < $nProducts) FROM '._DB_PREFIX_.'orders o
$qOrders .= ' OR '; LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
++$i; WHERE o.valid = 1 AND (';
$pIds[] = (int)$product['id_product']; $nProducts = count($params['products']);
} $i = 1;
$qOrders .= ')'; $pIds = array();
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($qOrders); foreach ($params['products'] as $product)
if (sizeof($orders))
{
$list = '';
foreach ($orders AS $order)
$list .= (int)$order['id_order'].',';
$list = rtrim($list, ',');
$list_product_ids = join(',', $pIds);
$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
WHERE od.id_order IN ('.$list.')
AND pl.id_lang = '.(int)$this->context->language->id.'
AND cl.id_lang = '.(int)$this->context->language->id.'
AND od.product_id NOT IN ('.$list_product_ids.')
AND i.cover = 1
AND product_shop.active = 1
ORDER BY RAND()
LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
');
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{ {
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium')); $qOrders .= 'od.product_id = '.(int)$product['id_product'];
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']); if ($i < $nProducts)
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2)) $qOrders .= ' OR ';
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL); ++$i;
elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1) $pIds[] = (int)$product['id_product'];
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
} }
$qOrders .= ')';
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($qOrders);
$this->smarty->assign(array('order' => (count($pIds) > 1 ? true : false), 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0), if (sizeof($orders))
'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE'))); {
$list = '';
foreach ($orders AS $order)
$list .= (int)$order['id_order'].',';
$list = rtrim($list, ',');
$list_product_ids = join(',', $pIds);
$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
WHERE od.id_order IN ('.$list.')
AND pl.id_lang = '.(int)$this->context->language->id.'
AND cl.id_lang = '.(int)$this->context->language->id.'
AND od.product_id NOT IN ('.$list_product_ids.')
AND i.cover = 1
AND product_shop.active = 1
ORDER BY RAND()
LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
');
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
}
$this->smarty->assign(array('order' => (count($pIds) > 1 ? true : false), 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
}
} }
return $this->display(__FILE__, 'crossselling.tpl'); return $this->display(__FILE__, 'crossselling.tpl', $this->getCacheId($cache_id));
} }
/** /**
@@ -193,52 +197,60 @@ class CrossSelling extends Module
*/ */
public function hookProductFooter($params) public function hookProductFooter($params)
{ {
$cache_id = 'crossselling|productfooter|'.(int)$params['product']->id;
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' if (!$this->isCached('crossselling.tpl', $this->getCacheId($cache_id)))
SELECT o.id_order
FROM '._DB_PREFIX_.'orders o
LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
WHERE o.valid = 1 AND od.product_id = '.(int)$params['product']->id);
if (sizeof($orders))
{ {
$list = ''; $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
foreach ($orders AS $order) SELECT o.id_order
$list .= (int)$order['id_order'].','; FROM '._DB_PREFIX_.'orders o
$list = rtrim($list, ','); LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
WHERE o.valid = 1 AND od.product_id = '.(int)$params['product']->id);
$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' if (sizeof($orders))
SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
WHERE od.id_order IN ('.$list.')
AND pl.id_lang = '.(int)$this->context->language->id.'
AND cl.id_lang = '.(int)$this->context->language->id.'
AND od.product_id != '.(int)$params['product']->id.'
AND i.cover = 1
AND product_shop.active = 1
ORDER BY RAND()
LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
');
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{ {
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium')); $list = '';
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']); foreach ($orders AS $order)
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2)) $list .= (int)$order['id_order'].',';
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL); $list = rtrim($list, ',');
elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
}
$this->smarty->assign(array('order' => false, 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0), $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE'))); SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
WHERE od.id_order IN ('.$list.')
AND pl.id_lang = '.(int)$this->context->language->id.'
AND cl.id_lang = '.(int)$this->context->language->id.'
AND od.product_id != '.(int)$params['product']->id.'
AND i.cover = 1
AND product_shop.active = 1
ORDER BY RAND()
LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
');
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
}
$this->smarty->assign(array('order' => false, 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
}
} }
return $this->display(__FILE__, 'crossselling.tpl'); return $this->display(__FILE__, 'crossselling.tpl', $this->getCacheId($cache_id));
}
public function hookActionOrderStatusPostUpdate($params)
{
$this->_clearCache('crossselling.tpl');
} }
} }
@@ -0,0 +1,9 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_0_7($object)
{
return $object->registerHook('actionOrderStatusPostUpdate');
}
+10 -10
View File
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<module> <module>
<name>productscategory</name> <name>productscategory</name>
<displayName><![CDATA[Products Category]]></displayName> <displayName><![CDATA[Products Category]]></displayName>
<version><![CDATA[1.3]]></version> <version><![CDATA[1.4]]></version>
<description><![CDATA[Display products of the same category on the product page.]]></description> <description><![CDATA[Display products of the same category on the product page.]]></description>
<author><![CDATA[PrestaShop]]></author> <author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab> <tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable> <is_configurable>1</is_configurable>
<need_instance>0</need_instance> <need_instance>0</need_instance>
<limited_countries></limited_countries> <limited_countries></limited_countries>
</module> </module>
+94 -68
View File
@@ -34,7 +34,7 @@ class productsCategory extends Module
public function __construct() public function __construct()
{ {
$this->name = 'productscategory'; $this->name = 'productscategory';
$this->version = '1.3'; $this->version = '1.4';
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->tab = 'front_office_features'; $this->tab = 'front_office_features';
$this->need_instance = 0; $this->need_instance = 0;
@@ -50,16 +50,22 @@ class productsCategory extends Module
public function install() public function install()
{ {
if (!parent::install() OR !$this->registerHook('productfooter') OR !$this->registerHook('header') OR !Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0)) Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0);
return false; $this->_clearCache('productscategory.tpl');
return true; return (parent::install()
&& $this->registerHook('productfooter')
&& $this->registerHook('header')
&& $this->registerHook('addproduct')
&& $this->registerHook('updateproduct')
&& $this->registerHook('deleteproduct')
);
} }
public function uninstall() public function uninstall()
{ {
if (!parent::uninstall() OR !Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE')) Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE');
return false; $this->_clearCache('productscategory.tpl');
return true; return parent::uninstall();
} }
public function getContent() public function getContent()
@@ -70,6 +76,7 @@ class productsCategory extends Module
elseif (Tools::isSubmit('submitCross')) elseif (Tools::isSubmit('submitCross'))
{ {
Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice')); Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
$this->_clearCache('productscategory.tpl');
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully')); $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
} }
$this->_html .= ' $this->_html .= '
@@ -100,75 +107,79 @@ class productsCategory extends Module
public function hookProductFooter($params) public function hookProductFooter($params)
{ {
$idProduct = (int)(Tools::getValue('id_product')); $id_product = (int)$params['product']->id;
$product = new Product((int)($idProduct)); $product = $params['product'];
/* If the visitor has came to this product by a category, use this one */
if (isset($params['category']->id_category))
$category = $params['category'];
/* Else, use the default product category */
else
{
if (isset($product->id_category_default) AND $product->id_category_default > 1)
$category = New Category((int)($product->id_category_default));
}
if (!Validate::isLoadedObject($category) OR !$category->active) $cache_id = 'productscategory|'.$id_product.'|'.(isset($params['category']->id_category) ? (int)$params['category']->id_category : $product->id_category_default);
return;
// Get infos if (!$this->isCached('productscategory.tpl', $this->getCacheId($cache_id)))
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
$middlePosition = 0;
// Remove current product from the list
if (is_array($categoryProducts) AND sizeof($categoryProducts))
{ {
foreach ($categoryProducts AS $key => $categoryProduct) /* If the visitor has came to this product by a category, use this one */
if ($categoryProduct['id_product'] == $idProduct) if (isset($params['category']->id_category))
{ $category = $params['category'];
unset($categoryProducts[$key]); /* Else, use the default product category */
break; else
} {
if (isset($product->id_category_default) AND $product->id_category_default > 1)
$category = new Category((int)$product->id_category_default);
}
if (!Validate::isLoadedObject($category) OR !$category->active)
return;
$taxes = Product::getTaxCalculationMethod(); // Get infos
if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')) $categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
$middlePosition = 0;
// Remove current product from the list
if (is_array($categoryProducts) AND sizeof($categoryProducts))
{
foreach ($categoryProducts AS $key => $categoryProduct) foreach ($categoryProducts AS $key => $categoryProduct)
if ($categoryProduct['id_product'] != $idProduct) if ($categoryProduct['id_product'] == $id_product)
{ {
if ($taxes == 0 OR $taxes == 2) unset($categoryProducts[$key]);
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2); break;
elseif ($taxes == 1)
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
} }
// Get positions
$middlePosition = round($sizeOfCategoryProducts / 2, 0);
$productPosition = $this->getCurrentProduct($categoryProducts, (int)$idProduct);
// Flip middle product with current product
if ($productPosition)
{
$tmp = $categoryProducts[$middlePosition-1];
$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
$categoryProducts[$productPosition] = $tmp;
}
// If products tab higher than 30, slice it
if ($sizeOfCategoryProducts > 30)
{
$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
$middlePosition = 15;
}
}
// Display tpl
$this->smarty->assign(array(
'categoryProducts' => $categoryProducts,
'middlePosition' => (int)$middlePosition,
'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
return $this->display(__FILE__, 'productscategory.tpl'); $taxes = Product::getTaxCalculationMethod();
if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
foreach ($categoryProducts AS $key => $categoryProduct)
if ($categoryProduct['id_product'] != $id_product)
{
if ($taxes == 0 OR $taxes == 2)
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2);
elseif ($taxes == 1)
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
}
// Get positions
$middlePosition = round($sizeOfCategoryProducts / 2, 0);
$productPosition = $this->getCurrentProduct($categoryProducts, (int)$id_product);
// Flip middle product with current product
if ($productPosition)
{
$tmp = $categoryProducts[$middlePosition-1];
$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
$categoryProducts[$productPosition] = $tmp;
}
// If products tab higher than 30, slice it
if ($sizeOfCategoryProducts > 30)
{
$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
$middlePosition = 15;
}
}
// Display tpl
$this->smarty->assign(array(
'categoryProducts' => $categoryProducts,
'middlePosition' => (int)$middlePosition,
'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
}
return $this->display(__FILE__, 'productscategory.tpl', $this->getCacheId($cache_id));
} }
public function hookHeader($params) public function hookHeader($params)
@@ -177,4 +188,19 @@ class productsCategory extends Module
$this->context->controller->addJS($this->_path.'productscategory.js'); $this->context->controller->addJS($this->_path.'productscategory.js');
$this->context->controller->addJqueryPlugin('serialScroll'); $this->context->controller->addJqueryPlugin('serialScroll');
} }
public function hookAddProduct($params)
{
$this->_clearCache('productscategory.tpl');
}
public function hookUpdateProduct($params)
{
$this->_clearCache('productscategory.tpl');
}
public function hookDeleteProduct($params)
{
$this->_clearCache('productscategory.tpl');
}
} }
@@ -0,0 +1,9 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_4($object)
{
return ($object->registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
}