Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

@@Gyakutsuki Thank you, i have managed to get rid of that error now. But still cant seem to get this module to show the discount in the checkout_confirmation page. 

 

This site is quite heavily modified in places, so not sure what to look at next. 

 

Everything else to do with the discount is working fine; creating a discount code, editing the code, if a wrong one is entered it shows the error message... it just never actually adds it. I have even gone through to enter card payments to check if it was at least taking it off there, but it isnt.  ( it is also not passing through the discount for paypal). 

 

So something must be breaking between checkout_payment and checkout_confirmation. 

 

If I go through with the purchase, it does link the discount coupon to the order in the discount_coupons_to_orders table, which is added at the checkout_process stage. 

 

I will just have to keep digging. 

Link to comment
Share on other sites

Look if the session is correct  in confirmation

echo  $_SESSION['coupon'];

exit;

 

I you don't see the session,you have a pb. See the page above, I explain in details this pb.


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

@@Gyakutsuki Thank you, I am not sure what you meant, sorry. Should i be putting:

 

echo  $_SESSION['coupon'];

exit;

 

on the page somewhere? if so - nothing came up. 

Could you link me to the solution you talked about, as cant see where you have mentioned it previously on the previous page. 

 

Sorry, i am probably being really dumb with this, but i am just really struggling with it!  :blush:  :(

Link to comment
Share on other sites

@@Gyakutsuki

 

Brilliant, thank you for this.. I have found a problem at the first stage, after doing 

 

 

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;
    }

 

the result is

 

