Magento Themes and Magento Extensions

Magento: Display More Than 5 New Products

Posted on December 5th, 2012 | Posted by admin

Sometimes we have to display more new products than default number. The default count of new products in Magento is fixed only 5. But you can display more than 5 new products without modifying Magento core files. You can use below code for setting new product count according to your requirement.

  1. {{block type=“catalog/product_new” name=“”
  2. alias=“product_homepage” template=“catalog/product/new.phtml”
  3. _productsCount=“20″}}

The “_productsCount” determine how many new products will be displayed. Here I have set 20 product but you can change this according to your requirement.

Magento – Easy Form Validation in magento

Posted on December 4th, 2012 | Posted by admin

Magento has some Default classes for validating form elements in frontend. We can make use of those existing
class names for our custom forms and reuse the client side validation code of  Magento.
Let’s see a couple of examples from magento source code

1. Adding the required class to any field label will give the asterisk to be appear in red color indicating it is
the mandatory field

  1. <label for=“name” class=“required”><em>*</em></label>

2. If you want to make a field mandatory just add required-entry class in the input tag as shown below

  1. <input name=“name” id=“name” class=“input-text required-entry” type=“text”>

3. If you want to validate the field value entered by the user there is a seperate class available.

Magento – the “read-only” community?

Posted on December 3rd, 2012 | Posted by admin

ntil recently I considered the Magento mostly as a “read-only” community. Especially when I started with my first Magento projects there wasn’t much information around. Every now and then Varien (later then Magento Inc.) published a new version. I checked what was new, tested our projects with it and used that version from then on. If we encountered some bugs we digged into the code. Usually spent lots of hours and energy to spot the bug and fix it, contact Magento support, waited a couple of days and got the answer, that this is a known bug. Usually their response contained an official “patch” that in most cases was very similar to how we’ve fixed that.

Almost every time I asked myself, how we could actually be the first ones stumbling over this issue. And Magento support proved: We weren’t.

Magento add Bestseller products by date range

Posted on December 2nd, 2012 | Posted by admin

Magento add Bestseller products by date range

Here is how to get a collection of products best sold in a given date range

03.$from = date("Y-m-d H:i:s", (time()-2592000));
04.$to = date("Y-m-d H:i:s", time());
06.$_productCollection= Mage::getResourceModel('reports/product_collection')
08.->addOrderedQty($from, $to, true)
09.->addAttributeToFilter('status', 1)
10.->setOrder('ordered_qty', 'desc')

Get Cart Quantity in Magento

Posted on December 1st, 2012 | Posted by admin

Get Cart Quantity in Magento

You can get the number of items currently in the cart using the following code.

$cart = Mage::getModel('checkout/cart')->getQuote()->getData();
echo (int)$cart['items_qty'];

However,if the cart is empty, writing only the above code will show error (Because $cart['items_qty'] is only set when there are items on the cart). For that you need to check if the value is set or not. Hence the total code will be like –