1

I want to get Attribute set ID in product page
Can you help me please

0

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());
}
12
  • I edited my question, Can you take a look please! – Toranto mina Jul 7 '20 at 16:35
  • product listing page?? – Pramod Jul 8 '20 at 3:33
  • product page as I mentionned plz – Toranto mina Jul 8 '20 at 8:45
  • check updated ans – Pramod Jul 8 '20 at 8:53
  • Where can I add this file plz – Toranto mina Jul 8 '20 at 9:21

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.