Just another WordPress.com weblog

Archive for the ‘Zend Framework’ Category

Join any table with collection in admin

Hello,

We can easily display different table values as a column in grid in adminend of magento.

For eg:
I have to add one field for displaying ‘rule_id’, ‘status’, ‘send_date’ field as a columns in customer grid.
//Customer grid collection
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id');
$this->setCollection($collection);

/***From here we can left join with ‘giftcard’ table, join criteria is ‘gf.customer_id = e.entity_id’ and in array we can specifie the ‘rule_id’ as index in column and its values are from table giftcard. i.e ‘gf.rule_id’ and i have grouped with customer primary key i.e ‘e.entity_id’ ***/

$collection->getSelect()->joinLeft(array('gf'=>'giftcard'),
'gf.customer_id = e.entity_id',
array(
'rule_id'=> 'gf.rule_id',
'status' => 'IF(gf.status IS NULL,"Unsend","Send")',
'send_date' => 'gf.created_time'
))
->group('e.entity_id');

//To add column
Add below

$this->addColumn('created_time', array(
'header' => Mage::helper('giftcard')->__('Coupon Send Date'),
'align' => 'left',
'index' => 'send_date',
'type' => 'datetime',
'gmtoffset' => true
));

I hope this will help you..
If this post is help you than please do reply,..

Thanks,
Bijal Bhavsar 🙂

Advertisements

View Random Products from a store

Create new PHTML file random_product.phtml at

app\design\frontend\perfino\default\template\catalog\product\

$_parent_category =  Mage::app()->getStore()->getRootCategoryId();
$storeId = Mage::app()->getStore()->getStoreId();

$_productCollection = Mage::getResourceModel(‘catalog/product_collection’)->addStoreFilter($storeId)->load();
$_items = $_productCollection->getItems();
$_collectionSize = $_productCollection->count();
shuffle($_items); ?>

<?php foreach ($_items as $_Product):

$_product = Mage::getModel(‘catalog/product’)->load($_Product->getId());

// put your listing coding here

<?php endforeach;?>

Now you can put block to call thatfile

{{block type=”catalog/product” template=”catalog/product/random_product.phtml”}}

–Vishal Surani