Jump to content

Output the value from Search.php query to product-list.tpl in Prestashop


Glenskie

Recommended Posts

I need to output in product-list.tpl file the result of a query from within classes/Search.php in Prestashop. The query in classes/Search.php is:
$sql = 'SELECT *
    FROM `'._DB_PREFIX_.'category_group` cg
    INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`
    INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`
    INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
    INNER JOIN `'._DB_PREFIX_.'product_part_number` ON p. `id_product` = `ID`
    '.Shop::addSqlAssociation('product', 'p', false).'
    WHERE c.`active` = 1
    AND product_shop.`active` = 1
    AND product_shop.`visibility` IN ("both", "search")
    AND product_shop.indexed = 1
    AND cg.`id_group` '.(!$id_customer ?  '= 1' : 'IN (
    SELECT id_group FROM '._DB_PREFIX_.'customer_group 
    WHERE id_customer = '.(int)$id_customer.'
    
    )');
    $results = $db->executeS($sql);
    
 
 This is outputting a series of "GREKA" values in the `'._DB_PREFIX_.'product_part_number` table at the top of the search results page from the query above:
 $eligible_products = array();
        
        foreach ($results as $row){
        $eligible_products[] = $row['id_product'];
        echo $row['GREKA'];
        }
What I need it to do is output the "GREKA" value within the tpl file themes/product-list.tpl for that product. This tpl file is using Smarty to output the results of the product search, I need to know how to call the "GREKA" value from the query to the foreach loop. I imagine it would be something like this:
 {foreach from=$products item=product name=products}
                 {$GREKA}
           {/foreach}

I have tried to put this line of code inside the foreach on the product-list.tpl and it gives me no output , it gives me an error: 

 

  Code:

{$product.GREKA}

Error:

Notice: Undefined index: GREKA

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.