Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

I think to appear the taxe, you need to implement the code like for the $OSCOM_Order->info['total'] = $OSCOM_Order->info['total'] - $discount;

The example above is an ideabut not sure. I am not in in this moment.

 

try to test this quickly in ot_discount_coupon.php after $order->info['subtotal'] -= $discount;

 

 

//take the similar code in your case sorry but I don't work on 2.3.x in the module order total. You must see the taxes and the total order
 

                $OSCOM_ShoppingCart= Registry::get('ShoppingCart');

                $products = $OSCOM_ShoppingCart->get_products();

                for ($i=0, $n=sizeof($products); $i<$n; $i++) {
                  $products_tax = Tax::getTaxRate($products[$i]['tax_class_id'], $OSCOM_Order->delivery['country_id'], $OSCOM_Order->delivery['zone_id']);
var_dump($products_tax);
                   $OSCOM_Order->info['total'] += $products_tax;
var_dump($OSCOM_Order->info['total'] );
}


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki Loic....$products_tax is the percentage of tax to charge....in my case it was 13% in yours it's probably 5%.....I can use that but I need to come up with the discount coupon amount to multiple it by....getting the discount coupon amount is the piece I'm missing.

 

Dan

Share this post


Link to post
Share on other sites

In quebec it's arround 14%, curently I try to resolve my clic system (3 to appear a taxe), after I will see the taxe. This example above is a way, not sur it's the best.



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@kymation Jim or any other code monkeys....any idea how I can access the data [Unknown tax rate] shown in the order obj I've described in this post...

 

http://forums.oscommerce.com/topic/213019-contribution-discount-coupon-codes/?p=1743115

 

The coffee is not working and I'm running out of hair.  Any help or tips/ideas you might have would be appreciated.

 

I'm trying to assign the data [Unknown tax rate] in that to a simple variable say...$tax_rate.  Doing that like so...

 

$tax_rate = $order->coupon['applied_discount']["Unknown tax rate"];

 

Unfortunately that gives me this Fatal Error.

 

Cannot use object of type discount_coupon as array.

 

I tried googling for information on that error but I'm just getting more and more confused. Arrgghhhhh....

 

Dan

 

 

Share this post


Link to post
Share on other sites

I don't know what your coupon addon has done to that poor order class, so I'm going to guess at the structure here:

$tax_rate = $order->coupon->applied_discount["Unknown tax rate"];

That will probably blow up spectacularly, but the error message might be informative.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Good guess Jim....it didn't blow up spectacularly :D and actually picked up the valve. :thumbsup:  Thanks for the help...it was driving me nuts.  (w00t) 

 

Funny you should mention the mess the coupon module made of the order class....I woke up this morning thinking I might need to back up and sort that out first.  The good news in all this, is that it has been a good learning experience.   I learned a lot about the ot modules and how they work together, as painful as it might have been.  

 

Thanks again...

 

Dan

Share this post


Link to post
Share on other sites

@@Gyakutsuki  Loic...with some help from Jim @@kymation I was able to pick up the discount amount, calculate the tax and adjust the tax and order totals to remove the tax on the discount.  The sc_order_total module rewrites the values used in $order->info['tax'] and $order->info['tax_groups'] so those values needed to be reworked.   I'm not really happy with what I had to do to sort this out but it works....perhaps when you get a chance to look at it you'll improve it.   Here it what I added to the sc_order_total module....

     // add condition for discount coupon module
	$tax_on_discount = ($order->coupon->applied_discount["Unknown tax rate"] * $products_tax/100);
	$order->info['tax'] -= $tax_on_discount;
	$order->info['tax_groups']["$products_tax_description"] -= $tax_on_discount;
	$order->info['total'] -= $tax_on_discount;

added to this section...

    			// Modified by Strider 42 to correct the order total figure when shop displays prices with tax
		    			if ( DISPLAY_PRICE_WITH_TAX == 'true' ) {
		    				$order->info['total'];
		    			} else {
		    				$order->info['total']+=$tax_val;
		    			}
		    		}
		    	} else {
		    		if (!class_exists('order')) {
		    			require(DIR_WS_CLASSES . 'order.php');
		    		}
		    		$order = new order;
		    	}
				
				// add condition for discount coupon module
					$tax_on_discount = ($order->coupon->applied_discount["Unknown tax rate"] * $products_tax/100);
					$order->info['tax'] -= $tax_on_discount;
				        $order->info['tax_groups']["$products_tax_description"] -= $tax_on_discount;
					$order->info['total'] -= $tax_on_discount;
				
				// EOF get taxes if not logged in (seems like less code than in order class)

HTHs.   If you rework it in anyway please let me know.

 

Dan

Share this post


Link to post
Share on other sites

Ok Dan, I am rewriting the class, let me time to test and i will explain you to integrate the classif you are interesting because I want I resolve pb inside and also my pb.

