Magento: Work With Product Collection

Hello friends,

At last week while working with magento store, we had a requirement to list out products after different filter. Like list out products according to particular category and attributes.

To satisfy our requirement we searched the web and found a proper solution, which is discussed below.

Magento uses a model type called collection, which is containing other models.

And mainly in magento a collection is used to handle product lists, but it is not the only purpose of collection.

Basically in magento we get a product collection by either category model or by product model.

So first of all we need to get category or product model and the syntax to get particular model is as under:

$collection = Mage::getModel('module/model_name');

Here, if we got category model then we can get products of particular category in product collection.

And if we got product model then we can get all the products of store in product collection.

While getting the product collection we can filter it by attribute or field and can sort it by attribute or field.

For Example:

$category_product_collection = Mage::getModel('catalog/category')->load($categoryid)
->addAttributeToFilter('manufacturer', $manufacturerid)
->addFieldToFilter('entity_id', $productid)
->addAttributeToFilter('visibility', $visibility)
->addAttributeToFilter('status', 1)
->addAttributeToSort('name', 'ASC')
->setOrder('created_at', 'desc');

In above example we load the category model and got the product collection of particular category.

And filtered the product collection according to manufacturer, visibility and status attributes and entity_id field, and also sort it by name attribute and created_at field.

Hope this will help you.


Make Rounded Corners With CSS

Hello friends,

Before few days while developing html page with css, we had a requirement to apply border with rounded corners.

To fulfill our requirement we searched the web and got a solution, which is as under.

In the CSS3 there is a standard property named “border-radius” to apply border with rounded corners.

The border-radius property is supported by all of the major browsers like: safari, chrome, internet explorer 9, opera and firefox.

And it is easy to apply border-radius property to element, just like other properties.

For Example:

.applyBorder {
    border-radius: 12px;

The above example gives unique rounded corner value to each four corners of element.

An individual border radius can also be applied.

.applyBorder {
    border-top-left-radius: 7px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 6px;
    border-bottom-left-radius: 8px;

And the syntax of sort hand border-radius is as under:

.applyBorder {
    border-radius: 12px 5px 12px 5px;

Now it is good to have ability to apply border with rounded corners with css, because it saves the time to load images and in handling requests to server.

Hope this will help you.


Magento: Change or Translate Text

Hello friends,

A month ago, while working with magento product attributes, we had a requirement to change the “Choose an Option…” text in dropdown option.

To satisfy our requirement we searched the forums and got many solutions.

But all the solutions were not up to the mark, and some suggested changes in the magento core part.

Then at last we have got a valuable solution, which is as under.

In magento there is a “.csv” file structure to change or translate text.

Within “/app/design/frontend/yournamespace/yourtheme/locale/yourlanguage /” translate.csv file is available. (If it is not available then create it.)

Now in that file, in new row, add “Choose an Option…” text in first column and add “any text to change” in second column. And save the file.

What exactly happens is that magento first checks our “translate.csv” file and checks for the translation text. Here it is taking first column as a base text. If we have written anything in the second column then it takes it as a translation text of the first column. So when we write our custom text in the second column, it actually thinks that our custom text is the translation of first column text and displays it. If we write nothing in the second column then it will display nothing. And if we don’t define any text in the file at all then it will take the default value from the original translation file of magento.

Yes, we have done that. Means the “Choose an Option…” text has been replaced with our customized text.

So now it is working fine for us. And there is nothing hard in implementing above solution.

Look the above solution is not only for “Choose an Option…” text, but one can change or translate any text with it.

For Example: If we want to change or translate “* Required Fields”, “Add to Cart”, “Add to Wishlist” or any such a text then it is very useful.

Hope this will help you.