Jump to content

Prestashop - Display particular product tag in product slider


Rollaen

Recommended Posts

Good day,

I would like to display text "Free delivery" in a product-slider.tpl for products that already have Free delivery as a product tag. However I do not want to display all product tags.

I tried this

{if (isset($product->tags) && $product->tags)}
   {if in_array('Free delivery', $product->tags.1)}
      <p>Free delivery</p>
   {/if}
{/if}

nevertheless the code only works in product.tpl. I do not know how to display "Free delivery" in the product-slider.tpl file.

Any advices are hearty welcome

Edited by Rollaen (see edit history)
Link to comment
Share on other sites

On 9/2/2018 at 12:39 PM, Rollaen said:

Good day,

I would like to display text "Free delivery" in a product-slider.tpl for products that already have Free delivery as a product tag. However I do not want to display all product tags.

I tried this


{if (isset($product->tags) && $product->tags)}
   {if in_array('Free delivery', $product->tags.1)}
      <p>Free delivery</p>
   {/if}
{/if}

nevertheless the code only works in product.tpl. I do not know how to display "Free delivery" in the product-slider.tpl file.

Any advices are hearty welcome

 

Override function getProductProperties from Product class:

 

public static function getProductProperties($id_lang, $row, Context $context = null)
{
    if (!$row['id_product']) {
        return false;
    }

    $row['tags'] = Tag::getProductTags((int)$row['id_product']);

    return parent::getProductProperties($id_lang, $row, $context);
}

 

Edited by joseantgv (see edit history)
Link to comment
Share on other sites

Good day

 

I tried to override Product.php in override/classes according to your function however it always shuts down entire website.

My code in Product.php:

 

<?php
class Product extends ProductCore
{

	
	public static function getProductProperties($id_lang, $row, Context $context = null)
{
    if (!$row['id_product']) {
        return false;
    }

    $row['tags'] = Tag::getProductTags((int)$row['id_product']);

    return parent::getProductProperties($id_lang, $row, $context)
}

}

Thanks in advance for your help

 

Rob

Link to comment
Share on other sites

On 13/2/2018 at 7:28 PM, Rollaen said:

Good day

 

I tried to override Product.php in override/classes according to your function however it always shuts down entire website.

My code in Product.php:

 


<?php
class Product extends ProductCore
{

	
	public static function getProductProperties($id_lang, $row, Context $context = null)
{
    if (!$row['id_product']) {
        return false;
    }

    $row['tags'] = Tag::getProductTags((int)$row['id_product']);

    return parent::getProductProperties($id_lang, $row, $context)
}

}

Thanks in advance for your help

 

Rob

 

Hi Rob, 

 

apologies for the delay, this buggy forum doesn't alert me with your new answer.

 

When you say that it "shuts down entire website" I suppose that you mean a blank page. Please enable errors https://www.prestashop.com/forums/topic/575132-how-to-enable-debug-mode-on-prestashop-17-and-older-versions-turn-on-error-reporting-blank-page/

  • Like 1
Link to comment
Share on other sites

Hello

 

I am sorry for that I answer this late.

 

Here is the problem according to debug mode for the code above.

Parse error: syntax error, unexpected '}' in /data/www/dpkk.cz/www.dpkk.cz/override/classes/Product.php on line 16

 

Thanks answer

Rob

 

Link to comment
Share on other sites

18 hours ago, Rollaen said:

Hello

 

I am sorry for that I answer this late.

 

Here is the problem according to debug mode for the code above.

Parse error: syntax error, unexpected '}' in /data/www/dpkk.cz/www.dpkk.cz/override/classes/Product.php on line 16

 

Thanks answer

Rob

 

 

Sorry, I forgot a semicolon:

<?php
class Product extends ProductCore
{	
    public static function getProductProperties($id_lang, $row, Context $context = null)
    {
        if (!$row['id_product']) {
            return false;
        }

        $row['tags'] = Tag::getProductTags((int)$row['id_product']);

        return parent::getProductProperties($id_lang, $row, $context);
    }
}

 

Link to comment
Share on other sites

On 19/2/2018 at 1:21 PM, Rollaen said:

Unfortunately this solution does not work. The condition does not display anything.

 

Thanks for answer

 

Rob

 

 

Hi Rob,

 

something's wrong/different in your store. I tested code before posting it. See attachments.

 

Please ensure that overrided code is executed, adding a die() or similar. Have you removed /cache/class_index.php?

ElbUWx[1].png

O1FEDM[1].jpg

  • Like 1
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...