Wednesday, March 7, 2012

Add files to products - no extension required

Here is how you can add files to products without using an extension. It can be useful for adding specification files, pdf catalogs or any other files you want. Put all your files in one folder let's say (media/productfiles/). Now in the product description you just add a simple link to that file using the WYSIWYG editor. If you don't want to use the description field for this you can create a new attribute (let's call it 'attachment') type 'Textarea', scope 'Store view' (in case you want to have different files for different languages), 'Enable WYSIWYG' Yes, 'Allow HTML Tags on Frontend' Yes. If you want to show the link(s) to file(s) in the product list not only the product details page set 'Used in Product Listing' to 'Yes'. If not set it to 'No'. Now add your new attribute to the attribute set that you need and start editing products. Add links to your files just like described above, but use the 'Attachment' attribute instead of Description. now all you have to do is edit the app/design/frontend/{interface}/{theme}/template/catalog/product/view.phtml and add this line where ever you want the links to appear:
<?php echo $this->getProduct()->getAttachment();?>
If you want to add the links to the list of products also edit app/design/frontend/{interface}/{theme}/template/catalog/product/list.phtml and add this piece of code inside the foreach loop for the products:
<?php echo $_product->getAttachment();?>
Cheers, Marius.