Magento get selected simple product id of configurable product on Product details page

Magento get selected simple product id of configurable product on Product details page

In this post we will show you Magento get selected simple product id of configurable product on Product details page, hear for Magento get selected simple product id of configurable product on Product details page we will give you demo and example for implement.

Utilizing my this arrangement you can get straightforward item Id of configurable item on item subtle elements page. Here is straightforward capacity how to accomplish that with no code adjustment. Only one Javascript record and format refresh..

How are we going to pre-select configurable traits? The determination of the qualities is controlled by the spConfig Javascript protest. In the event that you supply it with propertydefaultValues then the content will consequently choose particular things in the alternative drop-down records.

Paste the following code in app/design/frontend/default/[your theme]/template/catalog/product/view/type/options/configurable.phtml in side the script

or

Paste the following code in app/design/frontend/base/default/template/catalog/product/view/type/options/Configurable.phtml in side the script

spConfig.getIdOfSelectProducts = function()
{
var setexistingProducts = new Object();
for(var i=this.settings.length-1;i>=0;i--)
{
var selectedval = this.settings[i].options[this.settings[i].selectedIndex];
if(selectedval.config)
{
for(var setiproducts=0;setiproducts<selectedval.config.products.length;setiproducts++)
{
var setusedAsKey = selectedval.config.products[setiproducts]+"";
if(setexistingProducts[setusedAsKey] == undefined)
{
setexistingProducts[setusedAsKey] = 1;
}
else
{
setexistingProducts[setusedAsKey] = setexistingProducts[setusedAsKey]+1;
}
}
}
}
for (var keyValue in setexistingProducts)
{
for ( var keyValueInner in setexistingProducts)
{
if(Number(setexistingProducts[keyValueInner])<Number(setexistingProducts[keyValue]))
{
delete setexistingProducts[keyValueInner];
}
}
}
var sizeOfsetexistingProducts=0;
var currentSimpleProductId = "";
for(var keyValue in setexistingProducts)
{
currentSimpleProductId = keyValue;
sizeOfsetexistingProducts=sizeOfsetexistingProducts+1
}
if(sizeOfsetexistingProducts==1)
{
alert("Selected product is: "+currentSimpleProductId)
}
}

Now add onchange event to your dropdown in same page :

onchange="spConfig.getIdOfSelectProducts()"

your dropdown’s html looks like this…

<!-- Magento get selected simple product id of configurable product on Product details page -->
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" onchange="spConfig.getIdOfSelectProducts()" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>

Hope this code and post will helped you for implement Magento get selected simple product id of configurable product on Product details page. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  73  =  74

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US