cancel
Showing results for 
Search instead for 
Did you mean: 

Auto SKU, gone from forum but I lost the code change in an update. Can anyone help me with the code?

Auto SKU, gone from forum but I lost the code change in an update. Can anyone help me with the code?

I had a simple code change bookmarked from the forum. Guess my bad since I actually expected the bookmark to work forever (at least a while) and never actually saved the code change anywhere. 

 

The code changed when I did an update and now I need to add it back. 

 

The change had a couple lines to add/overwrite to automatically increment the next products sku from the last product listed's sku. 

 

Anyone have this code saved? Anyone know what and where I'd add such a thing?

 

Thank you in advance for your assistance. 

2 REPLIES 2

Re: Auto SKU, gone from forum but I lost the code change in an update. Can anyone help me with the c

Found it!

 

Open /app/design/adminhtml/default/default/template/catalog/product/edit.phtmland add the following snippet 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>

What this code does:

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

Therefore, you don’t have to manually enter the SKU yourself when adding the product.

 

Thanks a ton to magentothem (dot) com for archiving this!

Re: Auto SKU, gone from forum but I lost the code change in an update. Can anyone help me with the c

Ugh, not sure what is wrong but the code isn't working for me now. Anyone have any knowledge as to what is wrong?