在php的PrestaShop中按属性过滤产品

在php的PrestaShop中按属性过滤产品,prestashop,product,Prestashop,Product,我不仅仅是php新手,我理解部分代码,但大多数不理解 我正在修改一个模块,该模块根据所选类别将PrestaShop产品导出为PDF 现在,我希望“获取”功能能够获取所有活动的产品,而不是那些启用为“仅在线”的产品 调用产品的代码部分如下所示: public function getContent() { $context = Context::getContext(); $langmod = $context->langmod; $products = ''

我不仅仅是php新手,我理解部分代码,但大多数不理解

我正在修改一个模块,该模块根据所选类别将PrestaShop产品导出为PDF

现在,我希望“获取”功能能够获取所有活动的产品,而不是那些启用为“仅在线”的产品

调用产品的代码部分如下所示:

    public function getContent()
{
    $context = Context::getContext();
    $langmod = $context->langmod;
    $products = '';
    $i = 0;
    foreach (Tools::getValue('categoryBox') as $osque) {
        $productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, $active = true);
        $products[$i]['products'] = $productget;
        $id_lang = Context::getContext()->language->id;
        $sql = '
        SELECT `name`
        FROM `'._DB_PREFIX_.'category_lang`
        WHERE `id_category` = '.(int)$osque.'
        AND `id_lang` = '.(int)$id_lang;
        $name = Db::getInstance()->getValue($sql);
        $products[$i]['categorie'] = $name;
        $i++;
    }
检查这一点的布尔变量是:

online_only = true
online_only = false
所以我试着修改这行代码:

$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, $active = true, $online_only = false);
但是我得到了一张空白页

有什么帮助吗

感谢您的时间:)

尝试使用此覆盖(在override/classes/Product.php中):

为了避免缓存的麻烦,请删除站点根目录下缓存文件夹中的文件class_index.php


关于

你好ethercreation,你好Diego Reyes,ethercreation,我愿意为在模块中进行此类修改付费。我们是否可以私下联系?是:=)请通过MPThanks联系我,以获取您的回复,以太创意。我已经从PrestaShop论坛雇佣了一名开发人员,谢谢:)我已经解决了这个问题:D
<?php
class ProductCore extends ProductCore
{
    public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
        $only_active = false, Context $context = null, $pdf = false)
    {
        if (!$context)
        $context = Context::getContext();

    $front = true;
    if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
        $front = false;

    if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
        die (Tools::displayError());
    if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd')
        $order_by_prefix = 'p';
    else if ($order_by == 'name')
        $order_by_prefix = 'pl';
    else if ($order_by == 'position')
        $order_by_prefix = 'c';

    if (strpos($order_by, '.') > 0)
    {
        $order_by = explode('.', $order_by);
        $order_by_prefix = $order_by[0];
        $order_by = $order_by[1];
    }
    $sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name
            FROM `'._DB_PREFIX_.'product` p
            '.Shop::addSqlAssociation('product', 'p').'
            LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
            LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
            LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.
            ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'
            WHERE pl.`id_lang` = '.(int)$id_lang.
                ($id_category ? ' AND c.`id_category` = '.(int)$id_category : '').
                ($pdf ? ' AND p.`online_only` = 0' : '').
                ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').
                ($only_active ? ' AND product_shop.`active` = 1' : '').'
            ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).
            ($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : '');
    $rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    if ($order_by == 'price')
        Tools::orderbyPrice($rq, $order_way);

    foreach ($rq as &$row)
        $row = Product::getTaxesInformations($row);

    return ($rq);
}
}
$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, true, null, true);