我是新来的。我在PrestaShop 1.7中添加自定义主题时遇到了一个新产品标志,该标志是Bestselling。
[我发现ProductLazyArray.php
中有这些标志的定义,但是该文件是核心文件,我不确定是否应该修改它。
您能帮我吗?预先谢谢!
请参阅有关重写Prestashop类的官方指南
https://devdocs.prestashop.com/1.7/modules/concepts/overrides/
感谢您的回复。我已经通过在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;
}