Magento 模块更改仪表板图

时间:2023-01-20
本文介绍了Magento 模块更改仪表板图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这篇文章 更改 Magento 1.7/1.12 版本中的仪表盘图表 以允许处理"订单的销售显示在仪表盘图表上.我的文件位于正确的目录下方和内,并且在 config>advanced 中显示为活动状态.我还重新索引、刷新了缓存和刷新了生命周期统计信息.我在日志中没有看到任何错误.你能看出有什么问题吗?我有 firegento 并启用了日志记录,但这也不起作用.

仪表板上的收入总额似乎是正确的,但它没有反映在时间线图上.例如,上午 10 点可能有 30 个条款的净订单 2000 美元,但它没有显示在时间图上.谁可以修复下面的脚本以反映我的时间表,则悬赏赏金!

CaitlinHavener/Dashboard/etc/config.xml:

<配置><模块><CaitlinHavener_Dashboard><version>1.0</version></CaitlinHavener_Dashboard></模块><全球><模型><CaitlinHavener_Dashboard><class>CaitlinHavener_Dashboard_Model</class></CaitlinHavener_Dashboard><reports_resource><重写><order_collection>CaitlinHavener_Dashboard_Model_Reports_Resource_Order_Collection</order_collection></rewrite></reports_resource></模型></全球></config>

CaitlinHavener/Dashboard/Model/Reports/Resource/Order/Collection.php

 setMainTable('销售/订单');$adapter = $this->getConnection();/*** 重置所有列,因为结果将仅按 'created_at' 字段分组*/$this->getSelect()->reset(Zend_Db_Select::COLUMNS);/* $expression = sprintf('%s - %s - %s - (%s - %s - %s)',$adapter->getIfNullSql('main_table.base_total_invoiced', 0),$adapter->getIfNullSql('main_table.base_tax_invoiced', 0),$adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),$adapter->getIfNullSql('main_table.base_total_refunded', 0),$adapter->getIfNullSql('main_table.base_tax_refunded', 0),$adapter->getIfNullSql('main_table.base_shipping_refunded', 0));*/$expression = sprintf('%s - %s - %s - (%s - %s - %s)',$adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'),$adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'),$adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'),$adapter->getIfNullSql('main_table.base_total_refunded', 0),$adapter->getIfNullSql('main_table.base_tax_refunded', 0),$adapter->getIfNullSql('main_table.base_shipping_refunded', 0));如果($isFilter == 0){$this->getSelect()->columns(array()'收入' =>新 Zend_Db_Expr(sprintf('SUM((%s) * %s)', $表达式,$adapter->getIfNullSql('main_table.base_to_global_rate', 0)))));} 别的 {$this->getSelect()->columns(array()'收入' =>new Zend_Db_Expr(sprintf('SUM(%s)', $expression))));}$dateRange = $this->getDateRange($range, $customStart, $customEnd);$tzRangeOffsetExpression = $this->_getTZRangeOffsetExpression($range, 'created_at', $dateRange['from'], $dateRange['to']);$this->getSelect()-> 列(数组('数量' =>'COUNT(main_table.entity_id)','范围' =>$tzRangeOffsetExpression,))//转炉修改->where('main_table.state NOT IN (?)', array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,//Mage_Sales_Model_Order::STATE_NEW))//EOF修改-> order('range', Zend_Db_Select::SQL_ASC)-> 组($tzRangeOffsetExpression);$this->addFieldToFilter('created_at', $dateRange);返回 $this;}受保护的函数 _calculateTotalsLive($isFilter = 0){$this->setMainTable('销售/订单');$this->removeAllFieldsFromSelect();$adapter = $this->getConnection();//$baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_grand_total', 0);//$baseTotalRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0);//$baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_amount', 0);//$baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);//$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_amount', 0);//$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);//$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);$baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total');//这将检查是否没有发票,它将根据总计计算(因此当您生成和发票时,您也不会遇到数字问题)$baseTotalRefunded = $adapter->getIfNullSql('main_table.base_total_refunded', 0);$baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount');//税收也一样$baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount');//与这里相同的运输$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);$revenueExp = sprintf('%s - %s - %s - (%s - %s - %s)',$baseTotalInvoiced,$baseTaxInvoiced,$baseShippingInvoiced,$baseTotalRefunded,$baseTaxRefunded,$baseShippingRefunded);$taxExp = sprintf('%s - %s', $baseTaxInvoiced, $baseTaxRefunded);$shippingExp = sprintf('%s - %s', $baseShippingInvoiced, $baseShippingRefunded);如果($isFilter == 0){$rateExp = $adapter->getIfNullSql('main_table.base_to_global_rate', 0);$this->getSelect()->columns(大批('收入' =>new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $revenueExp, $rateExp)),'税' =>new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $taxExp, $rateExp)),'运输' =>new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $shippingExp, $rateExp))));} 别的 {$this->getSelect()->columns(大批('收入' =>new Zend_Db_Expr(sprintf('SUM(%s)', $revenueExp)),'税' =>new Zend_Db_Expr(sprintf('SUM(%s)', $taxExp)),'运输' =>new Zend_Db_Expr(sprintf('SUM(%s)', $shippingExp))));}$this->getSelect()->columns(array()'数量' =>'COUNT(main_table.entity_id)'))->where('main_table.state NOT IN (?)', array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,//Mage_Sales_Model_Order::STATE_NEW));返回 $this;}}?>

