Magento Coding Solutions

Magento How to get attribute name and value?

Magento How to get attribute name and value?


Get Attribute Id from Option Id

$_attributeId = Mage::getModel(‘eav/entity_attribute_option’)->load($optionId)->getAttributeId();
$_attribute = Mage::getModel(‘eav/entity_attribute’)->load($_attributeId);
echo $attribute->getFrontendLabel();


—————————————————

Get attribute’s name, value, type, and other parameters

/*** get attribute collection */

$attribute = $_product->getResource()->getAttribute(‘my_attribute’);

/*** get attribute type */

$attribute->getAttributeType();

/*** get attribute Label */

$attribute->getFrontendLabel();

/*** get attribute default value */

$attribute->getDefaultValue();

/*** check if the attribute is visible */

$attribute->getIsVisible();

/*** check if the attribute is required */

$attribute->getIsRequired();

/*** get attribute value*/

$attributeValue = Mage::getModel(‘catalog/product’)->load($_product->getId())->getMyAttribute();

Get value from a select box attribute

The attribute code is supposed to be ‘my_attribute‘

$attributeValue = Mage::getModel(‘catalog/product’)
->load($_product->getId())
->getAttributeText(‘my_attribute’);

Load any particular attribute by attribute code

$attributeInfo = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setCodeFilter(YOUR_ATTRIBUTE_CODE)
->getFirstItem();

// echo “<pre>”; print_r($attributeInfo->getData()); echo “</pre>”;

Get all option value list for the particular attribute

You can see above that I got attribute information by attribute code. My attribute information is stored as $attributeInfo. See code above.

Here is the code to get all option values for my attribute $attributeInfo.

$attributeOptions = $attributeInfo->getSource()->getAllOptions(false);

// echo “<pre>”; print_r($attributeOptions); echo “</pre>”;

Get all options of any attribute

Getting all options of attribute with attribute-code “color“.

$attribute = Mage::getSingleton(‘eav/config’)->getAttribute(‘catalog_product’, ‘color’);
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
}

Get attribute’s option information by option id

I have my attribute as $attributeInfo.
I have my attribute’s option value array as $attributeOptions.
See code above.
Suppose, I want to get detail information of any option listed in strong>$attributeOptions array. Here is the code to do so:-

$attributeId = $attributeInfo->getAttributeId();
$optionId = YOUR_ATTRIBUTE_OPTION_ID;
$attributeOptionSingle = Mage::getResourceModel(‘eav/entity_attribute_option_collection’)
->setPositionOrder(‘asc’)
->setAttributeFilter($attributeId)
->setIdFilter($optionId)
->setStoreFilter()
->load()
->getFirstItem();

// echo “<pre>”; print_r($attributeOptionSingle); echo “</pre>”;

Get attribute of particular entity type

Here, I am going to get information about ‘order_id‘ attribute of ‘invoice‘ entity type.

$entityType = Mage::getModel(‘eav/config’)->getEntityType(‘invoice’);
$entityTypeId = $entityType->getEntityTypeId();
$attribute = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setCodeFilter(‘order_id’)
->setEntityTypeFilter($entityTypeId)
->getFirstItem();

Get attribute options of Configurable product

$confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);

getModel Product alternative in magento

//$product = Mage::getModel('catalog/product');
    $product = new Mage_Catalog_Model_Product();

add product By quary sttring magento

 $newProductId=product_Id
 <?php
$carturl= Mage::getBaseUrl().'checkout/cart/add?product='.$newProductId.'&qty='.$qty;
                           
                           
    echo $carturl;
   
    $cart = Mage::getSingleton('checkout/cart');
       
            $cart->addProduct($newProductId, array(
                'qty' => $qty,
                'productId'=>$newProductId
                //'super_attribute' => array('136' => $sizeOptionId,'140'=>$borderOptionId,'144'=>$colorOptionId )
                )
            );
           
        // save the cart
        $cart->save();
   
        $baseUrl = Mage::getBaseUrl('web');
echo"<script language='javascript'>location.replace('".$baseUrl."index.php/checkout/cart/')</script>";

?>

Redirect A Customer To A Custom Url/Page After Logging In Magento


if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){ 
   $session = Mage::getSingleton('customer/session');
    $beforAutoUrl = Mage::getBaseUrl('web').$_SERVER['REQUEST_URI'];
    $session->setBeforeAuthUrl($beforAutoUrl);
    Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login"));    
}else{
    echo "Operation Will Perform";
   }

get Tire Price By Product Id in magento


**********************************************
get Tire Price By Product Id
**********************************************
$product_Id=2;

$custom = Mage::getModel('catalog/product')->load($product_Id);
                $tierPrice = $custom->getTierPrice();
                for($i=0;$i<count($tierPrice);$i++)
                    {
                  echo "price_id:".$tierPrice[$i]['price_id']."</br>";
                   echo " price:".$tierPrice[$i]['price']."</br>";
                   echo "price_qty:".$tierPrice[$i]['price_qty']."</br>";                       
                    }

