当我在Prestashop中单击HOME时,我想转到我的主要产品页面

问题描述 投票:2回答:4

[感谢Jon Lin,当有人单击我的网站URL时,我能够将我的PRESTASHOP网站重定向到PRODUCT页面而不是HOME页面。

截至目前,我的网站上只有1种产品,所以我总是想转到该PRODUCT页面。

但是现在,当某人在我的网站上并且在其他页面上,也许在购物车中...,并且他们单击HOME时,我希望他们返回到PRODUCT主页。不是实际的主页。

感谢您的帮助。

php prestashop
4个回答
0
投票

在配置中,在SEO和URL中,将基本uri更改为您的产品页面。


0
投票

如果绝对必须转到类别,则重定向方法是不错的选择,但是我有另一种方法。出于SEO的原因,我相信您不应该进行重定向。我要做的是将主页功能模块添加到您的主页并向其中添加分页,使其像一个类别一样。首先,在测试之前,我会备份核心和主题中的家庭功能文件,但这在1.5.4版本上对我有用。

您可以通过使用以下代码将名为paginationHomeFeatured.tpl的文件添加到./themes/yourtheme/modules/homefeatured/<HERE>中来进行操作。

{*
* 2007-2012 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 [email protected] 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 <[email protected]>
*  @copyright  2007-2012 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($no_follow) AND $no_follow}
{assign var='no_follow_text' value='rel="nofollow"'}
{else}
{assign var='no_follow_text' value=''}
{/if}
{if isset($p) AND $p}
  {assign var='requestPage' value=$base_dir|cat:'index.php'}
  {assign var='requestNb' value=$base_dir|cat:'index.php'}
{* {assign var='requestNb' value=$smarty.section.pagination.limits} *}

<!-- Pagination -->
<div id="pagination" class="pagination">
{if $start!=$stop}
  <ul class="pagination">
  {if $p != 1}
   {assign var='p_previous' value=$p-1}
   <li id="pagination_previous"><a {$no_follow_text} href="{$link->goPage($requestPage, $p_previous)}">&laquo;&nbsp;{l s='Previous'}</a></li>
  {else}
   <li id="pagination_previous" class="disabled"><span>&laquo;&nbsp;{l s='Previous'}</span></li>
  {/if}
  {if $start==3}
   <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
   <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 2)}">2</a></li>
  {/if}
  {if $start==2}
   <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
  {/if}
  {if $start>3}
   <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
   <li class="truncate">...</li>
  {/if}
  {section name=pagination start=$start loop=$stop+1 step=1}
   {if $p == $smarty.section.pagination.index}
    <li class="current"><span>{$p|escape:'htmlall':'UTF-8'}</span></li>
   {else}
    <li><a {$no_follow_text} href="{$link->goPage($requestPage, $smarty.section.pagination.index)}">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}</a></li>
   {/if}
  {/section}
  {if $pages_nb>$stop+2}
   <li class="truncate">...</li>
   <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
  {/if}
  {if $pages_nb==$stop+1}
   <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
  {/if}
  {if $pages_nb==$stop+2}
   <li><a href="{$link->goPage($requestPage, $pages_nb-1)}">{$pages_nb-1|intval}</a></li>
   <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
  {/if}
  {if $pages_nb > 1 AND $p != $pages_nb}
   {assign var='p_next' value=$p+1}
   <li id="pagination_next"><a {$no_follow_text} href="{$link->goPage($requestPage, $p_next)}">{l s='Next'}&nbsp;&raquo;</a></li>
  {else}
   <li id="pagination_next" class="disabled"><span>{l s='Next'}&nbsp;&raquo;</span></li>
  {/if}
  </ul>
{/if}
{if $nb_products > $products_per_page}
  <form action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get" class="pagination">
   <p>
    {if isset($search_query) AND $search_query}<input type="hidden" name="search_query" value="{$search_query|escape:'htmlall':'UTF-8'}" />{/if}
    {if isset($tag) AND $tag AND !is_array($tag)}<input type="hidden" name="tag" value="{$tag|escape:'htmlall':'UTF-8'}" />{/if}
    <input type="submit" class="button_mini" value="{l s='OK'}" />
    <label for="nb_item">{l s='items:'}</label>
    <select name="n" id="nb_item">
    {assign var="lastnValue" value="0"}
    {foreach from=$nArray item=nValue}
         {if $lastnValue <= $nb_products}
          <option value="{$nValue|escape:'htmlall':'UTF-8'}" {if $n == $nValue}selected="selected"{/if}>{$nValue|escape:'htmlall':'UTF-8'}</option>
         {/if}
         {assign var="lastnValue" value=$nValue}
    {/foreach}
    </select>
    {if is_array($requestNb)}
         {foreach from=$requestNb item=requestValue key=requestKey}
          {if $requestKey != 'requestUrl'}
           <input type="hidden" name="{$requestKey|escape:'htmlall':'UTF-8'}" value="{$requestValue|escape:'htmlall':'UTF-8'}" />
          {/if}
         {/foreach}
    {/if}
   </p>
  </form>
{/if}
</div>
<!-- /Pagination -->
{/if}

