How to get invoice increment_id on order grid? (Magento 1.7) - magento

I'm trying to get the increment_id from the sales_flat_invoice table to appear on my orders grid.
I've managed to do that, but then it will only show orders which has been invoiced.
The sum it up, what I'm trying to do, is to create a column which contain the increment_id of the invoice (if the order has been invoiced - if not, it should be blank).
The code is used was the following:
In _prepareCollection() :
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()
->join(
array('address' => $collection->getTable("sales/order_address")),
'main_table.entity_id = address.parent_id AND address.address_type = "shipping"',
array('postcode')
);
//$collection->join('invoice', 'main_table.entity_id = invoice.order_id', 'increment_id as invoice_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
In _prepareColumns() :
$this->addColumn('invoice_id', array(
'header' => 'Faktureret',
'index' => 'invoice_id',
'width' => '70px',
'type' => 'text',
));
Thanks and have a beautiful day!

If you want to add the invoice id in the sales order grid then you can use the following code in your prepareCollection() function as
$collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.order_id', 'increment_id as invoice_id');
By using the following code you will able to get the invoice id from the current order id in sales order grid.
after this add column field as
$this->addColumn('invoice_id',
array(
'header'=> $this->__('Invoice Id'),
'align' =>'right',
'type=' => 'text',
'index' => 'invoice_id',
)
);
For more follow me on
http://www.webtechnologycodes.com

You need to do a LEFT JOIN. Use ->joinLeft. ->join references to ->joinInner

To get invoice details from order detail. you can use
$_orders = $this->getOrders();
$_invoices = $_order->getInvoiceCollection();

Related

Magento invoice grid filter by joined attribute value

I'm using the following code to include a custom attribute, titled "sales rep" within the Magento invoice grid:
protected function _prepareCollection() {
$sales_rep = Mage::getResourceSingleton('customer/customer')->getAttribute('sales_rep');
$collection = Mage::getResourceModel('sales/order_invoice_grid_collection');
$collection->join('invoice', 'main_table.entity_id = invoice.entity_id',array('order_id as order_id'));
$collection->join('order', 'invoice.order_id = order.entity_id',array('customer_id as customer_id'));
$collection->getSelect()->joinLeft(
array('customer_sales_rep_table' => Mage::getSingleton('core/resource')->getTableName($sales_rep->getBackend()->getTable())),
'customer_sales_rep_table.entity_id = order.customer_id
AND customer_sales_rep_table.attribute_id = '.(int) $sales_rep->getAttributeId() . '
',
array('sales_rep'=>'value')
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
...
$this->addColumn('sales_rep', array(
'header' => Mage::helper('sales')->__('Sales Rep'),
'index' => 'sales_rep',
'filter' => false
));
This is working perfectly, just as long as the "addColumn" property "filter" is set to "false".
How would I go about allowing users to filter by this joined attribute?
You should add your column like this:
$this->addColumn('sales_rep', array(
'header' => Mage::helper('sales')->__('Sales Rep'),
'index' => 'sales_rep',
'filter_index' => 'customer_sales_rep_table.value'
));

magento show content according to condition in admin grid

I have developed custom admin module. I have used the usual methods _prepareCollection and _prepareColumns to show the data in Grid.
protected function _prepareCollection()
{
$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
$collection->getSelect()
->join( array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.seller_id and ce1.attribute_id = "5"', array('seller_name' => 'value'));
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
protected function _prepareColumns()
{
$helper = Mage::helper('sellers');
$currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
$this->addColumn('id', array(
'header' => $helper->__('Request No'),
'index' => 'id'
));
$this->addColumn('Requested Amount', array(
'header' => $helper->__('Requested Amount'),
'index' => 'request_amount'
));
$this->addColumn('Seller Name', array(
'header' => $helper->__('Seller Name'),
'index' => 'seller_name',
));
$this->addColumn('Status', array(
'header' => $helper->__('Status'),
'index' => 'status_flag'
));
All the data shows correctly according to the table values. But I want to show the Request Amount column values preceding with $ sign, e.g. $300 etc. Also, I want to show the status flag according to condition. Means if the status flag is 1 then I want to show the value as "Approved", if flag is 2 then "Pending" etc. How should I customize the collection data and show in grid according to my requirement? Help appreciated.
Thanks.
I have answered to a question similar to your requirement
How to properly add a shipping_description column in magento order grid?
Check my answer and try to compare with your problem. In this example there is the solution for our currency problem too.
So check this out.Hope it will be helpful.
Here you should implement Grid Renderer.
Here is complete tutorial for that : http://inchoo.net/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/
You can customize the value of any colum

Add and show new column in sales_flat_order and show this at order grid in magento

I have added a new column (exported)in sales_flat_order and add at files at this location:
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->addAttributeToSelect('*')
->joinAttribute('exported','sales/order','sales_flat_order.entity_id',null,'left');
}
protected function _prepareColumns()
{
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'name' =>'exported',
'value' =>$this->getExported()==1 ? 'true' : 'false',
));
}
after that it showing on order grid in admin site,but it is not showing value and name,
I am new in magento,so please help me ,
stuck from 2 days.
Thanks for Assistance.
The method _prepareCollection() uses sales_flat_order_grid table as asource, thus you have to add the column to sales_flat_order_grid table and update the values of that column from the appropriate column of sales_flat_order table.
In this case, Magento will automatically update this column in sales_flat_order_grid table for future orders.
The better way to display the boolean column is Yes/No renderer. Use the following code for this in _prepareColumns() method
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'options',
'width' => '70px',
'options' => array(
1 => Mage::helper('sales')->__('Yes'),
0 => Mage::helper('sales')->__('No'),
),
));
There are some other useful articles about cutomizing order grid. Check out the links below:
http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/
http://www.ecomdev.org/2010/07/27/adding-order-attribute-to-orders-grid-in-magento-1-4-1.html
http://www.demacmedia.com/magento-commerce/mini-tutorial-adding-column-to-orders-grid-in-magento-backend/
http://www.atwix.com/magento/column-to-orders-grid/

