在Magento Admin中:在报告/购物车/购物车中的商品 我想在“购物车中的产品”网格下添加“颜色”属性列。假设网上商店的所有产品都是可配置的产品 即;如果来自Webshop - 客户选择带有“红色”选项的测试产品(可配置产品),则该属性值应显示在报告中。
请建议最好的方法来实现这一目标!
答案 0 :(得分:0)
复制\ app \ code \ core \ Mage \ Reports \ Model \ Resource \ Quote \ Collection.php并粘贴到app \ code \ local \ Mage \ Reports \ Model \ Resource \ Quote \ Collection.php
覆盖公共功能prepareForProductsInCarts()功能
public function prepareForProductsInCarts()
{
$productEntity = Mage::getResourceSingleton('catalog/product_collection');
$productAttrName = $productEntity->getAttribute('name');
$productAttrNameId = (int) $productAttrName->getAttributeId();
$productAttrNameTable = $productAttrName->getBackend()->getTable();
$productAttrPrice = $productEntity->getAttribute('price');
$productAttrPriceId = (int) $productAttrPrice->getAttributeId();
$productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
$ordersSubSelect = clone $this->getSelect();
$ordersSubSelect->reset()
->from(
array('oi' => $this->getTable('sales/order_item')),
array(
'orders' => new Zend_Db_Expr('COUNT(1)'),
'product_id'))
->group('oi.product_id');
$this->getSelect()
->useStraightJoin(true)
->reset(Zend_Db_Select::COLUMNS)
->joinInner(
array('quote_items' => $this->getTable('sales/quote_item')),
'quote_items.quote_id = main_table.entity_id',
null)
->joinInner(
array('e' => $this->getTable('catalog/product')),
'e.entity_id = quote_items.product_id',
null)
->joinInner(
array('product_name' => $productAttrNameTable),
"product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}",
array('name'=>'product_name.value'))
->joinInner(
array('product_price' => $productAttrPriceTable),
"product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
array('price' => new Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')))
->joinLeft(
array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))),
'order_items.product_id = e.entity_id',
array()
)
->columns('e.*')
->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)')))
->columns('order_items.orders')
->where('main_table.is_active = ?', 1)
->group('quote_items.product_id');
return $this;
}
并替换为以下功能。
public function prepareForProductsInCarts()
{
$productEntity = Mage::getResourceSingleton('catalog/product_collection');
$productAttrName = $productEntity->getAttribute('name');
$productAttrNameId = (int) $productAttrName->getAttributeId();
$productAttrNameTable = $productAttrName->getBackend()->getTable();
$productAttrPrice = $productEntity->getAttribute('price');
$productAttrPriceId = (int) $productAttrPrice->getAttributeId();
$productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
$ordersSubSelect = clone $this->getSelect();
$ordersSubSelect->reset()
->from(
array('oi' => $this->getTable('sales/order_item')),
array(
'orders' => new Zend_Db_Expr('COUNT(1)'),
'product_id'))
->group('oi.product_id');
$this->getSelect()
->useStraightJoin(true)
->reset(Zend_Db_Select::COLUMNS)
->joinInner(
array('quote_items' => $this->getTable('sales/quote_item')),
'quote_items.quote_id = main_table.entity_id',
null)
->joinInner(
array('e' => $this->getTable('catalog/product')),
'e.entity_id = quote_items.product_id',
null)
->joinInner(
array('product_name' => $productAttrNameTable),
"product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}",
array('name'=>'product_name.value'))
->joinInner(
array('product_price' => $productAttrPriceTable),
"product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
array('price' => new Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')))
### Newly added script ###
->joinLeft(
array('cpei' => 'catalog_product_entity_int'),
'cpei.entity_id = e.entity_id AND cpei.attribute_id = 92',
array()
)
->joinLeft(
array('eaov' => 'eav_attribute_option_value'),
'eaov.option_id = cpei.value',
array('color'=>'eaov.value')
)
### End script ###
->joinLeft(
array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))),
'order_items.product_id = e.entity_id',
array()
)
->columns('e.*')
->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)')))
->columns('order_items.orders')
->where('main_table.is_active = ?', 1)
->group('quote_items.product_id');
return $this;
}
此处 cpei.attribute_id = 92 是我的“颜色”属性ID 。您可以根据自己的要求进行更改。
还在下面放入代码
\app\code\core\Mage\Adminhtml\Block\Report\Shopcart\Product\grid.php
档案。
$this->addColumn('color', array(
'header' =>Mage::helper('reports')->__('Color'),
'index' =>'color',
是的,我们可以将grid.php文件从core复制到本地文件夹。 在magento 1.7中工作和测试