If it succes, I tell you.



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki  Loic...re-writing the class....awesome.  :thumbsup:  

 

I'm definitely interested.  Good luck...I don't see any reason why it won't work.

 

If I can help with testing or anything just let me know.

 

Dan

Share this post


Link to post
Share on other sites

ok



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Dan Cole

Ok work like a charm

 

just a modification

 

1/ Remove in ot_discount.php this or insert comment

//            $OSCOM_Order->info['total'] = $OSCOM_Order->info['total'] - $discount;
//            $OSCOM_Order->info['subtotal'] -= $discount;
//            unset($_SESSION['coupon']);

2/ in classe coupon discount add this two functions

 

becarefull on that :

$_GET['shopping_cart']  or if ($PHP_SELF == 'shopping_cart') in shopping_cart.php

$_SESSION['shopping_cart'] i don't exactly remember is the name else change private by public and in getZoneCountryid() write var_dump($_SESSION).

/*
 * Display the id of the country zone id
 * @[member='param']
 * @[member='Return'] $zone_country_id, id country zone id
 * @[member='access'] private
*/
    private function getZoneCountryid() {
      if (isset($_GET['shopping_cart'])) {
//$tax_address['entry_zone_id']
        $zone_country_id = $_SESSION['cart_zone'];
      } else {
        $zone_country_id = $_SESSION['shopping_cart']['shipping_address']['zone_id'];

      }

      return $zone_country_id;
    }


/*
 * Display the id of the country
 * @[member='param']
 * @[member='Return'] $zone_country_id, id country
 * @[member='access'] private
*/
    private function getCountryid() {
      if (isset($_GET['shopping_cart'])) {
// $tax_address['entry_country_id']
        $country_id = $_SESSION['cart_country_id'];
      } else {
        $zone_country_id = $_SESSION['shopping_cart']['shipping_address']['country_id'];
      }

      return $country_id;
    }

