Jump to content

Filter products by attribute in php file


Recommended Posts

Hello everyone,

 

I am more than novice in php, I understand parts of the code but most do not understand.

I'm modifying a module that exports PrestaShop products to a PDF based on the selected category.

Now, I want the "get" function to get all the active products, but not those that are enabled as "online_only".

 

The part of the code that calls the products is this:

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++;
    }

The boolean variable that checks this is:

online_only = true
online_only = false

So i tried modifyng this line of code:

$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, $active = true, $online_only = false);

But I get a blank page..

 

Any help?

 

Thanks for your time :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...