array(4) { 

[0]=> array(5) { 
["code"]=> string(11) "ot_subtotal" 
["title"]=> string(10) "Sub-Total:" 
["text"]=> string(6) "£1.14" 
["value"]=> float(1.14) 
["sort_order"]=> string(1) "1" 
[1]=> array(5) { 
["code"]=> string(11) "ot_shipping" 
["title"]=> string(45) "UK Mainland (DPD Homecall 3 - 5 Day Service):" 
["text"]=> string(6) "£3.65" 
["value"]=> float(3.648) 
["sort_order"]=> string(1) "3" 
[2]=> array(5) { 
["code"]=> string(6) "ot_tax" 
["title"]=> string(11) "VAT Amount:" 
["text"]=> string(6) "£0.80" 
["value"]=> float(0.798) 
["sort_order"]=> string(1) "4" 
[3]=> array(5) { 
["code"]=> string(8) "ot_total" 
["title"]=> string(6) "Total:" 
["text"]=> string(23) "£4.79" 
["value"]=> float(4.788) 
["sort_order"]=> string(1) "5" 
}

 

It isnt even reading the discount coupon at this point.. any ideas? 

Link to comment
Share on other sites

EDIT: i edited the code to match the one above and it made no difference. 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

@@Gyakutsuki sorry, actually reading the code compared to the one you posted, its actually different, dont know how much a difference that will make but here is the code i actually have 

 

 

function process()    {

        $order_total_array = array();
        if (is_array($this->modules)) {
            reset($this->modules);
            while (list(, $value) = each($this->modules)) {
                $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 (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_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;
    }
Edited by evbeej
Link to comment
Share on other sites

your problem is the coupon value. It does'nt sent I think.

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

 could you look in order class if you have $_SESSION['coupon']

if yes write this

var_dump($_SESSION['coupon'])

exit;

and test

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

it breaks it, normal, you need to see an information about $_SESSION['coupon'].

If you see you coupon, it's ok, if not, pb. try to reinstall de contribution with a software like beyond compare.

It's important to the value else in checkout confirmation you won't see the information.


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

@@Gyakutsuki

 

Hmmm.. ive re installed this about 4 times, and its always the same. never appears in confirmation. Following this module ive added the following bits of code to order.php:

 

 

$products = $cart->get_products();

 

//kgt - discount coupons
 global $coupon;
 if( tep_session_is_registered( 'coupon' ) && tep_not_null( $coupon ) ) {
require_once( DIR_WS_CLASSES.'discount_coupon.php' );
$this->coupon = new discount_coupon( $coupon, $this->delivery );
$this->coupon->total_valid_products( $products );
$valid_products_count = 0;
 }
 //end kgt - discount coupons
 
for ($i = 0, $n = sizeof($products); $i < $n; $i++) {

 

 

//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 = tep_add_tax($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

 

 

//kgt - discount coupon

 if( is_object( $this->coupon ) ) {
$this->info['total'] = $this->coupon->finalize_discount( $this->info );
 }
//end kgt - discount coupon

 

Are you suggesting i have something else missing from this page? - sorry im not to good with the order total 

Link to comment
Share on other sites

if i add the var_dump in the first lot of KGT code on that page :

 

$products = $cart->get_products();

//kgt - discount coupons
 global $coupon;
 if( tep_session_is_registered( 'coupon' ) && tep_not_null( $coupon ) ) {
require_once( DIR_WS_CLASSES.'discount_coupon.php' );
$this->coupon = new discount_coupon( $coupon, $this->delivery );
$this->coupon->total_valid_products( $products );
$valid_products_count = 0;
//testing coupon issue
var_dump($coupon);
 }
        //end kgt - discount coupons

 

it appears with string(6) "erika2" at the top of the confirmation page...  does that help?

Link to comment
Share on other sites

it appears with string(6) "erika2" at the top of the confirmation page...  does that help?

Seems the value is created.

 

Try to test in order_total directory, discount_coupon.php if you see the calcul of the coupon by a

var_dump($this->output);

 

If you don't see the coupon line or not the calcul, it seems the $coupon does'nt pass, and it's better to use $_SESSION.

It can be a pb with php version.


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

@@Gyakutsuki

 

Please forgive me if i have misunderstood but...

 

i have added the var_dump to the following code in ot_discount_coupon.php:

 

function process() {

      global $order, $currencies;
      if( is_object( $order->coupon ) ) {
 
        //if the order total lines for multiple tax groups should be displayed as one, add them all together
        if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_LINES == 'false' ) $discount_lines = array( array_sum( $order->coupon->applied_discount ) );
        else $discount_lines = $order->coupon->applied_discount;
 
        if( is_array( $discount_lines ) ) foreach( $discount_lines as $tax_group => $discount ) {
          if( $discount > 0 ) {
            //add in the tax if needed:
            if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TAX == 'Display discount with discounted tax applied' && is_array( $order->coupon->discount_tax ) ) $discount += array_sum( $order->coupon->discount_tax );
            //determine the display type (with or without the minus sign):
            $display_type = ( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TYPE == 'true' ? '-' : '' );
            $text = $display_type . $currencies->format( $discount, true, $order->info['currency'], $order->info['currency_value'] );
            //add debug text if debug is on:
            if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $text .= print_r( "\n\n<!-- Discount Coupons DEBUG\n".print_r( $order, true )."\nEnd Discount Coupons DEBUG-->\n\n", true );
            $this->output[] = array( 'title' => $order->coupon->format_display( $tax_group ) . ':',
                                     'text' => $text,
                                     'value' => $display_type . $discount );
          }
        }
        //determine if we need to display a second line to show tax no longer applied
        if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TAX == 'Display discounted tax in separate line' && is_array( $order->coupon->discount_tax ) ) {
          $discounted_tax = array_sum( $order->coupon->discount_tax );
          $text = $display_type . $currencies->format( $discounted_tax, true, $order->info['currency'], $order->info['currency_value'] );
          $this->output[] = array( 'title' => MODULE_ORDER_TOTAL_DISCOUNT_COUPON_TAX_NOT_APPLIED . ':',
                                   'text' => $text,
                                   'value' => $display_type . $discounted_tax );
        }
var_dump($this->output);
      } else $this->enabled = false;
    }

 

This has added the following to the top of the confirmation: 

string(6) "erika2" array(0) { }

 

:( 

Link to comment
Share on other sites

Ok, if you don'tl tel me the files I don't search everytime.

I think your problem become in my opinion on the transfert value, I have some problem with that and that's why you need to use $_SESSION['coupon']. Go back on the page I sent you above and try to  follow the debug and test every time if you see all the values.

checkout_payment

discount class

checkout confirmation

order_total

checkout process

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

Following the link you send me Loic , i didnt get it working. 

 

However i have found something that might point to the issue. 

 

While checking at every point i have found that doing a var_dump here (in checkout_confirmation.php):

 

 

<?php

                        //order total code
                        if (MODULE_ORDER_TOTAL_INSTALLED) {
 
                            echo $order_total_modules->output();
 
                        }
 
                        var_dump($order->coupon);
 
?>

 

The following comes up: 

 

 

object(discount_coupon)#10 (5) { 

["messages"]=> array(0) { 
["coupon"]=> array(10) { 
["coupons_id"]=> string(6) "erika2" 
["coupons_description"]=> string(4) "test" 
["coupons_discount_amount"]=> string(4) "0.10" 
["coupons_discount_type"]=> string(7) "percent" 
["coupons_date_start"]=> NULL
["coupons_date_end"]=> NULL 
["coupons_max_use"]=> string(2) "10" 
["coupons_min_order"]=> string(6) "0.0000"
["coupons_min_order_type"]=> string(5) "price"
["coupons_number_available"]=> string(2) "10" 
["applied_discount"]=> array(1) { 
["VAT Amount"]=> int(0) 
["cart_info"]=> array(3) { 
["valid_products"]=> array(3) { 
["count"]=> int(0) 
["line_items"]=> int(0) 
["total"]=> int(0) 
["total_products"]=> array(3) { 
["count"]=> int(1) 
["line_items"]=> int(1) 
["total"]=> float(26.66) 
["exclusions"]=> array(3) { 
["categories"]=> array(0) { 
["products"]=> array(1) { 
[0]=> int(686) 
["manufacturers"]=> array(0) {
["discount_tax"]=> array(1) { 
["VAT Amount"]=> int(0) 
}

 

It looks as though whenever i have an item in my cart, it adds it to the 'exclusions' list? 

 

Anyone have any ideas? 

 

E

Edited by evbeej
Link to comment
Share on other sites

:- new problem! 

 

I have it set up so that the customer gets free shipping if they spend over £30. 

 

I have 2 items in the shopping cart, which totals £33.48

I add a discount of 50% which takes the total to 16.74

 

which now pushes the purchase to below the £30 free shipping limit, so i get the error:

Your calculated shipping charges have changed.

I have seen a couple if people mention this on theirs, and my version of the module (3.34 plus bug fixes) seems to have all those fixes incorporated already. 

 

as far as i can see, this bit of code which is on classes/discount_coupon.php, is meant to sort this... 

static function is_recalc_shipping() {
      global $order, $language;

      //calculate the order total:
      $order_total = $order->info['total'] - $order->info['shipping_cost'];
      if( DISPLAY_PRICE_WITH_TAX != 'true' ) $order_total -= $order->info['tax'];

      //check if there is free shipping
      if( strtolower(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING) == 'true' ) {
        include( DIR_WS_LANGUAGES.$language.'/modules/order_total/ot_shipping.php' );
        //if free shipping is enabled, make sure the discount does not bring the order total below free shipping limit
        if( $order->info['shipping_method'] == FREE_SHIPPING_TITLE ) { //if free shipping is the selected shipping method
          if( $order_total < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER ) { //if the discount lowers the total below the free shipping limit
           return true; 
		   
          }
        }
      }

      //check if table rate shipping has changed
      if( strtolower(MODULE_SHIPPING_TABLE_STATUS) == 'true' ) {
        include( DIR_WS_LANGUAGES.$language.'/modules/shipping/table.php' );
        if( substr($order->info['shipping_method'], 0, strlen(MODULE_SHIPPING_TABLE_TEXT_TITLE)) == MODULE_SHIPPING_TABLE_TEXT_TITLE && MODULE_SHIPPING_TABLE_MODE == 'price' ) {
          $table_cost = split( "[:,]", MODULE_SHIPPING_TABLE_COST );
          for( $i = 0; $i < count( $table_cost ); $i += 2 ) {
            if( $order_total <= $table_cost[$i] ) {
              $shipping = $table_cost[$i+1];
              break;
            }
          }
          if( $order->info['shipping_cost'] != $shipping ) { //if the discount lowers the total below the table rate
            return true;
          }
        }
      }

      return false;
    }

But it just doesnt seem to be doing it.. 

 

any ideas anyone? 

 

E

Edited by evbeej
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Hi

 

It's possible to add something on checkout_success to send me a mail when a specific discount code is used?

For example:

 

if ( $coupon['coupons_id'] == 'testcupon') {
 
$to = 'user@host';
$subject = 'Notification of testcupon';
$message = 'Discount cupon  $coupon['coupons_id'] was used by "firstname" "lastname" - total of orders: "total" - value from discount: "discount" ';
$from = "From: Owner Store <owner@hostt>";
mail($to,$subject,$message,$from);
 
}
Link to comment
Share on other sites

  • 2 weeks later...

Looking through this forum I too got the following error when trying to add excluded zones for a discount code...

1136 - Column count doesn't match value count at row 1

INSERT INTO discount_coupons_to_zones VALUES ( "POST5", 3 )

[TEP STOP]

...to get around it I manually added the zones into the discount_coupons_to_zones table via PHPMyAdmin - hopefully that helps other people having the same issue.

Link to comment
Share on other sites

  • 2 months later...

The insert should specify the columns to be inserted.

 

I'm still trying to  figure out how to do in

admin/includes/classes/coupons_exclusions.php

 

The code is a bit too generic.

Edited by vmn
Link to comment
Share on other sites

This is my dirty hack:

      //VMN2017.01.06var $type, $display_fields, $coupons_id, $table_name, $selected_options, $all_options;
      var $type, $inserted_columns, $display_fields, $coupons_id, $table_name, $selected_options, $all_options;
 

function save( $selected_options = array() ) {
            tep_db_query( $sql = 'DELETE FROM '.$this->table_name.' WHERE coupons_id="'.$this->coupons_id.'"' );
            //VMN2017.01.06 start
            $inserted_columns = '';
            if ($this->type  === 'zones') {
                $inserted_columns = ' (coupons_id, geo_zone_id)';
            }
            //VMN2017.01.06 end
            if( is_array( $selected_options ) && count( $selected_options ) > 0 ) {
                foreach( $selected_options as $ids ) {
                    //VMN2017.06.1tep_db_query( $sql = 'INSERT INTO '.$this->table_name.' VALUES ( "'.$this->coupons_id.'", '.(int)$ids.' )' );
                    tep_db_query( $sql = 'INSERT INTO '.$this->table_name. $inserted_columns . ' VALUES ( "'.$this->coupons_id.'", '.(int)$ids.' )' );
                }
            } else return false;
        }

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...