Magento 如何在保存付款方式之前获取报价总额?

Magento 如何在保存付款方式之前获取报价总额?,magento,magento-1.5,Magento,Magento 1.5,我正在尝试创建一个单步签出,但在签出页面中,我对订单审阅部分有问题。当我选择付款方式时,例如“货到付款”有5美元额外付款,或“支票订单”有%4折扣,或“信用卡付款”会在订单总额中增加额外付款。 在保存付款方式之前,我需要一种计算折扣的方法。有什么建议吗?订单有setShippingAmount和getShippingAmount方法。修改为添加“货到付款” 创建一个方法并将其添加为/etc/config.xml中签出\键入\ onepage \保存\订单事件的观察者 这是你问题的一部分。在我看来

我正在尝试创建一个单步签出,但在签出页面中,我对订单审阅部分有问题。当我选择付款方式时,例如“货到付款”有5美元额外付款,或“支票订单”有%4折扣,或“信用卡付款”会在订单总额中增加额外付款。 在保存付款方式之前,我需要一种计算折扣的方法。有什么建议吗?

订单有setShippingAmount和getShippingAmount方法。修改为添加“货到付款”

创建一个方法并将其添加为/etc/config.xml中签出\键入\ onepage \保存\订单事件的观察者


这是你问题的一部分。在我看来,您可以通过这种方式自定义左侧部件。

因为我们正在讨论Magento,所以有几种方法可以实现这一点。实现该功能的最佳方法是为折扣或附加费用创建自己的总模型

如何创建自定义Magento total模型 要创建自己的总体模型,首先需要创建一个模块,并将总体模型添加到配置中。

配置XML中指定的下一个类是invoice total model your\u模块/order\u invoice\u total\u yourTotal。

您需要在creditmemo total模型中实现的最后一个类,与invoice total模型类似,只是它扩展了抽象类Mage_Sales_model_Order_creditmemo_total_abstract

您还需要使用设置脚本添加属性:
/**
 * @var Mage_Sales_Model_Resource_Setup $installer
 */
$installer = Mage::getResourceModel('sales/setup', 'default_setup');

$installer->startSetup();

