Prestashop 1.7产品标志
我是新来的。我有一个问题,就是在PrestaShop 1.7的定制主题中添加了一个畅销的新产品标志 我发现在Prestashop 1.7产品标志,prestashop,product,flags,prestashop-1.7,Prestashop,Product,Flags,Prestashop 1.7,我是新来的。我有一个问题,就是在PrestaShop 1.7的定制主题中添加了一个畅销的新产品标志 我发现在ProductLazyArray.php中有这些标志的定义,但是这个文件是一个核心文件,我不确定是否应该修改它 你能帮我拿一下吗?提前谢谢你 看一下关于覆盖Prestashop类的官方指南 谢谢您的回复。我通过在ProductLazyArray.php中添加钩子解决了这个问题。它是这样的: \Hook::exec('actionProductFlagsModifier',
ProductLazyArray.php
中有这些标志的定义,但是这个文件是一个核心文件,我不确定是否应该修改它
你能帮我拿一下吗?提前谢谢你 看一下关于覆盖Prestashop类的官方指南
谢谢您的回复。我通过在ProductLazyArray.php中添加钩子解决了这个问题。它是这样的:
\Hook::exec('actionProductFlagsModifier', array (
'flags' => & $flags,
'product' => $this-> product,
));
我的模块逻辑如下:
public function getBestSellingProductsId() {
$bestSellingProducts = ProductSale::getBestSalesLight((int)$this->langID, 0);
$productsIdArray = array();
foreach ($bestSellingProducts as $bestSellingProduct) {
if (!empty($bestSellingProducts) && !in_array($bestSellingProduct['id_product'], $productsIdArray)) {
$productsIdArray[] = $bestSellingProduct['id_product'];
}
}
return $productsIdArray;
}
public function isBestSelling($arrayOfBestSellingIds = array(), $productId) {
if (!empty($arrayOfBestSellingIds)) {
if (in_array($productId, $arrayOfBestSellingIds)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public function hookActionProductFlagsModifier($params)
{
$bestSellings = $this->getBestSellingProductsId();
$allProductsId = $params['product']['id_product'];
if (!empty($allProductsId)) {
if (in_array($allProductsId, $bestSellings)) {
array_push($params['product'], $params['product']['is_best_seller'] = (int) in_array($allProductsId, $bestSellings));
}
}
if (in_array('is_best_seller', $params['product'])
&& $this->isBestSelling($bestSellings, $allProductsId)) {
$params['flags']['bestseller'] = array(
'type' => 'bestseller',
'label' => 'Hit'
);
}
return $params;
}
您可以将答案添加到您的que中。同样,它也将帮助许多开发者。嗨@Bartosz,我希望能够在一个产品上有多个自定义标志(畅销书、礼品创意等),并从产品后台页面设置它们。你的模块有可能做这样的事情吗?如果是这样,或者如果有帮助,你有机会分享吗?提前谢谢!嗨@Bartosz,它真的很有魅力,谢谢!但是如果我返回$params并且没有它也能正常工作,我会出错,再次感谢。