1

I want to change product title like below:

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

How should i do it?

2
  • please explain briefly Commented Sep 6, 2019 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
    Commented Sep 6, 2019 at 7:29

1 Answer 1

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();
}
6
  • Thanks, but how can i get attribute set name?
    – MGPM
    Commented Sep 6, 2019 at 7:57
  • update answer for get attribute set name Commented Sep 6, 2019 at 8:00
  • Thanks, it works! could you please answer my other questions too???
    – MGPM
    Commented Sep 6, 2019 at 8:15
  • add link which question Commented Sep 6, 2019 at 8:16
  • magento.stackexchange.com/questions/287228/…
    – MGPM
    Commented Sep 6, 2019 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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