Автор Тема: Блок новых товаров на странице  (Прочитано 960 раз)

21 Декабрь 2016, 17:25:34
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Доброго времени суток. На главной странице магазина есть слайдер товаров: новинок и рекомендуемых. Хочу поставить их еще на одну страницу. Наверно самое логичное добавить их в category.tpl, так, чтобы отображались только на странице с определенным id. Подскажите, как это сделать?
21 Декабрь 2016, 20:54:34
Ответ #1
  • Модератор
  • Ветеран
  • *****
  • Сообщений: 86688
  • Репутация: +25428/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Создайте свой хук, добавьте вывод хука в шаблон category.tpl. В модулях добавьте установку в этот хук и функцию хука.
21 Декабрь 2016, 21:08:12
Ответ #2
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Можно чуть подробнее? А то я даже до конца не понимаю что такое хук :) Знаю лишь какие модули должны работать на той странице.
21 Декабрь 2016, 21:12:36
Ответ #3
  • Модератор
  • Ветеран
  • *****
  • Сообщений: 86688
  • Репутация: +25428/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Тогда для понимания прочтите вот эту тему - http://prestashop-forum.ru/index.php/topic,1669.0.html
В том же разделе найдете как менять хуки в модулях.
22 Декабрь 2016, 20:39:21
Ответ #4
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Целый день пытался разобраться, что делать так и не понял. У меня есть 3 модуля, которые выводятся на главной:

"В модуле добавить хук в install" - я так понял, нужно прописать install прямо в tpl файле модуля.
Не знаю как по-нормальному найти файлы модуля, но на главной странице слайдеры выделяется строчкой <!-- Products list -->. Точно такую же я смог найти только в одном файле: product-list.tpl
{*
* 2007-2015 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 <contact@prestashop.com>
*  @copyright  2007-2015 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($products) && $products}
{*define number of products per line in other page for desktop*}
{if $page_name !='index' && $page_name !='product'}
{assign var='nbItemsPerLine' value=4}
{assign var='nbItemsPerLineTablet' value=2}
{assign var='nbItemsPerLineMobile' value=3}
{else}
{assign var='nbItemsPerLine' value=3}
{assign var='nbItemsPerLineTablet' value=3}
{assign var='nbItemsPerLineMobile' value=2}
{/if}
{*define numbers of product per line in other page for tablet*}
{assign var='nbLi' value=$products|@count}
{math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
{math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}
<!-- Products list -->
<div{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}">
{foreach from=$products item=product name=products}
{math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}
{if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}
{if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}
{if $totModuloMobile == 0}{assign var='totModuloMobile' value=$nbItemsPerLineMobile}{/if}
<div class="li ajax_block_product{if $page_name == 'index' || $page_name == 'product'} col-xs-4 col-md-3 {else} col-xs-12 col-sm-4 {/if}{if $smarty.foreach.products.iteration%$nbItemsPerLine == 0} last-in-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLine == 1} first-in-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModulo)} last-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 0} last-item-of-tablet-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 1} first-item-of-tablet-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 0} last-item-of-mobile-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 1} first-item-of-mobile-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModuloMobile)} last-mobile-line{/if}">
<div class="product-container" itemscope itemtype="http://schema.org/Product">
<div class="left-block">
<div class="product-image-container">


<a class="product_img_link" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url">

<img class="replace-2x img-responsive" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}" alt="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" title="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} itemprop="image" />
</a>
<div class="over">
<a href="{$product.link|escape:'html':'UTF-8'}" class="hov"></a>
</div>