解决方案

您必须了解 Magento 中的 Order 流程​​,才能完全了解图表的填充方式

  1. 订单作为新订单(如后付款订单 - 货到付款,...)或待处理订单(信用卡订单或贝宝等.所有在线支付方式)进入商店.
    • 可以在这一步取消订单(因为没有生成发票).
  2. 在线支付的情况下,支付成功(因此订单已开具发票 - 发票已生成).
  3. 订单在开具发票后发货(生成发货).
  4. 订单已退款(部分或全部),因此生成贷项通知单.

现在,如果您查看前面的步骤,您将看到如果订单处于 NEW 和 CANCELED STATE(不是状态),则不应计算收入

应在订单开具发票时计算(这样您将获得收入、运费和退款)

所以要统计收入和图表中NEW STATE的订单重写方法

<块引用>

app/code/core/Mage/Reports/Model/Resource/Order/Collection.php/***计算总计实时报告** @param int $isFilter* @return Mage_Reports_Model_Resource_Order_Collection*/受保护的函数 _calculateTotalsLive($isFilter = 0){}

//第 430 行->where('main_table.state NOT IN (?)', array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,Mage_Sales_Model_Order::STATE_NEW//注释此行));

所以现在如果你评论这一行,订单将被计入(订单图表)

但是仍然没有计算总数(因为没有发票/发货/退款)

因此,您需要将计算过程从使用发票金额更改为仅在发票之前使用 TOTALS 通过小的更改,您可以毫无错误地实现您想要的代码下面的代码

更改行(390 及以下为如下所示):

$baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total');//这将检查是否没有发票,它将根据总计计算(因此当您生成和发票时,您也不会遇到数字问题)$baseTotalRefunded = $adapter->getIfNullSql('main_table.base_total_refunded', 0);$baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount');//税收也一样$baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount');//与这里相同的运输$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);

所以在简单的答案中,解决方案没有改变计算方式,但解决方案改变了计算的默认值

遵循此更改,您将得到您真正想要的:)

I am following along with this post Change the Dashboard Graph in version 1.7/1.12 of Magento to allow the sales of "processing" orders to show up on the dashboard graph. My files are below and within the right directories as well as showing up as active in config>advanced. I have also reindexed, refreshed cache, and refreshed lifetime statistics. I am seeing no errors in the logs. Can you see what is wrong? I have firegento and have enabled logging, but that's not working either.

EDIT: The Revenue total on the dashboard seems correct, but its not reflecting on the timeline graph. For example there may be a net 30 terms order of $2000 at 10AM but it doesn't show on the time graph. Bounty for whoever can fix the script below to reflect on the timeline for me!

