Skip to main content
deleted 87 characters in body
Source Link
Artur Rain
  • 545
  • 2
  • 9
  • 29

Full code: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 $colorValuesecho =array$pAtt->getFrontendLabel() ?>-->
                        <div style="text-align:center;"><!--<ul>
                         <?php echo 
 $pAtt->getFrontendLabel() ?>-->
                         <ul> $output = array();
                         <?php   foreach($allProducts as $p): ?>{
                           <?php   if(!$p->isSaleable()) continue; ?>
                           <?php $out=$p  $output[$p->getAttributeText($pAtt->getName());] ?>= array(
                           <?php $frontValues[$out]=$out; ?>               'out' => $p->getAttributeText($pAtt->getName()),
                           <?php $colors=$p                'color' => $p->getData(strtolower($pAtt->getName())); 
 ?>                                         );
                           <?php $colorValues[$colors]=$colors;}
                         ?>
                          <?php endforeachforeach($output  as $key => $value) : ?>
                            <li><a id="a-<?php echo $out$value['color'] ?>"><?php echo implode('</li><li">', $frontValues);$value['out'] ?></a></li> 
                            <?php endforeach; ?>
                         </ul>
                        </div>
                      <?php endforeach ?>
                      </div>
                    <?php endif ?>
                  <?php endif ?>
                </div>

Full code:

                <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();
                          $colorValues =array() ?>
                        <div style="text-align:center;"><!--<?php echo $pAtt->getFrontendLabel() ?>-->
                         <ul>
                         <?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 $colorValues[$colors]=$colors; ?>
                         <?php endforeach ?>
                          <li><a id="a-<?php echo $out ?>"><?php echo implode('</li><li">', $frontValues); ?></a></li>
                         </ul>
                        </div>
                      <?php endforeach ?>
                      </div>
                    <?php endif ?>
                  <?php endif ?>
                </div>

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>
added 1864 characters in body
Source Link
Artur Rain
  • 545
  • 2
  • 9
  • 29

Full code:

                <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();
                          $colorValues =array() ?>
                        <div style="text-align:center;"><!--<?php echo $pAtt->getFrontendLabel() ?>-->
                         <ul>
                         <?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 $colorValues[$colors]=$colors; ?>
                         <?php endforeach ?>
                          <li><a id="a-<?php echo $out ?>"><?php echo implode('</li><li">', $frontValues); ?></a></li>
                         </ul>
                        </div>
                      <?php endforeach ?>
                      </div>
                    <?php endif ?>
                  <?php endif ?>
                </div>

Full code:

                <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();
                          $colorValues =array() ?>
                        <div style="text-align:center;"><!--<?php echo $pAtt->getFrontendLabel() ?>-->
                         <ul>
                         <?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 $colorValues[$colors]=$colors; ?>
                         <?php endforeach ?>
                          <li><a id="a-<?php echo $out ?>"><?php echo implode('</li><li">', $frontValues); ?></a></li>
                         </ul>
                        </div>
                      <?php endforeach ?>
                      </div>
                    <?php endif ?>
                  <?php endif ?>
                </div>
Source Link
Artur Rain
  • 545
  • 2
  • 9
  • 29

Add asociated array to the Values retrieved before

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,