Add the final price to the admin product grid in Magento?

How can I add the “final price” (with all catalog rules and special prices) to the product grid in the Magento admin?

UPDATE 12/12/2012 I am using v1.1.8 with a lot of settings, so I just did a new installation of v.1.1.8 and added addFinalPrice () to _prepareCollection () in the product grid, but now all I get is half-closed in the Product Management administrator. Any ideas?

+4
source share
2 answers

The final price depends on the website and customer group, do you have any business requirements that explain which of these prices should be shown? because in general, the data in the product grid is storage dependent.

In the simple case, you can add a price index table to the product collection and display data from it (the addPriceData method already exists in the product collection). (you can also implement a client group switch to make sure that you cover all possible cases)

In the example below, how to add a new column to the product grid http://www.magentocommerce.com/boards/viewthread/68993

simple product grid override example

step 1 override the 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 implements 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 a store, you can see the price, for "All stores" this data is not available

+1
source
 $collection->addPriceData() 

will be useful

0
source

Source: https://habr.com/ru/post/1437858/


All Articles