[*] MO : crossseling - Added hookShopingCart (uses all products in the cart)
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8182 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -31,7 +31,7 @@ if (!defined('_PS_VERSION_'))
|
||||
class CrossSelling extends Module
|
||||
{
|
||||
private $_html;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'crossselling';
|
||||
@@ -41,10 +41,10 @@ class CrossSelling extends Module
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
|
||||
$this->displayName = $this->l('Cross Selling');
|
||||
$this->description = $this->l('Customers who bought this product also bought:');
|
||||
|
||||
|
||||
if (!$this->isRegisteredInHook('header'))
|
||||
$this->registerHook('header');
|
||||
}
|
||||
@@ -54,6 +54,7 @@ class CrossSelling extends Module
|
||||
if (!parent::install() OR
|
||||
!$this->registerHook('productFooter') OR
|
||||
!$this->registerHook('header') OR
|
||||
!$this->registerHook('shoppingCart') OR
|
||||
!Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', 0))
|
||||
return false;
|
||||
return true;
|
||||
@@ -61,7 +62,10 @@ class CrossSelling extends Module
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
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'))
|
||||
return false;
|
||||
return true;
|
||||
@@ -93,31 +97,47 @@ class CrossSelling extends Module
|
||||
</form>';
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
|
||||
public function hookHeader()
|
||||
{
|
||||
$this->context->controller->addCSS(($this->_path).'crossselling.css', 'all');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns module content for left column
|
||||
*/
|
||||
public function hookProductFooter($params)
|
||||
* Returns module content
|
||||
*/
|
||||
public function hookshoppingCart($params)
|
||||
{
|
||||
|
||||
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT o.id_order
|
||||
if (!$params['products'])
|
||||
return;
|
||||
|
||||
$qOrders = '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);
|
||||
|
||||
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'];
|
||||
if ($i < $nProducts)
|
||||
$qOrders .= ' OR ';
|
||||
++$i;
|
||||
$pIds[] = (int)$product['id_product'];
|
||||
}
|
||||
$qOrders .= ')';
|
||||
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($qOrders);
|
||||
|
||||
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, p.show_price, cl.link_rewrite category, p.ean13
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
@@ -125,11 +145,11 @@ class CrossSelling extends Module
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.$this->context->shop->sqlLang('pl').')
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default'.$this->context->shop->sqlLang('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 p.active = 1
|
||||
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 p.active = 1
|
||||
ORDER BY RAND()
|
||||
LIMIT 10');
|
||||
|
||||
|
||||
$taxCalc = Product::getTaxCalculationMethod();
|
||||
foreach ($orderProducts AS &$orderProduct)
|
||||
{
|
||||
@@ -140,8 +160,56 @@ class CrossSelling extends Module
|
||||
elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
|
||||
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array('orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
|
||||
|
||||
$this->context->smarty->assign(array('order' => true, 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
|
||||
'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
|
||||
}
|
||||
return $this->display(__FILE__, 'crossselling.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns module content for left column
|
||||
*/
|
||||
public function hookProductFooter($params)
|
||||
{
|
||||
|
||||
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
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 = '';
|
||||
foreach ($orders AS $order)
|
||||
$list .= (int)$order['id_order'].',';
|
||||
$list = rtrim($list, ',');
|
||||
|
||||
$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, p.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)
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.$this->context->shop->sqlLang('pl').')
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default'.$this->context->shop->sqlLang('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 p.active = 1
|
||||
ORDER BY RAND()
|
||||
LIMIT 10');
|
||||
|
||||
$taxCalc = Product::getTaxCalculationMethod();
|
||||
foreach ($orderProducts AS &$orderProduct)
|
||||
{
|
||||
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], '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->context->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');
|
||||
|
||||
@@ -28,7 +28,13 @@
|
||||
<div id="crossselling">
|
||||
<script type="text/javascript">var middle = {$middlePosition_crossselling};</script>
|
||||
<script type="text/javascript" src="{$content_dir}modules/crossselling/js/crossselling.js"></script>
|
||||
<h2 class="productscategory_h2">{l s='Customers who bought this product also bought:' mod='crossselling'}</h2>
|
||||
<h2 class="productscategory_h2">
|
||||
{if $order}
|
||||
{l s='Customers who bought these products also bought:' mod='crossselling'}
|
||||
{else}
|
||||
{l s='Customers who bought this product also bought:' mod='crossselling'}
|
||||
{/if}
|
||||
</h2>
|
||||
<div id="{if count($orderProducts) > 5}crossselling{else}crossselling_noscroll{/if}">
|
||||
{if count($orderProducts) > 5}<a id="crossselling_scroll_left" title="{l s='Previous' mod='crossselling'}" href="javascript:{ldelim}{rdelim}">{l s='Previous' mod='crossselling'}</a>{/if}
|
||||
<div id="crossselling_list">
|
||||
|
||||
Reference in New Issue
Block a user