Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

Hi joli,

 

I also try this option but it does'nt work.

 

test class order total : show 4 method

test in checkout_process : show 3 method.

 

I try with discount by customer before subtotal and there is no problem.


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

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

 

Link to comment
Share on other sites

I continue my investigation

 

classes/order_total.php

 

    function process() {
      $order_total_array = array();
      if (is_array($this->modules)) {
        foreach($this->modules as $value) {
          $class = substr($value, 0, strrpos($value, '.'));
          if ($GLOBALS[$class]->enabled) {
            $GLOBALS[$class]->output = array();
            $GLOBALS[$class]->process();


             for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
              if (osc_not_null($GLOBALS[$class]->output[$i]['title']) && osc_not_null($GLOBALS[$class]->output[$i]['text'])) {
                $order_total_array[] = array('code' => $GLOBALS[$class]->code,
                                             'title' => $GLOBALS[$class]->output[$i]['title'],
                                             'text' => $GLOBALS[$class]->output[$i]['text'],
                                             'value' => $GLOBALS[$class]->output[$i]['value'],
                                             'sort_order' => $GLOBALS[$class]->sort_order);
              }
            }
          }
        }
      }


var_dump($order_total_array);
exit;




      return $order_total_array;
    }

result

array (size=4)
0 =>
array (size=5)
'code' => string 'ot_subtotal' (length=11)
'title' => string 'Sous-Total:' (length=11)
'text' => string '121.00$ CAD' (length=11)
'value' => float 121
'sort_order' => string '5' (length=1)
1 =>
array (size=5)
'code' => string 'ot_discount_coupon' (length=18)
'title' => string 'Code coupon lancement applique:' (length=31)
'text' => string '5.00$ CAD' (length=9)
'value' => string '5' (length=1)
'sort_order' => string '9' (length=1)
2 =>
array (size=5)
'code' => string 'ot_shipping' (length=11)
'title' => string 'Livraison gratuite (livraison offerte dés 5.):' (length=54)
'text' => string '0.00$ CAD' (length=9)
'value' => string '0.00' (length=4)
'sort_order' => string '10' (length=2)
3 =>
array (size=5)
'code' => string 'ot_total' (length=8)
'title' => string 'Total:' (length=6)
'text' => string ' 116.00$ CAD ' (length=13)
'value' => float 116
'sort_order' => string '60' (length=2)

I have my coupon  and my coupon is displayed in checkout_confirmation.php ! ==> good.

 

now I valide my checkout_confirmation.php

 

code in checkout_process.php

 

  require(DIR_WS_CLASSES . 'order_total.php');
  $order_total_modules = new order_total;


  $order_totals = $order_total_modules->process();


var_dump($order_total_modules);


var_dump($order_totals);
exit;

Now the result 

object(order_total)[43]
public 'modules' =>
array (size=5)
0 => string 'ot_subtotal.php' (length=15)
1 => string 'ot_discount_coupon.php' (length=22)
2 => string 'ot_shipping.php' (length=15)
3 => string 'ot_tax.php' (length=10)
4 => string 'ot_total.php' (length=12)



array (size=3)
0 =>
array (size=5)
'code' => string 'ot_subtotal' (length=11)
'title' => string 'Sous-Total:' (length=11)
'text' => string '121.00$ CAD' (length=11)
'value' => float 121
'sort_order' => string '5' (length=1)
1 =>
array (size=5)
'code' => string 'ot_shipping' (length=11)
'title' => string 'Livraison gratuite (livraison offerte dés 5.):' (length=54)
'text' => string '0.00$ CAD' (length=9)
'value' => string '0.00' (length=4)
'sort_order' => string '10' (length=2)
2 =>
array (size=5)
'code' => string 'ot_total' (length=8)
'title' => string 'Total:' (length=6)
'text' => string ' 121.00$ CAD ' (length=13)
'value' => float 121
'sort_order' => string '60' (length=2)

$order_total_modules ===> show the discount coupon

but $order_total_modules->process() delete the discount coupon

 

Do you havean idea because I don't see the solution.

 

thank you

 

 


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

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

 

Link to comment
Share on other sites

I am suspecting this free shipping not sure why just a feeling start your sort order with 1 not null and try changing free shipping to false and install a flat rate just to test seems to be failing here in checkout-confirmation.php

