Kita bisa menggunakan \Magento\Eav\Api\AttributeSetRepositoryInterface
untuk mendapatkan nama atribut.
Halaman Detail
Kita perlu mengganti \Magento\Catalog\Block\Product\View
blok. Suntikkan kelas ini pada konstruktor
/** @var \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet **/
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();
}
Sekarang, kita dapat menghubungi halaman detail produk: $block->getAttributeSetName();
Halaman daftar
Kita perlu mengganti \Magento\Catalog\Block\Product\ListProduct
blok
/** @var \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet **/
protected $attributeSet;
public function __construct(
......
\Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet
......
) {
......
$this->attributeSet = $attributeSet;
}
public function getAttributeSetName($product) {
$attributeSetRepository = $this->attributeSet->get($product->getAttributeSetId());
return $attributeSetRepository->getAttributeSetName();
}
Kita bisa menelepon $block->getAttributeSetName($_product)
.