In this function total_valid_products change this line (sorry don't remember exactlythe synthax, it's mine.

 

$this->getCountryid() and $this->getZoneCountryid() doesn't have any information, that's why the element does'nt display.

 

The bug is here

for( $i = 0; $i < count( $products ); $i++ ) {
 if (DISPLAY_PRICE_WITH_TAX == 'true'){
   $product_tax = Tax::getTaxRate($products[$i]['tax_class_id'], $this->getCountryid(), $this->getZoneCountryid());
....

If you want a  professionnal code program like phpstorm, you will see yours errors.

 

 

That's all,

 

I can send you the classe but I rewrite all and the code is different than the 2.3 (reverse ingeniring must be done) but with this element you have the solution, I think.

Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki Thanks Loic...sounds simple enough and I guess those variables aren't usually set since you're not logged in.   I'll have a peek and see if I can reverse engineer them.  BTW, why are you running on 2.4 anyway?

 

Also just so I understand...what did you end up doing with sc_order_total...as it is written I assume it would just over right the variables again.  No?

 

Dan

Edited by Dan Cole

Share this post


Link to post
Share on other sites

The add must be deleted, not interested in this case.

The contribution had a bug to zone id and country id, I just changed theses elements.



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki Can I assume that you needed to remove the $tax_val stuff in sc_order_total too?   If you're not loggin in I assume it would trash your tax on the discount.   Maybe I should just try it and see.  :)

 

Dan

Share this post


Link to post
Share on other sites

try with this, it work for me

          $products = $OSCOM_ShoppingCart->get_products();

          for ($i=0, $n=sizeof($products); $i<$n; $i++) {
            $products_tax = Tax::getTaxRate($products[$i]['tax_class_id'], $OSCOM_Order->delivery['country_id'], $OSCOM_Order->delivery['zone_id']);
            $products_tax_description = Tax::getTaxRateDescription($products[$i]['tax_class_id'], $OSCOM_Order->delivery['country_id'], $OSCOM_Order->delivery['zone_id']);

             if ( DISPLAY_PRICE_WITH_TAX == 'true' ) {
//Modified by Strider 42 to correct the tax calculation when a customer is not logged in
              $tax_val =  (($products[$i]['final_price']/100)*$products_tax)*$products[$i]['quantity'];
            } else {
              $tax_val =  (($products[$i]['final_price']*$products_tax)/100)*$products[$i]['quantity'];
            }

            if ( !empty($OSCOM_Order->info['tax']) ) {
              $OSCOM_Order->info['tax'] += $tax_val;
            } else {
              $OSCOM_Order->info['tax'] = $tax_val;
            }

            if (!empty($OSCOM_Order->info['tax_groups']) ) {
              $OSCOM_Order->info['tax_groups']['' . $products_tax_description . ''] += $tax_val;
            } else {
              $OSCOM_Order->info['tax_groups']['' . $products_tax_description . ''] = $tax_val;
            }


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki  Loic...

 

I assume the line number 103 shown below should read..

 

$country_id = $_SESSION['shopping_cart']['shipping_address']['country_id'];.

// $tax_address['entry_country_id']
        $country_id = $_SESSION['cart_country_id'];
      } else {
        $zone_country_id = $_SESSION['shopping_cart']['shipping_address']['country_id'];
      }

      return $country_id;
    }

Dan

Share this post


Link to post
Share on other sites

$zone_country_id must be $country_id



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki  Loic....just realized that we are working on different problems....I'm not even using the option to DISPLAY_PRICE_WITH_TAX so it's not a bug that I was experiencing.  Can I assume that you are not trying to apply or deduct a Coupon when you're not logged in?

 

Dan

Share this post


Link to post
Share on other sites

the system work when your are login or not



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Gyakutsuki Morning Loic,  I assume you're talking about the functions you added and the related changes...for me they didn't change anything since I don't have the DISPLAY_PRICE_WITH_TAX set to True -- the bug you experienced and fixed I never ran into.   Do you have your shopping_cart on line somewhere, where I can have a look?  I have a feeling we're doing two different things and are not working on or talking about the same issue.  I can PM you a link to my shopping cart if you are interested.   In any case I have the order totals working correctly whether you are logged in or not, I'm just not happy with the way I was forced to do it.  It would be nice to expand/add the discount amount and calculated tax to the order class...it would simplify things a lot.  

 

Dan

Share this post


Link to post
Share on other sites

no work with on not taxe. see my email



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

@@Dan Cole

 

Ok, depends on your configuration in order total and coupon (the setup is very important and you can have at the end some difference, yes it's a bug no simple to resolve)

you can have a difference between the shopping and the checkout process

 

This configuration for canada work for me :

 

Sort order in module total order

 

Coupon réduction 1 pixel_trans.gifpixel_trans.gif Expédition 10 pixel_trans.gifpixel_trans.gif Sous-Total 8 pixel_trans.gifpixel_trans.gif Taxes 20 pixel_trans.gifpixel_trans.gif Total 50

 

and in Coupon : the most important

 

display discount with coupon : true

calcul the discount after the taxe :false

display taxe applied : false

sort order : 1

 

 

and for shop configuration

display price with taxe : no

 

 

In my cart not connected

 

Code coupon test applique: -10.00CAD Sous-Total: 25.00CAD Livraison gratuite (livraison offerte dés 20.): 0.00CAD Zone TVH 9.975: 2.49CAD Zone TPS 5%: 1.25CAD Total: 28.74CAD

 

in my cart  connected :

 

Code coupon test applique: -10.00CAD Sous-Total: 25.00CAD Livraison gratuite (livraison offerte dés 20.): 0.00CAD Zone TVH 9.975: 2.49CAD Zone TPS 5%: 1.25CAD Total: 28.74CAD

 

in checkout confirmation

 

Code coupon test applique: -10.00CAD Sous-Total: 25.00CAD Livraison gratuite (livraison offerte dés 20.): 0.00CAD Zone TVH 9.975: 2.49CAD Zone TPS 5%: 1.25CAD Total: 28.74CAD


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

Thanks Loic....if you update the discount_coupon class please keep me in mind...when I get sometime I'll compare your settings with mine to see why yours works without the hacks I added and mine doesn't.  That should show us where the bug lies.  BTW, do you know what section of the code is adding this to the order class?  That's probably a good clue too...

        [discount_tax] => Array
                (
                    [Unknown tax rate] => 0
                )

Same thing with the applied discount array a lttle bit above it in the order class.

 

Dan

Share this post


Link to post
Share on other sites

Hello guys, 

 

sorry to interrupt your discussion, but i am having a few issues with this addon, and am hoping someone could point me in the right direction.

 

firstly, i was using an outdated discount code module that wasnt working completely. So decided it was time for an upgrade and found this one.

 

All was fine when installing, everything in admin worked perfectly. But i came across a problem when trying to add a discount to a shopping cart.. the discount just wouldnt appear in the confirmation page. Doing a bit of research i found a couple of solutions, give it a unique display order, make sure no other discount code is on site, as will disrupt in the order total. All done.. and it is still not appearing.

 

so, problem one is :

 

I cant get it to show!

 

Secondly, in trying to fix the above issue i have found the following error in my error log :

 

PHP Warning:  Missing argument 2 for shoppingCart::attributes_price(), called in /home/../shop/includes/classes/discount_coupon.php on line 305 and defined in /home/../shop/includes/classes/shopping_cart.php on line 303 

 

when doing the install i never went into the shopping_cart.php page. so not sure how to fix this one?

 

any help, or suggestion of where to look would be greatly appreciated. 

 

E

Share this post


Link to post
Share on other sites

shoppingCart::attributes_price does'nt exist in 2.3.x and replace this elementpar the old. $_SESSION['cart']->attributes_price I think.



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×