| VirtueMart 1.1.4 Discounts Fix |
|
This article demonstrates how to use PayPal to process VirtueMart shopping cart payments when discounts (coupons and or payments) are used.
In order to use coupons (especially when prices include tax) the code must be modified. The stable release of VirtueMart 1.1.4 does not handle PayPal payments correctly passing erroneous values to the PayPal object. Also, all order lines are consolidated into one line potentially confusing the shopper and limiting future enhancements.
Extensible Point Solutions Inc. has developed a solution to address the incorrect values and provide additional functionality in PayPal order detail. The solution requires refinement to address potential issues with timing of shopper login (see other considerations). The solution includes an improved cart layout and modifications to:
Please note the modified code is only available to EXPS clients.
To apply the solution copy (over write) the following files;
../administrator/components/com_virtuemart/classes/ps_checkout.php
../administrator/components/com_virtuemart/html/basket.php ../administrator/components/com_virtuemart/html/order.order_printdetails.php ../administrator/components/com_virtuemart/html/checkout.index.php
../components/com_virtuemart/themes/default/templates/basket/basket.html.php ../components/com_virtuemart/themes/default/templates/pages/account.order_details.tpl.php
...and then open this file in an editor and copy into VM / Administration / Store / List Payment Methods / Paypal / Configuration / Payment Extra Info:
paypal-cart.php
Note: Original files are included in the patch in case you need to roll back the solution.
Note: If you have already modified the files affected by this patch to not over write them or your modifications will be lost.
What this solution doesThe following four examples shows cart and PayPal output after the soltuon patch is applied. At the end of the examples there is one further example of what VirtueMart as released code produces.
Example 1 - Order where price includes tax, 10% coupon discount, $1 payment fee
CART
PAYPAL
Example 2 - Order where price includes tax, 10% coupon discount, $1 payment discount
CART
PAYPAL ![]()
Example 3 - Order where price does not include tax, 10% Coupon discount, $1 payment fee
CART
PAYPAL
Example 4 - Order where price does not include tax, 10% Coupon Discount, $1 payment discount
CART
PAYPAL
Example Without This Solution – Existing Code
Order where price includes tax, 10% coupon discount, $1 payment discount
CART
Issues: Tax total does not include shipping tax and is rounded incorrectly (should be 8.83 product tax).
PAYPAL
Issues: Total is incorrect, no tax information displays, item subtotal is incorrect, no order line detail displays.
The differences here underlines the main issue that this solution addresses – different code is used to display values in the cart than is used to update the order database table. As a result the display is almost correct while the order table data is incorrect causing incorrect values in PayPal, email confirmation and order maintenance views. The solution corrects calculations in ps_checkout.php and changes basket.php to only use these values.
Understanding Coupons
VirtueMart provides the capability to offer discount coupons that shoppers apply to orders and receive either a fixed or percentage based discount. There are three parameters that control how discounts are applied;
Admin – Front End Features – Enable Coupon Usage
Admin – Tax Configuration – Subtract Payment Discount Before Tax and Shipping
Note: In the course of developing this solution it was determined that VirtueMart 1.1.4 does not support discounting after tax and shipping as the configuration parameter suggests. Therefore, it is assumed that “Subtract Payment Discount Before Tax and Shipping” will always be checked.
Shopper Group – Show Price Including Tax
Scenarios
There four scenarios for discounting, two of which are support by this solution.
Sample Order:
Product $18.1818 ($20.00 including tax) Quantity: 4 Product Tax: 10% or $1.82 Shipping: $9.09 ($10.00 including tax) Shipping Tax: 10% or $0.91 Coupon: 10% Discount
Calculations for Scenario #1 Prices do not include tax and discounts applied before tax and shipping
Product 18.1818 x 4 = $72.72 (rounding) Coupon 10% = ($7.27)
Subtotal = $65.45 Product tax 10% = $6.55 Shipping 9.09 = $9.09 Shipping Tax 10% = $0.91
Order Total = $82.00
Calculations for Scenario #2 Prices include tax and discounts applied before tax and shipping
Product 18.1818 x 1.10 x 4 = $80.00
Coupon 10% = ($8.00)
Subtotal = $72.00
Shipping 9.09 x 1.10 = $10.00
Order Total = $82.00
Calculations for Scenario #3 – Not Supported Prices do not include tax and discounts applied after tax and shipping
Product 18.1818 x 4 = $72.73 Product tax 10% = $7.27
Shipping 9.09 = $9.09 Shipping Tax 10% = $0.91
Subtotal = $90.00
Coupon 10% = ($9.00)
Order Total = $81.00
Calculations for Scenario #4 – Not Supported Prices include tax and discounts applied after tax and shipping
Product 18.1818 x 1.10 x 4 = $80.00
Shipping 9.09 x 1.10 = $10.00
Subtotal = $90.00
Coupon 10% = ($9.00)
Order Total = $81.00
Analysis of the the scenarios shows that #1 and #2 produce the same order total but have different coupon discount amounts. Scenarios #3 and #4 provide the exact same results.
From an accounting perspective #1 and #2 are cleaner in that there need not be complex logic (rules) for applying discounts that might be required by #3 and #4 – how to allocate discount. For example, would a discount on the total be applied to the product and product tax while excluding shipping or would it be allocated evenly across all charges? How would a partial return be handled?
It appears as though #1 and #2 are the more typical scenarios and that if ever required #3 and #4 would first require development of specific business rules. For this reason #3 and #4 are not supported in this solution.
Other Considerations
References
Document: PayPal – Website Payments Standard Integration Guide, April 2007
|

