how to get option value By option_Id( from table eav_attribute_option_value) Magento


 /**************************************************
class to retrieve data from eav_attribute_option_value
*************************************

hear 29 is option_id;
$attr = Mage::getModel('eav/entity_attribute_option')
->getCollection()->setStoreFilter()
->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code')

->addFieldToFilter('main_table.option_id',array('eq'=>29))->getFirstItem();

echo "<pre>";
    print_r($attr->getData());
echo "</pre>";

get configrable Product Combination and ther Associate Product

*********************************************************************
Custom Cod

getConfigurableAttributes.php?product=30
*********************************************************************
$_REQUEST['product']

 <?php
include "../app/Mage.php";
Mage::app();
$fileData = "<xml>";
$product = Mage::getModel("catalog/product")->load($_REQUEST['product']);
if($product->getTypeId() == "configurable"){
    $associatedProducts=$product->getTypeInstance()->getUsedProducts();
   
    $fileData.='<configuration>';
   
    $ctr = 0;
    $configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();
    foreach($configurableAttributeCollection as $attribute){
        $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attribute->getProductAttribute()->getAttributeCode())->getFirstItem()->setEntity($product->getResource());
        $attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
        $fileData.='<attribute id="'.$attributeInfo->getAttributeId().'" code="'.$attributeInfo->getAttributeCode().'" label="'.$attributeInfo->getFrontend()->getLabel($product).'">';
       
       
        $ctr2 = 0;
        foreach($attributeOptions as $attributeOption){
            $visible = 0;
            foreach($associatedProducts as $associatedProduct){
                if($associatedProduct[$attributeInfo->getAttributeCode()] == $attributeOption['value'] && $associatedProduct->status==1){
                    $visible = '1';
                    break;
                }
            //    $productArr .= $associatedProduct[$attributeInfo->getAttributeCode()].' == '.$attributeOption['value'];//$associatedProduct->getId();
            }
            if($visible>0){
                $fileData.='<option value="'.$attributeOption['value'].'">'. $attributeOption['label'].'</option>';
            }
        }
        $fileData .='</attribute>';
    }
    $fileData .='</configuration>';
    $fileData .='<combinations>';
    foreach($associatedProducts as $associatedProduct){
        $fileData .= '<product id="'.$associatedProduct->getId().'" price="'.$associatedProduct->getPrice().'">';
        $ctr2 = 0;
        foreach($configurableAttributeCollection as $attribute){
            $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attribute->getProductAttribute()->getAttributeCode())->getFirstItem()->setEntity($product->getResource());
            $fileData .= '<attribute id="'.$attributeInfo->getAttributeId().'" value="'.$associatedProduct[$attributeInfo->getAttributeCode()].'"></attribute>';   
        }
        $fileData .= '</product>';
    }
    $fileData.='</combinations>';
}
header('Content-type: text/xml');
echo $fileData.='</xml>';
   
?>

Change Product Image on View Page to Associated Product's Image (Configurable Product)

/************************************************************
 Change Product Image on View Page to Associated Product's Image (Configurable Product)
/************************************************************

1) app/design/frontend/*/*/template/catalog/product/view.phtml

Change

<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>

To

Edit ——————- Fixed bug in IE caused by the last comma in the foreach loop

<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
    var assocIMG =  // Added  - Removed { here, causes issues with other scripts when not working with a configurable product.
    <?php
    if ($_product->getTypeId() == "configurable") {
        echo "{";
        $associated_products = $_product->loadByAttribute('sku', $_product->getSku())->getTypeInstance()->getUsedProducts();
        foreach ($associated_products as $assoc)
            $dados[] = $assoc->getId().":'".($assoc->image == "no_selection" || $assoc->image == "" ? $this->helper('catalog/image')->init($_product, 'image', $_product->image)->resize(365,400) : $this->helper('catalog/image')->init($assoc, 'image', $assoc->image)->resize(365,400))."'";
    } else {
        $dados[] =  "''";
    }
    echo implode(',', $dados );    
    if ($_product->getTypeId() == "configurable") {
        echo "}";
    }
    ?>
</script>

2 ) app/design/frontend/*/*/template/catalog/product/view/type/options/configurable.phtml

Change
<script type="text/javascript">
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>


To



<script type="text/javascript">

    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
    var selectedAssocProducts = {}; // Added
</script>

3. js/varien/configurable.js

a) Add to top : 


if(typeof selectedAssocProducts=='undefined') {

    var selectedAssocProducts = {};
}

b) In configureElement : function(element) 


add to end of function after the following lines

       this.reloadPrice();
//      Calculator.updatePrice();
add this :
/***** Load Associated Image : This should come after this.resetChildren is called *****/

