Jump to content

I want to add default product descriptions depending on the category


hisapon

Recommended Posts

Hello. 


I am building a store with Prestashop 8.2.1

I would like to add a description below the product description, depending on the category to which the product belongs.

Example
ProductA (category-A)
  Product description
  ++product description(A:Unified description by category)
  Product Tabs

ProductA (category-B)
  Product description
  ++product description(B:Unified description by category)
  Product Tabs

Can I achieve this with the standard features of Prestashop?

If anyone has achieved this with Addon Module, please let me know.

Link to comment
Share on other sites

>ps8modules

Thank you for reply.
I've attached a picture. Please check it out.

I'm looking for a way to add default descriptions for each category in position A or B.

 

スクリーンショット 2025-04-26 205206.png

Link to comment
Share on other sites

Hi.

There are several solutions.
One of the simplest is to create an override of Product.php and add your own static function + to that, insert a static function call into your product.tpl template.

Another option is to program a mini module and connect it to hooks. On the product page, you could use the displayReassurance hook (before the product tabs) or the displayFooterProduct hook (at the end of the product detail page), or create your own hook in the module and insert it into the product tpl template.

 

Override Product.php and override product.tpl:

Product.php + static function (sample)

public static function getProductCategoryDescription($idProduct, $idLang, $idShop = '1')
    {
        $db = Db::getInstance();
        $product = new Product((int)$idProduct);
        $context = Context::getContext();
        $idCategoryDefault = $product->id_category_default;
        $getDecription = $db->getValue('SELECT description FROM '._DB_PREFIX_.'category_lang WHERE id_category = '.$idCategoryDefault.' AND id_lang = '.$idLang.' AND id_shop = '.$idShop);
        return $getDecription;
    }

 

product.tpl (sample ./themes/classic/templates/catalog/product.tpl)

 {block name='display_category_description'}
              {if Product::getProductCategoryDescription($product.id, $language.id) != ''}
                <div id="category-description" class="text-muted">{Product::getProductCategoryDescription($product.id, $language.id) nofilter}</div>
              {/if}
            {/block}

image.thumb.png.312420312b9f025f7da1a7845aadee5b.png

Edited by ps8modules (see edit history)
  • Thanks 1
Link to comment
Share on other sites

Posted (edited)

Thank you for including the sample code.
I guess this problem can't be solved with Prestashop's standard functions.
It's a bit difficult for me, so I'll look for an add-on on the Marketplace.

I appreciate your advice.

Edited by hisapon (see edit history)
  • 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...