0
我在Magento上與此打架。Magento - 如何通過產品獲得收入
我添加到產品有序報告幾列,我想有一個與該特定產品的總收入。
檢查這個例子:http://awesomescreenshot.com/0e94d0yi29
的總收入數字是錯的,我做了每個訂單的審查,它不是這個數字。
我在做什麼錯了?下面的代碼:
網站>應用程序>代碼>核心>法師> Adminhtml>塊>報告>產品>售
class Mage_Adminhtml_Block_Report_Product_Sold_Grid extends Mage_Adminhtml_Block_Report_Grid
{
/**
* Sub report size
*
* @var int
*/
protected $_subReportSize = 0;
/**
* Initialize Grid settings
*
*/
public function __construct()
{
parent::__construct();
$this->setId('gridProductsSold');
}
protected function _afterLoadCollection()
{
$totalObj = new Mage_Reports_Model_Totals();
$this->setTotals($totalObj->countTotals($this));
}
/**
* Prepare collection object for grid
*
* @return Mage_Adminhtml_Block_Report_Product_Sold_Grid
*/
protected function _prepareCollection()
{
parent::_prepareCollection();
$this->getCollection()
->initReport('reports/product_sold_collection');
return $this;
}
protected function _getStore()
{
$storeId = (int) $this->getRequest()->getParam('store', 0);
return Mage::app()->getStore($storeId);
}
/**
* Prepare Grid columns
*
* @return Mage_Adminhtml_Block_Report_Product_Sold_Grid
*/
protected function _prepareColumns()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
$collection->addAttributeToSelect('producer_tag');
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$collection->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
}
if ($store->getId()) {
//$collection->setStoreId($store->getId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(
'name',
'catalog_product/name',
'entity_id',
null,
'inner',
$adminStore
);
$collection->joinAttribute(
'custom_name',
'catalog_product/name',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'status',
'catalog_product/status',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'visibility',
'catalog_product/visibility',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'price',
'catalog_product/price',
'entity_id',
null,
'left',
$store->getId()
);
}
else {
$collection->addAttributeToSelect('price');
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
}
$this->addColumn('name', array(
'header' =>Mage::helper('reports')->__('Product Name'),
'index' =>'order_items_name'
));
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->addColumn('set_name',
array(
'header'=> Mage::helper('catalog')->__('Category'),
'width' => '150px',
'index' => 'attribute_set_id',
'type' => 'options',
'options' => $sets,
));
$this->addColumn('producer_tag',
array(
'header'=> Mage::helper('catalog')->__('Producer Tag'),
'width' => '150px',
'index' => 'producer_tag',
'type' => 'text'
));
$store = $this->_getStore();
$this->addColumn('price',
array(
'header'=> Mage::helper('catalog')->__('Price'),
'type' => 'price',
'currency_code' => $store->getBaseCurrency()->getCode(),
'index' => 'price',
));
$this->addColumn('ordered_qty', array(
'header' =>Mage::helper('reports')->__('Quantity Ordered'),
'width' =>'120px',
'align' =>'right',
'index' =>'ordered_qty',
'total' =>'sum',
'type' =>'number'
));
$currencyCode = $this->getCurrentCurrencyCode();
$rate = $this->getRate($currencyCode);
$this->addColumn('revenue',
array(
'header'=> Mage::helper('catalog')->__('Revenue (Only Complete Orders)'),
'type' => 'currency',
'index' => 'price',
'total' => 'sum',
'type' => 'currency',
'currency_code' => $currencyCode,
'rate' => $rate,
));
$this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV'));
$this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel XML'));
return parent::_prepareColumns();
}
}
不要誤會我在做什麼錯在這裏。
我的目標是報告我對每件產品做了多少錢。
任何幫助或理想將受到歡迎。
在此先感謝。
在另一個線程中看到了你的答案,但我正在按照Product Ordered當前報告進行操作,但正如我與其他開發人員討論的那樣,並不建議這樣做。 我想要一份包含一系列日期的產品報告,所有與細節一起銷售的產品。但我正在與開發人員進行覈對。 非常感謝您的反饋! – Soledawn 2015-02-10 18:44:17
這是毫無意義的,如果最終的價格變化總是會爲每個人做。 – 2016-11-14 10:43:03