// If an option doesnt have a value attribute, it'll take its innerHTML as its value - hence the reason for || element.value.substr(0,6) == 'choose'
if (!element.value || element.value.substr(0,6) == 'choose') return; // Selected "choose option"
var attributeId = element.id.replace(/[a-z]*/, '');
for (var a in this.config.attributes)
{
    for (i = 0; i < this.config.attributes[a].options.length; i++)
    {
        if (this.config.attributes[a].options[i].id != element.value) continue;
        selectedAssocProducts[a] = this.config.attributes[attributeId].options[i].products;
    }
}

var productNo = intersect(selectedAssocProducts) || selectedAssocProducts[attributeId][0];
$('image').src = assocIMG[productNo];

c) Change resetChildren : function(element) to


resetChildren : function(element){

    delete selectedAssocProducts[element.config.id]; // Added
    if(element.childSettings) {      
        for(var i=0;i<element.childSettings.length;i++){
            element.childSettings[i].selectedIndex = 0;
            element.childSettings[i].disabled = true;              
            delete selectedAssocProducts[element.childSettings[i].config.id]; // Added
            if(element.config){
                this.state[element.config.id] = false;                  
            }
        }
    }
},

d) Add to end of file 


function intersect(ar) // ar can be an array of arrays or an asssociative array

{
    if (ar == null) return false;
     
    var a = new Array();
 
    if (ar.length == undefined) // Associate Array
    {      
        for (var i in ar)
         a.push(ar[i]);      
    }    
    else
     a = ar;
 
    if (a.length == 1) return false; // Single array ? Nothing to intersect with

    var common = new Array();
    function loop(a, index, s_index, e_index)
    {              
        if (index == null) index = 0;
        if (s_index == null) s_index = 0;
        if (e_index == null) e_index = a[index].length;
        if (index == a.length - 1) return;          
     
        for (var i = s_index; i < e_index; i++)
        {
            if (common.indexOf(a[index][i]) != -1) continue;
            for (var j = 0; j < a[index + 1].length; j++)
            {
                if (a[index][i] != a[index+1][j]) continue;                      
                loop(a, index + 1, j, j + 1);
                if (index + 1 == a.length - 1) { common.push(a[index][i]); break; }                      
            }
        }          
    }      

    loop(a);
    return common;
}

Add price slider In Short By in magento

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Category layered navigation
 *
 * @see Mage_Catalog_Block_Layer_View
 */

 $current_catId=Mage::registry('current_category');
 if($current_catId>0){
 $max_price=Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMaxPrice();

 $min_price=Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMinPrice();


 }else{
 $db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT max(price) as max_price ,min(price)as min_price FROM catalog_product_index_price ORDER BY customer_group_id');
$rows = $result->fetch();

$max_price= $rows['max_price'];
$min_price= $rows['min_price'];
}



?>


<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
   <script>
  $(function() {
    $( "#slider-range" ).slider({
      range: true,
      min: <?php echo $min_price;?>,
      max: <?php echo $max_price;?>,
      values: [ <?php echo $min_price;?>, <?php echo $max_price;?> ],
      slide: function( event, ui ) {
        $( "#amount" ).val( + ui.values[ 0 ] + " - " + ui.values[ 1 ] );
      }
    });
    $( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) +
      " - " + $( "#slider-range" ).slider( "values", 1 ) );
  });
 
 
   function callPriceSlider()
{
var priceRang=$("#amount").val();
alert(priceRang);
var urlSpl=document.URL.split('?');
alert(urlSpl[0]+"-----"+urlSpl[1]);
var redirectUrl=urlSpl[0]+'?price='+priceRang.split(' ').join('');
alert(redirectUrl);

document.location.href=redirectUrl;

}
  </script>

 
 

<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">

    <div class="block-content">
        <?php echo $this->getStateHtml() ?>
        <?php if ($this->getLayer()->getState()->getFilters()): ?>
            <div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
        <?php endif; ?>
        <?php if($this->canShowOptions()): ?>
            <p class="block-subtitle"><?php echo $this->__('Categories') ?></p>
            <dl id="narrow-by-list">
                <?php $_filters = $this->getFilters() ?>
                <?php foreach ($_filters as $_filter): ?>
                <?php if($_filter->getItemsCount()): ?>
                    <dt><?php echo $this->__($_filter->getName()) ?></dt>
                    <dd><?php echo $_filter->getHtml() ?></dd>
                <?php endif; ?>
                <?php endforeach; ?>

<dt>Price Slider:</dt>
<dd id="slider" style="height:1px"></dd>
<dd><p>
 <label for="amount">Price range:</label>
 <input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>

<div id="slider-range"></div>
</dd>


            <dd><label onclick='callPriceSlider()' style="cursor:pointer;"> <b>Search</b> <label>

</dd>




            </dl>

            <script type="text/javascript">decorateDataList('narrow-by-list')</script>
        <?php endif; ?>
    </div>
</div>
<?php endif; ?>

get product max and min price by current category (product Filter ) magento

