I want to get Attribute set ID in product page
Can you help me please
1 Answer
create GetAttributes.php
<?php
namespace Vendor\Module\Model;
use Magento\Framework\Exception\LocalizedException;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Api\ProductAttributeManagementInterface;
class GetAttributes
{
/**
* @var ProductAttributeManagementInterface
*/
private $productAttributeManagement;
public function __construct(
ProductAttributeManagementInterface $productAttributeManagement
) {
$this->productAttributeManagement = $productAttributeManagement;
}
/**
* Get Product Attributes from the attribute set.
*
* @return ProductAttributeInterface[]
*/
public function getAttributeListBySetId()
{
$attributeSetId = 4; // Default Attribute set
try {
$getAttributes = $this->productAttributeManagement
->getAttributes($attributeSetId);
} catch (NoSuchEntityException $exception) {
throw new NoSuchEntityException(__($exception->getMessage()));
}
return $getAttributes;
}
}
Now just call that collection where ever you want Hope this helps
Update:-
this is the way you can call that methods
$getAttributes = $this->getAttributeListBySetId();
foreach ($getAttribute as $attribute){
var_dump($attribute->debug());
}