Skip to main content
deleted 43 characters in body
Source Link
protected $_groupCollection; 
 

  public function __construct(

 
    
 \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $_groupCollection

) {



 
    $this->_groupCollection = $_groupCollection;
    parent::__construct($context);
}
public function getAttributeGroupId($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     $groupCollection->addFieldToFilter('attribute_group_name','Grid Attributes');
     
     
     return $groupCollection->getFirstItem(); 

}

public function getAttributeGroups($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     
     $groupCollection->setOrder('sort_order','ASC');
     return $groupCollection; 

}
 public function getGroupAttributes($pro,$groupId, $productAttributes){
    $data=[];
    $no =__('No');
    foreach ($productAttributes as $attribute){

      if ($attribute->isInGroup($pro->getAttributeSetId(), $groupId) && $attribute->getIsVisibleOnFront() ){
          if($attribute->getFrontend()->getValue($pro) && $attribute->getFrontend()->getValue($pro)!='' && $attribute->getFrontend()->getValue($pro)!=$no){
            $data[]=$attribute;
          }
      }

    }

  return $data;
 }
$groupid=$block->getAttributeGroupId($_product->getAttributeSetId());
$attributesgroups=$block->getAttributeGroups($_product>getAttributeSetId());

$productAttributes=$product->getAttributes();

$i=0;

$countAttributes=$block->getCountAttributes($product,$attributesgroups,$productAttributes);

?>

