2017-11-28 21 views

答えて

0
/** 
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory 
*/ 
protected $_groupCollection; 


public function __construct(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory 
) 
{  
$this->_groupCollection = $groupCollectionFactory;  
} 

/** 
* @param $attributSetID 
* @return array 
*/ 
public function getAttributeGroupName($attributeSetID){ 

    $groups = $this->_groupCollection->create(); 
    $groups->setAttributeSetFilter($attributeSetID); 

    $groupData = []; 
    /* @var $group \Magento\Eav\Model\Entity\Attribute\Group */ 
    foreach ($groups as $group) { 
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
     $attributeCollection = $objectManager->create('Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection'); 

     $attributeCollection 
      ->setAttributeGroupFilter($group->getId()) 
      ->setAttributeSetFilter($attributeSetID); 

     foreach ($attributeCollection->getAllIds() as $attributeId) { 
      $groupData[$attributeId] = $group->getAttributeGroupName(); 
     } 

    } 
      return $groupData; 

}