felvecourt Posted June 1, 2012 Share Posted June 1, 2012 Hi All , I ahve installed the Discount Coupon addon and attached document contains are the changes that I have made manually as the website is already running from long time . Now my problem is that , whenever I add any discount code in field and continue , it never give me discount ,I always have to refresh the chehout_confirmation.php page. how to resolve this issue . The Second Scnerio ======== Let say once I have added the discount and completed my order and again started with a new order ,and if I dont add anything on the discount code and continue , it still give me the discount .Now If I again refresh the page it make it all sorted me . Please any idea's to resolve this issue or let me know any good addon that will work without any problems and I am bit in rush to deliver it to my client. Can any one have a look to the code added for checkout_confirmation.php page and order,php as I think there are the main files running the logic ? I have follwed the below steps and made changes admin/includes/boxes/catalog.php ---------------------------------------------- line 29 replace '<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>' ); with //kgt - discount coupons '<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>'. '<a href="' . tep_href_link(FILENAME_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_DISCOUNT_COUPONS . '</a>' ); //end kgt - discount coupons admin/includes/database_tables.php -------------------------------------------- add //kgt - discount coupons define('TABLE_DISCOUNT_COUPONS', 'discount_coupons'); define('TABLE_DISCOUNT_COUPONS_TO_ORDERS', 'discount_coupons_to_orders'); //end kgt - discount coupons admin/includes/filenames.php -------------------------------------------------- add //kgt - discount coupons define('FILENAME_DISCOUNT_COUPONS','coupons.php'); //end kgt - discount coupons admin/includes/languages/english.php ------------------------------------------ add //kgt - discount coupons define('BOX_CATALOG_DISCOUNT_COUPONS', 'Discount Coupons'); //end kgt - discount coupons catalog/checkout_confirmation.php --------------------------------------------- line 63 after if (is_array($payment_modules->modules)) { $payment_modules->pre_confirmation_check(); } add //kgt - discount coupons if( tep_not_null($HTTP_POST_VARS['coupon']) ) { //if they have entered something in the coupon field // verify the coupon code $passed = false; $check_code_query = tep_db_query("select coupons_max_use as max_use, coupons_min_order as min_order from " . TABLE_DISCOUNT_COUPONS . " where coupons_id = '" . tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) . "' and ( coupons_date_start < NOW() or coupons_date_start is null ) and ( coupons_date_end > NOW() or coupons_date_end is null )"); if( tep_db_num_rows( $check_code_query ) != 1 ) { //if no rows are returned, then they haven't entered a valid code if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //unregister the session $error_message = ENTRY_DISCOUNT_COUPON_ERROR; //display the error message } else { $row = tep_db_fetch_array( $check_code_query ); //since there is one record, we have a valid code if( $row['max_use'] != '0' ) { //if max_use==0, then use is unlimited, otherwise, we need to verify the customer hasn't //used this coupon more than max_use times $check_use_query = tep_db_query("select count(*) as cnt from ".TABLE_ORDERS." o inner join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o on dc2o.orders_id=o.orders_id and o.customers_id = $customer_id and dc2o.coupons_id='".tep_db_prepare_input( $HTTP_POST_VARS['coupon'] )."'"); $use = tep_db_fetch_array( $check_use_query ); if( $row['max_use'] > $use['cnt'] ) $passed = true; //proceed if max_use is greater than the number of times this customer has used the code else { echo 'bb'; $passed = false; //do not proceed echo 'ii'; $error_message = sprintf( ENTRY_DISCOUNT_COUPON_USE_ERROR, $use['cnt'], $row['max_use'] ); //display the error message for number of times used } } else $passed = true; //if max_use==0, then use is unlimited //now we need to check if the order total matches the min_order if( $row['min_order'] != 0 && $row['min_order'] > $order->info['subtotal'] ) { $passed = false; echo 'h'; $error_message = sprintf( ENTRY_DISCOUNT_COUPON_MIN_ERROR, $currencies->format( $row['min_order'], true, $order->info['currency'], $order->info['currency_value'] ) ); } else $passed = true; //proceed if min_order==0 or if min_order is less than the order subtotal } if( $passed ) { //if we have passed all tests, register the coupon in the session if (!tep_session_is_registered('coupon')) tep_session_register('coupon'); $coupon = tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ); } else if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //otherwise, remove the coupon from the session } else if( tep_session_is_registered('coupon') ) {tep_session_unregister('coupon'); $passed = true;}else{tep_session_unregister('coupon');$passed=true;}//if the coupon field is empty, unregister the coupon from the session if( $passed == false ) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode($error_message), 'SSL')); ///if there was an error, redirect to the payment page //end kgt - discount coupons catalog/checkout_process.php --------------------------------------------- line 166 after $sql_data_array = array('orders_id' => $insert_id, 'orders_status_id' => $order->info['order_status'], 'date_added' => 'now()', 'customer_notified' => $customer_notification, 'comments' => $order->info['comments']); tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); add //kgt - discount coupons $sql_data_array = array( 'coupons_id' => $order->info['coupon'], 'orders_id' => $insert_id ); tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array ); //end kgt - discount coupons catalog/checkout_payment.php ------------------------------------------------ line 336 after <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td><?php echo tep_draw_textarea_field('comments', 'soft', '60', '5'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> add <?php /* kgt - discount coupons */ ?> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><b><?php echo TABLE_HEADING_COUPON; ?></b></td> </tr> </table></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><?php echo ENTRY_DISCOUNT_COUPON.' '.tep_draw_input_field('coupon', '', 'size="32"'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <?php /* end kgt - discount coupons */ ?> catalog/includes/classes/order.php -------------------------------------------- line 162 after $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $currency, 'currency_value' => $currencies->currencies[$currency]['value'], 'payment_method' => $payment, 'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''), 'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''), 'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''), 'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''), 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), add //kgt - discount coupons 'coupon' => (isset($GLOBALS['coupon']) ? $GLOBALS['coupon'] : ''), 'applied_discount' => array(), //end kgt - discount coupons line 244 replace $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']; $this->info['subtotal'] += $shown_price; with /$applied_discount = 0; $this_actual_shown_price = null; print_r($this->info); if( !empty( $this->info['coupon'] ) ) { $check_code_query = tep_db_query($sql = "select * from " . TABLE_DISCOUNT_COUPONS . " where coupons_id = '" . $this->info['coupon'] . "'"); $check_code = tep_db_fetch_array($check_code_query); if($check_code['coupons_discount_type']=='percent') { $applied_discount = $currencies->calculate_price( $this->products[$index]['final_price'] * $check_code['coupons_discount_amount'], $this->products[$index]['tax'] ) * $this->products[$index]['qty']; if( isset( $this->info['applied_discount'][$this->products[$index]['tax_description']] ) ) { $this->info['applied_discount'][$this->products[$index]['tax_description']] += $applied_discount; } else { $this->info['applied_discount'][$this->products[$index]['tax_description']] = $applied_discount; } if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) { $this_actual_shown_price = ($currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']) - $applied_discount; $applied_discount = 0; } $shown_price = ($currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']) - $applied_discount; $this->info['subtotal'] += $shown_price; if( isset( $this_actual_shown_price ) ) $shown_price = $this_actual_shown_price; } if($check_code['coupons_discount_type']=='fixed') { $applied_discount=$check_code['coupons_discount_amount']; $shown_price=($currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])- $applied_discount; $this->info['subtotal'] += $shown_price; } } else { //When no Discount code added to the field $shown_price=($currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])- $applied_discount; $this->info['subtotal'] += $shown_price; } //end kgt - discount coupon line 272 after if (DISPLAY_PRICE_WITH_TAX == 'true') { $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost']; } else { $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; } add //kgt - discount coupon if( !empty( $this->info['coupon'] ) && MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) { foreach( $this->info['applied_discount'] as $discount ){ $this->info['total'] -= $discount; } } //end kgt - discount coupon catalog/includes/database_tables.php ------------------------------------------ add //kgt - discount coupons define('TABLE_DISCOUNT_COUPONS', 'discount_coupons'); define('TABLE_DISCOUNT_COUPONS_TO_ORDERS', 'discount_coupons_to_orders'); //end kgt - discount coupons catalog/includes/languages/english.php ---------------------------------------- add //kgt - discount coupons define('ENTRY_DISCOUNT_COUPON_ERROR', 'The coupon code you have entered is not valid.'); define('ENTRY_DISCOUNT_COUPON_USE_ERROR', 'Our records show that you have used this coupon %s time(s). You may not use this code more than %s time(s).'); define('ENTRY_DISCOUNT_COUPON_MIN_ERROR', 'The minimum order total for this coupon is %s'); define('ENTRY_DISCOUNT_COUPON', 'Coupon Code:'); //end kgt - discount coupons catalog/includes/languages/english/checkout_payment.php ---------------------- add //kgt - discount coupons define('TABLE_HEADING_COUPON', 'Do you have a promotional code or discount coupon?' ); //end kgt - discount coupons Thanks in advance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.