问题
How do I add an invoice fee to an order with my payment module? I guess this should be done during the checkout process through my payment method model. Perhaps I should create and add an item/product to the cart/quote/order object?
I don't know how to do any of these things though. Please help
回答1:
Although possible it is not for the feint-hearted. Here is a rough run-down of the steps to add a line to the totals area, which will then add your fee to the grand total.
In the config node <global><sales><quote><total>
add a new entry (see app/code/core/Mage/Sales/etc/config.xml
for more examples)
<paymentFee>
<class>yourmodule/quote_address_total_paymentFee</class> <!-- A model -->
<after>subtotal</after>
</paymentFee>
Also in the config.xml
add the following to <global>
...
<fieldsets>
<sales_convert_quote>
<payment_fee><to_order>*</to_order></payment_fee>
</sales_convert_quote>
</fieldsets>
Create the model to calculate the fee.
class Your_Module_Model_Quote_Address_Total_Warranty extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
public function __construct()
{
$this->setCode('paymentFee');
}
public function collect(Mage_Sales_Model_Quote_Address $address)
{
// Check the payment method in use, if it is yours do...
$address->setPaymentFee($fee);
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
if ($address->getPaymentFee()) {
$address->addTotal(array(
'code' => $this->getCode(),
'title' => 'Your module payment message',
'value' => $address->getPaymentFee()
));
}
return $this;
}
}
In your module's setup, modify the sales_flat_quote
and sales_flat_order
tables to add a payment_fee column.
The <after>
value in the config is responsible for determining the order of calculation, it can be a comma-separated list of totals' codes including "tax", "discount", etc. You may also specify a <before>
value for the same purposes. The $address->addTotal
in fetch()
method will do the work of updating the grand total, which is what the customer will be charged. It is necessary to alter the quote and order tables so the fee you have charged is recorded and shown to the admin.
It is also possible to specify your own renderer if the default will not do, I have done this also but is even more complex.
回答2:
If you haven't worked with Magento's codebase before, I wouldn't recommend that you start with that, it's fairly complex. Using an extension is probably the safest option.
I haven't used it, but I believe this extension should do the job.
Standard disclaimer: I'm not affiliated with the vendor in any way. Caveat emptor.
来源:https://stackoverflow.com/questions/4499000/magento-how-do-i-add-an-invoice-fee-to-an-order-during-checkout-process