点击此类别产品列表上方的类别后,我想阻止此类产品的促销活动。
我目前在类别中有一个模块blockpecials钩子,我可以在促销上复制/显示随机促销产品或所有产品(如在主页上)。我需要这类促销产品,我会点击,如何咬它?
if (Configuration::get('PS_CATALOG_MODE'))
return;
// We need to create multiple caches because the products are sorted randomly
$random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1)));
if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
{
if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return;
$this->smarty->assign(array(
'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
}
return $this->display(__FILE__, 'blockspecials.tpl', (Configuration::get('BLOCKSPECIALS_NB_CACHES') ? $this->getCacheId('blockspecials|'.$random) : null));
如何更改功能getRandomSpecial
以显示当前类别的展示推广产品?
我没有使用Prestashop进步
答案 0 :(得分:1)
以这种方式修改函数Product :: getRandomSpecial中的查询(第一个$ sql)
$sql = 'SELECT product_shop.id_product, IFNULL(product_attribute_shop.id_product_attribute,0) id_product_attribute
FROM
`'._DB_PREFIX_.'product_reductions` pr,
`'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'category_product` category_product
ON (p.`id_product` = category_product.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop
ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')
WHERE p.id_product=pr.id_product AND category_product.`id_category` = '.(int)Tools::getValue('id_category').' AND (pr.id_product_attribute = 0 OR product_attribute_shop.id_product_attribute = pr.id_product_attribute) AND product_shop.`active` = 1
'.$sql_groups.'
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
ORDER BY RAND()';
然后替换下一行
$result = Db::getInstance()->getRow($sql);
与
$results = Db::getInstance()->executeS($sql);
添加新变量
$specialProducts = array();
然后包含所有代码,直到条件结束括号为代码
foreach ($results as $result) {
if (!$id_product = $result['id_product']) {
return false;
}
// no group by needed : there's only one attribute with cover=1 for a given id_product + shop
$sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`,
p.`ean13`, p.`upc`, image_shop.`id_image` id_image, il.`legend`,
DATEDIFF(product_shop.`date_add`, DATE_SUB("'.date('Y-m-d').' 00:00:00",
INTERVAL '.(Validate::isUnsignedInt(
Configuration::get('PS_NB_DAYS_NEW_PRODUCT')
) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
DAY)) > 0 AS new
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop
ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
'.Product::sqlStock('p', 0).'
WHERE p.id_product = '.(int)$id_product;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (!$row) {
return false;
}
$row['id_product_attribute'] = (int)$result['id_product_attribute'];
$specialProducts[] = Product::getProductProperties($id_lang, $row);
}
return $specialProducts;
然后使用下一个更改修改模块文件modules / blockspecials / blockspecials.php。查找代码
if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
{
if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return;
$this->smarty->assign(array(
'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
}
并将其替换为
if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
{
if (!($specials = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return;
$this->smarty->assign(array(
'specials' => $specials,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
}
你也可以修改主题/ your_theme / modules / blockspecials / blockspecials.tpl,找到
{if $special}
<ul>
<li class="clearfix">
<a class="products-block-image" href="{$special.link|escape:'html':'UTF-8'}">
<img
class="replace-2x img-responsive"
src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'small_default')|escape:'html':'UTF-8'}"
alt="{$special.legend|escape:'html':'UTF-8'}"
title="{$special.name|escape:'html':'UTF-8'}" />
</a>
<div class="product-content">
<h5>
<a class="product-name" href="{$special.link|escape:'html':'UTF-8'}" title="{$special.name|escape:'html':'UTF-8'}">
{$special.name|escape:'html':'UTF-8'}
</a>
</h5>
{if isset($special.description_short) && $special.description_short}
<p class="product-description">
{$special.description_short|strip_tags:'UTF-8'|truncate:40}
</p>
{/if}
<div class="price-box">
{if !$PS_CATALOG_MODE}
<span class="price special-price">
{if !$priceDisplay}
{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}
{/if}
</span>
{if $special.specific_prices}
{assign var='specific_prices' value=$special.specific_prices}
{if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
<span class="price-percent-reduction">-{$specific_prices.reduction*100|floatval}%</span>
{/if}
{/if}
<span class="old-price">
{if !$priceDisplay}
{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}
{/if}
</span>
{hook h="displayProductPriceBlock" product=$special type="price"}
{/if}
</div>
</div>
</li>
</ul>
并替换为
{if $specials}
<ul>
{foreach from=$specials item='special'}
<li class="clearfix">
<a class="products-block-image" href="{$special.link|escape:'html':'UTF-8'}">
<img
class="replace-2x img-responsive"
src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'small_default')|escape:'html':'UTF-8'}"
alt="{$special.legend|escape:'html':'UTF-8'}"
title="{$special.name|escape:'html':'UTF-8'}" />
</a>
<div class="product-content">
<h5>
<a class="product-name" href="{$special.link|escape:'html':'UTF-8'}" title="{$special.name|escape:'html':'UTF-8'}">
{$special.name|escape:'html':'UTF-8'}
</a>
</h5>
{if isset($special.description_short) && $special.description_short}
<p class="product-description">
{$special.description_short|strip_tags:'UTF-8'|truncate:40}
</p>
{/if}
<div class="price-box">
{if !$PS_CATALOG_MODE}
<span class="price special-price">
{if !$priceDisplay}
{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}
{/if}
</span>
{if $special.specific_prices}
{assign var='specific_prices' value=$special.specific_prices}
{if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
<span class="price-percent-reduction">-{$specific_prices.reduction*100|floatval}%</span>
{/if}
{/if}
<span class="old-price">
{if !$priceDisplay}
{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}
{/if}
</span>
{hook h="displayProductPriceBlock" product=$special type="price"}
{/if}
</div>
</div>
</li>
{/foreach}
</ul>
上述操作必须帮助您实现任务