I want to change product title like below:
Brand attribute value + attribute set name + guarantee = product title
How should i do it?
I want to change product title like below:
Brand attribute value + attribute set name + guarantee = product title
How should i do it?
- 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('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();
}