首页 > 解决方案 > Prestashop 1.7 产品标志

问题描述

我是新来的。我在PrestaShop 1.7的自定义主题中添加一个新产品标志时遇到了问题,即畅销

我发现 inProductLazyArray.php是这些标志的定义,但这个文件是核心文件,我不确定是否应该修改它。

你能帮我做那个吗?先感谢您!

标签: prestashopproductflagsprestashop-1.7

解决方案


感谢回复。我已经通过在 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;
}

推荐阅读