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
Solved! Go to Solution.
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.
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.