Magento: How to Add a Profit Column to Admin Create Order Table Grid

This tutorial will help you display a profit column in the Create New Order’s Product Table Grid from Magento’s administration board by calculating the difference between the total price (product price times quantity) and products¬†acquisition cost (product acquisition cost times quantity).

create-new-order-profit-column-magento

The first step is to activate the product cost attribute. To do this, go to the Magento Administration Page/Catalog/Attributes/Manage Attributes and enable it for your products. Try not to make it accessible from the front-end users.

Now go to your products and add the acquisition price in the costs’ text field.

activate-cost-attribute-magento

The second step is to go to the FTP account, and edit/app/design/adminhtml/default/default/template/sales/order/create/items/grid.phtml by adding the following code to define the name of the column. Notice that there are two similar code sections in the file, so you can add this line to both of them:

<th class="no-link"><?php echo $this->helper('sales')->__('Price') ?></th>
<th class="no-link"><?php echo $this->helper('sales')->__('Qty') ?></th>
<th class="no-link"><?php echo $this->helper('sales')->__('Subtotal') ?></th>
<th class="no-link"><?php echo $this->helper('sales')->__('Discount') ?></th>
<th class="no-link"><?php echo $this->helper('sales')->__('Row Subtotal') ?></th>
<th class="no-link"><?php echo $this->helper('sales')->__('Profit') ?></th>  

Now add the cell cotaining the actual value of the profit:

 <?php endif; ?>
 <?php endif; ?>
 
 </td>
 <td>
 <?php $bucati=$_item->getQty()*1; ?>
 <?php $costprodus=$_item->getBaseCost(); ?>
 <?php $pret=$_item->getCalculationPrice()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition(); ?>
 <?php 
 if(!empty($costprodus)){
 echo $bucati*$pret-$costprodus*$bucati;
 $totalprofit+=$bucati*$pret-$costprodus*$bucati;
 }
 else echo "N/A";
 ?>
 
 </td>
 <td class="last">
 <select name="item[<?php echo $_item->getId() ?>][action]" style="width:100px;">
 <option value=""></option>
 <option value="remove"><?php echo $this->helper('sales')->__('Remove') ?></option>

That’s it. Save the file and upload it back to your server.

Tagged on: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *