cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the name of the product

SOLVED

Changing the name of the product

Is there a way to change the way the product name is displayed on the website without actually altering its name in the system?

Specifically, I'm trying to shorten/alter the product names inside bundles to make it easier to read.

 

Thanks,

Alex

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Changing the name of the product

Hello @alex_huang1 

 

yes it is possible.

 

you need to create a plugin  for that.

 

e.

app/code/Company/Module/etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="training_catalog_product" type="Company\Module\Plugin\Catalog\Model\Product"/>
    </type>
</config>

app/code/Company/Module/Plugin/Catalog/Model/Product.php

class Product
{
    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
        $title = $subject->getAttributeText('second_name');
        return $title;
    }
}

hope it will help you.

 

if works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

1 REPLY 1

Re: Changing the name of the product

Hello @alex_huang1 

 

yes it is possible.

 

you need to create a plugin  for that.

 

e.

app/code/Company/Module/etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="training_catalog_product" type="Company\Module\Plugin\Catalog\Model\Product"/>
    </type>
</config>

app/code/Company/Module/Plugin/Catalog/Model/Product.php

class Product
{
    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
        $title = $subject->getAttributeText('second_name');
        return $title;
    }
}

hope it will help you.

 

if works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer