- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
- 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.
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!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?