product grid column filter not working in magento

I am going to display only configurable products in my grid. and added one column to display number of simple configurable products under this product. for this i wrote like this. it is working fine. displaying number of simple products of configurable in columns. but how to apply column filter to this. it is not working. here is my query
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
$collection->getSelect()
->joinLeft(
array('a'=>'catalog_product_super_link'),
'a.parent_id = e.entity_id',
array('assoc_count'=>'count(a.parent_id)'))->group('e.entity_id');
displaying column here
$this->addColumn('assoc_count',array(
'header'=> Mage::helper('catalog')->__('Count SimplePro'),
'width' => '80px',
'index' => 'assoc_count',
));
Try to use filter_condition_callback
$this->addColumn('assoc_count',array(
'header'=> Mage::helper('catalog')->__('Count SimplePro'),
'width' => '80px',
'index' => 'assoc_count',
'filter_condition_callback' => array($this, 'assocFilterCallback'),
));
protected function assocFilterCallback($collection, $column) {
$val = $column->getFilter()->getValue();
if (is_null(#$val))
return;
$collection->getSelect()->having('assoc_count=?', $val);
}
May be code should be rebuild, but I think you understand the idea.

Magento - Add zip code / postcode to the order grid in Magento 1.6.2

I am trying to get the order grid to display the postcode/ zip code of the of the customer.
I am trying to join the sales_flat_order_address alias with the collection but to no success.
protected function _prepareCollection() {
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('postcode'));
//var_dump($collection);
$this->setCollection($collection);
return parent::_prepareCollection();
}
Can any one please help me figure out a solution for this.
Before return parent::_prepareCollection(); You should create a join:
$collection->getSelect()->joinLeft(array('billing'=>'sales_flat_order_address'),
'main_table.entity_id = billing.parent_id AND billing.address_type="billing"',array('billing.postcode AS bp'));
If you want the shipping postcode instead, use:
$collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'),
'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp'));
And in the method _prepareColumns paste:
$this->addColumn('bp', array(
'header' => Mage::helper('sales')->__('Billing Postcode'),
'index' => 'bp',
'width' => '60px',
'filter_index' => 'billing.postcode'
));
That worked for me in a recent project.

Resources