【发布时间】:2017-03-21 17:06:04
【问题描述】:
我在 Magento 1.9 中有简单的产品,我可以合并发货,并希望根据 sku 在结帐时更改总运费(以及在购物车视图中进行运费估算等计算)。例如,如果购买了一个或两个具有正确 sku 的小部件,它们的总重量为 1 磅。如果购买了 3 到 5 个具有正确 sku 的小部件,它们的总重量为 2 磅等。如果包含所有物品,Tablerates 可以处理这个问题。但是,我必须将其限制为由 sku 确定的某些项目。
所以目前在 Magento 中,每件商品的重量为 1 磅,总重量为 number of items * 1 lbs。我找到了显示总重量或在数据库中更新项目重量的答案,但没有一个能满足这些要求。我对 Magento 非常陌生,并且正在努力实现这一目标。如果您回复建议的代码更改,能否具体说明应该编辑的文件位置?
编辑
按照 Mladen Ilić 的建议,我提出了以下代码,用于计算事件 sales_quote_collect_totals_after 事件的总权重。 如何将调整后的新重量发送给 Magneto 以在结帐时使用?
/app/etc/modules/Weight_Extension.xml
<?xml version="1.0"?>
<config>
<modules>
<Weight_Extension>
<codePool>local</codePool>
<active>true</active>
</Weight_Extension>
</modules>
</config>
/app/code/locale/Weight/Extension/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Weight_Extension>
<version>0.0.1</version>
</Weight_Extension>
</modules>
<global>
<models>
<weight_extension>
<class>Weight_Extension_Model</class>
</weight_extension>
</models>
<events>
<sales_quote_collect_totals_after>
<observers>
<weight_extension>
<class>weight_extension/observer</class>
<method>adjustTotalWeight</method>
</weight_extension>
</observers>
</sales_quote_collect_totals_after>
</events>
</global>
</config>
/app/code/locale/Weight/Extension/Model
<?php
class Weight_Extension_Model_Observer
{
public function adjustTotalWeight($observer)
{
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$combinedItems = 0;
foreach($items as $item)
{
if($item->getSku() == 1 || $item->getSku() == 2)
{
$combinedItems++;
}
}
if($combinedItems > 0 && $combinedItems < 3)
$weight = 1;
if($combinedItems >= 3 && $combinedItems < 6)
$weight = 2;
//send new $weight to Magento and persist through checkout?
}
}
如何将调整后的新重量发送给 Magneto 以在结账时使用?
【问题讨论】:
标签: magento magento-1.9