0

I try to explain my problem. I'm working with a Store created by other people and it's difficult to me understanding everything. The Store have a custom template and, in my view.phtml, I found the Code below. With this Code, for the specified Attributes, I have a New Tab (called "Finiture") in the Product Details. In this Tab are displayed the images of the Finishes (colors and materials) that are searched based on the Store View's Label. This is the problem! For each Store View I have to put (in catalog/media/finiture) a .jpg file. So I have 2 or 3 copy of the same file with a different names. I want instead the images be searched based on the Admin Label. With this change I can put (in catalog/media/finiture) only one .jpg file for each Row. How can I made this change? Thanks to everyone.

<div id="tabs-6" class="tab-item">

                <?php

                if ($_product->isSaleable() && $this->hasOptions()):
                $newmenu = array();

$attrs  = $_product->setStoreFilter(0)->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
    if(
(0 == strcmp("finish", $attr['attribute_code']))||
(0 == strcmp("structure", $attr['attribute_code']))
) {

        $options    = $attr['values'];

        foreach($options as $option) {
            //var_dump($option);

            $__ll = str_replace(array('^', '$'), array('<span class="ll_macroattribute">', '</span>'), $option['store_label']);

            //print "{$option['store_label']}<br />";

            $filter = $option['store_label'];

            $macro = '';

            if ($filter[0] == '^'){

                            $macro = substr($filter, strpos($filter, "^")+1, strpos($filter, "$")-(strpos($filter, "^")+1));

            }

            $url = strtolower(str_replace(array('"', ' '), ' ', $macro).'_'.trim(str_replace('^'.$macro.'$', '', $option['store_label']))).'.jpg';

            $url = str_replace(' ', '', $url);
            $url = str_replace('è', 'e', $url);
            $url = str_replace('é', 'e', $url);
            $url = str_replace('à', 'a', $url);
            $url = str_replace('ì', 'i', $url);
            $url = str_replace('ò', 'o', $url);
            $url = str_replace('ù', 'u', $url);
            $url = str_replace("'", "", $url);

            array_push($newmenu, array("url" => $url, "filter" => '<span class="ll_macroattribute">'.trim(strtoupper(str_replace('^'.$macro.'$', '', $option['store_label']))).'</span><br>', "macro" => '<span class="ll_macroattribute" style="color:#666;">' . $macro . '</span>'));

            //echo $__ll.'<br>';

        }

    }

}

$last = '';
$out = '';


if (count($newmenu) < 1 )
    echo '
    <style>
    #tab_finiture { display:none;}
</syle>
    ';


