Prestashop 1.7产品标志

问题描述 投票:1回答:2

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

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

您能帮我吗?预先谢谢!

prestashop product flags prestashop-1.7
2个回答
0
投票

请参阅有关重写Prestashop类的官方指南

https://devdocs.prestashop.com/1.7/modules/concepts/overrides/


0
投票

感谢您的回复。我已经通过在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;
}
© www.soinside.com 2019 - 2024. All rights reserved.