Set Default Weight, Set Status to be ‘Enabled’ by Default and Tax Class to be ‘None’

Just like the points made from this post: Auto-generated SKU for new product, it’s annoying to have to enter some of the fields every time you create a new product because apparently, we want it ‘Enabled’ in status; weight doesn’t matter so much; and most of the products belong to one tax class or simply ‘None’.

To reduce repeatedly wasted time and increase productivity when creating products, just edit /app/design/adminhtml/default/default/template/catalog/product/edit.phtml and add the following JavaScript to the end of the file:

<script type="text/javascript">
if(document.getElementById('status').value == ""){
    document.getElementById('status').options[1].selected = true;
}
if(document.getElementById('weight').value == ""){
    document.getElementById('weight').value = "1.0";
}
if(document.getElementById('tax_class_id').value == ""){
    document.getElementById('tax_class_id').options[1].selected = true;
}
</script>

Now the Weight field will have a default value of ’1.0′, the Status field is selected ‘Enable’ by default and the Tax Class is selected as ‘None’ by default.

Auto-generated Product SKU when Adding New Product

SKU isn’t needed in all stores and it’s sometimes annoying to have to enter it for every new product. Is there any way for Magento to automatically generate new SKU for new products?

There is.

Open /app/design/adminhtml/default/default/template/catalog/product/edit.phtml and 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.

You can do more with this

By adding extra JavaScript code to edit.phtml in a similar way, you can set default values for text input fields and make options selected by default for drop-down selections in the product editor.

SEO Friendly Tag URLs for Your Magento Store

By default, you would have a tag URL such as this for your Magento store:

http://www.example.com/tag/product/list/tagId/3/

While it’s perfectly static, it doesn’t look good without tag names in the URL nor does it inspire trust. We want it to be more neater as:

http://www.example.com/tag/royal/

It’s actually a very simple problem that’s ready to be solved if you are willing to spend $39 bucks. Iceberg Commerce has the exact solution: Magento SEO Product Tag Urls

Simply purchase the package, download it, uncompress and upload the app directory to your store installation. It’s upgrade-proof because they are well separated from the rest of the system. You don’t even have to overwrite any files.

Clear your Magento cache and you would see SEO-friendly tag URLs all over your store: individual product page, tags list page, etc.

They’ve got also a lot of other interesting and useful extensions for your Magento store.

Malicious / Spam Search Terms in Magento Popular Search Terms

If you’ve got a fairly popular Magento store, you’ve probably got the problem of spam or malicious search terms showing up on the Popular Search Terms page. It’s ugly and you want to get rid of them once and for all, but at the same time leaving legitimate search terms performed by good-will users intact.

Of course you do. Me too. Look at this:

Magento store spam searches

So how to delete spam search terms from Popular Search Terms page?

What I’ve done is to edit the /app/design/frontend/default/your_theme/template/catalogsearch/term.phtml until it looks something like this:

		<?php
		$princessly_search_term = $this->htmlEscape($_term->getName());
		if (strpos($princessly_search_term, '%') !== false
			|| strpos($princessly_search_term, "'") !== false
			|| strpos($princessly_search_term, '`') !== false
			|| strpos($princessly_search_term, '=') !== false) {
			continue;
		}
		?>
            <li><a href="<?php echo $this->getSearchUrl($_term) ?>" style="font-size:<?php echo $_term->getRatio()*70+75 ?>%;"><?php echo $princessly_search_term ?></a></li>

The PHP function strpos() checks if a specific character is existent in the string $princessly_search_term which contains the originally raw search phrase. If it does, it’s not displayed (continue to the next phrase and check it to see if it does).

Most malicious / spam search attempts contain ‘%’, “‘”, or ‘=’ which normal users wouldn’t use in a legitimate search for your products. Now the Popular Search Terms page is a lot more clean and user friendly.