How can I add the "final price" (with all the catalog rules and special prices taken into account) to the product grid in the Magento admin?
UPDATE 10/12/2012 I am using v1.1.8 with a large number of customizations so I just did a fresh install of v.1.1.8 and added addFinalPrice() to the _prepareCollection() in the product grid, but now all I get is a semi-blank screen in the Manage Products admin. Any ideas?
final price depends on website and customer group, do you have business requirement which explain which of these prices needs to be shown? because in common case data in product grid depends on store.
In simple case, you can add price index table to collection of products and show data from it (In products collection already exists method addPriceData
). (also you can implement customer-group switcher to be sure that you have covered all possible cases)
At link below example how to add new column to products grid http://www.magentocommerce.com/boards/viewthread/68993
simple example how to override products grid
step 1 override grid in config.xml of your module
<config>
...
<global>
...
<blocks>
...
<adminhtml>
<rewrite>
<catalog_product_grid>Test_Catalog_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
</rewrite>
</adminhtml>
...
</blocks>
...
</global>
...
</config>
step 2 implement your block
class Test_Catalog_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
/**
* get customer group id
*
* @return int
*/
protected function _getCustomerGroupId()
{
$customerGroupId = (int) $this->getRequest()->getParam('customer_group_id', 0);
return $customerGroupId;
}
/**
* prepare collection
*
* @return Test_Catalog_Block_Adminhtml_Catalog_Product_Grid
*/
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$collection->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
}
if ($store->getId()) {
$collection->addPriceData($this->_getCustomerGroupId(), $this->_getStore()->getWebsiteId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(
'name',
'catalog_product/name',
'entity_id',
null,
'inner',
$adminStore
);
$collection->joinAttribute(
'custom_name',
'catalog_product/name',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'status',
'catalog_product/status',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'visibility',
'catalog_product/visibility',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'price',
'catalog_product/price',
'entity_id',
null,
'left',
$store->getId()
);
}
else {
$collection->addAttributeToSelect('price');
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
}
$this->setCollection($collection);
Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
}
/**
* Prepare columns
*
* @return Mage_Adminhtml_Block_Widget_Grid
*/
protected function _prepareColumns()
{
$this->addColumnAfter('final_price',
array(
'header'=> Mage::helper('catalog')->__('Final Price'),
'type' => 'price',
'currency_code' => $this->_getStore()->getBaseCurrency()->getCode(),
'index' => 'final_price',
), 'price');
return parent::_prepareColumns();
}
}
now, if you select store you will be able see price, for "All Store Views" this data is unavailable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With