foreach ($newmenu as $row){

                        $row['url'] = str_replace('è', 'e', $row['url']);

                        if (($last != $row['macro'])&&($last==''))
                        {
                            $last = $row['macro'];
                            $out .= '<div style="clear:both;margin-bottom:10px;">';
                            $out .= '<div style="float:left;width:145px;min-height:70px;">'.$row['macro'].'</div>';
                            $out .= '<div style="float:left;width: 570px;">';

                            $file = 'http://www.mywebsite.com/media/catalog/finish/'.$row['url'];
                            $file_headers = @get_headers($file);
                            if($file_headers[0] == 'HTTP/1.1 404 Not Found') {

                                $url = '';

                            }
                            else {

                                $url = '<img src="http://www.mywebsite.com/media/catalog/finish/'.$row['url'].'" style="border:none;width:160px;height:160px;">';

                            }

                            $out .= '<div style="float:left;width:190px;min-height:190px;">'.$row['filter'].$url.'</div>';
                        }
                        elseif (($last != $row['macro'])&&($last!=''))
                        {
                            $last = $row['macro'];
                            $out .= '</div><div style="clear:both;"></div></div>';
                            $out .= '<div style="clear:both;margin-bottom:10px;">';
                            $out .= '<div style="float:left;width:145px;min-height:70px;">'.$row['macro'].'</div>';
                            $out .= '<div style="float:left;width: 570px;">';

                            $file = 'http://www.mywebsite.com/media/catalog/finish/'.$row['url'];
                            $file_headers = @get_headers($file);
                            if($file_headers[0] == 'HTTP/1.1 404 Not Found') {

                                $url = '';

                            }
                            else {

                                $url = '<img src="http://www.mywebsite.com/media/catalog/finish/'.$row['url'].'" style="border:none;width:160px;height:160px;">';

                            }

                            $out .= '<div style="float:left;width:190px;min-height:190px;">'.$row['filter'].$url.'</div>';

                        }else{

                            if (($last!='')){

                                $file = 'http://www.mywebsite.com/media/catalog/finish/'.$row['url'];
                                $file_headers = @get_headers($file);
                                if($file_headers[0] == 'HTTP/1.1 404 Not Found') {

                                    $url = '';

                                }
                                else {

                                    $url = '<img src="http://www.mywebsite.com/media/catalog/finish/'.$row['url'].'" style="border:none;width:160px;height:160px;">';

                                }

                                $out .= '<div style="float:left;width:190px;min-height:190px;">'.$row['filter'].$url.'</div>';

                            }else{

                                $out .= '<div style="clear:both;margin-bottom:10px;">';
                                $out .= '<div style="float:left;width:190px;min-height:190px;">'.$row['macro'].'</div>';
                                $out .= '<div style="float:left;width: 600px;">';

                                $file = 'http://www.mywebsite.com/media/catalog/finish/'.$row['url'];
                                $file_headers = @get_headers($file);
                                if($file_headers[0] == 'HTTP/1.1 404 Not Found') {

                                    $url = '';

                                }
                                else {

                                    $url = '<img src="http://www.mywebsite.com/media/catalog/finish/'.$row['url'].'" style="border:none;width:160px;height:160px;">';

                                }

                                $out .= '<div style="float:left;width:190px;min-height:190px;">'.$row['filter'].$url.'</div>';

                            }

                        }    

                        /*
                        var_dump($row['macro']);
                        echo '<br>';

                        var_dump($row['filter']);
                        echo '<br>';
                        var_dump(count($row['filter']));
                        echo'<br><br>################<br>';
                        */




                    }

                    $out .= '</div></div>';
                    $out .= '<div style="clear:both;"></div>';
                    echo $out;
                    endif;
                                       ?>





</div>
  • No-one can help me? I found This Article but I don't understand how can I make what I need. Can someone help me? – Zig Jul 4 '14 at 12:59
  • I still don't find a solution..Anyone have an idea to solve this problem. I can explain it better if this is the problem. Thanks – Zig Jul 14 '14 at 23:53
0
public function getAttributeAdminText($_product, $attributeCode) {
    $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCode);

    $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
         ->setPositionOrder('asc')
         ->setAttributeFilter($attributeId)
         ->setStoreFilter(0)
         ->addFieldToFilter('tdv.option_id', array('eq' => $_product->getData($attributeCode)))
         ->load();

    foreach ($collection as $value) {
        return $value->getDefaultValue();
    }
}

With the above function, you can get the Admin attribute option label of a given attribute, for a given product. Just call $adminLabel = getAttributeAdminText($_product, 'finish'); to find it. (I suggest putting this function in a Helper class if you know how.)

0

More in line with Magento's own Mage_Catalog_Model_Product::getAttributeText would be to use

$_product->getResource()
  ->getAttribute('attribute_code')
  ->setStoreId(0)
  ->getSource()
  ->getOptionText($_product->getData('attribute_code'));

Of course you would use this code in places where otherwise you would use $_product->getAttributeText('attribute_code') but where you need the admin value. You will query the DB for this one value per product, so don't use this method if you're looping collections or trying to get all admin values of an attribute.

In your case though it's perfect, on the product view page as basis for an image name. This would also be a good solution to display washing care icons or those kinds of attributes with their admin value as file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.