Hello.
I need to display the field "special_price" in the admin panel, under "Manage categories > Category products", as in this example:
I added field in the root file app\code\core\Mage\Adminhtml\Block\Catalog\Category\Tab\Product.php :
$this->addColumn('special_price', array( 'header' => Mage::helper('catalog')->__('Special_price'), 'type' => 'currency', 'width' => '30px', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), 'index' => 'special_price' ));
It works, but do not want to change the core files. I decided to try to make module (in php I am not strong and modules has never done).
================
Created structure:
app/etc/modules/Fermery_GridCategorySort.xml
app/code/local/Fermery/GridCategorySort:
> Model
> Helper
> etc
• In Model i put the file Product.php (which put the contents of the root Product.php, only added another field "special_price"). And I changed the line redirection:
class Fermery_GridCategorySort_Model_Product extends Mage_Adminhtml_Block_Widget_Grid
• In Helper put the file Data.php, who left empty:
<?php class Fermery_GridCategorySort_Helper_Data extends Mage_Core_Helper_Abstract{}
• In etc put the file config.xml with this content:
<config> <modules> <Fermery_GridCategorySort> <version>0.1.0</version> </Fermery_GridCategorySort> </modules> <global> <helpers> <gridcategorysort> <class>Fermery_GridCategorySort_Helper</class> </gridcategorysort> </helpers> <models> <gridcategorysort> <class>Fermery_GridCategorySort_Model</class> </gridcategorysort> <catalog> <rewrite> <product>Fermery_GridCategorySort_Model_Product</product> </rewrite> </catalog> </models> </global> </config>
As a result, the module outputs an error:
Fatal error: Call to a member function addAttributeToSelect() on a non-object in ...\includes\src\Mage_Adminhtml_Block_Catalog_Category_Tab_Product.php
I can not understand what to do next. How to fix the error. Therefore, I will be very glad to any your advice.
In fact, you can do that without creating an extension.
What you need to do is to copy the file app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php and move it to app/code/local/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php (kepp folder structure unchanged).
Then, open the file app/code/local/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php. In the file you need to rewrite the method _prepareCollection().
Find:
$collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('sku') ->addAttributeToSelect('price') ->addStoreFilter($this->getRequest()->getParam('store')) ->joinField('position', 'catalog/category_product', 'position', 'product_id=entity_id', 'category_id='.(int) $this->getRequest()->getParam('id', 0), 'left');
$collection->joinAttribute('special_price', 'catalog_product/special_price', 'entity_id', null, 'left');
$this->addColumn('special_price', array( 'header' => Mage::helper('catalog')->__('special Price'), 'type' => 'price', 'width' => '1', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), 'index' => 'special_price' ));
That's it.
Let me know if it worked
Thank you very much, this method has helped to solve the problem.
Only need insert this column (then the column appears):
$this->addColumn('special_price', array( 'header' => Mage::helper('catalog')->__('Special_price'), 'type' => 'currency', 'width' => '30px', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), 'index' => 'special_price' ));
Yes! I followed the same instructions and it worked straight away!
Thanks a lot!