I have this code, witch retrieves the values I need:
<?php foreach($allProducts as $p): ?>
<?php if(!$p->isSaleable()) continue; ?>
<?php $out=$p->getAttributeText($pAtt->getName()); ?>
<?php $frontValues[$out]=$out; ?>
<?php $colors=$p->getData(strtolower($pAtt->getName())); ?>
<?php endforeach ?>
This is the markup that places this to my page:
<li><a id="a-<?php echo $out ?>"><?php echo implode('</li><li>">', $frontValues); ?></a></li>
The problem is that the echo $out
is retrieved only ones, but there are more items in the array and all of them get's the same value, witch is not good for me.
The problem is that I can't figure out, how to make an Asociated Array to the values of $frontValaues
array and add accordingly assign the correct id to the retrieved item.
I tryed adding
<?php $colorValues[$colors]=$colors; ?>
in foreach
, and then replicating the same implode method, like this:
<li><a id="a-<?php echo implode('', $colorValues); ?>"><?php echo implode('</li><li>">', $frontValues); ?></a></li>
but then this array is adding all the values to the ID.
How can I separate them? So the only correct retrevied value would be asociated to the <a>
.
I'm quite a newby here, so any suggestion is welcome.
Thanks,
Full code and working for anyone who may be interested in it
<div class="color">
<?php if($_product->isConfigurable()): ?>
<?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php if(count($attributes)): ?>
<div>
<?php foreach($attributes as $att): ?>
<?php $pAtt=$att->getProductAttribute();
if ($pAtt->getFrontendLabel() != 'Color') continue;
//get the child products
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
$frontValues =array(); ?>
<div style="text-align:center;"><!--<?php echo $pAtt->getFrontendLabel() ?>-->
<ul>
<?php
$output = array();
foreach($allProducts as $p){
if(!$p->isSaleable()) continue;
$output[$p->getAttributeText($pAtt->getName())] = array(
'out' => $p->getAttributeText($pAtt->getName()),
'color' => $p->getData(strtolower($pAtt->getName()))
);
}
?>
<?php foreach($output as $key => $value) : ?>
<li><a id="a-<?php echo $value['color'] ?>"><?php echo $value['out'] ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach ?>
</div>
<?php endif ?>
<?php endif ?>
</div>