Magento - Добавление нового столбца в таблицу заказов на продажу не работает
Я пытаюсь добавить новый столбец в сетку заказов клиентов Magento (Admin > Sales > Orders). Я попытался следовать инструкциям, расположенным здесь: http://www.atwix.com/magento/customize-orders-grid/
Я скопировал файл ядра в локальную папку, чтобы переопределить его:
От: /public_html/wholesale/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
Кому: /public_html/wholesale/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
Любопытно, что независимо от того, какие изменения я делаю в любом другом файле, на стороне администратора ничего не меняется. Я даже не могу заставить Mage::log() работать.
Как только я преодолею эту проблему, мне нужно убедиться, что изменения, которые я делаю, правильные. Я только пытаюсь получить название компании клиента. Вот две части, которые я добавил:
protected function _prepareCollection()
{
// This line is from the original
$collection = Mage::getResourceModel($this->_getCollectionClass());
// This is the call where I try to bring in the extra field
// from another sales table
$collection->getSelect()->join(
'sales_flat_order_address',
'sales_flat_order.entity_id = sales_flat_order_address.parent_id',
array('company')
);
// These lines are also default
$this->setCollection($collection);
return parent::_prepareCollection();
}
В _prepareColumns():
$this->addColumn('company', array(
'header' => Mage::helper('sales')->__('Company'),
'index' => 'billing_company',
));
К вашему сведению, я использую Magento 1.7.0.2
Спасибо за ваше время!
1 ответ
Попробуй это:
protected function _prepareCollection()
{
// This line is from the original
$collection = Mage::getResourceModel($this->_getCollectionClass());
// Join billing 'company' field from sales_flat_order_address table
$collection->getSelect()->join(
array('addressTable' => 'sales_flat_order_address'),
'main_table.entity_id = addressTable.parent_id AND addressTable.address_type = "billing"',
array('billing_company'=>'company')
);
// These lines are also default
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function filterBillingCompany($collection, $column) {
$val = (string)trim($column->getFilter()->getValue());
if ($val != "") {
$collection->getSelect()->where("addressTable.company LIKE '%{$val}%'");
}
return $this;
}
В _prepareColumns():
$this->addColumn('company', array(
'header' => Mage::helper('sales')->__('Company'),
'index' => 'billing_company',
'filter_condition_callback' => array($this, 'filterBillingCompany'),
));