prestashop - Prestashop 1.7 产品标志
问题描述
我是新来的。我在PrestaShop 1.7的自定义主题中添加一个新产品标志时遇到了问题,即畅销。
我发现 inProductLazyArray.php
是这些标志的定义,但这个文件是核心文件,我不确定是否应该修改它。
你能帮我做那个吗?先感谢您!
解决方案
感谢回复。我已经通过在 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;
}
推荐阅读
- javascript - VBScript:将剪贴板设置为变量并返回变量
- python - 如何在行中读取json文件
- c# - 部署具有 MSI 的容器实例和部署到其中的容器无法读取 keyvault 机密
- angularjs - UI-Router 父状态可以访问它的子成员吗?
- javascript - 如何使用javascript检查数组是否包含值?
- c# - 如何指定程序的配置(appdata)文件夹的名称?
- couchbase - Couchbase 集群创建问题
- file - 用于更改打印参数的 Postscript 文件编辑
- java - CORS 策略:请求的资源 Spring Boot Rest API 上不存在“Access-Control-Allow-Origin”标头
- visual-studio-code - 格式化代码时如何在新行上停止大括号