********************************
get product max and min price by current category (product Filter ) magento
*********************************
<?php
 $max_price=Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMaxPrice();

 $minPrice=Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMinPrice();
?>

$db = Mage::getSingleton('core/resource')->getConnection('core_write');
    $result = $db->query('SELECT max(price) as max_price ,min(price)as min_price FROM catalog_product_index_price ORDER BY customer_group_id');
    $rows = $result->fetch();

    $max_price = $rows['max_price'];
    $min_price = $rows['min_price'];

Get Max and Min product Price in Magento

<?php  $db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT price ,final_price, min_price, max_price, tier_price, group_price FROM catalog_product_index_price ORDER BY customer_group_id');

$result = $db->query('SELECT max(price) as max_price ,min(price)as min_price FROM catalog_product_index_price ORDER BY customer_group_id');




$rows = $result->fetch();


?>

Magento Search is Not Working. What to do?

Magento Search not working on your website? Perhaps some of our tips will help you to solve this problem.

The first:
Check for errors when indexing your site. To test run re-indexing (System > Configuration > Index Management), wait for the site and clear the cache (System > Configuration > Cache Management).

get all custom options by product Id Magento

/************************************************************
get All Custom option Individual By Product Id
**************************************************************

/* ==========Get OptionID ======== */
$_productId=1;
$productDub = Mage::getModel('catalog/product')->load($_productId);
//$productDub = Mage::getModel('catalog/product')->load(167);
$optionCollection=array();

foreach ($productDub->getOptions() as $o) {

$optionType = $o->getType();
// echo 'Type = '.$optionType;
if ($optionType == 'drop_down') {
$values ='';
$values = $o->getValues();
$optionFinish=array();
$i=0;
$selectOp=array();
foreach ($values as $k => $v) {

$optionOder=$o->getSort_order();
$default_title=$o->default_title;
$v->getData();
$option_type_id=$v->option_type_id;
$option_id=$v->option_id;
$title=$v->title;
$price=$v->price;
$price_type=$v->price_type;
$sort_order=$v->sort_order;


for($i=0;$i<count($expOp);$i++){
$expOp2=explode(',',$expOp[$i]);
if($optionOder==$expOp2[0]){
if($expOp2[1]==$title){
$optionValId[$option_id]=$option_type_id;
$selectOp=$optionValId;
}

}

}

}

}else if($optionType=='field'){
$values='';
$v = $o->getData();
//print_r($v);
$default_title=$o->default_title;
$option_type_id=$v['option_type_id'];
$option_id=$v['option_id'];
$title=$v['title'];
$price=$v['price'];
if($title=="width"){
$width_option_id= $option_id;
}
if($title=="height"){
$height_option_id=$option_id;
}


}else {
//print_r($o);
}
}
/* ==========END Get OptionID ======== */

Programmatic Add to cart product and there options and supper attribute etc in Magento

******************************************
Programmatic Add to cart and option in Magento
**************************************
<?php
$carturl = Mage::getBaseUrl()."checkout/cart/";
$cart = Mage::getSingleton('checkout/cart');
$cart->addProduct($productIdtoadd, array(
'qty' => $qty,
'total_price'=>$total,
'super_attribute' => array($attributeid =>$assproductColorOptionId),
'options' =>array($option_id=> $value,
                                                          $width_option_id => $width,

 )
)
);

$cart->save();
echo "<script language='javascript'>location.href='".$carturl."'</script>";

?>

custom module to product view page with custom options


custom module to product view page with custom options *****************************************************************
passing the product Id and get there image gallery custom product ************************************************************
<?php

//print_r($_REQUEST);

?>

<?php $productDub = Mage::getModel('catalog/product')->load($_REQUEST['productId']);?>

<script type="text/javascript">

var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);

</script>




<div class="product-view">

<div class="product-essential">




<div style="border: 1px solid #c6c6c6;width: 53%;float: left;">

<div class="product-img-box" style="margin:0 auto;">

<p class="product-image" style="overflow: hidden; z-index: 9;">

<img id="image" src="<?php echo $productDub->getImageUrl(); ?>" alt="testg2" title="testg2" style="width: 265px; left: 0px; top: 58px; z-index: 0;"></p>





<?php $ajxurl=Mage::getBaseUrl('web')."index.php/cart"; ?>

</div>



<div class="more-views" style="float:left;">

<ul>

<?php $galleryData = $productDub->getData('media_gallery'); ?>

<?php foreach($galleryData as $gallary){ ?>

<?php foreach($gallary as $galla){ ?>

<?php //echo "<pre>"; print_r($galla); echo "</pre>"; ?>

<li style="float:left;">

<a href="#" onclick="popWin('<?php echo $baseurl."/index.php/catalog/product/gallery/id/".$product_id."/image/".$galla['value_id'] ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title=""><img src="<?php echo Mage::getBaseUrl('media').'catalog/product'.$galla['file']; ?>" width="100" height="100" alt=""></a>

</li>

<?php }

} ?>

