拆解Magento’s 搜集Totals: An Example
拆解Magento’s 搜集Totals: An Example

拆解Magento’s 搜集Totals: An Example

2013年5月15日发布 in 发展历程
拆解Magento’s 搜集Totals: Orders and Caveats
2013年5月8日
使用我们的新PayPal扩展程序保存Magento中的信用卡
2013年8月15日

以前的条目

在本系列的前几篇文章中,我们 ’我们深入研究了Magento用于计算和显示购物车总额的过程。有了这个结论,我们’ll walk through an example of a 新 total 搜集or, step by step.

I’ll re-emphasize that 搜集Totals can be useful to you 在 more ways than 上e. Implementing a 新 total 搜集or can serve various purposes. For a complete example, however, I’我们将重点放在最简单的应用程序上:创建一个新的,独特的总计,将其添加到其余内容中并与之一起显示。

我不是一个拥有真正合法使用案例的在线商家,我’我将不得不为自己做一个半生半熟的场景做些准备。让’例如,我经营着Cozy Crafts网站,我在那里出售自己的手工工艺品。我网站的一项重要产品是,除了会标或颜色选择的典型方案外,客户还可以给出自定义我的产品的说明。为简单起见,我’我只是要展示一个自定义选项文本区域,客户可以在其中输入说明,我将针对每个SKU(而不是针对每个商品)应用统一的定额申博娱乐,但增加批量时的固定定额费用。

好吧,也许吧’并不是制定价格的最合理方法,但它足以作为“custom surcharge”总。保持示例尽可能简单,我们’假设对于可进行定制的产品,我’只需使用以下命令创建产品的单独版本“-CUSTOM”附加到SKU。希望提供自定义说明的客户会将此版本的产品放入购物车中。

I’ll从模块的完整config.xml开始:

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?XML文件 ="1.0"?>
<config>
    <modules>
        <CozyCrafts_CustomSurcharge>
            <version>1.0.0</version>
        </ CozyCrafts_CustomSurcharge>
    </modules>
    <global>
        <blocks>
            <cozycraft_surcharge>
                <class>CozyCrafts_CustomSurcharge_Block</class>
            </cozycraft_surcharge>
        </blocks>
        <models>
            <cozycraft_surcharge>
                <class>CozyCrafts_CustomSurcharge_Model</class>
                <resourceModel>cozycraft_surcharge_resource</resourceModel>
            </cozycraft_surcharge>
            <cozycraft_surcharge_resource>
                <class>CozyCrafts_CustomSurcharge_Model_Resource</class>
            </ cozycraft_surcharge_resource>
        </models>
        <helpers>
            <cozycraft_surcharge>
                <class>CozyCrafts_CustomSurcharge_Helper</class>
            </cozycraft_surcharge>
        </helpers>
        <resources>
            <cozycraft_surcharge_setup>
                <setup>
                    <module>CozyCrafts_CustomSurcharge</module>
                </setup>
            </ cozycraft_surcharge_setup>
        </resources>
        <fieldsets>
            <sales_convert_quote_address>
                <base_custom_surcharge_amount>
                    <to_order>*</to_order>
                </ base_custom_surcharge_amount>
                <custom_surcharge_amount>
                    <to_order>*</to_order>
                </ custom_surcharge_amount>
            </ 销售量_convert_quote_address>
            <sales_convert_quote_item>
                <base_custom_surcharge_amount>
                    <to_order_item>*</to_order_item>
                </ base_custom_surcharge_amount>
                <custom_surcharge_amount>
                    <to_order_item>*</to_order_item>
                </ custom_surcharge_amount>
            </ 销售量_convert_quote_item>
        </fieldsets>
        <sales>
            <quote>
                <totals>
                    <custom_surcharge>
                        <class>
                            cozycraft_surcharge / 销售量_quote_address_total_customsurcharge
                        </class>
                        <after>小计</after>
                        <renderer>
                            cozycraft_surcharge / checkout_total_customsurcharge
                        </renderer>
                    </custom_surcharge>
                </totals>
            </quote>
            <order_invoice>
                <totals>
                    <custom_surcharge>
                        <class>
                            cozycraft_surcharge / 销售量_order_invoice_total_customsurcharge
                        </class>
                        <after>小计</after>
                    </custom_surcharge>
                </totals>
            </order_invoice>
            <order_creditmemo>
                <totals>
                    <custom_surcharge>
                        <class>
                            cozycraft_surcharge / 销售量_order_creditmemo_total_customsurcharge
                        </class>
                        <after>小计</after>
                    </custom_surcharge>
                </totals>
            </order_creditmemo>
        </sales>
    </global>
    <frontend>
        <layout>
            <updates>
                <cozycrafts_customsurcharge>
                    <file>cozycrafts_customsurcharge.xml</file>
                </ cozycrafts_customsurcharge>
            </updates>
        </layout>
    </frontend>
    <adminhtml>
        <layout>
            <updates>
                <cozycrafts_customsurcharge>
                    <file>cozycrafts_customsurcharge.xml</file>
                </ cozycrafts_customsurcharge>
            </updates>
        </layout>
    </adminhtml>
