php - Looping attributes brand -
im trying loop attributes brands, blank, , doesnt give error, cant figure out wrong code.
im quite sure problem in code, since put static data in view, , working fine, notice problem in "$val[0]=", reason cant first charecters of string "$val".
here source:
<div class="brandlist"> <div class="lettermenu"> <ul> <li style="float:left;">a-z brands list</li> <li><a class="letterlink" href="#a">a</a></li> <li><a class="letterlink" href="#b">b</a></li> <li><a class="letterlink" href="#c">c</a></li> <li><a class="letterlink" href="#d">d</a></li> <li><a class="letterlink" href="#e">e</a></li> <li><a class="letterlink" href="#f">f</a></li> <li><a class="letterlink" href="#g">g</a></li> <li><a class="letterlink" href="#h">h</a></li> <li><a class="letterlink" href="#i">i</a></li> <li><a class="letterlink" href="#j">j</a></li> <li><a class="letterlink" href="#k">k</a></li> <li><a class="letterlink" href="#l">l</a></li> <li><a class="letterlink" href="#m">m</a></li> <li><a class="letterlink" href="#n">n</a></li> <li><a class="letterlink" href="#o">o</a></li> <li><a class="letterlink" href="#p">p</a></li> <li><a class="letterlink" href="#q">q</a></li> <li><a class="letterlink" href="#r">r</a></li> <li><a class="letterlink" href="#s">s</a></li> <li><a class="letterlink" href="#t">t</a></li> <li><a class="letterlink" href="#u">u</a></li> <li><a class="letterlink" href="#v">v</a></li> <li><a class="letterlink" href="#w">w</a></li> <li><a class="letterlink" href="#x">x</a></li> <li><a class="letterlink" href="#y">y</a></li> <li><a class="letterlink" href="#z">z</a></li> </ul> </div> <?php $attribute = mage::getmodel('eav/config')->getattribute('catalog_product', 'manufacturer'); $alpha="a"; foreach ( $attribute->getsource()->getalloptions(true, true) $option){ $attributearray[$option["value"]] = $option["label"]; }foreach($attributearray $key=>$val){ $url = "/catalogsearch/advanced/result/"."?manufacturer%5b%5d=".$key; if ($val[0]==="") {} elseif ($alpha===$val[0]){ ?> <div class="brandname"><a href="<?php echo $url?>"> <?php echo $val; ?></a></div><?php } else { echo "<div id='". $val[0] ."' class='letter'>".$val[0]."</div>"; ?> <div class="brandname"><a href="<?php echo $url?>"> <?php echo $val; ?></a></div> <?php $alpha=$val[0]; }} ?> ?> </div> <style> .brandlist {margin:auto;} .brandname {min-width:200px;float:left;width:25%;padding:10px;} .letter {display:inline-block;width:100%;background:#9f9f9f;padding:10px;} .lettermenu {margin-top:0px;text-align: center;} .letterlink {min-width:20px;width:3.4%;float:left;margin-right:0px;} </style>
use below code getting collecion on attribute:
<?php $name='manufacturer'; $attributeinfo = mage::getresourcemodel('eav/entity_attribute_collection')->setcodefilter($name)->getfirstitem(); $attributeid = $attributeinfo->getattributeid(); $attribute = mage::getmodel('catalog/resource_eav_attribute')->load($attributeid); $attributeoptions = $attribute ->getsource()->getalloptions(false); print_r($attributeoptions); ?>
Comments
Post a Comment