Jul 26, 2013

How To Sort Cart Items in Magento

/* Fetching the updated cart items */
$items = array();

$cart = Mage::getModel('sales/quote_item')->getCollection()
->setQuote(Mage::getModel('checkout/cart')->getQuote())
->addFieldToSelect('*')
->addOrder('updated_at', 'desc');      

foreach ($cart as $item)
{
if (!$item->isDeleted() && !$item->getParentItemId()) {
$items[] = $item;
}

Now you are ready to use $items object.

If you want to use this $items object in cart then

Replace:
foreach($this->getItems() as $_item):

With:
foreach($items as $_item):

And you will get the sorted cart items by last modified date in descending order.

Jul 10, 2013

How to add new Attribute options programmatically in Magento

Example:

$arg_attribute = 'manufacturer';
$arg_value = 'value to be added';

$attr_model = Mage::getModel('catalog/resource_eav_attribute');
$attr = $attr_model->loadByCode('catalog_product', $arg_attribute);
$attr_id = $attr->getAttributeId();

$option['attribute_id'] = $attr_id;
$option['value']['any_option_name'][0] = $arg_value;

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($option);

Note: This example taken from the webspeaks blog.

For more detail click here webspeaks