在 Magento 管理员中:在报告/购物车/购物车中的产品下。
我想在“购物车中的产品”网格下添加“颜色”属性列。假设网店中的所有产品都是可配置产品。
IE; 如果从网上商店 - 客户选择带有颜色“红色”选项的测试产品(可配置产品),则该属性值应显示在报告中。
请提出实现这一目标的最佳方法!
在 Magento 管理员中:在报告/购物车/购物车中的产品下。
我想在“购物车中的产品”网格下添加“颜色”属性列。假设网店中的所有产品都是可配置产品。
IE; 如果从网上商店 - 客户选择带有颜色“红色”选项的测试产品(可配置产品),则该属性值应显示在报告中。
请提出实现这一目标的最佳方法!
复制 \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 文件从核心复制到本地文件夹。 在 magento 1.7 中工作和测试