From c2bcc5baa1e6dd73f46a0811bf8889b80bcdc982 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Fri, 4 Oct 2013 18:32:31 +0200 Subject: [PATCH] [*] FO : TM home modules preparation --- classes/ProductSale.php | 15 ++++- modules/blockbestsellers/blockbestsellers.php | 2 +- modules/homefeatured/homefeatured.php | 1 + modules/homefeatured/js/homefeatured.js | 36 +++++++++++ .../blockbestsellers-home.tpl | 34 +--------- .../blocknewproducts/blocknewproducts.tpl | 28 +-------- .../modules/homefeatured/homefeatured.tpl | 44 +------------ themes/default/product-list-home.tpl | 62 +++++++++++++++++++ 8 files changed, 119 insertions(+), 103 deletions(-) create mode 100644 modules/homefeatured/js/homefeatured.js create mode 100644 themes/default/product-list-home.tpl diff --git a/classes/ProductSale.php b/classes/ProductSale.php index 2f8166a4d..698306cf4 100644 --- a/classes/ProductSale.php +++ b/classes/ProductSale.php @@ -86,7 +86,8 @@ class ProductSaleCore MAX(image_shop.`id_image`) id_image, il.`legend`, ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), - INTERVAL '.$interval.' DAY)) > 0 AS new + INTERVAL '.$interval.' DAY)) > 0 AS new, + IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` '.Shop::addSqlAssociation('product', 'p', false).' @@ -142,10 +143,12 @@ class ProductSaleCore $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`, - ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category + ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, p.quantity, p.customizable, + IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, p.out_of_stock FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` '.Shop::addSqlAssociation('product', 'p').' + LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (ps.`id_product` = pa.`id_product` AND pa.default_on = 1) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' @@ -166,6 +169,7 @@ class ProductSaleCore GROUP BY product_shop.id_product ORDER BY sales DESC LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; + if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) return false; @@ -173,6 +177,13 @@ class ProductSaleCore { $row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']); $row['id_image'] = Product::defineProductImage($row, $id_lang); + $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); + $row['price_tax_exc'] = Product::getPriceStatic( + (int)$row['id_product'], + false, + ((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int)$row['id_product_attribute'] : null), + (Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6) + ); } return $result; } diff --git a/modules/blockbestsellers/blockbestsellers.php b/modules/blockbestsellers/blockbestsellers.php index 2d06046b5..cfe87a90d 100644 --- a/modules/blockbestsellers/blockbestsellers.php +++ b/modules/blockbestsellers/blockbestsellers.php @@ -217,7 +217,7 @@ class BlockBestSellers extends Module if (Configuration::get('PS_CATALOG_MODE')) return false; - if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, 5))) + if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, 8))) return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false); $bestsellers = array(); diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 5d7ec5b57..5a2b1ca54 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -112,6 +112,7 @@ class HomeFeatured extends Module public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all'); + $this->context->controller->addJS(($this->_path).'js/homefeatured.js'); } public function hookDisplayHome($params) diff --git a/modules/homefeatured/js/homefeatured.js b/modules/homefeatured/js/homefeatured.js new file mode 100644 index 000000000..62606689b --- /dev/null +++ b/modules/homefeatured/js/homefeatured.js @@ -0,0 +1,36 @@ +/* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +$(document).ready(function() +{ + $('.title_block').click(function(){ + var button = $(this); + $('#index #center_column .products_block').removeClass('active'); + button.parent('.products_block').addClass('active'); + $('#index #center_column .products_block .block_content').hide(0, function(){ + button.next('.block_content').show(0); + }); + }); +}); \ No newline at end of file diff --git a/themes/default/modules/blockbestsellers/blockbestsellers-home.tpl b/themes/default/modules/blockbestsellers/blockbestsellers-home.tpl index 9aa6884da..e52fd8017 100644 --- a/themes/default/modules/blockbestsellers/blockbestsellers-home.tpl +++ b/themes/default/modules/blockbestsellers/blockbestsellers-home.tpl @@ -22,35 +22,5 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - - -
-

{l s='Top sellers' mod='blockbestsellers'}

- {if isset($best_sellers) AND $best_sellers} -
- {assign var='liHeight' value=320} - {assign var='nbItemsPerLine' value=4} - {assign var='nbLi' value=$best_sellers|@count} - {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines} - {math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight} - -

{l s='All best sellers' mod='blockbestsellers'}

-
- {else} -

{l s='No best sellers at this time' mod='blockbestsellers'}

- {/if} -
-
- +{capture name=title}{l s='Best sellers' mod='blockbestsellers'}{/capture} +{include file="$tpl_dir./product-list-home.tpl" id="blockbestsellers_block" title=$smarty.capture.title products=$best_sellers} diff --git a/themes/default/modules/blocknewproducts/blocknewproducts.tpl b/themes/default/modules/blocknewproducts/blocknewproducts.tpl index 208e7f63f..f57e2ffd0 100644 --- a/themes/default/modules/blocknewproducts/blocknewproducts.tpl +++ b/themes/default/modules/blocknewproducts/blocknewproducts.tpl @@ -22,29 +22,5 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - - -
-

{l s='New products' mod='blocknewproducts'}

-
- {if $new_products !== false} -
    - {foreach from=$new_products item='product' name='newProducts'} - {if $smarty.foreach.newProducts.index < 2} - {$product.legend|escape:html:'UTF-8'} - {/if} - {/foreach} -
-
- {foreach from=$new_products item=newproduct name=myLoop} -
{$newproduct.name|strip_tags|escape:html:'UTF-8'}
- {if $newproduct.description_short}
{$newproduct.description_short|strip_tags:'UTF-8'|truncate:75:'...'}
{l s='Read more' mod='blocknewproducts'}
{/if} - {/foreach} -
-

» {l s='All new products' mod='blocknewproducts'}

- {else} -

» {l s='No new products at this time' mod='blocknewproducts'}

- {/if} -
-
- \ No newline at end of file +{capture name=title}{l s='New arrivals' mod='blocknewproducts'}{/capture} +{include file="$tpl_dir./product-list-home.tpl" id="blocknewproducts_block" title=$smarty.capture.title products=$new_products} \ No newline at end of file diff --git a/themes/default/modules/homefeatured/homefeatured.tpl b/themes/default/modules/homefeatured/homefeatured.tpl index 89b472bf2..4a346ac11 100644 --- a/themes/default/modules/homefeatured/homefeatured.tpl +++ b/themes/default/modules/homefeatured/homefeatured.tpl @@ -22,45 +22,5 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - - - - +{capture name=title}{l s='Popular' mod='homefeatured'}{/capture} +{include file="$tpl_dir./product-list-home.tpl" id="homefeatured_block" title=$smarty.capture.title} \ No newline at end of file diff --git a/themes/default/product-list-home.tpl b/themes/default/product-list-home.tpl new file mode 100644 index 000000000..45e19689c --- /dev/null +++ b/themes/default/product-list-home.tpl @@ -0,0 +1,62 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{if isset($title)}{$title}{/if}

+ {if isset($products) AND $products} +
+ {assign var='liHeight' value=250} + {assign var='nbItemsPerLine' value=4} + {assign var='nbLi' value=$products|@count} + {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines} + {math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight} +
    + {foreach from=$products item=product name=homeProducts} + {math equation="(total%perLine)" total=$smarty.foreach.homeProducts.total perLine=$nbItemsPerLine assign=totModulo} + {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if} +
  • + {$product.name|escape:html:'UTF-8'}{if isset($product.new) && $product.new == 1}{l s='New'}{/if} +
    {$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}
    + +
    + {l s='View'} + {if isset($product.show_price) && $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}

    {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}

    {else}
    {/if} + {if ((isset($product.id_product_attribute) && $product.id_product_attribute == 0) OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND (isset($product.available_for_order) && $product.available_for_order) AND !isset($restricted_country_mode) AND $product.minimal_quantity == 1 AND $product.customizable != 2 AND !$PS_CATALOG_MODE} + {if ($product.quantity > 0 OR $product.allow_oosp)} + {l s='Add to cart'} + {else} + {l s='Add to cart'} + {/if} + {else} +
    + {/if} +
    +
  • + {/foreach} +
+
+ {else} +

{l s='No products'}

+ {/if} + \ No newline at end of file