</config>

的relevant bits, starting from the top:

  • 的“fieldsets”节点负责确保我们新数据库字段中的值从报价传递到订单。
  • 我们的申博娱乐总额及其模型类别在“全球/销售/报价/总计”, “全球/销售/订单发票/总计” and “全球/销售/ order_creditmemo /总计”节点。注意使用<after> to position our 搜集or’s calculations directly 后 the 小计 搜集or. We also define <renderer>在quote节点中,因为我们将对购物车和结帐中的总计使用自定义块。

下一步是在适当的表上添加总计数据库字段。我们’将添加相同的两个字段– “custom_surcharge_amount” and “base_custom_surcharge_amount” –到以下表格:sales_flat_quote_item,sales_flat_quote_address_item(用于多次运输),sales_flat_quote_address,sales_flat_order_item,sales_flat_order,sales_flat_invoice和sales_flat_creditmemo。 (将这些字段同时添加到sales_flat_invoice_item和sales_flat_creditmemo_item是很常见的,但为简单起见,我们在此示例中避免了这一点。)这是位于模块中sql / cozycraft_surcharge_setup / 在stall-1.0.0的安装脚本的摘录。 .php,这对于两个字段和所有表都将重复:

的PHP
1
2
3
4
5
6
7
8
9
10
$安装程序->getConnection()
    ->addColumn($安装程序->getTable('sales / 引用_address'),
            'base_custom_surcharge_amount',
            数组(
                '类型' => Varien_Db_Ddl_Table ::TYPE_DECIMAL,
                '长度' => '12,4',
                '可空的'  => 真正,
                '评论' => “基本自定义申博娱乐”,
            )
     );

接下来我们’再来看我们的申博娱乐报价总模型:

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CozyCrafts_CustomSurcharge_Model_Sales_Quote_Address_Total_Customsurcharge
    延伸 Mage_Sales_Model_Quote_Address_Total_Abstract
{
    受保护的 $ _surchargeTiers = 数组(
        0 => 10,
        5 => 20,
        15 => 30,
    );
    
    上市 功能 __构造()
    {
        $ this->setCode(“ custom_surcharge”);
    }
}

我们的模型扩展了Mage_Sales_Model_Quote_Address_Total_Abstract。在这里,我们’设置了申博娱乐的数量等级。 (例如,如果我们的购物车中有5到14个定制产品,将加收20美元的申博娱乐。)在构造函数中,我们在模型上设置了总代码,与配置中使用的代码匹配。 XML文件。

到目前为止,我们’ve let Magento know where to find our total model and when to use it 在 the sequence of 总数 搜集ion. Immediately 后 the “collect” method is run 上 the 小计 搜集or model, the same method will be called 上 ours. Here is the code that will execute:

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
上市 功能 搜集(Mage_Sales_Model_Quote_Address $ address)
{
    父母::搜集($ address);
    
    前言 ($ this->_getAddressItems($ address) $项目) {
        如果 (preg_match('/ -CUSTOM $ /', $项目->getSku())) {
            $ this->_applyItemSurcharge($项目);
        }
    }
 
    返回 $ this;
}
 
受保护的 功能 _applyItemSurcharge($项目)
{
    $ baseSurcharge = 0;
    前言 ($ this->_surchargeTiers $层 => $ amt) {
        如果 ($项目->getQty() < $层) {
            打破;
        }
        $ baseSurcharge = $ amt;
    }
 
    $申博娱乐 = 法师::应用程式()->getStore()->convertPrice($ baseSurcharge);
    
    $项目->setBaseCustomSurchargeAmount($ baseSurcharge);
    $项目->setCustomSurchargeAmount($申博娱乐);
    
    $ this->_addBaseAmount($ baseSurcharge);
    $ this->_addAmount($申博娱乐);
}

