Mapping the attribute options in the dropdowns to actual products can be done by using the spConfig
javascript variable printed on the product view page of every configurable product.
var spConfig = new Product.Config({
"attributes":{
"502":{
"id":"502",
"code":"shoe_size",
"label":"Shoe Size",
"options":[{
"id":"46",
"label":"3",
"price":"0",
"oldPrice":"0",
"products":["32"]
},{
"id":"45",
[...]
}]
}},
[...]});
Notice the products
keys that have an array of product ids. Using some javascript that observes the onchange
event of your option dropdowns you should be able to work your way through the array ending up with the product the user has chosen.
Now for mapping that to the product SKU, you're probably best of retrieving them from a custom javascript array which you can create by using the code from this article. So now for some untested code
$simple_collection = Mage::getModel('catalog/product_type_configurable')->setProduct(Mage::registry('current_product'))
->getUsedProductCollection()
->addAttributeToSelect('sku')
->addFilterByRequiredOptions();
$id_to_sku = array();
foreach ($simple_collection as $_item)
{
$id_to_sku['p'+$_item->getId()] = $_item->getSku();
}
echo '<script type="text/javascript">
var confIdToSku = '.json_encode($id_to_sku).';
</script>';
Which would output an array like
var confIdToSku = {"p32":"pr-sku-1", "p35":"pr-sku-2"}
That would enable you to map the product ID to the SKU you need.
I'd suggest creating a new PHTML file for this in your template directory, using block type core/template
and calling that in the template/catalog/product/view.phtml
.
I'm no hero with Javascript so I didn't include any javascript code examples in my answer, I hope you can figure that part out for yourself.
Use Magento event observer and use catalog_product_save_before event on this function you need update magento Product url key field (url_key)
<global>
<events>
<catalog_product_save_before>
<observers>
<stockalert>
<type>singleton</type>
<class>yourmodel/observer</class>
<method>autoupdateurlKey</method>
</stockalert>
</observers>
</catalog_product_save_before>
</events>
</global>
And Observer code is:
public function autoupdateurlKey($observer)
{
$product=$observer->getEvent()->getProduct();
$oldUrlKey=$product->getOrigData('url_key');
$Sku=$product->getSku();
$TypeId=$product->getTypeId();
// put yourlogic
$product->getData('url_key',$YourNewUrl);
return $this;
}
Best Answer
In Magento if we are working with the custom HTML integration then we want to display the products SKU on the product listing page as well as on the Product description page as by default it is not displayed in Magento frontend. It is very easy to display the product SKU on the frontend.
Diaplay SKU On The Product Listing Page.
Step 1. Navigate to the
/app/design/frontend/default/your_custom_template/template/catalog/product/list.phtml
or Navigate to the/app/design/frontend/base/default/template/catalog/product/list.phtml
open the file in the editor of your choice.Step 2. Add the code below in the appropriate position where you want to display the SKU
Now refresh the browser cache and you have done.