Friday 19 April 2013

Auto generated SKU when add product in magento


Open /app/design/adminhtml/default/default/template/catalog/product/edit.phtml and add the following code to the bottom of the file:

<?php
    $dbread = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql = $dbread->query("SELECT * FROM catalog_product_entity ORDER BY created_at DESC LIMIT 1");
    $res = $sql->fetch();
?>
<script type="text/javascript">
if(document.getElementById('sku').value == ""){
    document.getElementById('sku').value = <?php echo (int)$res["sku"] + 1; ?>;
}
</script>


Note:Read the SKU (must be an integer) of the last added product.
     Increment the SKU by 1.
     Pre-populate the incremented new SKU to the SKU field by JavaScript.

2 comments:

  1. You can check magento sku auto generator extension: http://uscoding.net/magento-sku-auto-generator.html
    It will save your time.

    ReplyDelete

  2. Great blog. All posts have something to learn. Your work is very good and i appreciate you and hoping for some more informative posts.keep writing
    magento development company in bangalore 

    ReplyDelete