CaitlinHavener/Dashboard/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <CaitlinHavener_Dashboard>
            <version>1.0</version>
        </CaitlinHavener_Dashboard>
    </modules>
    <global>
        <models>
            <CaitlinHavener_Dashboard>
                <class>CaitlinHavener_Dashboard_Model</class>
            </CaitlinHavener_Dashboard>
            <reports_resource>
                <rewrite>
                    <order_collection>CaitlinHavener_Dashboard_Model_Reports_Resource_Order_Collection</order_collection>
                </rewrite>
            </reports_resource>
        </models>
    </global>
</config>

CaitlinHavener/Dashboard/Model/Reports/Resource/Order/Collection.php

    <?php
/**
 * Show all orders, not only the invoiced one
 */
class CaitlinHavener_Dashboard_Model_Reports_Resource_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection
{
    protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilter = 0)
    {
        $this->setMainTable('sales/order');
        $adapter = $this->getConnection(); 
        /**
         * Reset all columns, because result will group only by 'created_at' field
         */
        $this->getSelect()->reset(Zend_Db_Select::COLUMNS);

       /*  $expression = sprintf('%s - %s - %s - (%s - %s - %s)',
            $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
            $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
            $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
            $adapter->getIfNullSql('main_table.base_total_refunded', 0),
            $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
            $adapter->getIfNullSql('main_table.base_shipping_refunded', 0)
        ); */

        $expression = sprintf('%s - %s - %s - (%s - %s - %s)',
            $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'),
            $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'),
            $adapter->getIfNullSql('main_table.base_shipping_invoiced',  'main_table.base_shipping_amount'),
            $adapter->getIfNullSql('main_table.base_total_refunded', 0),
            $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
            $adapter->getIfNullSql('main_table.base_shipping_refunded', 0)
        );


        if ($isFilter == 0) {
            $this->getSelect()->columns(array(
                'revenue' => new Zend_Db_Expr(
                    sprintf('SUM((%s) * %s)', $expression,
                        $adapter->getIfNullSql('main_table.base_to_global_rate', 0)
                    )
                 )
            ));
        } else {
            $this->getSelect()->columns(array(
                'revenue' => new Zend_Db_Expr(sprintf('SUM(%s)', $expression))
            ));
        }

        $dateRange = $this->getDateRange($range, $customStart, $customEnd);

        $tzRangeOffsetExpression = $this->_getTZRangeOffsetExpression(
            $range, 'created_at', $dateRange['from'], $dateRange['to']
        );

        $this->getSelect()
            ->columns(array(
                'quantity' => 'COUNT(main_table.entity_id)',
                'range' => $tzRangeOffsetExpression,
            ))
            //BOF modification
           ->where('main_table.state NOT IN (?)', array(
                Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
               // Mage_Sales_Model_Order::STATE_NEW
               )
            )
            //EOF modification
            ->order('range', Zend_Db_Select::SQL_ASC)
            ->group($tzRangeOffsetExpression);

        $this->addFieldToFilter('created_at', $dateRange);

        return $this;
    }

    protected function _calculateTotalsLive($isFilter = 0)
    {
        $this->setMainTable('sales/order');
        $this->removeAllFieldsFromSelect();

        $adapter = $this->getConnection();

        // $baseTotalInvoiced    = $adapter->getIfNullSql('main_table.base_grand_total', 0);
        // $baseTotalRefunded    = $adapter->getIfNullSql('main_table.base_discount_refunded', 0);
        // $baseTaxInvoiced      = $adapter->getIfNullSql('main_table.base_tax_amount', 0);
        // $baseTaxRefunded      = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);
        // $baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_amount', 0);
        // $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);
        // $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);

        $baseTotalInvoiced    = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'); // This will check if there is no invoice it will calculate based on the grand totals ( so when you generate and invoice u will have no issues with the numbers also )
$baseTotalRefunded    = $adapter->getIfNullSql('main_table.base_total_refunded', 0);
$baseTaxInvoiced      = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'); // Same here for taxes
$baseTaxRefunded      = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);
$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'); // Same here for shipping 
$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);

        $revenueExp = sprintf('%s - %s - %s - (%s - %s - %s)',
            $baseTotalInvoiced,
            $baseTaxInvoiced,
            $baseShippingInvoiced,
            $baseTotalRefunded,
            $baseTaxRefunded,
            $baseShippingRefunded
        );
        $taxExp = sprintf('%s - %s', $baseTaxInvoiced, $baseTaxRefunded);
        $shippingExp = sprintf('%s - %s', $baseShippingInvoiced, $baseShippingRefunded);

        if ($isFilter == 0) {
            $rateExp = $adapter->getIfNullSql('main_table.base_to_global_rate', 0);
            $this->getSelect()->columns(
                array(
                    'revenue'  => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $revenueExp, $rateExp)),
                    'tax'      => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $taxExp, $rateExp)),
                    'shipping' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $shippingExp, $rateExp))
                )
            );
        } else {
            $this->getSelect()->columns(
                array(
                    'revenue'  => new Zend_Db_Expr(sprintf('SUM(%s)', $revenueExp)),
                    'tax'      => new Zend_Db_Expr(sprintf('SUM(%s)', $taxExp)),
                    'shipping' => new Zend_Db_Expr(sprintf('SUM(%s)', $shippingExp))
                )
            );
        }


        $this->getSelect()->columns(array(
            'quantity' => 'COUNT(main_table.entity_id)'
        ))
        ->where('main_table.state NOT IN (?)', array(
            Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
            //Mage_Sales_Model_Order::STATE_NEW
            )
         );

        return $this;
    }

}
?>

