1

I want to change product title like below:

Brand attribute value + attribute set name + guarantee = product title

How should i do it?

  • please explain briefly – Rk Rathod Sep 6 at 7:24
  • @RkRathod want to replace frontend title in product page with this structure: attrset name + brand attribute + model + title + country of manufacture. EX: laptop + lenovo + ideapad + with gift + USA => title = laptop lenovo ideapad with gift USA. – MGPM Sep 6 at 7:29
1
  1. 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>
  1. app/code/Company/Module/Plugin/Catalog/Model/Product.php
class Product
{
    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
        $title = $subject->getAttributeText('attribute_name'); //here you can set product name as per your requirement.
        return $title;
    }
}

get Attribute Set Name :-

protected $attributeSet;

public function __construct(
    ......
    \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet
    ......
) {
   ......
   $this->attributeSet = $attributeSet;
}


//Build method to get attribute set
public function getAttributeSetName() {

    $product = $this->getProduct();
    $attributeSetRepository = $this->attributeSet->get($product->getAttributeSetId());
    return $attributeSetRepository->getAttributeSetName();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.