Joomla SupportVirtueMart SupportPHP Development

Latest News

Bundled Extensions for Virtuemart 1.1.4

VM Turbo 1.1 is a bundle of fixes and extensions developed by EXPS for Virtuemart 1.1.4. The bundle contains:

Read more...

Wildcard SSL Certificates
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:

 

  • Corrections to ps_checkout.php functions; calc_order_totals( &$d ) and function calc_order_subtotal( &$d )
  • Updates to; checkout_index.php for basket.php include
  • Updates to; account.order_details.tpl.php and order.order_printdetails.php for tax amounts
  • Complete re-write of basket.php to consolidate basket.php and ro_basket.php, to correct cart display values.
  • Add new file basket.html.php a template file that replaces basket_b2b.html.php, basket_b2c.html.php, ro_basket_b2b.html.php, ro_basket_b2c.html.php
  • Add new file paypal-cart.php that replaces code in PayPal payment method. Now uses “_xcart that displays order lines in PayPal and passes correct values.

 

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 does

The 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

vm example cart 1

 

PAYPAL

pp example cart 1

 

Example 2 - Order where price includes tax, 10% coupon discount, $1 payment discount

 

CART

vm example cart 2

PAYPAL

pp example cart 2

 

Example 3 - Order where price does not include tax, 10% Coupon discount, $1 payment fee

 

CART

vm example cart 3

 

PAYPAL

pp example cart 3

 

Example 4 - Order where price does not include tax, 10% Coupon Discount, $1 payment discount

 

CART

vm example cart 4

 

PAYPAL

pp example cart 4

 

 

Example Without This Solution – Existing Code

 

Order where price includes tax, 10% coupon discount, $1 payment discount

 

CART

vm cart as is

 

Issues: Tax total does not include shipping tax and is rounded incorrectly (should be 8.83 product tax).

 

PAYPAL

pp example cart as is

 

 

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

  • Determines whether shoppers can enter a coupon code

 

Admin – Tax Configuration – Subtract Payment Discount Before Tax and Shipping

  • Determines whether discounts are applied on the order total including product, tax and shipping or applied only on the product amount before tax

  • Side effect of setting “Show Price Including Tax” is that discounts are applied on product + product tax amount

  • There are four levels of discounting in VirtueMart; Shopper Group discounts, Product discounts, Coupons and Payment discounts (which can also be fees).

 

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

  • Determines whether the prices include tax or not.

  • If prices include tax the order detail in PayPal will show an amount for tax as an item line with a string that includes the tax amount. Otherwise, taxes display in the PayPal subtotals.

 

 

Scenarios

 

There four scenarios for discounting, two of which are support by this solution.

 

  1. Prices do not include tax and discounts applied before tax and shipping

  2. Prices include tax and discounts applied before tax and shipping

  3. Not Supported - Prices do not include tax and discounts applied after tax and shipping

  4. Not Supported - Prices include tax and discounts applied after tax and shipping

 

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

 

  1. VirtueMart utilizes session cookies to store some shopper and order details on the front end. The stored cookies can be problematic when the order fails out of the natural flow, for example when the shopper deletes the cart contents. The session cookie can (and does) persist in such cases causing unexpected behavior (from the shoppers perspective) such as not allowing re-entry of the coupon code because the redeemed coupon variable is set in the session – even when the cart is deleted. Sometimes it will be necessary to explicitly delete the session cookie in the browser to clear these variables.
  2. Cookies also effect the PayPal object loading in that shoppers with PayPal accounts (where paypal cookie exists) will be directed to a page geared to PayPal user login, whereas shopper with no cookie are directed to a page geared to credit card use. In either case the shopper can pay with credit card or PayPal account – just be aware of the behavior.
  3. If you have previously saved “Shipping Calculations” in your PayPal profile you must check the over ride option to calculate shipping charges option in order for shipping charges to be loaded into the PayPal object. This solution is using the variable “shipping_1” to pass shipping amounts, which according to the documentation is not correct and we should use “shipping”. Unfortunately, we discovered the strange behavior with the over ride option while testing “shipping” - which does not ever pass a value. A support request as been submitted to PayPal on this to get clarification on proper use. For now we use “shipping_1” and check the over ride parameter in PayPal Profile.
  4. Shoppers can use the same (permanent) coupon code on multiple orders!
  5. Shopper must be logged in when prices include tax or coupon can be applied before prices show tax amount (tax based on ship to), which messed up the discount calculations. Fixing this requires further analysis and input from the community (how should it work).

 

References

 

Document: PayPal – Website Payments Standard Integration Guide, April 2007

 

URL: https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_html_cart_upload