的“collect” method accepts an 在stance of Mage_Sales_Model_Quote_Address, and our call to the 父母 method ensures this is set 上 our model (which is important for the _addAmount methods). From the address, we get the 搜集ion of items and 应用程式ly our surcharge to each that matches the “-CUSTOM”SKU的后缀。应用我们的申博娱乐涉及在项目上同时设置custom_surcharge和base_custom_surcharge,以及使用内置的_addBaseAmount和_addAmount,这将在地址上设置适当的字段并将其与其余总计相加。

有了这些,我们’准备测试将自定义产品添加到我们的购物车中。当我们这样做时,我们应该会看到申博娱乐反映在总计中(尽管本身并未显示–接下来)。查看sales_flat_quote_address和sales_flat_quote_item表,将显示已保存在报价记录中的适当值。接下来是整体模型’s “fetch” method:

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
上市 功能 (Mage_Sales_Model_Quote_Address $ address)
{
    $金额 = $ address->getCustomSurchargeAmount();
    如果 ($金额!=0) {
        $ address->addTotal(数组(
                '码' => $ this->getCode(),
                '标题' => 法师::帮手('cozycraft_surcharge')
                    ->__(“海关申博娱乐”),
                '值' => $金额
        ));
    }
    返回 $ this;
}

回想起那个“fetch”在执行Mage_Checkout_Block_Cart_Totals :: renderTotals的过程中,在每个总模型上调用。这里没有进行任何计算;那些已经发生在“collect.”相反,我们只是返回一个包含总数的数组’s代码以及要显示的标题和值。

如果我们没有’t defined a custom 渲染器 块 在 配置.xml, this would be all that’需要确保我们的总数与其他人一起出现。自从我们这样做以来,我们还有很多事情要做。这里’是我们的代码块,实际上仅是为了定义用于显示我们的申博娱乐的单独模板而存在:

的PHP
1
2
3
4
5
CozyCrafts_CustomSurcharge_Block_Checkout_Total_Customsurcharge
    延伸 Mage_Checkout_Block_Total_Default
{
    受保护的 $ _template = 'cozycraft_surcharge / checkout / total / surcharge.phtml';
}

这是模板,我们’通过添加一些样式和包括一个链接的默认设置进行自定义,该链接将打开一个弹出窗口,其中包含我们的申博娱乐的说明:

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<tr 风格=“颜色:#f00;” >
    <th 科尔斯潘="<?php 回声 $ this->getColspan(); ?>"
        风格="<?php 回声 $ this->getTotal()->getStyle() ?>"
        =“正确”>
        <?php 如果 ($ this->getRenderingArea()
            == $ this->getTotal()->getArea()): ?>
            <strong>
        <?php 万一; ?>
        <?php 回声 $ this->转义(
                $ this->getTotal()->getTitle()
        ); ?><b><br />
        <a 风格=“字体大小:10px”
            href="<?php 回声 法师::帮手('cozycraft_surcharge')->getInfoUrl() ?>"
            =“新窗户”>
            <?php 回声 法师::帮手('cozycraft_surcharge')
                ->__(“为什么我们要收取这笔费用?”)?>
        </a></b>
        <?php 如果 ($ this->getRenderingArea()
            == $ this->getTotal()->getArea()): ?>
            </strong>
        <?php 万一; ?>
    </th>
    <td 风格="<?php 回声 $ this->getTotal()->getStyle() ?>"
        =“正确”>
        <?php 如果 ($ this->getRenderingArea()
            == $ this->getTotal()->getArea()): ?>
        <strong>
        <?php 万一; ?>
        <?php 回声 $ this->帮手('查看')
            ->formatPrice($ this->getTotal()->getValue()) ?>
        <?php 如果 ($ this->getRenderingArea()
            == $ this->getTotal()->getArea()): ?>
        </strong>
        <?php 万一; ?>
    </td>
</tr>

Now we can see our total displayed 在 the cart. 的following is what is shown when we have 2 of 上e custom product (for a surcharge of $10) and 5 of another (for a surcharge of $20) 在 the cart:

自定义总计

的“fieldset”我们在config.xml中看到的节点将负责将申博娱乐从报价项传递到订单项,并从报价地址传递到订单本身。为了使申博娱乐实际显示在订单确认电子邮件中和管理员中,我们’我们必须完成布局更新,但是在此之前,我们’还将分别查看发票和贷记凭证总计模型。