$installer->addAttribute('order', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('order', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('invoice', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('invoice', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('creditmemo', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('creditmemo', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->endSetup();
为了在管理区域中显示新的总计,需要使用布局XML为其添加总计块。为模块中的adminhtml区域注册布局更新文件。以下是一个示例内容:

现在唯一缺少的是将总金额从报价地址复制到订单的字段集,以及从订单复制到发票和creditmemo的字段集。将以下XML添加到config.XML中:

就这样。总数将显示在任何地方,包括生成的PDF。
正如我所说,有许多其他方法可以简单地更新核心中已存在的所有模型的值,但这是实现它的完整方法。

感谢您的回复,但我需要在保存订单之前进行此计算。所有装运方式选择、付款方式选择和订单审核将一起显示在同一页面上。我想知道我是否可以在编程选择付款方式后获得折扣计算。不:请原谅梅萨杰·亚兹丹·索拉·戈尔德姆·西泽德·图尔克姆·苏努兹……奥汉,尝试另一种观察者方法,而不是一页保存顺序。要获得magento的完整活动列表,请不要:Bende o kadar sorunun içinden seni seçtim zaten:重复,涵盖相同的问题回答得很好。如果涉及税收,你知道该怎么办吗。另请看我的问题:谢谢你的回答和你的时间,但我尝试了几乎相同的事情,你孤独的问题是获得我需要保存报价的总数。但是我需要在保存报价之前得到总数。假设我有三种不同的付款方式,每种方式都有不同的规则。我想在向用户显示付款方式名称以供选择时,在付款方式名称旁边显示总计。所以我需要在选择它并保存quote对象之前计算总数。我希望我的问题更清楚一点。我完成了上述所有步骤。成功了。我只想为特定的发货方式启用此功能,必须做哪些更改?Kuku,只需在您的total models collect方法中检查发货方式。
<global>
  <sales>
    <quote>
      <totals>
        <your_total>
          <class>your_module/quote_address_total_yourTotal</class>
          <after>shipping</after><!-- calculate after these total models -->
          <before>grand_total,tax</before><!-- calculate before these total models -->
        </your_total>
      </totals>
    </quote>
    <order_invoice>
      <totals>
        <your_total>
          <class>your_module/order_invoice_total_yourTotal</class>
          <after>shipping</after>
          <before>grand_total,tax</before>
        </your_total>
      </totals>
    </order_invoice>
    <order_creditmemo>
      <totals>
        <your_total>
          <class>your_module/order_creditmemo_total_yourTotal</class>
          <after>shipping</after>
          <before>grand_total,tax</before>
        </your_total>
      </totals>
    </order_creditmemo>
  </sales>
  <pdf>
    <totals>
      <your_total translate="title">
        <title>Your Total</title>
        <source_field>your_total</source_field>
        <font_size>7</font_size>
        <display_zero>0</display_zero>
        <sort_order>450</sort_order>
      </your_total>
    </totals>
  </pdf>
</global>
class Your_Module_Model_Quote_Address_Total_YourTotal
    extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    // Calculate your total value
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        // Calculate the totals based on the information in the $address
        // and the $address->getQuote()
        // To get the items in the cart use $address->getAllItems()
        // To get the payment method use getPayment()->getMethodInstance()
        // etc

        // When your totals are known..
        $this->_addAmount($total); // store view currency amount
        $this->_addBaseAmount($baseTotal); // base currency amount

        // Also store in address for later reference in fetch()
        $address->setMyTotal($total);
        $address->setBaseMyTotal($baseTotal);

        return $this;
    }

    // If the total should be displayed in the cart and the checkout
    // add them to the address model here, otherwise just return
    // (it will still be calculated and added to the grand total)
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        if ($address->getMyTotal() > 0)
        {
            $address->addTotal(array(
                'code'  => $this->getCode(),
                'title' => Mage::helper('your_module')->__('Your Total'),
                'value' => $address->getMyTotal()
            ));
        }
        return $this;
    }
}
class Your_Module_Model_Order_Invoice_Total_YourTotal
    extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
    // Collect the totals for the invoice
    public function collect(Mage_Sales_Model_Order_Invoice $invoice)
    {
        $order = $invoice->getOrder();
        $myTotal = $order->getMyTotal();
        $baseMyTotal = $order->getBaseMyTotal();

        $invoice->setGrandTotal($invoice->getGrandTotal() + $myTotal);
        $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $basemyTotal);

        return $this;
    }
}
/**
 * @var Mage_Sales_Model_Resource_Setup $installer
 */
$installer = Mage::getResourceModel('sales/setup', 'default_setup');

$installer->startSetup();

$installer->addAttribute('order', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('order', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('invoice', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('invoice', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('creditmemo', 'base_your_total', array(
    'label' => 'Base Your Total',
    'type'  => 'decimal',
));

$installer->addAttribute('creditmemo', 'your_total', array(
    'label' => 'Your Total',
    'type'  => 'decimal',
));

$installer->endSetup();
<layout version="0.1.0">

  <adminhtml_sales_order_view>
    <reference name="order_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_view>

  <adminhtml_sales_order_invoice_new>
    <reference name="invoice_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_invoice_new>

  <adminhtml_sales_order_invoice_updateqty>
    <reference name="invoice_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_invoice_updateqty>

  <adminhtml_sales_order_invoice_view>
    <reference name="invoice_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_invoice_view>

  <adminhtml_sales_order_creditmemo_new>
    <reference name="creditmemo_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_creditmemo_new>

  <adminhtml_sales_order_creditmemo_view>
    <reference name="creditmemo_totals">
      <block type="your_module/sales_total_yourTotal" name="total_your_total" as="your_total"/>
    </reference>
  </adminhtml_sales_order_creditmemo_view>

</layout>
// Many ways to implement this, here is one option
class Your_Module_Block_Sales_Total_YourTotal
    extends Mage_Core_Block_Abstract
{
    public function initTotals()
    {
        $parent = $this->getParentBlock();

        $value = $parent->getSource()->getMyTotal();

        if ($value > 0)
        {
            $total = new Varien_Object(array(
            'code'  => 'my_total',
            'value' => $parent->getSource()->getMyTotal(),
            'base_value' => $parent->getSource()->getBaseMyTotal(),
            'label' => $this->__('My Total'),
            'field' => 'my_total'
            ));
            $parent->addTotal($total, 'my_total');
        }
        return $this;
    }
}
<fieldsets>
    <sales_convert_quote_address>
        <shipping_surcharge><to_order>*</to_order></shipping_surcharge>
        <base_shipping_surcharge><to_order>*</to_order></base_shipping_surcharge>
    </sales_convert_quote_address>
    <sales_convert_order>
        <shipping_surcharge><to_invoice>*</to_invoice><to_cm>*</to_cm></shipping_surcharge>
    </sales_convert_order>
</fieldsets>