下一步,将homefeatured.tpl更改为..

{*
* 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 [email protected] 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 <[email protected]>
*  @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
*}

<!-- MODULE Home Featured Products -->
<div id="featured-products_block_center" class="block products_block clearfix">
    <p class="title_block">{l s='Featured products' mod='homefeatured'}</p>
    {if isset($products) AND $products}
        <div class="block_content">
            {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}
            <ul style="height:{$ulHeight}px;">
            {foreach from=$products item=product name=homeFeaturedProducts}
                {math equation="(total%perLine)" total=$smarty.foreach.homeFeaturedProducts.total perLine=$nbItemsPerLine assign=totModulo}
                {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}
                <li class="ajax_block_product {if $smarty.foreach.homeFeaturedProducts.first}first_item{elseif $smarty.foreach.homeFeaturedProducts.last}last_item{else}item{/if} {if $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 0}last_item_of_line{elseif $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 1} {/if} {if $smarty.foreach.homeFeaturedProducts.iteration > ($smarty.foreach.homeFeaturedProducts.total - $totModulo)}last_line{/if}">
                    <a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}" class="product_image"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product.name|escape:html:'UTF-8'}" />{if isset($product.new) && $product.new == 1}<span class="new">{l s='New' mod='homefeatured'}</span>{/if}</a>
                    <p class="s_title_block"><a href="{$product.link}" title="{$product.name|truncate:50:'...'|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></p>
                    <div class="product_desc"><a href="{$product.link}" title="{l s='More' mod='homefeatured'}">{$product.description_short|strip_tags|truncate:65:'...'}</a></div>
                    <div>
                        <a class="lnk_more" href="{$product.link}" title="{l s='View' mod='homefeatured'}">{l s='View' mod='homefeatured'}</a>
                        {if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><span class="price">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}

                        {if ($product.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $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)}
                            <a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&amp;id_product={$product.id_product}&amp;token={$static_token}&amp;add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Add to cart' mod='homefeatured'}</a>
                            {else}
                            <span class="exclusive">{l s='Add to cart' mod='homefeatured'}</span>
                            {/if}
                        {else}
                            <div style="height:23px;"></div>
                        {/if}
                    </div>
                </li>
            {/foreach}
            </ul>
        </div>
    {else}
        <p>{l s='No featured products' mod='homefeatured'}</p>
    {/if}

    {* To add pagination - add three line below *}
    <div class="content_sortPagiBar homefeaturedPaged">
        {include file="./paginationHomeFeatured.tpl"}
    </div>

</div>
<!-- /MODULE Home Featured Products -->

最后,在您的核心目录中编辑homefeatured.php。