//kgt - discount coupons
  if( tep_not_null( $coupon ) && is_object( $order->coupon ) ) { //if they have entered something in the coupon field
    $order->coupon->verify_code();
    if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG != 'true' ) {
		  if( !$order->coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
			  if( $order->coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_SHIPPING_CALC_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
		  } else {
			  if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
			  tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $order->coupon->get_messages() ) ), 'SSL' ) ); //redirect to the payment page
		  }
    }
	} else { //if the coupon field is empty, unregister the coupon from the session
		if( tep_session_is_registered('coupon') ) { //we had a coupon entered before, so we need to unregister it
      tep_session_unregister('coupon');
      //now check to see if we need to recalculate shipping:
      require_once( DIR_WS_CLASSES.'discount_coupon.php' );
      if( discount_coupon::is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_SHIPPING_CALC_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
    }
	}
	//end kgt - discount coupons
	
// load the selected shipping module
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping($shipping);

  require(DIR_WS_CLASSES . 'order_total.php');
  $order_total_modules = new order_total;
  $order_total_modules->process();

and make sure that code shp date code  is still not in there that was a bug for a long time about line 155

<!-- ship date -->
To improve is to change; to be perfect is to change often.

 

Link to comment
Share on other sites

No the pb is not the free chipping. I change the shipping by flat and taken other.

The problem is between checkout_confirmation.php and checkout_process.php and after this line in checkout_confirmation.php

 

  require(DIR_WS_CLASSES . 'order_total.php');
  $order_total_modules = new order_total;
  $order_total_modules->process();   ==> a coupon appear with a var_dump

Just to find !


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

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

 

Link to comment
Share on other sites

the problem is between the 2 lines in checkout_process.php

 

 
$order_total_modules = new order_total(); ===> see the coupon
 $order_totals = $order_total_modules->process(); ===> coupon deseapear
 
I lost the something, why !!! researching.
Edited by Gyakutsuki


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

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

 

Link to comment
Share on other sites

ok, the pb is inside this order_total.php.

 

between checkout_payment.php and checkout_confirmation.php, the process work fine with order_total.php

between checkout_confirmation and  checkout_processus.php (see above), the order_total.php put pb.

 

See the result

  function process() {


      $order_total_array = array();
      if (is_array($this->modules)) {


        var_dump($this->modules);   =============>  step 1 below ===> all is ok
        exit;


        foreach($this->modules as $value) {
          $class = substr($value, 0, strrpos($value, '.'));
          if ($GLOBALS[$class]->enabled) {
            $GLOBALS[$class]->output = array();
            $GLOBALS[$class]->process();
             for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
              if (osc_not_null($GLOBALS[$class]->output[$i]['title']) && osc_not_null($GLOBALS[$class]->output[$i]['text'])) {
                $order_total_array[] = array('code' => $GLOBALS[$class]->code,
                                             'title' => $GLOBALS[$class]->output[$i]['title'],
                                             'text' => $GLOBALS[$class]->output[$i]['text'],
                                             'value' => $GLOBALS[$class]->output[$i]['value'],
                                             'sort_order' => $GLOBALS[$class]->sort_order);
              }
            }
          }
        }
      }


        var_dump($order_total_array);   =============>  step 2 ==> all is not ok after the loop
        exit;




      return $order_total_array;
    }

 

step 1 ==>  see the coupon 

array (size=5)
0 => string 'ot_subtotal.php' (length=15)
1 => string 'ot_discount_coupon.php' (length=22)
2 => string 'ot_shipping.php' (length=15)
3 => string 'ot_tax.php' (length=10)
4 => string 'ot_total.php' (length=12)

step2: result
 

array (size=3)
0 =>
array (size=5)
'code' => string 'ot_subtotal' (length=11)
'title' => string 'Sous-Total:' (length=11)
'text' => string '22.92$ CAD' (length=10)
'value' => float 22.92
'sort_order' => string '5' (length=1)
1 =>
array (size=5)
'code' => string 'ot_shipping' (length=11)
'title' => string 'Prix forfaitaire (Prix forfaitaire):' (length=36)
'text' => string '5.00$ CAD' (length=9)
'value' => string '5.00' (length=4)
'sort_order' => string '10' (length=2)
2 =>
array (size=5)
'code' => string 'ot_total' (length=8)
'title' => string 'Total:' (length=6)
'text' => string ' 27.92$ CAD ' (length=12)
'value' => float 27.92
'sort_order' => string '60' (length=2)


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

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

 

