2

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

到目前为止,我的网站上只有 1 个产品,所以我总是想去那个 PRODUCT 页面。

但是现在,当有人在我的网站上并且他们在其他页面上时,可能在购物车中......,他们点击主页我想让他们回到主产品页面。不是实际的主页。

谢谢你的帮助。

4

4 回答 4

0

如果您绝对必须转到您的类别,则重定向方法很好,但是我有另一种方法。出于搜索引擎优化的原因,我认为您不应该进行重定向。我要做的是将 homefeatured 模块添加到您的主页并为其添加分页,使其就像一个类别。首先,在测试之前,我会在核心和主题中备份您的 homefeatured 文件,但这在 1.5.4 版本上对我有用。

您可以通过使用以下代码添加一个名为paginationHomeFeatured.tplto的文件来做到这一点。./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 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-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 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-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 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-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');












    }
}

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

于 2013-09-08T11:36:56.167 回答
0

这很容易修复。让我们考虑您的产品产品 ID 为 5,并且此时也忽略 SEO 友好的网址。打开文件controllers/front/IndexController.php并在唯一的initContent函数 中的某处添加以下代码。

Tools::redirect('index.php?id_product=5&controller=product');

现在,当有人访问网站的主页时,该用户将被重定向到产品页面。如果启用了 SEO 友好 url,则 prestashop 将自动在该特定产品的 prestashop 的地址栏中显示 SEO url。

模式 dev 必须设置为 false

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

希望这会帮助你。

于 2013-09-05T13:12:48.670 回答
0

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

于 2013-09-05T11:51:21.710 回答
0

它对我有用。就我而言,我将主页更改为我的另一个 URL。其他产品页面仍然正常工作。为此,请转到controllers/front/IndexController.php并更改在initContent 函数的某处添加以下代码。

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。我希望你觉得这有帮助。

于 2019-10-13T16:03:30.193 回答