在 Magento 的订单和发票网格中获取客户自定义属性
Get Customer's Custom Attribure in Order and Invoice Grids in Magento
我在互联网上搜索了答案,包括许多 SO 问题,但 none 似乎提供了我需要的东西。
我有一个客户自定义属性 (customer_number
)。我需要能够在管理区域的 Orders 和 Invoices 网格中显示此内容。
我已经通过将 Mage_Adminhtml_Block_Orders_Grid
复制到本地池并使用下面的代码获得客户电子邮件
$collection->getSelect()
->join(
'sales_flat_order_address',
'main_table.entity_id = sales_flat_order_address.parent_id',
array('email')
);
显然,这仅适用于 Orders 网格。
谁能帮我获取这些表中的 customer_number
属性?
使用 CE 1.9。
更新
我在 _prepareCollection()
中添加了以下代码的列:
$gen_number_attr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('gen_number');
$collection->getSelect()->joinLeft(
array(
'table_customer_number' => $gen_number_attr->getBackend()->getTable()),
'main_table.customer_id = table_customer_number.entity_id AND table_customer_number.attribute_id = '.$gen_number_attr->getId(). ' AND table_customer_number.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array(
'customer_number' =>'table_customer_number.value'
)
);
现在的问题是,当我尝试过滤时出现以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_number' in 'where clause', query was: SELECT COUNT(*) FROM `sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order_address` ON main_table.entity_id = sales_flat_order_address.parent_id WHERE (`customer_number` LIKE '%123%')
如有任何帮助,我们将不胜感激!
命令:- 复制默认的 'app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.phtml' 并将其放在 'app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.phtml' 中。现在从新的本地目录打开 Grid.php 文件并仔细查看以下代码块:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
/* adding term and condition section */
$customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition');
$collection->getSelect()
->joinLeft(
array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()),
'main_table.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array('term_condition' =>'cusTerm_conditionTb.value')
);
/* end adding term and condition section */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
/* adding term and condition tab */
$this->addColumn('term_condition', array(
'header' => Mage::helper('sales')->__('Term and condition'),
'index' => 'term_condition',
));
/* adding term and condition tab */
}
发票:- 复制默认的 'app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.phtml' 并将其放入 'app/code/local/Mage/Adminhtml/Block/Sales/Invoice/Grid.phtml'。现在从新的本地目录打开 Grid.php 文件并仔细查看以下代码块:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
/* adding term and condition section */
$customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition');
$collection->getSelect()
->joinLeft(
array('sales_flat_order'),
'main_table.order_id = sales_flat_order.entity_id',
array('customer_id' =>'customer_id')
);
$collection->getSelect()
->joinLeft(
array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()),
'sales_flat_order.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array('term_condition' =>'cusTerm_conditionTb.value')
);
/* end adding term and condition section */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
/* adding term and condition tab */
$this->addColumn('term_condition', array(
'header' => Mage::helper('sales')->__('Term and condition'),
'index' => 'term_condition',
));
/* adding term and condition tab */
}
我在互联网上搜索了答案,包括许多 SO 问题,但 none 似乎提供了我需要的东西。
我有一个客户自定义属性 (customer_number
)。我需要能够在管理区域的 Orders 和 Invoices 网格中显示此内容。
我已经通过将 Mage_Adminhtml_Block_Orders_Grid
复制到本地池并使用下面的代码获得客户电子邮件
$collection->getSelect()
->join(
'sales_flat_order_address',
'main_table.entity_id = sales_flat_order_address.parent_id',
array('email')
);
显然,这仅适用于 Orders 网格。
谁能帮我获取这些表中的 customer_number
属性?
使用 CE 1.9。
更新
我在 _prepareCollection()
中添加了以下代码的列:
$gen_number_attr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('gen_number');
$collection->getSelect()->joinLeft(
array(
'table_customer_number' => $gen_number_attr->getBackend()->getTable()),
'main_table.customer_id = table_customer_number.entity_id AND table_customer_number.attribute_id = '.$gen_number_attr->getId(). ' AND table_customer_number.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array(
'customer_number' =>'table_customer_number.value'
)
);
现在的问题是,当我尝试过滤时出现以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_number' in 'where clause', query was: SELECT COUNT(*) FROM `sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order_address` ON main_table.entity_id = sales_flat_order_address.parent_id WHERE (`customer_number` LIKE '%123%')
如有任何帮助,我们将不胜感激!
命令:- 复制默认的 'app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.phtml' 并将其放在 'app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.phtml' 中。现在从新的本地目录打开 Grid.php 文件并仔细查看以下代码块:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
/* adding term and condition section */
$customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition');
$collection->getSelect()
->joinLeft(
array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()),
'main_table.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array('term_condition' =>'cusTerm_conditionTb.value')
);
/* end adding term and condition section */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
/* adding term and condition tab */
$this->addColumn('term_condition', array(
'header' => Mage::helper('sales')->__('Term and condition'),
'index' => 'term_condition',
));
/* adding term and condition tab */
}
发票:- 复制默认的 'app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.phtml' 并将其放入 'app/code/local/Mage/Adminhtml/Block/Sales/Invoice/Grid.phtml'。现在从新的本地目录打开 Grid.php 文件并仔细查看以下代码块:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
/* adding term and condition section */
$customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition');
$collection->getSelect()
->joinLeft(
array('sales_flat_order'),
'main_table.order_id = sales_flat_order.entity_id',
array('customer_id' =>'customer_id')
);
$collection->getSelect()
->joinLeft(
array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()),
'sales_flat_order.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
array('term_condition' =>'cusTerm_conditionTb.value')
);
/* end adding term and condition section */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
/* adding term and condition tab */
$this->addColumn('term_condition', array(
'header' => Mage::helper('sales')->__('Term and condition'),
'index' => 'term_condition',
));
/* adding term and condition tab */
}