</ul>

</div>



</div>





<div style="float:right;width:46%; ">



<div class="product-name">

<h1><?php echo $productDub->getName(); ?></h1>

</div>
<?php //if ($this->canEmailToFriend()): ?>

<p class="email-friend"><a href="<?php //echo Mage::helper('catalog/product')->getEmailToFriendUrl($productDub) ?>"><?php //echo $this->__('Email to a Friend') ?></a></p>

<?php //endif; ?>
<form action="<?php echo Mage::getBaseUrl('web').'customizer/index.php?product='.$_REQUEST['productId'];?>" method="post" id="product_addtocart_form"<?php if($productDub->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>


<div class="product-options" id="product-options-wrapper">

<?php if ($productDub->hasRequiredOptions()){ ?>

<p class="required"><?php echo '* Required Fields';?></p>

<?php } ?>

<?php


foreach ($productDub->getOptions() as $o) {

$optionType = $o->getType();

$option_title=$o->default_title;

$option_id=$o->option_id;
//echo 'Type = '.$optionType."</br>";

// echo 'Title = '.$option_title."</br>";

//echo 'optionId='. $option_id;

?>

<dt><label<?php if ($o->getIsRequire()) echo ' class="required"' ?>><?php if ($o->getIsRequire()) echo '<em>*</em>' ?><?php echo $o->getTitle(); ?></label></dt>

<div class="input-box">

<dd class="last" >

<?php

if ($optionType == 'drop_down') {

$values ='';

$values = $o->getValues();

$optionFinish=array();

$i=0;

$selectOp=array();

$requareval='';

if($o->getIsRequire()){

$requareval="required-entry";

}

echo ' <select name="options['.$option_id.']" id="select_'.$option_id.'" class="'.$requareval.' product-custom-option" title="" onchange="opConfig.reloadPrice()">

<option value="">-- Please Select --</option>';

foreach ($values as $k => $v) {

$option_type_id=$v->option_type_id;

$title=$v->title;

$price=$v->price;

$price_type=$v->price_type;

?>

<option value="<?php echo $option_type_id;?>" price="<?php echo $price; ?>"> <?php echo $title;?></option>

<?php

unset($v);

}

echo '</select>';

}else if($optionType=='checkbox'){

$values ='';

$values = $o->getValues();

echo '<ul id="options-'.$option_id.'-list" class="options-list">';

?>

<?php foreach ($values as $k => $v) {



$option_type_id='';

$title='';

$price_type='';

$option_type_id=$v->option_type_id;

$title=$v->title;

$price=$v->price;

$price_type=$v->price_type;

$requareval='';

if($o->getIsRequire()){

$requareval="validate-one-required-by-name";

}







?>

<li><input type="checkbox" class="checkbox <?php echo $requareval;?> product-custom-option" onclick="opConfig.reloadPrice()" name="options[<?php echo$option_id;?>][]" id="options_<?php echo $option_id.'_'.$option_type_id;?>" value="<?php echo $option_type_id;?>" price="<?php echo $price;?>"><span class="label"><label for="options_<?php echo $option_id.'_'.$option_type_id;?>"><?php echo $title; ?> </label></span>

<script type="text/javascript">$('options_<?php echo $option_id."_".$option_type_id;?>').advaiceContainer = 'options-<?php echo $option_id;?>-container';$('options_<?php echo $option_id."_".$option_type_id;?>').callbackFunction = 'validateOptionsCallback';</script></li>

<?php




unset($v);

} ?>

<span id="options-<?php echo $option_id;?>-container"></span>




</ul>



<?php

}else if($optionType=='radio'){



$values ='';

$values = $o->getValues();

$requareval='';

if($o->getIsRequire()){

$requareval="validate-one-required-by-name";

}



echo '<ul id="options-'.$option_id.'-list" class="options-list">';

?>

<?php foreach ($values as $k => $v) {



$option_type_id='';

$title='';

$price_type='';

$option_type_id=$v->option_type_id;

$title=$v->title;

$price=$v->price;

$price_type=$v->price_type;

?>

<li><input type="radio" class="radio <?php echo $requareval;?> product-custom-option" onclick="opConfig.reloadPrice()" name="options[<?php echo$option_id;?>][]" id="options_<?php echo $option_id.'_'.$option_type_id;?>" value="<?php echo $option_type_id;?>" price="<?php echo $price;?>"><span class="label"><label for="options_<?php echo $option_id.'_'.$option_type_id;?>"><?php echo $title; ?> </label></span><script type="text/javascript">$('options_<?php echo $option_id."_".$option_type_id;?>').advaiceContainer = 'options-<?php echo $option_id;?>-container';$('options_<?php echo $option_id."_".$option_type_id;?>').callbackFunction = 'validateOptionsCallback';</script></li>

<?php } ?>
</ul>

<span id="options-<?php echo $option_id;?>-container"></span>

<?php

}else if($optionType=='field'){

$values='';

$v = $o->getData();

$default_title=$o->default_title;

$option_type_id=$v['option_type_id'];

$option_id=$v['option_id'];

$title=$v['title'];

$price=$v['price'];

if($title=="width"){

$width_option_id= $option_id;

}

if($title=="height"){

$height_option_id=$option_id;

}
}else {

//print_r($o);

}

echo '</dd></div>';


/* ==========END Get OptionID ======== */

unset($o);

}

?>


<div class="add-to-box">

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo "Add to Cart"; ?></span></span></button>

</div>

</div>




</form>

</div>

</div>




</div>

<script type="text/javascript">decorateGeneric($('#product-options-wrapper dl'), ['last']);</script>

<script type="text/javascript">

//<![CDATA[

var productAddToCartForm = new VarienForm('product_addtocart_form');

productAddToCartForm.submit = function(button, url) {

if (this.validator.validate()) {

var form = this.form;

var oldUrl = form.action;




if (url) {

form.action = url;

}

var e = null;

try {

this.form.submit();

} catch (e) {

}

this.form.action = oldUrl;

if (e) {

throw e;

}




if (button && button != 'undefined') {

button.disabled = true;

}

}

}.bind(productAddToCartForm);




productAddToCartForm.submitLight = function(button, url){

if(this.validator) {

var nv = Validation.methods;

delete Validation.methods['required-entry'];

delete Validation.methods['validate-one-required'];

delete Validation.methods['validate-one-required-by-name'];

// Remove custom datetime validators

for (var methodName in Validation.methods) {

if (methodName.match(/^validate-datetime-.*/i)) {

delete Validation.methods[methodName];

}

}




if (this.validator.validate()) {

if (url) {

this.form.action = url;

}

this.form.submit();

}

Object.extend(Validation.methods, nv);

}

}.bind(productAddToCartForm);

//]]>

</script>

<script type="text/javascript">

//<![CDATA[

var optionFileUpload = {

productForm : $('product_addtocart_form'),

formAction : '',

formElements : {},

upload : function(element){

this.formElements = this.productForm.select('input', 'select', 'textarea', 'button');

this.removeRequire(element.readAttribute('id').sub('option_', ''));




template = '<iframe id="upload_target" name="upload_target" style="width:0; height:0; border:0;"><\/iframe>';




Element.insert($('option_'+element.readAttribute('id').sub('option_', '')+'_uploaded_file'), {after: template});




this.formAction = this.productForm.action;




var baseUrl = '<?php echo $this->getUrl('*/product/upload') ?>';

var urlExt = 'option_id/'+element.readAttribute('id').sub('option_', '');




this.productForm.action = parseSidUrl(baseUrl, urlExt);

this.productForm.target = 'upload_target';

this.productForm.submit();

this.productForm.target = '';

this.productForm.action = this.formAction;

},

removeRequire : function(skipElementId){

for(var i=0; i<this.formElements.length; i++){

if (this.formElements[i].readAttribute('id') != 'option_'+skipElementId+'_file' && this.formElements[i].type != 'button') {

this.formElements[i].disabled='disabled';

}

}

},

addRequire : function(skipElementId){

for(var i=0; i<this.formElements.length; i++){

if (this.formElements[i].readAttribute('name') != 'options_'+skipElementId+'_file' && this.formElements[i].type != 'button') {

this.formElements[i].disabled='';

}

}

},

uploadCallback : function(data){

this.addRequire(data.optionId);

$('upload_target').remove();




if (data.error) {




} else {

$('option_'+data.optionId+'_uploaded_file').value = data.fileName;

$('option_'+data.optionId+'_file').value = '';

$('option_'+data.optionId+'_file').hide();

$('option_'+data.optionId+'').hide();

template = '<div id="option_'+data.optionId+'_file_box"><a href="#"><img src="var/options/'+data.fileName+'" alt=""><\/a><a href="#" onclick="optionFileUpload.removeFile('+data.optionId+')" title="Remove file" \/>Remove file<\/a>';




Element.insert($('option_'+data.optionId+'_uploaded_file'), {after: template});

}

},

removeFile : function(optionId)

{

$('option_'+optionId+'_uploaded_file').value= '';

$('option_'+optionId+'_file').show();

$('option_'+optionId+'').show();




$('option_'+optionId+'_file_box').remove();

}

}

var optionTextCounter = {

count : function(field,cntfield,maxlimit){

if (field.value.length > maxlimit){

field.value = field.value.substring(0, maxlimit);

} else {

cntfield.innerHTML = maxlimit - field.value.length;

}

}

}




Product.Options = Class.create();

Product.Options.prototype = {

initialize : function(config) {

this.config = config;

this.reloadPrice();

document.observe("dom:loaded", this.reloadPrice.bind(this));

},

reloadPrice : function() {

var config = this.config;

var skipIds = [];

$('body .product-custom-option').each(function(element){

var optionId = 0;

element.name.sub(/[0-9]+/, function(match){

optionId = parseInt(match[0], 10);

});

if (config[optionId]) {

var configOptions = config[optionId];

var curConfig = {price: 0};

if (element.type == 'checkbox' || element.type == 'radio') {

if (element.checked) {

if (typeof configOptions[element.getValue()] != 'undefined') {

curConfig = configOptions[element.getValue()];

}

}

} else if(element.hasClassName('datetime-picker') && !skipIds.include(optionId)) {

dateSelected = true;

$('.product-custom-option[id^="options_' + optionId + '"]').each(function(dt){

if (dt.getValue() == '') {

dateSelected = false;

}

});

if (dateSelected) {

curConfig = configOptions;

skipIds[optionId] = optionId;

}

} else if(element.type == 'select-one' || element.type == 'select-multiple') {

if ('options' in element) {

$A(element.options).each(function(selectOption){

if ('selected' in selectOption && selectOption.selected) {

if (typeof(configOptions[selectOption.value]) != 'undefined') {

curConfig = configOptions[selectOption.value];

}

}

});

}

} else {

if (element.getValue().strip() != '') {

curConfig = configOptions;

}

}

if(element.type == 'select-multiple' && ('options' in element)) {

$A(element.options).each(function(selectOption) {

if (('selected' in selectOption) && typeof(configOptions[selectOption.value]) != 'undefined') {

if (selectOption.selected) {

curConfig = configOptions[selectOption.value];

} else {

curConfig = {price: 0};

}

optionsPrice.addCustomPrices(optionId + '-' + selectOption.value, curConfig);

optionsPrice.reload();

}

});

} else {

optionsPrice.addCustomPrices(element.id || optionId, curConfig);

optionsPrice.reload();

}

}

});

}

}

function validateOptionsCallback(elmId, result) {

var container = $(elmId).up('ul.options-list');

if (result == 'failed') {

container.removeClassName('validation-passed');

container.addClassName('validation-failed');

} else {

container.removeClassName('validation-failed');

container.addClassName('validation-passed');

}

}

var opConfig = new Product.Options(<?php echo $this->getJsonConfig() ?>);

//]]>

</script>

Get product and there All Attribute by the category Id

***********************************************************************
Get product and there attribute by category Id
**********************************************************************
require_once '../app/Mage.php'; Mage::app();
<?
$cateColl='35+36+37+';
$categoryid=explode('+',$cateColl);
$brandname=array();
$brandIdcoll=array();
for($i=0;$i<count($categoryid)-1;$i++)
{

$category=Mage::getModel('catalog/category')->load($categoryid[$i])->getProductCollection()->addAttributeToSelect('*');
foreach ($category as $_product)
{

$attribute=$_product->getResource()->getAttribute("brand");
/* Checking if the attribute is either select or multiselect type.*/
if($attribute->usesSource())
{
/* Getting all the sources (options) and print as label-value pair */
$options = $attribute->getSource()->getAllOptions(false);
foreach($options as $optionval)
{

echo "Lable:".$optionval['label']."Value:".$optionval['value'];

}
}
}
}
} ?>