解决方案

You have to understand the Order process in Magento so you can fully understand how the chart being populated

  1. Order come to the Store as new Order ( like post paid orders - Cash on Delivery, ... ) or Pending order ( credit card orders or paypal etc.. all online payment methods ).
    • Order can be canceled at this step ( as no invoice generated ).
  2. In case of online payment, payment gone through successfully ( So the order is invoiced - invoice generated ).
  3. Order Shipped after being invoiced ( Shipment is generated ).
  4. Order refunded ( partial or complete ) so credit memos generated.

Now if you look at the previous steps and you will see that the Revenue not supposed to be calculated if the Order is in NEW and CANCELED STATE ( not status )

It should be calculated when the Order gets invoiced ( so you will get the revenue and shipping fees and the refunds )

So to count the orders in NEW STATE in the revenue and the graph Override the method

app/code/core/Mage/Reports/Model/Resource/Order/Collection.php
/**
 * Calculate totals live report
 *
 * @param int $isFilter
 * @return Mage_Reports_Model_Resource_Order_Collection
 */
protected function _calculateTotalsLive($isFilter = 0){}

   // Line 430
    ->where('main_table.state NOT IN (?)', array(
        Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
        Mage_Sales_Model_Order::STATE_NEW // Comment this line 
        )
     );

So now if you comment this line the order Will be counted in the ( ORDERS chart graph )

but the totals is still not calculated ( because there is no invoice / shipments / refunds )

So you need to change the calculation process from using the invoiced amount to use the TOTALS only even before invoice With small changes you can achieve what you want without mistakes Code below

Change the lines ( 390 and below to be like the following ):

$baseTotalInvoiced    = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'); // This will check if there is no invoice it will calculate based on the grand totals ( so when you generate and invoice u will have no issues with the numbers also )
$baseTotalRefunded    = $adapter->getIfNullSql('main_table.base_total_refunded', 0);
$baseTaxInvoiced      = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'); // Same here for taxes
$baseTaxRefunded      = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);
$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'); // Same here for shipping 
$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);

So In simple answer the solution is not changed the Way of calculation, But the solution change the Default values of the calculations

Follow this changes and you will get what you exactly want :)

这篇关于Magento 模块更改仪表板图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:保存“特价"的表在哪里?在 Magento 中? 下一篇:在 T-SQL 中反序列化 PHP 序列化数据

相关文章

最新文章