getGroupAttributes($product,$attributesgroup->getAttributeGroupId(),$productAttributes);if($attributes){?>
   
foreach ($attributesgroups as $attributesgroup):
  <h3 class="col label"$attributes scope="row"><?php= echo$block->getGroupAttributes($product, $attributesgroup->getAttributeGroupName>getAttributeGroupId(), ?></h3>$productAttributes);
 if ($attributes) {
    ?>
     <h3 class="col 
 label" scope="row"><?php echo $attributesgroup->getAttributeGroupName() ?></h3>
    <div class="additional-attributes-wrapper table-wrapper block">
        <table class="data table additional-attributes" id="product-attribute-specs-table">
            <tbody>   
        
         <?php
  foreach ($attributes as $attribute): ?>
    
    
     
          <tr>
                        <td class="col label" scope="row"><?php echo $attribute->getFrontendLabel() ?></td>
                        <td class="col data feature" data-th="<?php echo $attribute->getFrontendLabel() ?>"><?php /* @escapeNotVerified */ echo $attribute->getFrontend()->getValue($product) ?></td>
            </tr>
        </tr>
        
     
     <?php    
 endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php
}
    endforeach;
?>
protected $_groupCollection; 
 

  public function __construct(

 
    
 \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $_groupCollection

) {



 
    $this->_groupCollection = $_groupCollection;
    parent::__construct($context);
}
public function getAttributeGroupId($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     $groupCollection->addFieldToFilter('attribute_group_name','Grid Attributes');
     
     
     return $groupCollection->getFirstItem(); 

}

public function getAttributeGroups($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     
     $groupCollection->setOrder('sort_order','ASC');
     return $groupCollection; 

}
 public function getGroupAttributes($pro,$groupId, $productAttributes){
    $data=[];
    $no =__('No');
    foreach ($productAttributes as $attribute){

      if ($attribute->isInGroup($pro->getAttributeSetId(), $groupId) && $attribute->getIsVisibleOnFront() ){
          if($attribute->getFrontend()->getValue($pro) && $attribute->getFrontend()->getValue($pro)!='' && $attribute->getFrontend()->getValue($pro)!=$no){
            $data[]=$attribute;
          }
      }

    }

  return $data;
 }
$groupid=$block->getAttributeGroupId($_product->getAttributeSetId());
$attributesgroups=$block->getAttributeGroups($_product>getAttributeSetId());

$productAttributes=$product->getAttributes();

$i=0;

$countAttributes=$block->getCountAttributes($product,$attributesgroups,$productAttributes);

?>

getGroupAttributes($product,$attributesgroup->getAttributeGroupId(),$productAttributes);if($attributes){?>
        <h3 class="col label" scope="row"><?php echo $attributesgroup->getAttributeGroupName() ?></h3>
       
       
         <div class="additional-attributes-wrapper table-wrapper block">
    <table class="data table additional-attributes" id="product-attribute-specs-table">
        <tbody> 
        
 <?php
 foreach ($attributes as $attribute): ?>
    
    
     
          <tr>
                <td class="col label" scope="row"><?php echo $attribute->getFrontendLabel() ?></td>
                <td class="col data feature" data-th="<?php echo $attribute->getFrontendLabel() ?>"><?php /* @escapeNotVerified */ echo $attribute->getFrontend()->getValue($product) ?></td>
            </tr>
        
        
     
     <?php    
 endforeach; ?>
       </tbody>
    </table>
    </div>
protected $_groupCollection; 

public function __construct(
 \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $_groupCollection

) {
    $this->_groupCollection = $_groupCollection;
    parent::__construct($context);
}
public function getAttributeGroupId($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     $groupCollection->addFieldToFilter('attribute_group_name','Grid Attributes');
     
     
     return $groupCollection->getFirstItem(); 

}

public function getAttributeGroups($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     
     $groupCollection->setOrder('sort_order','ASC');
     return $groupCollection; 

}
 public function getGroupAttributes($pro,$groupId, $productAttributes){
    $data=[];
    $no =__('No');
    foreach ($productAttributes as $attribute){

      if ($attribute->isInGroup($pro->getAttributeSetId(), $groupId) && $attribute->getIsVisibleOnFront() ){
          if($attribute->getFrontend()->getValue($pro) && $attribute->getFrontend()->getValue($pro)!='' && $attribute->getFrontend()->getValue($pro)!=$no){
            $data[]=$attribute;
          }
      }

    }

  return $data;
 }
$groupid=$block->getAttributeGroupId($_product->getAttributeSetId());
$attributesgroups=$block->getAttributeGroups($_product>getAttributeSetId());

$productAttributes=$product->getAttributes();

$i=0;

$countAttributes=$block->getCountAttributes($product,$attributesgroups,$productAttributes);

foreach ($attributesgroups as $attributesgroup):
    $attributes = $block->getGroupAttributes($product, $attributesgroup->getAttributeGroupId(), $productAttributes);
if ($attributes) {
    ?>
    <h3 class="col label" scope="row"><?php echo $attributesgroup->getAttributeGroupName() ?></h3>
    <div class="additional-attributes-wrapper table-wrapper block">
        <table class="data table additional-attributes" id="product-attribute-specs-table">
            <tbody>   
                <?php foreach ($attributes as $attribute): ?>
                    <tr>
                        <td class="col label" scope="row"><?php echo $attribute->getFrontendLabel() ?></td>
                        <td class="col data feature" data-th="<?php echo $attribute->getFrontendLabel() ?>"><?php /* @escapeNotVerified */ echo $attribute->getFrontend()->getValue($product) ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php
}
    endforeach;
?>
Source Link

Try below code for this:

Create a block file and add this code:

protected $_groupCollection; 


  public function __construct(


    
 \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $_groupCollection

) {




    $this->_groupCollection = $_groupCollection;
    parent::__construct($context);
}
public function getAttributeGroupId($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     $groupCollection->addFieldToFilter('attribute_group_name','Grid Attributes');
     
     
     return $groupCollection->getFirstItem(); 

}

public function getAttributeGroups($attributeSetId)
{
     $groupCollection = $this->_groupCollection->create();
     $groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);
     
     $groupCollection->setOrder('sort_order','ASC');
     return $groupCollection; 

}
 public function getGroupAttributes($pro,$groupId, $productAttributes){
    $data=[];
    $no =__('No');
    foreach ($productAttributes as $attribute){

      if ($attribute->isInGroup($pro->getAttributeSetId(), $groupId) && $attribute->getIsVisibleOnFront() ){
          if($attribute->getFrontend()->getValue($pro) && $attribute->getFrontend()->getValue($pro)!='' && $attribute->getFrontend()->getValue($pro)!=$no){
            $data[]=$attribute;
          }
      }

    }

  return $data;
 }

And after this call that in your phtml file

$groupid=$block->getAttributeGroupId($_product->getAttributeSetId());
$attributesgroups=$block->getAttributeGroups($_product>getAttributeSetId());

$productAttributes=$product->getAttributes();

$i=0;

$countAttributes=$block->getCountAttributes($product,$attributesgroups,$productAttributes);

?>

getGroupAttributes($product,$attributesgroup->getAttributeGroupId(),$productAttributes); if($attributes){ ?>
        <h3 class="col label" scope="row"><?php echo $attributesgroup->getAttributeGroupName() ?></h3>
       
       
        <div class="additional-attributes-wrapper table-wrapper block">
    <table class="data table additional-attributes" id="product-attribute-specs-table">
        <tbody> 
        
<?php
foreach ($attributes as $attribute): ?>
    
   
    
         <tr>
                <td class="col label" scope="row"><?php echo $attribute->getFrontendLabel() ?></td>
                <td class="col data feature" data-th="<?php echo $attribute->getFrontendLabel() ?>"><?php /* @escapeNotVerified */ echo $attribute->getFrontend()->getValue($product) ?></td>
            </tr>
        
        
    
    <?php    
endforeach; ?>
       </tbody>
    </table>
    </div>