<?php
/*
* 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 [email protected] 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 <[email protected]>
*  @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 (!defined('_PS_VERSION_'))
    exit;

class HomeFeatured extends Module
{
    private $_html = '';
    private $_postErrors = array();

    function __construct()
    {
        $this->name = 'homefeatured';
        $this->tab = 'front_office_features';
        $this->version = '0.9';
        $this->author = 'PrestaShop';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('Featured products on the homepage.');
        $this->description = $this->l('Displays featured products in the middle of your homepage.');
    }

    function install()
    {
        if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header'))
            return false;
        return true;
    }

    public function getContent()
    {
        $output = '<h2>'.$this->displayName.'</h2>';
        if (Tools::isSubmit('submitHomeFeatured'))
        {
            $nbr = (int)(Tools::getValue('nbr'));
            if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
                $errors[] = $this->l('An invalid number of products has been specified.');
            else
                Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr));
            if (isset($errors) AND sizeof($errors))
                $output .= $this->displayError(implode('<br />', $errors));
            else
                $output .= $this->displayConfirmation($this->l('Your settings have been updated.'));
        }
        return $output.$this->displayForm();
    }

    public function displayForm()
    {
        $output = '
        <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
            <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
                <p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br />
                <label>'.$this->l('Define the number of products to be displayed.').'</label>
                <div class="margin-form">
                    <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />
                    <p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p>

                </div>
                <center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>
            </fieldset>
        </form>';
        return $output;
    }

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

    public function hookHeader($params)
    {
        $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all');
    }

    public function hookDisplayHome($params)
    {
/*      $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
        $nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
        $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

        $this->smarty->assign(array(
            'products' => $products,
            'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
            'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
        ));

        return $this->display(__FILE__, 'homefeatured.tpl');
*/



        $controller = new FrontController();
            $controller->productSort();
        $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
            $nbProducts = $category->getProducts(NULL, NULL, NULL, $controller->orderBy, $controller->orderWay, true);
        $controller->pagination($nbProducts);

        $this->smarty->assign('nb_products', $nbProducts);

        $products = $category->getProducts((int)Context::getContext()->language->id, (int)($controller->p),
                (int)($controller->n), $controller->orderBy, $controller->orderWay);

        $this->smarty->assign(array(
                'products' => $products,
                'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
                'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
                'id_category' => (int)($category->id),
                'id_category_parent' => (int)($category->id_parent),
                'return_category_name' => Tools::safeOutput($category->name),
                'path' => Tools::getPath((int)($category->id), $category->name)
                ));

        return $this->display(__FILE__, 'homefeatured.tpl');












    }
}

这是我避免在首页上进行重定向的解决方案。希望有帮助。


0
投票

很容易修复。让我们假设您的产品的产品ID为5,并且目前还忽略了SEO友好的网址。打开文件controllers / front / IndexController.php,并将以下代码添加到唯一的[[initContent函数中。

Tools::redirect('index.php?id_product=5&controller=product');
现在,当有人访问该网站的主页时,该用户将被重定向到产品页面。如果启用了SEO友好URL,则prestashop将在该特定产品的prestashop地址栏中自动显示SEO URL。

Mode dev必须设置为false

请将id_product 5更改为您的产品ID。

希望这会对您有所帮助。


0
投票
它为我工作。就我而言,我将主页更改为另一个URL。其他产品页面仍然可以正常工作。为此,请转到

controllers / front / IndexController.php并在initContent function中更改以下代码。Tools::redirect('http://newwebsiteurl.com/');

即您将删除下面函数中的所有内容

{ parent::initContent(); $this->addJS(_THEME_JS_DIR_.'index.js'); $this->context->smarty->assign(array('HOOK_HOME' => Hook::exec('displayHome'), 'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'), 'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent') )); $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); }

并用这样的东西替换:

{ parent::initContent(); Tools::redirect('http://newwebsiteurl.com/'); }

它在我的网站Soup Embassy上对我有用,我希望对您也有用。如果在此处检查Soup Category上的URL,您将看到它在目录/ buy-online /中,并且当您单击主页链接或徽标时,它将重定向到没有扩展名的URL。希望对您有所帮助。
© www.soinside.com 2019 - 2024. All rights reserved.