Jump to content

Gift Certificates - Cart Doesn't Discount Total?


bsmither

Recommended Posts

When a customer is checking out and enters a code for a Gift Certificate, does the total of the order not get reduced by the amount of the voucher?

 

Please edit /classes/cart.class.php, find near line 1152:

    private function _applyProductDiscount(&$price, $product_id, $quantity = 1) {
        // Apply 'assigned product' discounts on a per-product basis
        if (isset($product_id) && is_numeric($product_id)) {
            if (isset($this->basket['coupons']) && is_array($this->basket['coupons'])) {
                foreach ($this->basket['coupons'] as $key => $data) {
                    $products = unserialize($data['product']);
                    $incexc = array_shift($products);

 

On a new line after the foreach statement, add:

                    if($data['gc']) continue;

 

 

A gift certificate (GC) is not applied against any products. So when the GC details are databased in CubeCart_coupons, the column 'product_id' forces MySQL to make a default interpretation and stores a zero-length string (zls).

In Cart->_applyProductDiscount(), CubeCart works through all GCs and coupons the customer applied to the order. Let's say only a GC was applied. Again, the list of products this GC applies to is a zls.

When the code begins to work on the GC, the zls is unserialized. According to PHP, "In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued."

My experiments show that the variable containing the result of the unserialization, $products that has a value of boolean false, also is considered to have a count of 1.

At the end of Cart->_applyProductDiscount(), a test is made for the count of $products. If greater than zero, the assumption is that there is at least 'include' or 'exclude' as the first element's value, or (in the case of legacy coupons) a number that represents the product this coupon is good for.

Thus we have a situation where a GC was processed through Cart->_applyProductDiscount() when it shouldn't (unless and until GCs can target products, categories, etc), but because the GC is processed, the code misbehaves because of the zls and causes a false positive with $this->_item_discount.

When $this->_item_discount is tested in Cart->_applyDiscounts(), the false positive causes even GCs to be skipped.

Cart->_applyProductDiscount() is the function that reduces the item's price according to the coupon's details (which has a bug related to fixed-price amounts).

Cart->_applyDiscounts() is the function that sums up allowable discounts from general-use vouchers. (This function is not the function that reduces the voucher's cash-load by the amount consumed.)

 

This worked for me. Your mileage (kilometer-age?) may vary. Devellion may have other ideas about how to fix this.

Link to comment
Share on other sites

Hi bsmither - yes this works!

 

now, another issue pops up.

 

In our cart, we are using PayPal Pro.  The GC is applied in the cart before going to PayPal to login, but by the time I returned to the store to check out, the value of the GC has been taken but it isn't reflected in the cart price any longer.  IE the cart price goes back to the original value, and if I try to use the GC again, a message indicates that the voucher has expired.  Upon checking in the control panel, the value of the GC was reduced already, before I have completed checking out.

 

Hope that makes sense to you.

Link to comment
Share on other sites

I don't know how PayPal Pro works (I use a free Test gateway written by Goober that simulates making a successful payment).

 

How do you 'return to the store to checkout'? Doesn't CubeCart send you to the PayPal system to make payment, then you are returned back to CubeCart with indications that the transaction is now finished?

 

How does PayPal enter into the customer experience before the CubeCart is ready to send the cart data to PayPal?

Link to comment
Share on other sites

Hi - your description accurately reflects the PayPal Standard process..  the Pro process is much more complicated in that the order is passed back and forth so payment can be completed on the shopping site instead of in paypal. No worries (at least for me for now)  I successfully talked my client into using the standard, and the GC now works correctly in total but there is something funny about how it is showing up in the checkout page - the discount amount isn't reflecting the shipping, but shipping is actually covered and is coming off in the grand total.  Probably just a little tweak required to make the total discount equal to exactly what is being applied to the grand total?

 

ie Before GC

 

product - $1.00

subtotal - $1.00

shipping - $1.50

grand total - $2.50

 

After GC

 

 

product - $1.00

subtotal - $1.00

shipping - $1.50

GC #. - $25,00

Total Discount - $1.00

grand total - $0.00

 

have I said thanks for all your work on this?  thanks!

Link to comment
Share on other sites

i am using flat rate shipping.

shouldn't the GC come off the bottom line, regardless of how much is shipping and how much is product? or does it just come off the product, in which case we still have a problem because it is currently being applied to the total even though it isn't showing up that way in the "discount" field.

Link to comment
Share on other sites

Actually, when you think about it, a Gift Certificate is real money cash. I mean, someone gave you money for this GC. This isn't a coupon where you, the store owner, loses a few bucks in the hopes of having the customer put other things in the cart ("getting the foot traffic"), or as a reward/incentive for buying a bunch of high-markup items ("customer loyalty").

 

By what right can we say that this real money can't be used in any way the customer wants? It's real money paying for the items, the taxes, and the shipping,

 

What do you think?

 

And I'm back into the code....

Link to comment
Share on other sites

I made an order through CC521(a) and my customer experience is this (it was late at night and I may have some of the details wrong):

 

When first presented with a checkout screen as a logged in customer, I am presented with an option to choose my shipping and to enter a GC number. I have recoded CC to not choose the cheapest shipping method automatically, but to have it show --Please Select--. The javascript for this page will not allow it to be submitted until a choice is made.

 

When I choose my shipping (and there are no problems with accepting that choice), CubeCart will automatically submit the form, set up the shipping, and take me back to that same screen.

 

If I had entered the GC number, it will get processed. The amount expected to be taken from the GC will be shown (I can still change everything on this screen, so nothing is fixed), the current cash-load on the GC is shown, and my (expected?)Grand Total has been reduced. I think the Grand Total at this point should indicate this is an estimate only. And I lost my shipping choice.

 

I reselect the shipping option, which automatically submits the form and I am taken back to this same page, but the GC has not reduced its current cash-load nor the estimated discount, even though CubeCart now knows the estimated shipping cost. (I would like that fixed.)

 

When I click Checkout (and if everything goes right), I am taken to the screen to choose the payment gateway -- if necessary. (On this screen, there is no unchangeable summary of the cart. And if necessary, because if the GC paid for the entirety of the order, there is no need to go through a gateway.)

 

Because I haven't committed myself to making payment, the cash-load on the GC has not been reduced. (I checked the database.)

 

But once the order goes to Processing, everything works out as it should in the end. Although it would be nice to know that Gift Certificate X-A916 was used and by specifically how much and how much remains. (Is there a way for someone who presents a GC code to be able to find out the current balance?)

 

Normally, the code in the gateway would trigger CubeCart to send an email thanking me for my payment. I think I will work on having the GC transactor do the same.

Link to comment
Share on other sites

  • 2 weeks later...

My coupons does not works when I use the value , for example $5  the discount show as off but not under the total .. only % works correctly when creating coupons or GC 

and I updated yesterday to the last V5 versions , my customer woke me up around 2: 00 am in the morning with this problem , I had to change it to % and it worked 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...