在prestashop中的制造tpl文件中调用blocklayered模块

时间:2017-02-06 09:16:54

标签: php smarty prestashop

我想在我的manufacture-list.tpl文件中使用blocklayered(分层导航块)模块。我使用了这段代码:

{include file='./modules/blocklayered/blocklayered.tpl'}

但它不起作用我想在制造页面的左栏中找到分层过滤器,它已经出现在类别页面中。

1 个答案:

答案 0 :(得分:0)

这是不可能的。这个问题已被多次询问,反应总是一样的。

Blocklayered模块用于处理类别,不能用于其他任何事情。

对此的解决方案是继续使用制造商列表页面,但是使用为制造商定义的过滤器更改每个制造商的链接以指向您的根类别。然后,用户将被重定向到您的根类别,其中blocklayered active并在所需的制造商上进行过滤。

我是以这种方式为我的客户做的:(我已经添加了一些代码来按字母顺序对制造商进行排序,并通过带快速访问菜单的第一个字母对其进行分组)。

档案/override/controllers/front/ManufacturerController.php

class ManufacturerController extends ManufacturerControllerCore
{
    protected $blocklayered = null;

    public function __construct()
    {
        parent::__construct();

        require_once(_PS_MODULE_DIR_ . 'blocklayered/blocklayered.php');
        $this->blocklayered = new BlockLayered();
    }

    /**
     * Assign template vars if displaying the manufacturer list
     */
    protected function assignAll()
    {
        if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
            $data = Manufacturer::getManufacturers(true, $this->context->language->id, true, false, false, false);

            $no_products = array();
            foreach ($data as $key => $item) {
                $data[$key]['link'] = Context::getContext()->link->getCategoryLink(MY_CATEGORY_ROOT, null, null, str_replace($this->getAnchor(), '_', Tools::link_rewrite($this->blocklayered->l('Manufacturer'))) . $this->getAnchor() . str_replace($this->getAnchor(), '_', Tools::link_rewrite($data[$key]['name'])));
                $data[$key]['image'] = (!file_exists(_PS_MANU_IMG_DIR_.$item['id_manufacturer'].'-'.ImageType::getFormatedName('medium').'.jpg')) ? false : $item['id_manufacturer'];
                if ($item['nb_products'] == 0)
                {
                    $no_products[] = $key;
                }
            }

            foreach ($no_products as $key)
            {
                unset($data[$key]);
            }

            $manufacturersByLetters = array();

            foreach ($data as $item)
            {
                $letter = strtoupper(substr($item['name'], 0, 1));
                if (! isset($manufacturersByLetters[$letter]))
                {
                    $manufacturersByLetters[$letter] = array();
                }
                $manufacturersByLetters[$letter][] = $item;
            }

            ksort($manufacturersByLetters, SORT_STRING);
            foreach ($manufacturersByLetters as &$manufacturers)
            {
                usort($manufacturers, function($manu1, $manu2) {
                    return strcmp(strtolower($manu1['name']), strtolower($manu2['name']));
                });
            }
            unset($manufacturers);

            $this->context->smarty->assign(array(
                'nbManufacturers' => count($data),
                'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
                'manufacturersByLetters' => $manufacturersByLetters
            ));
        } else {
            $this->context->smarty->assign('nbManufacturers', 0);
        }
    }

    protected function getAnchor()
    {
        static $anchor = null;
        if ($anchor === null)
            if (!$anchor = Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'))
                $anchor = '-';
        return $anchor;
    }
}

档案/themes/my_theme/manufacturer-list.tpl

{capture name=path}{l s='Nos marques'}{/capture}

<h1>
    <span>{l s='Nos Marques'}</span>
</h1>
{if isset($errors) AND $errors}
    {include file="$tpl_dir./errors.tpl"}
{else}
    {if $nbManufacturers > 0}
        <div id="manufacturer_menu">
            <span id="manufacturer_menu_title">{l s='Accéder directement à une lettre'}</span>
            <ul>
                {foreach from=$manufacturersByLetters item=manufacturers key=letter name=manufacturersByLetters}
                    <li{if $smarty.foreach.manufacturersByLetters.first} class="active"{/if}><a href="#manufacturer_list_letter_{$letter}">{$letter}</a></li>
                {/foreach}
            </ul>
        </div>

        {foreach from=$manufacturersByLetters item=manufacturers key=letter name=manufacturersByLetters}
            <h2 class="manufacturer_list_letter_wrapper{if $smarty.foreach.manufacturersByLetters.first} first{/if}">
                <span class="manufacturer_list_letter" id="manufacturer_list_letter_{$letter}">{$letter}</span>
            </h2>
            <ul class="manufacturer_list row">
            {strip}
                {foreach from=$manufacturers item=manufacturer name=manufacturers}
                    <li class="col-lg-1 col-md-2 col-sm-3 col-xs-6">
                        <div class="row">
                            <div class="col-xs-12">
                                <a class="manufacturer_list_name_wrapper" href="{$manufacturer.link|escape:'html':'UTF-8'}" title="{$manufacturer.name|escape:'html':'UTF-8'}">
                                    <div>
                                        {if isset($manufacturer.image) && $manufacturer.image}
                                            <img src="{$img_manu_dir}{$manufacturer.image|escape:'html':'UTF-8'}-medium_default.jpg" alt="{$manufacturer.name|escape:'html':'UTF-8'}" />
                                        {else}
                                            <span class="manufacturer_list_name">{$manufacturer.name|escape:'html':'UTF-8'}</span>
                                        {/if}
                                    </div>
                                </a>
                                {if isset($manufacturer.nb_products) && $manufacturer.nb_products > 0}
                                    <a class="manufacturer_list_link" href="{$manufacturer.link|escape:'html':'UTF-8'}" title="{$manufacturer.name|escape:'html':'UTF-8'}">
                                        <span class="manufacturer_list_link_name">{$manufacturer.name|escape:'html':'UTF-8'}</span>
                                        <span class="manufacturer_list_link_action">
                                            {if isset($manufacturer.nb_products) && $manufacturer.nb_products == 1}
                                                {l s='Afficher le produit'}
                                            {elseif isset($manufacturer.nb_products) && $manufacturer.nb_products > 0}
                                                {l s='Afficher les %d produits' sprintf=$manufacturer.nb_products|intval}
                                            {/if}
                                             <i class="icon-chevron-right right"></i>
                                        </span>
                                    </a>
                                {/if}
                            </div>
                        </div>
                    </li>
                {/foreach}
            {/strip}
            </ul>
        {/foreach}
        <script type="text/javascript">
            $("#manufacturer_menu a").on('click', function() {
                var $a = $(this)
                $('html, body').animate({
                    scrollTop: $($a.attr('href')).offset().top
                }, 750);
                return false;
            });
        </script>
    {/if}
{/if}