Remove header footer left right from custom module Magento

***************************************************************
Custom module  front end Layout  modulname.xml and set layout One column
***************************************************************
      hear "admincustomizerlogo"  is custom module


   <layout version="0.0.9">

  <admincustomizerlogo_index_index>
<remove name="header"/>
<remove name="footer"/>
       <remove name="right"></remove>
       <remove name="left"></remove>

    <reference name="root">
      <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>

    <reference name="content">
      <block type="admincustomizerlogo/index" name="admincustomizerlogo_index" template="admincustomizerlogo/index.phtml"/>
    </reference>
  </admincustomizerlogo_index_index>
</layout>


 
      
     
   
        
        
   
   

 

How to get all super attribute options for a configurable item in Magento / How to get All option by Configurable product Id

/*****************************************************************
How to get Configurable product Option by product Id
****************************************************************
require_once '../app/Mage.php';
Mage::app();
$product=Mage::getModel('catalog/product')->load(18);
/*$configurableAttributeCollection=$product->getTypeInstance()->getConfigurableAttributes();

foreach($configurableAttributeCollection as $attribute){
$attributeid = $attribute->getProductAttribute()->getId();
//echo "super:->".$attributeid."";
  $new = $attributeid;
} */



$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();


foreach ($productAttributeOptions as $productAttribute) {
echo $productAttribute['label']."";
echo $productAttribute['attribute_id']."-------"."";

foreach ($productAttribute['values'] as $attribute) {

echo "id:".$attribute['value_index']."price:".$attribute['pricing_value']. $attribute['store_label']."";

}

}
?>