对于开票,我们决定使用以下规则:对于每个订单商品,我们只会在一次开具发票后开具全部申博娱乐发票 充分数量已开票。像这样的策略通常可以使按项目跟踪申博娱乐金额成为一个好主意,但我们’我们将只对整个发票进行跟踪,以使自己满意。这里’是我们的发票总类。 (请注意,使用我们自己的逻辑来确定是否’是最后一张发票,而不是依赖“isLast”,如上一篇有关发票和贷记凭证的文章所述。)

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
CozyCrafts_CustomSurcharge_Model_Sales_Order_Invoice_Total_Customsurcharge
    延伸 Mage_Sales_Model_Order_Invoice_Total_Abstract
{
    上市 功能 搜集(Mage_Sales_Model_Order_Invoice $发票)
    {
        $发票->setCustomSurchargeAmount(0);
        $发票->setBaseCustomSurchargeAmount(0);
 
        //获取我们已经开票的任何金额
        $ prevInvoiceCustomSurchargeAmt = 0;
        $ prevInvoiceBaseCustomSurchargeAmt = 0;
        前言 ($发票->getOrder()->getInvoiceCollection() $ prev发票) {
            如果 ($ prev发票->getCustomSurchargeAmount() && !$ prev发票->已取消()) {
                $ prevInvoiceCustomSurchargeAmt + = $ prev发票->getCustomSurchargeAmount();
                $ prevInvoiceBaseCustomSurchargeAmt + = $ prev发票->getBaseCustomSurchargeAmount();
            }
        }
 
        $ customSurchargeAmt = 0;
        $ baseCustomSurchargeAmt = 0;
        $ 在voiceIsLast = 真正;
        前言 ($发票->getAllItems() $项目) {
            $ orderItem = $项目->getOrderItem();
            如果 ($ orderItem->isDummy()) {
                继续;
            }
 
            如果 (!$项目->最后()) {
                $ 在voiceIsLast = ;
            }
 
            $ orderItemQty = $ orderItem->getQtyOrdered();
            $ orderItemPrevInvoiced = $ orderItem->getQtyInvoiced();
 
            //如果要开票此项目的最后数量,请开票申博娱乐
            如果 (($ orderItemPrevInvoiced + $项目->getQty()) == $ orderItemQty) {
                $ customSurchargeAmt + = $ orderItem->getCustomSurchargeAmount();
                $ baseCustomSurchargeAmt + = $ orderItem->getBaseCustomSurchargeAmount();
            }
        }
        //为了安全起见,如果这是最后一张发票,请用全部剩余申博娱乐覆盖
        如果 ($ 在voiceIsLast) {
            $ customSurchargeAmt = $发票->getOrder()->getCustomSurchargeAmount() - $ prevInvoiceCustomSurchargeAmt;
            $ baseCustomSurchargeAmt = $发票->getOrder()->getBaseCustomSurchargeAmount() - $ prevInvoiceBaseCustomSurchargeAmt;
        }
 
        $发票->setCustomSurchargeAmount($ customSurchargeAmt);
        $发票->setBaseCustomSurchargeAmount($ baseCustomSurchargeAmt);
 
        $发票->setGrandTotal($发票->getGrandTotal()+$ customSurchargeAmt);
        $发票->setBaseGrandTotal($发票->getBaseGrandTotal()+$ baseCustomSurchargeAmt);
 
        返回 $ this;
    }
}

