Magento sort items ordered - magento

When I'm in: index.php/admin/sales_order/view/order_id/[ID]/key/[KEY]/ I can see the: "Items Ordered"
I'm looking for the code where the products are loaded in this table. I want to sort the ordered items by SKU.
Any hints?
PS:
I was looking in app/code/core/Mage/Adminhtml/Block/Sales/Order/View but couldn't find anything.

$collection->getSelect()->join(array(
'item'=>$collection->getTable('sales/order_item')),
'item.order_id=`main_table`.entity_id AND item.product_type="simple"',
array(
'skus' => new Zend_Db_Expr('group_concat(item.sku SEPARATOR ", ")'),
'name' => new Zend_Db_Expr('group_concat(item.name SEPARATOR ", ")')
));
$this->addColumn('skus', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'skus',
'type' => 'text',
));
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('NAME'),
'index' => 'name',
'type' => 'text'
));

You can add SKU as an option in the Manage Attributes menu in Admin. Having done that, set it to be the default in System > Configuration > Catalog > Catalog > Product Listing Sort By.
try this
alternatively you might like this

Related

Magento 1.9: sort grid view

I've added a column to my gridview and it suppose to show remaining days of an event.
$this->addColumn('calculate_days', array(
'header' => Mage::helper('myodule')->__('Remaining'),
'type' => 'options',
'width' => '200px',
'options' => $options,
'frame_callback' => array($this, 'getRemaining'),
'filter_condition_callback' => array($this, '_calculateFilter')
));
getRemaining method:
public function getRemaining($value, $row, $column)
{
// some calculation to find out remaining days based on some conditions
return $days;
}
If I don't specify the index key, clicking on the Remaining column does not work. So I've added index key to addColumn like bellow:
$this->addColumn('calculate_days', array(
'header' => Mage::helper('myodule')->__('Remaining'),
'type' => 'options',
'width' => '200px',
'index' => 'created_at',
'options' => $options,
'frame_callback' => array($this, 'getRemaining'),
'filter_condition_callback' => array($this, '_calculateFilter')
));
now the sort is WORK but not correctly. when I specify the index, sort applied by index column(in this case will sort by created_at) but I want to sort by remaining days.
what should I do to solve this problem? or is there any sort callback?
Why don't you add this value as a new field in this grid? And then update this field values each day by a cronjob.
Then you will have in a native way the items sorted and also you avoid to recalculate each value each time you filter o see this grid.
Hope it helps,
Regards

How to add elements to a fieldset in magento horizontally rather than vertically

I am adding few check boxes in to magento using the fieldset option like the following.
$fieldset = $form->addFieldset('display', array(
'legend' => $helper->__('Schedule Sales Order Transfer'),
'class' => 'fieldset-wide'
));
for($i=01; $i*5<60; $i++){
$time = $i*5;
$fieldset->addField('min'.$time, 'checkbox', array(
'name' => 'Checkbox',
'checked' => false,
'onclick' => self::setAll("min"),
'onchange' => "",
'value' => ''.$time,
'disabled' => false,
'after_element_html' => '<small>'.$time.'</small>',
'tabindex' => 1
));
}
By doing so, all the check boxes are coming one below another. Is it possible to make it one adjacent to another i.e., horizontally?
Anybody Please suggest the solution ASAP...
Thank you,
In your Code return like <tr>...</tr><tr>..</tr>, so if you need to add custom css or js to achieve what you expected,
or
for($i=01; $i*5<60; $i++){
$time[$i]['value'] = $i*5;
$time[$i]['label'] = $i*5;
}
$fieldset->addField('Time', 'checkboxes', array(
'label' => $this->__('Time'),
'name' => 'time[]',
'values' => $time,
'value' => '1',
'tabindex' => 1
));
its return like <tr><td>label</td><td>value<ul><li></li>....<li></li></ul></td></tr>
then you continue your stuff.,
Note: I'm just suggest the possible ways

How to add column Date Shipped to Sales Order Grid magento

I'm stuck with adding column to sales order grid from shipment grid.
The problem is: "Purchased On" in DB has name "created_at", "Date Shipped" has also name "created_at", so when I join "created_at" from "sales_flat_shipment_grid" I see purchased on date only with name date shipped.
I'm using this code:
in _prepareCollection()
$collection->getSelect()->joinLeft(array('sfsg'=>'sales_flat_shipment_grid'),'sfsg.order_increment_id=main_table.increment_id',array('sfsg.created_at'));
and in _prepareColumns()
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Date Shipped'),
'index' => 'created_at',
'type' => 'datetime',
'filter_index'=>'sfsg.created_at',
));
Could you please help me with this?
After few hours of trying I've found answer in my case it is:
in _prepareCollection() add
$collection->getSelect()->joinLeft(array('sfsg'=>$resource->getTableName('sales_flat_shipment_grid')),'sfsg.order_increment_id=main_table.increment_id',array(
'shiped' => new Zend_Db_Expr('group_concat(sfsg.created_at SEPARATOR " | ")'),
));
and in _prepareColums()
$this->addColumn('shiped', array(
'header' => Mage::helper('sales')->__('Date Shipped'),
'index' => 'shiped',
'type' => 'datetime',
'filter_index'=>'sfsg.created_at',
));

Magento Admin Grid - How to assign an action/function to a button?

I created a new module and I managed to list all the orders from the shop.
I also added a button (with this code).
$link= Mage::helper('adminhtml')->getUrl('adminhtml/order/sync/') .'id/$entity_id';
$this->addColumn('action_edit', array(
'header' => $this->helper('catalog')->__('Action'),
'width' => 15,
'sortable' => false,
'filter' => false,
'type' => 'action',
'actions' => array(
array(
'url' => $link,
'caption' => $this->helper('catalog')->__('Sync'),
),
)
));
I really don't know how to assign an action to this button. What I should create in my custom module ? A new controller?
I need to display something or get some data when I click this button...
thank you very much
I think you should write
public function YourActionNameAction()
{
}
in your Module controller file

How to customize the database value in magento customer grid

I created new magento grid for customer module for special purpose.
In that there have a column usertype it have value as 0,1,2.
It will displayed in customer grid page as 0,1,2.
But i need to display if value is,
0 -> Inactive
1 -> Activated
2 -> Baned
How can i dothis?
This is my code grid.php in _prepareColumns() :
$this->addColumn('usertype', array(
'header' => Mage::helper('customer')->__('Usertype'),
'width' => '150',
'index' => 'usertype'
));
If this is possible in magento.
if your greed implements Mage_Adminhtml_Block_Widget_Grid I suggest you to modify
you addColumn call to
$this->addColumn('usertype',
array(
'header'=> Mage::helper('customer')->__('Usertype'),
'width' => '150px',
'index' => 'usertype',
'type' => 'options',
'options' => $values
));
Where $values should be formatted as
array( 'value_id' => 'value_label')
Now you have dropdown created with values.
Then update _prepareCollection() function and add attribute values to customer grid collection
$collection->joinAttribute('usertype', 'customer/usertype', 'entity_id', null, 'left');
I got the solution from this
By using rendere will help to load vlaues to each row.

Resources