get Custom Option in magento

           $productDub= Mage::getModel('caltalog/product')->load('ProductId');
   foreach ($productDub->getOptions() as $o) {
                                                                               
                                                                                                 $optionType = $o->getType();
                                                                                                 $option_title=$o->default_title;
                                                                                                 $option_id=$o->option_id;
                                                                                                 
                                                                                                //echo 'Type = '.$optionType."";
                                                                                                // echo 'Title = '.$option_title."";
                                                                                                 //echo 'optionId='. $option_id;
                                                                                                 ?>
                                                                                                 
                                                                                                 
$o->getTitle(); ?>
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                if ($optionType == 'drop_down') {
                                                                                                                $values ='';
                                                                                                                $values = $o->getValues();
                                                                                                                $optionFinish=array();
                                                                                                                $i=0;
                                                                                                                $selectOp=array();
                                                                                                                $requareval='';
                                                                                                if($o->getIsRequire()){
                                                                                                                $requareval="required-entry";
                                                                                                }
                                                                                                               
                                                                                                                echo '
                                                                                                                ';
                                                                                                                foreach ($values as $k => $v) {
                                                                                                                                $option_type_id=$v->option_type_id;
                                                                                                                                $title=$v->title;
                                                                                                                                $price=$v->price;
                                                                                                                                $price_type=$v->price_type;
                                                                                                                ?>
                                                                                                               
                                                                                                               
                                                                                                                                unset($v);
                                                                                                                                }
                                                                                                                echo '
';
                                                                                                               
                                                                                                               
                                                                                                }else if($optionType=='checkbox'){
                                                                                                               
                                                                                                                                $values ='';
                                                                                                                                $values = $o->getValues();
                                                                                                                 echo '
    ';
                                                                                                                ?>
                                                                                                                $v) {
                                                                                                               
                                                                                                                                $option_type_id='';
                                                                                                                                $title='';
                                                                                                                                $price_type='';
                                                                                                                                $option_type_id=$v->option_type_id;
                                                                                                                                $title=$v->title;
                                                                                                                                $price=$v->price;
                                                                                                                                $price_type=$v->price_type;
                                                                                                                                                $requareval='';
                                                                                                                                if($o->getIsRequire()){
                                                                                                                                                $requareval="validate-one-required-by-name";
                                                                                                                                }
                                                                                                                               
                                                                                                                               
                                                                                                                               
                                                                                                                ?>
                                                                                                                                               
  •                                                                                                                                                
                                                                                                                                   

                                                                                                                                                    unset($v);
                                                                                                                                    } ?>
                                                                                                                                   

                                                                                                                   
                                                                                                                                                                                                                   
                                                                                                   
                                                                                                    }else if($optionType=='radio'){
                                                                                                                   
                                                                                                                                    $values ='';
                                                                                                                                    $values = $o->getValues();
                                                                                                                    $requareval='';
                                                                                                                                    if($o->getIsRequire()){
                                                                                                                                                    $requareval="validate-one-required-by-name";
                                                                                                                                    }
                                                                                                   
                                                                                                                     echo '
      ';
                                                                                                                    ?>
                                                                                                                    $v) {
                                                                                                                   
                                                                                                                                    $option_type_id='';
                                                                                                                                    $title='';
                                                                                                                                    $price_type='';
                                                                                                                                    $option_type_id=$v->option_type_id;
                                                                                                                                    $title=$v->title;
                                                                                                                                    $price=$v->price;
                                                                                                                                    $price_type=$v->price_type;
                                                                                                                    ?>
                                                                                                                                                   
  •  
  • product-custom-option" onclick="opConfig.reloadPrice()" name="options[][]" id="options_" value="" price="">
                                                                                                                                                   
                                                                                                                                                   
                                                                                                                                                   
                                                                                                                                                   
                                                                                                                                                   
                                                                                                                                   
                                                                                                                                   

                                                                                                                   
                                                                                                                   
                                                                                                                                                                                                                   
                                                                                                   
                                                                                                    }else if($optionType=='field'){
                                                                                                    $values='';
                                                                                                    $v = $o->getData();
                                                                                                    $default_title=$o->default_title;
                                                                                                                                    $option_type_id=$v['option_type_id'];
                                                                                                                                    $option_id=$v['option_id'];
                                                                                                                                    $title=$v['title'];
                                                                                                                                    $price=$v['price'];
                                                                                                                                    if($title=="width"){
                                                                                                                                    $width_option_id= $option_id;
                                                                                                                                    }
                                                                                                                                    if($title=="height"){
                                                                                                                                    $height_option_id=$option_id;
                                                                                                                                    }
                                                                                                                                   
                                                                                                                   
                                                                                                    }else {
                                                                                                                    //print_r($o);
                                                                                                    }
                                                                   
                                                                                   
                                                                                    echo '
    ';
                                                   
                                                                                   
                                                                                    /* ==========END Get OptionID ======== */
                                                                                    unset($o);
                                                                    }