感谢Jon Lin,当有人点击我的网站网址时,我能够重定向我的PRESTASHOP网站,转到PRODUCT页面而不是HOME页面。
截至目前,我的网站上只有1个产品,所以我总是想去那个PRODUCT页面。
然而现在,当有人在我的网站上并且他们在其他页面上时,可能在购物车中...,然后他们点击HOME我想让他们回到主要的PRODUCT页面。不是实际的HOME页面。
感谢您的帮助。
答案 0 :(得分:0)
在配置中,在SEO和URL中,将基本uri更改为您的产品页面。
答案 1 :(得分:0)
很容易修复。让我们考虑您的产品产品ID为5,并且暂时忽略SEO友好的网址。打开文件 controllers / front / IndexController.php ,并在唯一的 initContent 函数中的某处添加以下代码。
Tools::redirect('index.php?id_product=5&controller=product');
现在,当某些用户访问该网站的主页时,该用户将被重定向到产品页面。如果启用了SEO友好网址,那么prestashop会自动在prestashop的地址栏中显示该网址的特定产品。
模式开发必须设置为false
请将id_product 5更改为您的产品ID。
希望这会对你有所帮助。
答案 2 :(得分:0)
如果你绝对必须去你的类别,重定向方法是好的,但我有另一种方法。出于搜索引擎优化的原因,我相信你不应该做重定向。我会做的是我会将homefeatured模块添加到您的主页并添加分页,使其像一个类别。首先,我会在测试之前在核心和你的主题中备份你的homefeatured文件,但这对我来说在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 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)}">« {l s='Previous'}</a></li>
{else}
<li id="pagination_previous" class="disabled"><span>« {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'} »</a></li>
{else}
<li id="pagination_next" class="disabled"><span>{l s='Next'} »</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&id_product={$product.id_product}&token={$static_token}&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');
}
}
这将是我避免在主页上重定向的解决方案。希望有所帮助。
答案 3 :(得分: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。希望对您有所帮助。