Page 1 of 41234

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 CAST(sku AS unsigned) 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.

Display all product images on the product page (view.phtml)

Lots of online stores nowadays are blatantly showing all the sharp and tempting images of the product on the product page. They are all there for you and the visitors to examine one after another simply by window scrolling – no gimmicks such as cloud zooming or lightbox, etc. While technical cleverness such as cloud zooming or lightbox may seem pretty, they are hardly any more usable than the plain old way of just splashing the product images by simple HTML code.

I prefer the old way which would actually engage the visitors.

However, by default Magento has only narrowly arranged thumbnails of the product images, the visitor has to click those thumbnails to see the large version – waste of user attention and they could leave because it costs more to get what they want (to see a larger picture). What we want to do is to simply display all the product images in large versions on the product page where the visitors are instantly satisfied.

Display all product images WITHOUT watermarks

To do this, find /app/design/frontend/default/your_theme/template/catalog/product/view.phtml and add this snippet anywhere appropriate (change the bold part to your own theme path):

<div class="product_images_exhibit">
	<h2><?php echo $this->__('Product Images') ?></h2>
	<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
	<?php if($_images) {?>
		<?php foreach($_images as $_image) {?>
			<p><img src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(848, null);?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php echo $this->htmlEscape($_image->getLabel());?>" /></p>
		<?php } ?>
	<?php } ?>
</div>

That’s it! See what I’ve done for my store: http://www.princessly.com/trumpet-a-line-v-neck-asym-drop-waist-sleeveless-straps-wedding-dress-w-court-train.html

Display all product images WITH watermarks

With “->setWatermarkImageOpacity(0)” the displayed images will not have watermarks on them. This is better for user experience but may enable image stealing. To add the watermarks, just get rid of “->setWatermarkImageOpacity(0)“:

<div class="product_images_exhibit">
	<h2><?php echo $this->__('Product Images') ?></h2>
	<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
	<?php if($_images) {?>
		<?php foreach($_images as $_image) {?>
			<p><img src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(848, null);?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php echo $this->htmlEscape($_image->getLabel());?>" /></p>
		<?php } ?>
	<?php } ?>
</div>

You would still need to configure watermarks in System -> Configuration -> Design to make this work.

Get Canonical URL of A Product in .PHTML

Canonical URL is a great way to focus SEO power. Without it, search engines would have no idea which particular page among all the similar pages are the most important. Magento, as sophisticated as it can get, does have lots of similar pages regarding the same piece of content such as a product.

When you are adding social buttons, it may not be enough to just add the button and let it detect the current page URL itself. For example, when the user clicks “Edit” of a cart item and gets to the edit page of that item, it’s almost the same as the canonical item page.

If you have social buttons on that page then chances are they won’t be useful at all because they would be promoting the edit page rather than the canonical page. Thus, we need to feed canonical URL rather than the current page URL to them.

How to get the canonical URL of a product programmatically?

It’s as simple as this:

echo $product->getUrlModel()->getUrl($product, array('_ignore_category'=>true));

Make sure you change $product to whatever you are using for the product in your PHTML template.

Avalanche Coupon Code for 15% Off from Fast Division

Avalanche is the premium Magento theme crafted and maintained by Fast Division. Read my personal review of Avalanche and you would know how excellent it is. And it doesn’t stop there because Jake is currently FULLY occupied in shaping and sculpting this One Theme for Magento. The last email I got from him he said:

Avalanche is doing very well. I’m extremely busy with support emails and customization requests. I might have to start a forum and definitely write more help articles so this becomes more manageable until I get a community manager.

fast divisionAvalanche is obviously taking off. Have a Magento store? Get on the wagon before everyone else does and use this coupon code to get 15% off your Avalanche license:

MAGENTOGOREVIEW

Just supply this coupon in the “Enter coupon code” field before clicking “Continue” to check out with PayPal.

avalanche coupon code

Resize Watermark by Percentage of the Original Product Image

In the configurations Magento only lets you set an absolute pixel value for the dimensions (width & height) of the watermark image you upload. What if any of the product images are smaller than the specified width of the watermark? An incomplete watermark will be printed on the product image. Everything but pretty.

What we want to do is to resize the watermark image on the fly proportionately to the size of the product image. For example, the width of the watermark will always be 50% of that of the product image. This way, we wouldn’t have such issues as incomplete watermarks.

I have Cloud Zoom extension installed so all I need to edit is the /app/design/frontend/default/forest_fashion/template/magento-team/cloud-zoom/catalog/product/view/media.phtml file. Not sure which file should be edited in your case but should be close.

In media.phtml, you can get the width of the original product image by this:

$_originalWidth = $this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth();

And calculate watermark width on the fly by this:

function iGetWatermarkSize($_originalWidth) {
	// My watermark is 430x90. Change following values accordingly with your own.
	$_watermarkSizeWidth = .5 * $_originalWidth;
	$_watermarkSizeHeight = $_watermarkSizeWidth * 90 / 430;
	$_watermarkSize = $_watermarkSizeWidth.'x'.$_watermarkSizeHeight;
	return $_watermarkSize;
}
$_watermarkSize = iGetWatermarkSize($_originalWidth);

And then the watermarked image URL should be:

$url = $this->helper('catalog/image')->init($_product, 'image')->setWatermarkSize($_watermarkSize)

That’s it. Now $url should contain the URL to the new image with watermark resized proportionately to the width of the original image by percentage, 50%.

 

Magento: Get Original Width and Height of Product Images

Took me a while to find this but it’s actually in the Image Helper docs: http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Helper_Image.html

To get the width and height of the original product image (not resized ones, but the original ones that are uploaded when creating the product):

$this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth()
$this->helper('catalog/image')->init($_product, 'image')->getOriginalHeight()

This is very useful when you need to make decisions based upon the dimensions of the original product image. For example, if the uploaded product image is smaller than 500px in width, the Zoom View would shrink to the image width; if not, the Zoom View would stay at 500px in width.

Hide and Don’t Display N/A Attributes

There will be some attributes that are not compulsory when you are creating the product. And they will be ‘N/A’ or ‘No’ on the product page if you don’t specify values for them. That doesn’t look pretty. Customers might ask why this product doesn’t have this feature? To save you from the awkwardness, we may be better off by removing those ‘N/A’ or ‘No’ attributes.

How to remove or hide ‘N/A’ attributes on Magento product pages?

It’s simple. Just open and edit this file:

/app/design/frontend/default/my_theme/template/catalog/product/view/attributes.phtml

Change the bold part default/my_theme to wherever your theme resides. If attributes.phtml is not there, copy this one there:

/app/design/frontend/base/default/template/catalog/product/view/attributes.phtml

And then open and edit it:

/app/design/frontend/default/my_theme/template/catalog/product/view/attributes.phtml

You would be greeted by something like this:

<?php foreach ($_additional as $_data): ?>
	<tr>
		<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
		<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
	</tr>
<?php endforeach; ?>

Just add a line in there (bold part):

<?php foreach ($_additional as $_data): ?>
	<?php if ($_data['value'] == 'N/A') {continue;} ?>
	<tr>
		<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
		<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
	</tr>
<?php endforeach; ?>

So if the attribute value is ‘N/A’, the foreach loop would continue to the next round instead of outputting the attribute value.
 

Page 1 of 41234