最后,我们需要处理贷项凭证计算。我们的退款逻辑比发票更简单:’除非整个订单已退还,否则我们将认为我们的申博娱乐不予退还。 (我们’在类似的现实生活场景中,管理员可能希望选择是否在最终贷项凭单上退还这笔款项,但这将需要对管理表单本身进行一些自定义。当然,如果我们只是希望在所有情况下都不退还申博娱乐,’根本不需要一个总模型。)我们的贷项凭证总模型:

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
CozyCrafts_CustomSurcharge_Model_Sales_Order_Creditmemo_Total_Customsurcharge
    延伸 Mage_Sales_Model_Order_Creditmemo_Total_Abstract
{
    上市 功能 搜集(Mage_Sales_Model_Order_Creditmemo $ creditmemo)
    {
        $ creditmemo->setCustomSurchargeAmount(0);
        $ creditmemo->setBaseCustomSurchargeAmount(0);
 
        //为安全起见,请获取我们已经退还的任何金额(不可能!)
        //这样我们可以确保我们退还的款项不多于费用
        $ prevCreditmemoCustomSurchargeAmt = 0;
        $ prevCreditmemoBaseCustomSurchargeAmt = 0;
        前言 ($ creditmemo->getOrder()->getCreditmemosCollection() $ prevCreditmemo) {
            如果 ($ prevCreditmemo->getCustomSurchargeAmount() && ($ prevCreditmemo->getState() != Mage_Sales_Model_Order_Creditmemo ::STATE_CANCELED)) {
                $ prevCreditmemoCustomSurchargeAmt + = $ prevCreditmemo->getCustomSurchargeAmount();
                $ prevCreditmemoBaseCustomSurchargeAmt + = $ prevCreditmemo->getBaseCustomSurchargeAmount();
            }
        }
 
        $ allowedAmount          = $ creditmemo->getOrder()->getCustomSurchargeAmount() - $ prevCreditmemoCustomSurchargeAmt;
        $ baseAllowedAmount      = $ creditmemo->getOrder()->getBaseCustomSurchargeAmount() - $ prevCreditmemoBaseCustomSurchargeAmt;
 
        //遍历项目以查找这是否是最后一个贷项通知单
        $ creditmemoIsLast = 真正;
        前言 ($ creditmemo->getAllItems() $项目) {
            $ orderItem = $项目->getOrderItem();
            如果 ($ orderItem->isDummy()) {
                继续;
            }
 
            如果 (!$项目->最后()) {
                $ creditmemoIsLast = ;
                打破;
            }
        }
 
        //仅在整个订单都已退款的情况下,才退还申博娱乐
        如果 ($ creditmemoIsLast) {
            $ creditmemo->setCustomSurchargeAmount($ allowedAmount);
            $ creditmemo->setBaseCustomSurchargeAmount($ baseAllowedAmount);
 
            $ creditmemo->setGrandTotal($ creditmemo->getGrandTotal()+$ allowedAmount);
            $ creditmemo->setBaseGrandTotal($ creditmemo->getBaseGrandTotal()+$ baseAllowedAmount);
        }
 
        返回 $ this;
    }
}

所有的’剩下的是定义将用于显示订单,发票和贷记凭证总计的模块类,并将其添加到布局XML的适当区域中。

值得庆幸的是,我们可以在所有三种情况下使用相同的类。与块’s “getSource” method, we’ll 取 the source model from the 父母 块, which may be an order, 在voice, or credit memo. Our total amount is 取ed from any of the three with the same method, so we won’不管返回的是什么。

的PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CozyCrafts_CustomSurcharge_Block_Sales_Order_Totals_Customsurcharge
    延伸 Mage_Core_Block_Abstract
{
    上市 功能 getSource()
    {
        返回 $ this->getParentBlock()->getSource();
    }
 
    / **
    *将此总计加到父级
     * /
    上市 功能 初始化总计()
    {
        如果 ((浮动)$ this->getSource()->getCustomSurchargeAmount() == 0) {
            返回 $ this;
        }
        总计$ = Varien_Object(数组(
            '码'  => “ custom_surcharge”,
            '领域' => “ custom_surcharge_amount”,
            '值' => $ this->getSource()->getCustomSurchargeAmount(),
            '标签' => $ this->__(“海关申博娱乐”)
        ));
        $ this->getParentBlock()->addTotalBefore(总计$, '运输');
        返回 $ this;
    }
}

我们的布局XML将很长。它’一个小块,但需要在很多地方添加。至少我们可以一次定义每个布局更新,然后在一行中多次应用它们。这里’s的craftcrafts_customsurcharge.xml的前端版本:

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?XML文件 ="1.0"?>
<layout =“ 0.1.0”>
    <cozycrafts_customsurcharge_add_order_total>
        <reference 名称=“ order_totals”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_order_total>
 
    <cozycrafts_customsurcharge_add_invoice_total>
        <reference 名称=“发票总额”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_invoice_total>
 
    <cozycrafts_customsurcharge_add_creditmemo_total>
        <reference 名称=“ creditmemo_totals”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_creditmemo_total>
 
    <sales_order_view>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </sales_order_view>
    <sales_order_invoice>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </sales_order_invoice>
    <sales_order_creditmemo>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ 销售量_order_creditmemo>
    <sales_order_print>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </sales_order_print>
    <sales_order_print发票>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ 销售量_order_print发票>
    <sales_order_printcreditmemo>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ 销售量_order_printcreditmemo>
    <sales_email_order_items>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </ 销售量_email_order_items>
    <sales_email_order_invoice_items>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ 销售量_email_order_invoice_items>
    <sales_email_order_creditmemo_items>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ 销售量_email_order_creditmemo_items>
    <sales_guest_view>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </sales_guest_view>
    <sales_guest_invoice>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </sales_guest_invoice>
    <sales_guest_creditmemo>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ 销售量_guest_creditmemo>
    <sales_guest_print>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </sales_guest_print>
    <sales_guest_print发票>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ 销售量_guest_print发票>
    <sales_guest_printcreditmemo>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ 销售量_guest_printcreditmemo>
