Category Archives: Magento

Get custom Image Attribute value on product listing page Magento

1) Open the page catalog xml and search the for the string “catalog/product/list.phtml’

2) Include the code
<action method=”addAttribute”><name>alternate_another_imageimage</name></action>
after
<block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”>

3) Call the below given code on list.phtml

$another_image = $this->helper(‘catalog/image’)->init($_product, another_image)->resize(135); // Assuming another_image is the attribute code

Change the layout of category page Magento

Include The Below given code

<reference name=”root”>
<action method=”setTemplate”><template>page/2columns-left.phtml</template></action>
</reference>

right under the default tag in in catalog.xml page

OR

Edit the page page.xml and replace the code

<block type=”page/html” name=”root” output=”toHtml” template=”page/3columns.phtml”>

With

<block type=”page/html” name=”root” output=”toHtml” template=”page/2columns-left.phtml”>

Getting selected simple product id in configurable product Magento

1) place the code right after “ var spConfig = new Product.Config(getJsonConfig() ?>);”
spConfig.getIdOfSelectedProduct = function()
{
var existingProducts = new Object();
for(var i=this.settings.length-1;i>=0;i–)
{
var selected = this.settings[i].options[this.settings[i].selectedIndex];
if(selected.config)
{
for(var iproducts=0;iproducts<selected.config.products.length;iproducts++)
{
var usedAsKey = selected.config.products[iproducts]+””;
if(existingProducts[usedAsKey]==undefined)
{
existingProducts[usedAsKey]=1;
}
else
{
existingProducts[usedAsKey]=existingProducts[usedAsKey]+1;
}
}
}
}
for (var keyValue in existingProducts)
{
for ( var keyValueInner in existingProducts)
{
if(Number(existingProducts[keyValueInner])<Number(existingProducts[keyValue]))
{
delete existingProducts[keyValueInner];
}
}
}
var sizeOfExistingProducts=0;
var currentSimpleProductId = “”;
for ( var keyValue in existingProducts)
{
currentSimpleProductId = keyValue;
sizeOfExistingProducts=sizeOfExistingProducts+1
}
if(sizeOfExistingProducts==1)
{
alert(“Selected product id  is: “+currentSimpleProductId)
}

}

2) call the function on the change event of dropdown

1) place the code right after “ var spConfig = new Product.Config(getJsonConfig() ?>);”
spConfig.getIdOfSelectedProduct = function()
{
var existingProducts = new Object();
for(var i=this.settings.length-1;i>=0;i–)
{
var selected = this.settings[i].options[this.settings[i].selectedIndex];
if(selected.config)
{
for(var iproducts=0;iproducts<selected.config.products.length;iproducts++)
{
var usedAsKey = selected.config.products[iproducts]+””;
if(existingProducts[usedAsKey]==undefined)
{
existingProducts[usedAsKey]=1;
}
else
{
existingProducts[usedAsKey]=existingProducts[usedAsKey]+1;
}
}
}
}
for (var keyValue in existingProducts)
{
for ( var keyValueInner in existingProducts)
{
if(Number(existingProducts[keyValueInner])<Number(existingProducts[keyValue]))
{
delete existingProducts[keyValueInner];
}
}
}
var sizeOfExistingProducts=0;
var currentSimpleProductId = “”;
for ( var keyValue in existingProducts)
{
currentSimpleProductId = keyValue;
sizeOfExistingProducts=sizeOfExistingProducts+1
}
if(sizeOfExistingProducts==1)
{
alert(“Selected product id  is: “+currentSimpleProductId)
}

}

2) call the function on the change event of dropdown

<select onchange=”spConfig.getIdOfSelectedProduct()”