Magento Themes and Magento Extensions

Batch Product Entity Updates in Magento

Share
Posted on March 16th, 2013 | Posted by admin

Batch Product Entity Updates in Magento
I’ve been writing scripts that interact directly with the database to modify products, etc., but today, I found a much better way to do things. Although direct DB modification is FAST, it’s also very unsafe, and I’m very wary of putting our clients’ sites at risk in order to do the updates they want. Magento, although very frustrating, offers some flexible functionality to alter its often immense database. Following is a PHP script I wrote to update products based on a CSV. The CSV contains product SKUs, but it can be easily modified to grab IDs from a CSV, and one can export their products and modify the fields they want, and then modify the script slightly to modify entities where needed, and grab the correct columns from the database. It will also resume if it needs to be terminated early (useful because it can take a long time for large updates), and reports percentage of completion. So, without further ado….

How to check if product image added or place holder image used

Share
Posted on March 12th, 2013 | Posted by admin

in Magento place holder image are always used when you get product URL or using Catalog_Helper_Image. But you know sometime, you don’t like this behavior and you need to be able to check if there is an image associated with the product or if the placeholder image will be used.

OK here is the solution

1
2
3
4
5
if ($_product->getSmallImage()=='no_selection' ) { //small_image is not set
// do your custom code
} else {
//display normal image?
}

Magento Product Collections

Share
Posted on December 14th, 2012 | Posted by admin

Using product collections can be very beneficial to Magento developers. In order to understand  Magento Product Collections, you should have an understanding of what a Collection is, in addition to having an understanding of Magento Models.

In short, a Magento Model is similar to an object in the sense that it contains both data and methods. A Magento Collection is a Model type that contains other models. So when we use the terminology “product collection”, we’re basically talking about all of the products in any given situation.

To retrieve all the products of a particular category, we simply open the category Model and load the product collection of that category. It looks something like this:

Programmatically Create Magento Product Packages

Share
Posted on November 30th, 2012 | Posted by admin

On a recent project I had to write a piece of code which I thought I’d share with the Magento community in case it comes in useful for anyone. I have put all the code into one ‘add to cart’ controller below for the sake of simplicity, but you could break it up into separate methods to clean up the code a bit.

In a nutshell, all products on the site have a normal price and some have a package price. If they have a package price they are capable of being purchased with other products as part of a package deal, but only two at a time. Therefore these products had to be purchased as one product using the special prices as we can’t have customers adjusting the quantities of items added to the cart. Here’s the code in myPackageController.php broken up:

Magento Use Custom Product Attributes to Add CMS Static Block to Product Page

Share
Posted on November 23rd, 2012 | Posted by admin

The Magento shopping cart has wonderful tools like attributes that makes it easy for users to control custom content on your products. Recently, I have had a client that needs to display the same information over multiple products. So rather than manually adding it on one product, I thought it would be easier to link a custom cms static block to the product page. While this seems like an easy thing to do, Magento makes this a bit complicated to set up. So this tutorial is meant to show you how to do this! After this tutorial you will be able to control static cms blocks from any product in your Magento store.

So let’s begin.
Setting up your Custom Product Attribute.
First we need to set up a custom product attribute correctly in magento. This will let us create a few cms static blocks and link them to our product. First login to your magento backend and go to Catalog > Attribute > Manage Attributes. Once the page reloads click on “Add New Attribute”. This will take you to a page where you can set up your attribute.

Page 1 of 712345»...Last »