{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
<div class="content_price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
<span itemprop="price" class="price product-price">
{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</span>
<meta itemprop="priceCurrency" content="{$currency->iso_code}" />
{if isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
{hook h="displayProductPriceBlock" product=$product type="old_price"}
<span class="old-price product-price">
{displayWtPrice p=$product.price_without_reduction}
</span>

{/if}
{hook h="displayProductPriceBlock" product=$product type="price"}
{hook h="displayProductPriceBlock" product=$product type="unit_price"}
{/if}
</div>
{/if}
{if isset($product.new) && $product.new == 1}
<span class="new-label">{l s='New'}</span>

{/if}
{if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
<span class="sale-label">{l s='Sale!'}</span>

{/if}
{if $product.specific_prices.reduction_type == 'percentage'}
<span class="sale-label">-{$product.specific_prices.reduction * 100}%</span>
{/if}

{if $page_name != 'inex'}
<div class="functional-buttons clearfix">
{hook h='displayProductListFunctionalButtons' product=$product}
{if isset($comparator_max_item) && $comparator_max_item}
<div class="compare">
<a class="add_to_compare" href="{$product.link|escape:'html':'UTF-8'}" data-id-product="{$product.id_product}"> <i class="icon-columns"></i></a>
</div>
{/if}
{if isset($quick_view) && $quick_view}
<div class="quickview">
<a class="quick-view" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
<i class="icon-eye-open"></i>
</a>
</div>
{/if}


</div>
{/if}


</div>
{hook h="displayProductDeliveryTime" product=$product}
{hook h="displayProductPriceBlock" product=$product type="weight"}


</div>
<div class="right-block">
<h5 itemprop="name">
{if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}
<a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" >
{$product.name|truncate:45:'...'|escape:'html':'UTF-8'}
</a>
</h5>
{hook h='displayProductListReviews' product=$product}
<p class="product-desc" itemprop="description">
{$product.description_short|strip_tags:'UTF-8'|truncate:460:'...'}
</p>
{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="content_price">
{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
<span itemprop="price" class="price product-price">
{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</span>
<meta itemprop="priceCurrency" content="{$currency->iso_code}" />
{if isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
{hook h="displayProductPriceBlock" product=$product type="old_price"}
<span class="old-price product-price">
{displayWtPrice p=$product.price_without_reduction}
</span>
{hook h="displayProductPriceBlock" id_product=$product.id_product type="old_price"}

{/if}
{hook h="displayProductPriceBlock" product=$product type="price"}
{hook h="displayProductPriceBlock" product=$product type="unit_price"}
{/if}
</div>
{/if}
<div class="button-container">
{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.customizable != 2 && !$PS_CATALOG_MODE}
{if (!isset($product.customization_required) || !$product.customization_required) && ($product.allow_oosp || $product.quantity > 0)}
{capture}add=1&amp;id_product={$product.id_product|intval}{if isset($static_token)}&amp;token={$static_token}{/if}{/capture}
<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart', true, NULL, $smarty.capture.default, false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product="{$product.id_product|intval}" data-minimal_quantity="{if isset($product.product_attribute_minimal_quantity) && $product.product_attribute_minimal_quantity > 1}{$product.product_attribute_minimal_quantity|intval}{else}{$product.minimal_quantity|intval}{/if}">
<span>{l s='Add to cart'}</span>
</a>
{else}
<span class="button ajax_add_to_cart_button btn btn-default disabled">
<span>{l s='Add to cart'}</span>
</span>
{/if}
{/if}

</div>


{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && !$product.allow_oosp}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="available-dif">
<link itemprop="availability" href="http://schema.org/LimitedAvailability" />{l s='Product available with different options'}
</span>
{else}
<span class="out-of-stock">
<link itemprop="availability" href="http://schema.org/OutOfStock" />{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}

</div>

</div><!-- .product-container> -->
</div>
{/foreach}
</div>
{addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL}
{addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL}
{addJsDef comparator_max_item=$comparator_max_item}
{addJsDef comparedProductsIds=$compared_products}
{/if}
В общем застрял уже в начальной стадии создания хука :)
22 Декабрь 2016, 20:53:39
Ответ #5
  • Ветеран
  • *****
  • Сообщений: 3419
  • Репутация: +79/-6
  • Сообщество PrestaShop
    • Просмотр профиля
Цитировать
"В модуле добавить хук в install"
В самом модуле есть файл php (название одинаковое с названием модуля).
В этом файле нужно изменить функцию install
public function install() {
    if !parent::install()
        || !$this->registerHook('myHook'))
        ....
        return false;
    return true;
}
22 Декабрь 2016, 21:07:01
Ответ #6
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Это сделал, добавил || !$this->registerHook('novinki')
<?php
/*
* 2007-2014 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 <contact@prestashop.com>
*  @copyright  2007-2014 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 (!defined('_PS_VERSION_'))
exit;

class 
NewproductsSlider extends Module
{
protected static $cache_products;

public function __construct()
{
$this->name 'newproductsslider';
$this->tab 'front_office_features';
$this->version '1.6.2';
$this->author 'Tooniu';
$this->need_instance 0;

$this->bootstrap true;
parent::__construct();

$this->displayName $this->l('Slider of new products on the homepage');
$this->description $this->l('Displays new products in slider on homepage.');
}

public function install()
{
$this->_clearCache('*');
Configuration::updateValue('NEWPRODUCTS_NBR'6);


if (!parent::install()
|| !$this->registerHook('header')
|| !$this->registerHook('addproduct')
|| !$this->registerHook('updateproduct')
|| !$this->registerHook('deleteproduct')
|| !$this->registerHook('categoryUpdate')
|| !$this->registerHook('displayHome')
|| !$this->registerHook('novinki')
)
return false;

return true;
}

public function uninstall()
{
$this->_clearCache('*');

return parent::uninstall();
}

public function getContent()
{
$output '';
$errors = array();
if (Tools::isSubmit('submitNewproductsSlider'))
{
$nbr Tools::getValue('NEWPRODUCTS_NBR');
if (!Validate::isInt($nbr) || $nbr <= 0)
$errors[] = $this->l('The number of products is invalid. Please enter a positive number.');


if (isset($errors) && count($errors))
$output $this->displayError(implode('<br />'$errors));
else
{
Configuration::updateValue('NEWPRODUCTS_NBR', (int)$nbr);
Tools::clearCache(Context::getContext()->smarty$this->getTemplatePath('newproducts.tpl'));
$output $this->displayConfirmation($this->l('Your settings have been updated.'));
}
}

return $output.$this->renderForm();
}

public function hookDisplayHeader($params)
{
$this->hookHeader($params);
}

public function hookHeader($params)
{
if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'index')

$this->context->controller->addJS($this->_path.'js/newproducts.js');
$this->context->controller->addJS($this->_path.'js/owl.carousel.min.js');
$this->context->controller->addCSS($this->_path.'css/owl.carousel.css');
$this->context->controller->addCSS($this->_path.'css/owl.theme.css');


$this->context->controller->addCSS(_THEME_CSS_DIR_.'product_list.css');
$this->context->controller->addCSS(($this->_path).'newproducts.css''all');
}

public function _cacheProducts()
{
if (!isset(NewproductsSlider::$cache_products))
{
$nb = (int)Configuration::get('NEWPRODUCTS_NBR');


NewproductsSlider::$cache_products Product::getNewProducts((int) $this->context->language->id0, (int)$nb);
}

if (NewproductsSlider::$cache_products === false || empty(NewproductsSlider::$cache_products))
return false;
}


public function hookDisplayHome($params)
{
if (!$this->isCached('newproducts.tpl'$this->getCacheId()))
{
$this->_cacheProducts();
$this->smarty->assign(
array(
'products' => NewproductsSlider::$cache_products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'items' => Configuration::get('tooniu_nbrhome')

)
);
}

return $this->display(__FILE__'newproducts.tpl'$this->getCacheId());
}


public function hookAddProduct($params)
{
$this->_clearCache('*');
}

public function hookUpdateProduct($params)
{
$this->_clearCache('*');
}

public function hookDeleteProduct($params)
{
$this->_clearCache('*');
}

public function hookCategoryUpdate($params)
{
$this->_clearCache('*');
}

public function _clearCache($template$cache_id NULL$compile_id NULL)
{
parent::_clearCache('NewproductsSlider.tpl');
parent::_clearCache('tab.tpl''NewproductsSlider-tab');
}

public function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs'
),
'description' => $this->l('To add products to your homepage, simply add them to the corresponding product category (default: "Home").'),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Number of products to be displayed'),
'name' => 'NEWPRODUCTS_NBR',
'class' => 'fixed-width-xs',
'desc' => $this->l('Set the number of products that you would like to display on homepage (default: 8).'),
),

),
'submit' => array(
'title' => $this->l('Save'),
)
),
);

$helper = new HelperForm();
$helper->show_toolbar false;
$helper->table $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language $lang->id;
$helper->allow_employee_form_lang Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->id = (int)Tools::getValue('id_carrier');
$helper->identifier $this->identifier;
$helper->submit_action 'submitNewproductsSlider';
$helper->currentIndex $this->context->link->getAdminLink('AdminModules'false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);

return $helper->generateForm(array($fields_form));
}

public function getConfigFieldsValues()
{
return array(
'NEWPRODUCTS_NBR' => Tools::getValue('NEWPRODUCTS_NBR', (int)Configuration::get('NEWPRODUCTS_NBR')),
);
}
}
В category.tpl в самом конце добавил {hook h='novinki'}
{*
* 2007-2015 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 <contact@prestashop.com>
*  @copyright  2007-2015 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}




{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
{if isset($category)}
{if $category->id AND $category->active}
    {if $scenes || $category->id_image}
<div class="content_scene_cat">
            {if $scenes}
                  <div class="content_scene">
                        <!-- Scenes -->
                        {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
                        {if $category->description}
                            <div class="cat_desc rte">
                            {if Tools::strlen($category->description) > 350}
                                <div id="category_description_short">{$description_short}</div>
                                <div id="category_description_full" class="unvisible">{$category->description}</div>
                                <a href="{$link->getCategoryLink($category->id_category, $category->link_rewrite)|escape:'html':'UTF-8'}" class="lnk_more">{l s='More'}</a>
                            {else}
                                <div>{$category->description}</div>
                            {/if}
                            </div>
                        {/if}
                    </div>
{else}
                    <!-- Category image -->
                    <div class="content_scene_cat_bg"{if $category->id_image} style="background:url({$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')|escape:'html':'UTF-8'})  center no-repeat; background-size:cover; min-height:{$categorySize.height}px;"{/if}>
                        {if $category->description}
                            <div class="cat_desc">
                            <span class="category-name">
                                {strip}
                                    {$category->name|escape:'html':'UTF-8'}
                                    {if isset($categoryNameComplement)}
                                        {$categoryNameComplement|escape:'html':'UTF-8'}
                                    {/if}
                                {/strip}
                            </span>
                            {if Tools::strlen($category->description) > 350}
                                <div id="category_description_short" class="rte">{$description_short}</div>
                                <div id="category_description_full" class="unvisible rte">{$category->description}</div>
                                <a href="{$link->getCategoryLink($category->id_category, $category->link_rewrite)|escape:'html':'UTF-8'}" class="lnk_more">{l s='More'}</a>
                            {else}
                                <div class="rte">{$category->description}</div>
                            {/if}
                            </div>
                        {/if}
                     </div>
                  {/if}
            </div>
{else}

<div class="bighead">
<h1 class="page-heading product-listing">                     {strip}
                                    {$category->name|escape:'html':'UTF-8'}
                                    {if isset($categoryNameComplement)}
                                        {$categoryNameComplement|escape:'html':'UTF-8'}
                                    {/if}
                                {/strip}</h1>
{$category->description}
</div>
<script type="text/javascript">
$(document).ready(function() {
$('.bighead').appendTo( $('#categoryimg') );
});
</script>
{/if}

{if isset($subcategories)}
        {if (isset($display_subcategories) && $display_subcategories eq 1) || !isset($display_subcategories) }
<!-- Subcategories -->
<div id="subcategories">
<p class="subcategory-heading">{l s='Subcategories'}</p>
<ul class="clearfix">
{foreach from=$subcategories item=subcategory}
<li>
               <a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'|truncate:350}</a>
</li>
{/foreach}
</ul>
</div>
        {/if}
{/if}
{if $products}
<div class="content_sortPagiBar clearfix">
{include file="./product-compare.tpl"}
             {include file="./nbr-product-page.tpl"}
{include file="./product-sort.tpl"}

               
               
</div>
{include file="./product-list.tpl" products=$products}

<div class="content_sortPagiBar bot">
{include file="./product-compare.tpl"}
{include file="./product-sort.tpl"}
</div>
<div class="bottom-pagination-content clearfix">
                {include file="./pagination.tpl" paginationId='bottom'}
</div>
{/if}
{elseif $category->id}
<p class="alert alert-warning">{l s='This category is currently unavailable.'}</p>
{/if}
{/if}

<script type="text/javascript">
    $(document).ready(function() {
$('.content_scene_cat').appendTo( $('#categoryimg') );
});
</script>
{hook h='novinki'}
Почистил кэш, зашел в модули - ничего не изменилось. Я так понял, нужно еще функцию создавать, что-то типа этого
public function hooknovinki($params)
{
    return $this->display(__FILE__, 'mymodule.tpl');
}
Только что писать вместо __FILE__? И вместо mymodule.tpl должен быть category.tpl?
23 Декабрь 2016, 12:03:19
Ответ #7
  • Ветеран
  • *****
  • Сообщений: 16667
  • Репутация: +14630/-5
  • Сообщество PrestaShop
    • Просмотр профиля
"mymodule.tpl" - это новый файл для показа блока.
Его нужно создать.
23 Декабрь 2016, 12:57:48
Ответ #8
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
"mymodule.tpl" - это новый файл для показа блока.
Его нужно создать.
Хорошо, а что в нем должно содержаться?
23 Декабрь 2016, 13:08:15
Ответ #9
  • Ветеран
  • *****
  • Сообщений: 3419
  • Репутация: +79/-6
  • Сообщество PrestaShop
    • Просмотр профиля
Открой tpl в модуле, который меняешь и увидишь.
html + переменные smarty.
23 Декабрь 2016, 15:14:00
Ответ #10
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Открой tpl в модуле, который меняешь и увидишь.
html + переменные smarty.
Какой tpl и как его открыть в модуле? Я добавил в конце файла newproductsslider.php следующий код:
public function hooknovinki($params)
{
    return $this->display(__FILE__, 'novinki.tpl');
}
Теперь надо создать этот самый novinki.tpl, что туда поместить?
23 Декабрь 2016, 15:37:03
Ответ #11
  • Ветеран
  • *****
  • Сообщений: 3419
  • Репутация: +79/-6
  • Сообщество PrestaShop
    • Просмотр профиля
В папку модуля newproductsslider помести шаблон tpl.
23 Декабрь 2016, 15:53:00
Ответ #12
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
В папку модуля newproductsslider помести шаблон tpl.
Тот самый шаблон novinki.tpl? А что поместить в сам шаблон?
26 Декабрь 2016, 15:32:08
Ответ #13
  • Новичок
  • *
  • Сообщений: 27
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
В общем, что бы я ни делал, мой хук в модулях так и не появляется.
Нашел как выглядит функция этого слайдера на главной странице:
public function hookDisplayHome($params)
{
if (!$this->isCached('newproducts.tpl', $this->getCacheId()))
{
$this->_cacheProducts();
$this->smarty->assign(
array(
'products' => NewproductsSlider::$cache_products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'items' => Configuration::get('tooniu_nbrhome')

)
);
}

return $this->display(__FILE__, 'newproducts.tpl', $this->getCacheId());
}
Чем моя функция должна отличаться от этой?
26 Декабрь 2016, 16:30:13
Ответ #14
  • Модератор
  • Ветеран
  • *****
  • Сообщений: 33325
  • Репутация: +26771/-0
    • Просмотр профиля
В prestashop 1.5 и 1.6.
В модуле добавить хук в install, создать одноименную функцию и создать шаблон tpl.
public function install() {
    if !parent::install() || !$this->registerHook('myCustomHook'))
        return false;
    return true;
}
public function hookMyCustomHook($params)
{
    return $this->display(__FILE__, 'mymodule.tpl');
}

В шаблоне страницы, на которой нужно вывести шаблон модуля, добавить код
{hook h='myCustomHook'}
Добавьте хук в install(), добавьте функцию
public function hookMyCustomHook($params)
{
    return $this->display(__FILE__, 'mymodule.tpl');
}
Создайте шаблон mymodule.tpl
<p>{l s='My module' mod='название модуля'}</p>В шаблон tpl страницы, на которой хотите проказать модуль, добавьте
{hook h='myCustomHook'}Переустановите модуль.
Отключите кеширование.
Откройте вашу страницу. Если увидите текст "My module", можете дорабатывать модуль.