Link to comment
Share on other sites

I continue my monologue but it can help someone if  a day there is the same pb !

 

I found where is the pb, 

discount_coupon after checkout confirmation.php is not take in consideration. that's why the values is taken by order_total.php.


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

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

 

Link to comment
Share on other sites

found solution

 

In order.php 

find

 

// discount coupons
      global $coupon;
      
      if( isset($_SESSION['coupon']) && tep_not_null( $coupon ) ) {
        $coupon = $_SESSION['coupon'];
        require(DIR_WS_CLASSES.'discount_coupon.php' );
        $this->coupon = new discount_coupon( $coupon, $this->delivery );
        $this->coupon->total_valid_products( $products );
        $valid_products_count = 0;
      }

replace by

 

      if( isset($_SESSION['coupon']) && tep_not_null($_SESSION['coupon']) ) {
        require(DIR_WS_CLASSES.'discount_coupon.php' );
        $this->coupon = new discount_coupon(  $_SESSION['coupon'], $this->delivery );
        $this->coupon->total_valid_products( $products );
        $valid_products_count = 0;
      }

That's all.

 

This solution must be apply for the futur version on osc.

 


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

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

 

Link to comment
Share on other sites

Well that was a good bit of bug hunting  :)  is this because of the new  session handling in 2.3.4 ?

 

Regards

Joli

Edited by joli1811
To improve is to change; to be perfect is to change often.

 

Link to comment
Share on other sites

the futur version of osc change, there repercussion some modification can affect an addon. Concerning the coupon, just little modification must be do also in checkout_confirmation.php $coupon, become $_SESSION['coupon']. But this modification can be done on the current version of osc.


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

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

 

Link to comment
Share on other sites

  • 3 weeks later...

I am running version 3.0 of Discount Coupon Codes.  The files have been modified from some other add-ons which were added.  Because of this I am not able to just drop in modifications but rather have to do a compare and try to pick out what needs to be changed.

 

I am having a problem that I see mentioned frequently in this forum thread but don't see a resolution.  I use table based shipping and when the discount applied brings you into a new shipping zone you get caught in a loop where it brings you to checkout_shipping and displays an error of 'Your calculated shipping charges have changed.'.   Then you just get stuck in the loop every time you enter the coupon.

 

If anyone could help me with a resolution to this issue I would greatly apprecitate it.  Thanks.

Link to comment
Share on other sites

  • 4 weeks later...

Hi all,

 

Been searching and browsing this topic but cannot seem to find the problem that I have. Sorry if I'm double-posting, but time is scarse (as ever).

 

Problem: Order-total is not zero when coupon is negative.

Environment: osC v2.3.3.4, add-on v3.34

E.g.:

Subtotal: €3.90

Shipping:€2.95

Coupon xxx: -€9.99

Total: €0.51 (<== should be zero!)

Settings:

Sort Order
90
Display subtotal with applied discount?
false
Display tax in discount line?
Display discount with discounted tax applied
Exclude product specials?
true
Display discount total lines for each tax group?
true
Allow negative order total?
false
 

Coupon of €8.26, fixed amount, with 21% tax this is €9.99.

 

Weird thing: the order-total remains 0.51 regardless of the subtotal value (as long as the calculation remains negative).

 

Any ideas?

TIA!

Edited by dfirefire
Link to comment
Share on other sites

  • 4 weeks later...

Need help if anyone is still monitoring this thread.

 

I set up coupon codes for specific items by excluding everything except these items.  If a customer adds more than one of the non-excluded items, I would like the discount to be applied to each item.  Not sure if this module is supposed to do that right out of the box but it's not working for me.

 

Item discount= $1.00

 

 

3 x item = $15

Discount - $1 (want it to be $3)

 

Total $14 

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
internetautomart on 07 November 2010 - 22:49 in General Add-Ons Support

'internetautomart', on 07 Nov 2010 - 12:15, said:snapback.png

after searching I saw no one else with this issue.

