被卖我期待加入到产品格列(在管理方面予以明确),以显示有多少次这样的产品已经销往显示号码。以下是我从其他几个职位拼凑在一起后至今:的Magento:次的产品在产品网格
在应用程序/代码/本地/命名空间/ Qtysold /座/ Adminhtml /目录/产品/ Grid.php
<?php
class Namespace_Qtysold_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
/* Overwritten to be able to add custom columns to the product grid. Normally
* one would overwrite the function _prepareCollection, but it won't work because
* you have to call parent::_prepareCollection() first to get the collection.
*
* But since parent::_prepareCollection() also finishes the collection, the
* joins and attributes to select added in the overwritten _prepareCollection()
* are 'forgotten'.
*
* By overwriting setCollection (which is called in parent::_prepareCollection()),
* we are able to add the join and/or attribute select in a proper way.
*
*/
public function setCollection($collection)
{
/* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
$store = $this->_getStore();
if ($store->getId() && !isset($this->_joinAttributes['qty_sold'])) {
$collection->joinAttribute(
'qty_sold',
'reports/product_collection',
'entity_id',
null,
'left',
$store->getId()
);
}
else {
$collection->addAttributeToSelect('qty_sold');
}
echo "<pre>";
var_dump((string) $collection->getSelect());
echo "</pre>";
parent::setCollection($collection);
}
protected function _prepareColumns()
{
$store = $this->_getStore();
$this->addColumnAfter('qty_sold',
array(
'header'=> Mage::helper('catalog')->__('Qty Sold'),
'type' => 'number',
'index' => 'qty_sold',
),
'price'
);
return parent::_prepareColumns();
}
}
一对夫妇这里的东西。 1)$ store->的getId()返回0,所以它永远不会成第一块setCollection,是正确的行为,因为它是管理区域? 2)如果我强迫joinAttribute运行,它会导致它有点意料之中的,因为报告没有出现真正成为一个实体异常(无效的实体...),但我不是在这整个实体企业真正清楚。 3)在其他例子(像这样的:http://www.creativemediagroup.net/creative-media-web-services/magento-blog/30-show-quantity-sold-on-product-page-magento),他们使用的是这样的:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addOrderedQty($from, $to, true)
->addAttributeToFilter('sku', $sku)
->setOrder('ordered_qty', 'desc')
->getFirstItem();
而且我不知道是否有任何方式“加盟”本报告/ product_collection或是否有什么办法重新创建其“addOrderedQty”数据?
这是Magento的1.7。我可以根据需要提供更多细节。我是Magento开发的初学者,所以任何帮助(包括学习资源)都将不胜感激。谢谢!