</layout>

和这里’s the admin 版:

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?XML文件 ="1.0"?>
<layout =“ 0.1.0”>
    <cozycrafts_customsurcharge_add_order_total>
        <reference 名称=“ order_totals”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_order_total>
 
    <cozycrafts_customsurcharge_add_invoice_total>
        <reference 名称=“发票总额”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_invoice_total>
 
    <cozycrafts_customsurcharge_add_creditmemo_total>
        <reference 名称=“ creditmemo_totals”>
            <block 类型=“ cozycraft_surcharge / 销售量_order_totals_customsurcharge” 名称=“ total_custom_surcharge” />
        </reference>
    </ cozycrafts_customsurcharge_add_creditmemo_total>
 
    <adminhtml_sales_order_view>
        <update 处理=“ cozycrafts_customsurcharge_add_order_total” />
    </ adminhtml_sales_order_view>
    <adminhtml_sales_order_invoice_new>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ adminhtml_sales_order_invoice_new>
    <adminhtml_sales_order_invoice_updateqty>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ adminhtml_sales_order_invoice_updateqty>
    <adminhtml_sales_order_invoice_view>
        <update 处理=“ cozycrafts_customsurcharge_add_invoice_total” />
    </ adminhtml_sales_order_invoice_view>
    <adminhtml_sales_order_creditmemo_new>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ adminhtml_sales_order_creditmemo_new>
    <adminhtml_sales_order_creditmemo_updateqty>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ adminhtml_sales_order_creditmemo_updateqty>
    <adminhtml_sales_order_creditmemo_view>
        <update 处理=“ cozycrafts_customsurcharge_add_creditmemo_total” />
    </ adminhtml_sales_order_creditmemo_view>
</layout>

至此,我们的模块已完成。我们’ve successfully 应用程式lied our own 海关申博娱乐 to the cart and made sure it makes it through to the final cart. After seeing the complexity of the code Magento implements to 处理 总数, the volume of code we actually had to write to implement our own actually doesn’t seem half bad!

I hope this series has done something to bolster your confidence 在 dealing with the 总数 搜集ion process. 的more you deal with it, the less you’当客户感到恐惧时’的要求涉及自定义总计,而您越不容易’ll resort to a hack when a 新 total 搜集or might be just the thing to save the day!

8 评论s

  1. 马辛 说:

    嘿克里斯,
    很棒的文章!这对我处理额外的申博娱乐很有帮助。
    But I have encountered 上e problem. I need Magento to calculate the surcharge tax and add it to the final tax amount. 我尝试更改的值和我的模块config.xml中的标签, but… still nothing 🙁

    请问你能帮帮我吗?

    • 马辛 说:

      应该是:“我尝试更改的值‘before’ and ‘after’我的模块config.xml中的标签”

    • 克里斯·南宁加 说:

      从它的声音,我’m not sure a separate total 搜集or is really what you’re looking for. (Might make more sense to override the tax 搜集or.) But at any rate, simply making your 搜集or run 后 the native tax 搜集or won’t be enough; 在side your 搜集or you’d need to 取 and directly manipulate the native tax total fields.

      干杯!

发表评论 取消回复

您的电子邮件地址不会被公开。 必需的地方已做标记 *

该网站使用Akismet减少垃圾邮件。 了解如何处理您的评论数据.

最近的帖子查看全部
2020年10月22日
通过 阿什莉·科利弗 商业见解, 优雅的骆马 2020年10月22日
毫无疑问,2020年是历史性的一年。火灾,全球大流行,暴动,老虎王等’只是冰山一角。如 […]