with this contributions mod in my orders.php file (instruction to edit line 244) I get a DOUBLE price on the item in the cart.

I.E. them item has a sell price of 50 in the order section it shows 100. the shopping cart on the right hand side still shows 50 though.

any one know what change i need to make to that bit of code to stop the doubling?

this also happens whether the coupon contrib is active or not.

I found the fix on the contrib page.

where the instructions said replace on line 244 use this code instead:

//kgt - discount coupons

if( is_object( $this->coupon ) ) {

$applied_discount = 0;

$discount = $this->coupon->calculate_discount( $this->products[$index], $valid_products_count );

if( $discount['applied_discount'] > 0 ) $valid_products_count++;

$shown_price = $this->coupon->calculate_shown_price( $discount, $this->products[$index] );

$this->info['subtotal'] += $shown_price['shown_price'];

$shown_price = $shown_price['actual_shown_price'];

} else {

$shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);

$this->info['subtotal'] += $shown_price;

}

/**************

$shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];

$this->info['subtotal'] += $shown_price;

**************/

//end kgt - discount coupons

 

I am having problem same as above, i tried that code but still no luck. Please help. thank you

Link to comment
Share on other sites

  • 10 months later...

 

found solution

 

In order.php 

find

 

// discount coupons
      global $coupon;
      
      if( isset($_SESSION['coupon']) && tep_not_null( $coupon ) ) {
        $coupon = $_SESSION['coupon'];
        require(DIR_WS_CLASSES.'discount_coupon.php' );
        $this->coupon = new discount_coupon( $coupon, $this->delivery );
        $this->coupon->total_valid_products( $products );
        $valid_products_count = 0;
      }

replace by

 

      if( isset($_SESSION['coupon']) && tep_not_null($_SESSION['coupon']) ) {
        require(DIR_WS_CLASSES.'discount_coupon.php' );
        $this->coupon = new discount_coupon(  $_SESSION['coupon'], $this->delivery );
        $this->coupon->total_valid_products( $products );
        $valid_products_count = 0;
      }

That's all.

 

This solution must be apply for the futur version on osc.

 

 

 

@@Gyakutsuki Loic I was just reading about your detective work on this.  It was a good read and I enjoyed seeing the process you went through.  What I didn't see is what became of it.   Did it fix the PayPal Express issue and were you able to add the Discount Code routine to the shopping_cart page and also have it work with PayPal Express?

 

Dan

Link to comment
Share on other sites

@@greasemonkey Scott I just reading up on this old thread...reviewing the PayPal Express issue and was wondering if you tested Loic's solution before you moved on to Lambros's Disount Code module?

 

Dan

Link to comment
Share on other sites

@Dan Cole

I use with paypal standard,I don't know if it work with paypal express, but it should be.

Edited by Gyakutsuki


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

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

 

Link to comment
Share on other sites

@@Dan Cole I moved on some time ago to http://addons.oscommerce.com/info/7700 ... because it was/is (I think) the only version that works with PayPal Express and then I updated it to work in BS (which I think you followed my notes here; http://www.oscommerce.com/forums/topic/402359-modding-up-a-234bs-gold/)

 

I believe @@Tsimi version is based on this as well???

 

@@raiwa helped me get this working with free shipping coupon - which I don't use anymore....I now use a flat rate module modified to show $0.00 shipping at free shipping amount so customers can "upgrade" to paid shipping and receive it faster.

Link to comment
Share on other sites

@@greasemonkey

 

That is correct. I converted that addon to BS a while ago since it was straight forward, code-wise and didn't require too many changes to the core and database.

Plus it is the only one I know that works bug-free with PayPal Express and all the other payment modules.

When you pay with PP Express it even shows the discount listed which is nice.

Edited by Tsimi
Link to comment
Share on other sites

@@Tsimi @@greasemonkey Thanks guys....I'm kind of locked into the Discount Coupon add-on because it works with an email program that I use.  PayPal Express isn't really a concern for me personally but if I'm going to invest some time in setting up a module for it, it would be nice to have it work with PayPal Express....sounds like Loic's @@Gyakutsuki fix surfaced after you guys moved on so I guess we don't know if that solves the problem or not.  Hopefully we'll see.

 

Dan

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...