I have a foreach loop and a array that counts the total attributes from a attribute group.
What I need that the array only counts the attributes that have a value.
This is the code:
< ?php
function show_av($_product, $av_merk, $id, $labelchck) {
$av_attr_value = '';
$av_attribute_group = $_product->getAttributes($id);
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$groupmodel = $objectManager->get('MagentoEavModelEntityAttributeGroup')->load($id);
?>
< ?php
$icount = 1;
$len_count = count($av_attribute_group);
foreach ($av_attribute_group as $av_attribute_groups):
$av_attr_name = $av_attribute_groups->getName();
$av_attr_label = $_product->getResource()->getAttribute($av_attr_name)->getFrontend()->getLabel($_product);
$av_attr_value = $_product->getResource()->getAttribute($av_attr_name)->getFrontend()->getValue($_product);
$spec_container_name = $groupmodel->getAttributeGroupName();
if( $av_attr_value != "" ) :
if($icount < = 1) {
?>
< ?php } ?>< ?php echo $av_attr_label; ?>
< ?php if ($av_attr_value == "Yes" || $av_attr_value == "Ja") : ?>< ?php elseif ($av_attr_value == "No" || $av_attr_value == "Nee") : ?>< ?php
else :
echo $av_attr_value;
endif;
?>
< ?php echo $icount ?>
< ?php echo $len_count ?>
< ?php if ($icount == $len_count) { ?>
Last item
< ?php } ?>
< ?php endif; ?>
< ?php $icount++; endforeach; ?>
< ?php } ?>
How can I let the array only collect the attributes with a value?