pouyak Posted July 12, 2009 Share Posted July 12, 2009 anyone knows how to fix the following error caused by discount_coupon.php.... Warning: Illegal offset type in /homepages/13/d269723143/htdocs/store/includes/classes/discount_coupon.php on line 361 Warning: Illegal offset type in isset or empty in /homepages/13/d269723143/htdocs/store/includes/classes/discount_coupon.php on line 364 Warning: Illegal offset type in /homepages/13/d269723143/htdocs/store/includes/classes/discount_coupon.php on line 365 Warning: Cannot modify header information - headers already sent by (output started at /homepages/13/d269723143/htdocs/store/includes/classes/discount_coupon.php:361) in /homepages/13/d269723143/htdocs/store/includes/functions/general.php on line 33 <?php/* * discount_coupon.php * August 4, 2006 * author: Kristen G. Thorson * ot_discount_coupon_codes version 3.0 * * * Released under the GNU General Public License * */ class discount_coupon { var $messages, $coupon, $applied_discount, $cart_info; function discount_coupon( $code, $delivery ) { $this->messages = array(); $this->coupon = array(); $this->applied_discount = array(); $this->cart_info = array( 'valid_products' => array( 'count' => 0, 'line_items' => 0, 'total' => 0 ), 'total_products' => array( 'count' => 0, 'line_items' => 0, 'total' => 0 ), 'exclusions' => array() ); $this->get_coupon( $code, $delivery ); //get the module configuration values for debugging if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) { $check_values_query = tep_db_query( $sql = "SELECT configuration_key, configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key LIKE 'MODULE_ORDER_TOTAL_DISCOUNT_COUPON%' OR configuration_key = 'DISPLAY_PRICE_WITH_TAX' OR configuration_key = 'MODULE_SHIPPING_TABLE_STATUS' OR configuration_key = 'MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING'" ); while( $row = tep_db_fetch_array( $check_values_query ) ) { $this->message( 'INFO: '.$row['configuration_key'].' = '.$row['configuration_value'], 'debug' ); } } } function verify_code() { //check the global number of discounts that may be used if( $this->coupon['coupons_number_available'] != 0 ) { $this->check_num_available(); } //if coupons_max_use==0, then use is unlimited, otherwise, we need to verify the customer hasn't used this coupon more than coupons_max_use times if( $this->coupon['coupons_max_use'] != 0 ) { $this->check_coupons_max_use(); } } function get_coupon( $code, $delivery ) { global $customer_id; //needed for customer_exclusions $check_code_query = tep_db_query( $sql = "SELECT dc.* FROM " . TABLE_DISCOUNT_COUPONS . " dc WHERE coupons_id = '".tep_db_input( $code )."' AND ( coupons_date_start <= CURDATE() OR coupons_date_start IS NULL ) AND ( coupons_date_end >= CURDATE() 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 $this->message( ENTRY_DISCOUNT_COUPON_ERROR ); //display the error message } else { //customer_exclusions $check_user_query = tep_db_query( $sql = 'SELECT dc2u.customers_id FROM '.TABLE_DISCOUNT_COUPONS_TO_CUSTOMERS.' dc2u WHERE customers_id='.(int)$customer_id.' AND coupons_id="'.tep_db_input( $code ).'"' ); if( tep_db_num_rows( $check_user_query ) > 0 ) { $this->message( ENTRY_DISCOUNT_COUPON_ERROR ); //display the error message //use this to debug exclusions: //$this->message( 'Customer exclusion check failed' ); } //shipping zone exclusions $check_user_query = tep_db_query($sql = 'SELECT dc2z.geo_zone_id FROM '.TABLE_DISCOUNT_COUPONS_TO_ZONES.' dc2z LEFT JOIN '.TABLE_ZONES_TO_GEO_ZONES.' z2g USING( geo_zone_id ) WHERE ( z2g.zone_id='.(int)$delivery['zone_id'].' or z2g.zone_id = 0 or z2g.zone_id IS NULL ) AND ( z2g.zone_country_id='.(int)$delivery['country_id'].' or z2g.zone_country_id = 0 ) AND dc2z.coupons_id="'.tep_db_input( $code ).'"' ); if (tep_db_num_rows( $check_user_query ) > 0 ) { $this->message( ENTRY_DISCOUNT_COUPON_ERROR ); //display the error message //use this to debug exclusions: //$this->message( 'Shipping Zones exclusion check failed' ); } //end shipping zone exclusions $row = tep_db_fetch_array( $check_code_query ); //since there is one record, we have a valid code $this->coupon = $row; } } function check_coupons_min_order() { switch( $this->coupon['coupons_min_order_type'] ) { //minimum number of products: case 'quantity': global $cart; $total = $this->cart_info['valid_products']['count']; if( $this->coupon['coupons_min_order'] > $total ) { //make sure there are enough products in the cart $this->message( sprintf( ENTRY_DISCOUNT_COUPON_MIN_QUANTITY_ERROR, $this->coupon['coupons_min_order'] ) ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Failed to pass check_coupons_min_order(): $total='.$total, 'debug' ); return false; } break; //minimum price: case 'price': default: global $order, $currencies; $total = $this->cart_info['valid_products']['total']; //if we display the subtotal without the discount applied, then just compare the subtotal to the minimum order if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' && $this->coupon['coupons_min_order'] > $total ) { $this->message( sprintf( ENTRY_DISCOUNT_COUPON_MIN_PRICE_ERROR, $currencies->format( $this->coupon['coupons_min_order'], true, $order->info['currency'], $order->info['currency_value'] ) ).'.' ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Failed to pass check_coupons_min_order(): $total='.$total, 'debug' ); return false; //if we display the subtotal with the discount applied, then we need to compare the subtotal with the discount added back in to the minimum order } else if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'true' ) { $subtotal = $total; foreach( $this->applied_discount as $discount ) { $subtotal += $discount; } if( $this->coupon['coupons_min_order'] > $subtotal ) { $this->message( sprintf( ENTRY_DISCOUNT_COUPON_MIN_PRICE_ERROR, $currencies->format( $this->coupon['coupons_min_order'], true, $order->info['currency'], $order->info['currency_value'] ) ).'.' ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Failed to pass check_coupons_min_order(): $subtotal='.$subtotal, 'debug' ); return false; } } break; } return true; } function check_coupons_max_use() { global $customer_id; $check_use_query = tep_db_query($sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_ORDERS." AS o INNER JOIN ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o ON dc2o.orders_id=o.orders_id AND o.customers_id = '".(int)$customer_id."' AND dc2o.coupons_id='".tep_db_input( $this->coupon['coupons_id'] )."'"); $use = tep_db_fetch_array( $check_use_query ); //show error message if coupons_max_use is equal to the number of times this customer has used the code if( $this->coupon['coupons_max_use'] <= $use['cnt'] ) { $this->message( sprintf( ENTRY_DISCOUNT_COUPON_USE_ERROR, $use['cnt'], $this->coupon['coupons_max_use'] ) ); //display the error message for number of times used return false; } return true; } function check_num_available() { //count the number of times this coupon has been used $check_use_query = tep_db_query( $sql = 'SELECT COUNT(*) AS cnt FROM '.TABLE_DISCOUNT_COUPONS_TO_ORDERS.' WHERE coupons_id="'.tep_db_input( $this->coupon['coupons_id'] ).'"' ); $use = tep_db_fetch_array( $check_use_query ); if( $this->coupon['coupons_number_available'] <= $use['cnt'] ) { $this->message( ENTRY_DISCOUNT_COUPON_AVAILABLE_ERROR ); //display error that this coupon is no longer valid return false; } return true; } 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; } function is_allowed_product( $product_id ) { //category exclusion if( !is_array( $this->cart_info['exclusions']['categories'] ) ) { //only create the array when we need to and only once //check to see if the product is in one of the limited categories $check_category_query = tep_db_query( $sql = 'SELECT categories_id FROM '.TABLE_DISCOUNT_COUPONS_TO_CATEGORIES.' WHERE coupons_id="'.tep_db_input( $this->coupon['coupons_id'] ).'"' ); $this->cart_info['exclusions']['categories'] = array(); if( tep_db_num_rows( $check_category_query ) > 0 ) { //for each category, get all the child categories while( $categories = tep_db_fetch_array( $check_category_query ) ) { $this->cart_info['exclusions']['categories'][] = $categories['categories_id']; tep_get_subcategories( $this->cart_info['exclusions']['categories'], $categories['categories_id'] ); } //$this->excluded_categories are all categories and subcategories excluded from use with the coupon code $this->cart_info['exclusions']['categories'] = array_unique( $this->cart_info['exclusions']['categories'] ); } } if( count( $this->cart_info['exclusions']['categories'] ) > 0 ) { $c_path = tep_get_product_path( $product_id ); //get the product's cPath $this_products_catgeory_array = tep_parse_category_path( $c_path ); //convert the product's cPath into an array //if the product's cPath and the excluded categories array have elements in common, then the product is excluded $intersection = array_intersect( $this_products_catgeory_array, $this->cart_info['exclusions']['categories'] ); if( is_array( $intersection ) && count( $intersection ) > 0 ) { //use this to debug exclusions: if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$category.' failed manufacturer exclusion check', 'debug' ); return false; } } //end category exclusion //product exclusion if( !is_array( $this->cart_info['exclusions']['products'] ) ) { //only create the array when we need to and only once //check to see if the product is in one of the limited categories $check_product_query = tep_db_query( $sql = 'SELECT products_id FROM '.TABLE_DISCOUNT_COUPONS_TO_PRODUCTS.' WHERE coupons_id="'.tep_db_input( $this->coupon['coupons_id'] ).'"' ); $this->cart_info['exclusions']['products'] = array(); if( tep_db_num_rows( $check_product_query ) > 0 ) { while( $products = tep_db_fetch_array( $check_product_query ) ) { $this->cart_info['exclusions']['products'][] = $products['products_id']; } } } if( count( $this->cart_info['exclusions']['products'] ) > 0 ) { if( in_array( $product_id, $this->cart_info['exclusions']['products'] ) ) { //use this to debug exclusions: if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$product_id.' failed product exclusion check', 'debug' ); return false; } } //end product exclusion //manufacturer exclusion if( !is_array( $this->cart_info['exclusions']['manufacturers'] ) ) { //only create the array when we need to and only once //check to see if the product is in one of the limited categories $check_manufacturer_query = tep_db_query( $sql = 'SELECT manufacturers_id FROM '.TABLE_DISCOUNT_COUPONS_TO_MANUFACTURERS.' WHERE coupons_id="'.tep_db_input( $this->coupon['coupons_id'] ).'"' ); $this->cart_info['exclusions']['manufacturers'] = array(); if( tep_db_num_rows( $check_manufacturer_query ) > 0 ) { while( $manufacturers = tep_db_fetch_array( $check_manufacturer_query ) ) { $this->cart_info['exclusions']['manufacturers'][] = $manufacturers['manufacturers_id']; } } } if( count( $this->cart_info['exclusions']['manufacturers'] ) > 0 ) { $check_manufacturer_query = tep_db_query( $sql = 'SELECT manufacturers_id FROM '.TABLE_PRODUCTS.' WHERE products_id="'.(int)$product_id.'"' ); if( tep_db_num_rows( $check_manufacturer_query ) > 0 ) { $manufacturers = tep_db_fetch_array( $check_manufacturer_query ); if( in_array( $manufacturers['manufacturers_id'], $this->cart_info['exclusions']['manufacturers'] ) ) { //use this to debug exclusions: if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$product_id.' failed manufacturer exclusion check', 'debug' ); return false; } } } //end manufacturer exclusion //specials exclusion if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_EXCLUDE_SPECIALS == 'true' ) { if( ( $special_price = tep_get_products_special_price( $product_id ) ) !== null ) { $this->cart_info['exclusions']['products'][] = $product_id; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$product_id.' failed specials exclusion check. Adding product to excluded products array.', 'debug' ); return false; } } //end specials exclusion return true; } function is_exists_exclusions() { if( $this->cart_info['valid_products']['total'] != $this->cart_info['total_products']['total'] ) return true; if( $this->cart_info['valid_products']['count'] != $this->cart_info['total_products']['count'] ) return true; return false; } //this function is for tracking the product totals and count so that we can correctly calculate the discount function total_valid_products( $products = array() ) { global $cart; for( $i = 0; $i < count( $products ); $i++ ) { if (DISPLAY_PRICE_WITH_TAX == "true"){ $product_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']); $price = ( tep_add_tax($products[$i]['price'], $product_tax) + $cart->attributes_price( $products[$i]['id'] ) ) * $products[$i]['quantity']; }else{ $price = ( $products[$i]['price'] + $cart->attributes_price( $products[$i]['id'] ) ) * $products[$i]['quantity']; } $this->cart_info['total_products']['total'] += $price; $this->cart_info['total_products']['count'] += $products[$i]['quantity']; $this->cart_info['total_products']['line_items']++; if( $this->is_allowed_product( tep_get_prid( $products[$i]['id'] ) ) ) { //not an excluded product $this->cart_info['valid_products']['count'] += $products[$i]['quantity']; $this->cart_info['valid_products']['total'] += $price; $this->cart_info['valid_products']['line_items']++; } } } function calculate_discount( $product = array(), $current_product = 0 ) { if( !$this->is_allowed_product( tep_get_prid( $product['id'] ) ) ) { //check that the product isn't excluded $applied_discount = 0; //don't apply a discount if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Excluded product '.$product['id'].'. Discount of '.$applied_discount.' not applied.', 'debug' ); } else { switch( $this->coupon['coupons_discount_type'] ) { case 'shipping': $applied_discount = 0; break; case 'fixed': //get the percentage of the total discount to apply to this item: $percentage_applied = $this->coupon['coupons_discount_amount'] / $this->cart_info['valid_products']['total']; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Percentage of discount applied to product '.$product['id'].': '.$percentage_applied.'.', 'debug' ); //calculate the applied discount: $applied_discount = $product['final_price'] - $percentage_applied; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Fixed discount applied to product '.$product['id'].': '.$applied_discount.'.', 'debug' ); //this section is to make sure that both the fixed discount and the tax are correct: if( $this->cart_info['valid_products']['line_items'] == ( $current_product + 1 ) ) { $difference = $this->coupon['coupons_discount_amount'] - ( array_sum( $this->applied_discount ) + $applied_discount ); if( $difference != 0 ) { if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Fixed adjustment for product '.$product['id'].': difference: '.$difference.' unadjusted applied_discount: '.$applied_discount, 'debug' ); $applied_discount += $difference; } } //end code to ensure accurate fixed discount and tax break; case 'percent': $applied_discount = $product['final_price'] * $this->coupon['coupons_discount_amount'] * $product['qty']; break; } if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$product['id'].' passed exclusion check. Discount '.$applied_discount.' applied. ('.$this->coupon['coupons_discount_type'].')', 'debug' ); } //now determine how we need to handle tax: if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_TAX != 'None' ) { $discount_tax = $this->apply_tax( $applied_discount, $product['tax'], false, true ) - $applied_discount; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Tax not applied to product '.$product['id'].': '.$discount_tax, 'debug' ); } else $discount_tax = 0; //tally the discount tax amount for each tax group if( isset( $this->discount_tax[$product['tax_description']] ) ) $this->discount_tax[$product['tax_description']] += $discount_tax; else $this->discount_tax[$product['tax_description']] = $discount_tax; //tally the discount amount for each tax group if( isset( $this->applied_discount[$product['tax_description']] ) ) $this->applied_discount[$product['tax_description']] += $applied_discount; else $this->applied_discount[$product['tax_description']] = $applied_discount; $discount = array('applied_discount' => $applied_discount, 'discount_tax' => $discount_tax); return $discount; } function calculate_shown_price( $discount, $product ) { $actual_shown_price = null; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Discount of '.( $discount['applied_discount'] + $discount['discount_tax'] ).' applied to product '.$product['id'].' ($'.$product['final_price'] * $product['qty'].').', 'debug' ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) { //we don't want to display the subtotal with the discount applied, so apply the discount then set the applied_discount variable to zero so that it's not added into the order subtotal, but is still used to correctly calculate tax $actual_shown_price = ( $this->apply_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) - ( $discount['applied_discount'] + $discount['discount_tax'] ); $applied_discount = 0; $shown_price = $this->apply_tax( $product['final_price'], $product['tax'] ) * $product['qty']; //$product['final_price'] * $product['qty']; } else { $shown_price = ( $this->apply_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) - ( $discount['applied_discount'] + $discount['discount_tax'] ); } //if we need to display the subtotal without the discount applied, then add the shown price to the subtotal, then change shown price to the price with the applied discount in order to properly calculate taxes if( !isset( $actual_shown_price ) ) $actual_shown_price = $shown_price; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Calculating tax on '.$actual_shown_price.'. Displayed price '.$shown_price.'.', 'debug' ); $shown_price_array = array( 'shown_price' => $shown_price, 'actual_shown_price' => $actual_shown_price ); return $shown_price_array; } function finalize_discount( $info ) { //make sure we meet the order minimum if( !$this->check_coupons_min_order() ) { $this->applied_discount = array(); if( $this->is_exists_exclusions() ) $this->message( ENTRY_DISCOUNT_COUPON_EXCLUSION_ERROR ); //add on to the min_order error message since we have excluded items } if( !$this->is_errors() ) { //if there are no errors, we can apply the discount if( $this->coupon['coupons_discount_type'] == 'shipping' ) { //discount shipping if the coupon type is shipping //bugfix by xinxi if($this->cart_info['valid_products']['count']>0){ $this->applied_discount['shipping'] = $info['shipping_cost'] * $this->coupon['coupons_discount_amount']; $this->applied_discount['shipping'] = $this->applied_discount['shipping']; $info['total'] -= $this->applied_discount['shipping']; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Shipping Discount of '.$this->applied_discount['shipping'].' applied.', 'debug' ); }//end bugfix by xinxi } else if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) { //subtract the discount from the order total if it's not displayed in the subtotal foreach( $this->applied_discount as $discount ) { $info['total'] -= $discount; if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Discount of '.$discount.' applied to order total.', 'debug' ); } } if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_ALLOW_NEGATIVE == 'false' && $info['total'] < 0 ) $info['total'] = 0; } return $info['total']; } //this function is for making sure rounding doesn't happen except when desired function apply_tax( $price, $tax, $round = false, $force = false ) { if( DISPLAY_PRICE_WITH_TAX == 'true' || $force ) { if( $tax != 0 ) $price = tep_add_tax( $price, $tax ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Applied tax of '.$tax.' to: '.$price, 'debug' ); } if( $round ) { global $currencies; $price = tep_round( $price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places'] ); if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Rounded price: '.$price, 'debug' ); } return $price; } function format_display( $tax_group = '' ) { global $order, $currencies; //if using multiple languages, get the language format string from the proper language file, otherwise, use the module configuration field $display = ( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_USE_LANGUAGE_FILE == 'true' ? MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_FILE : MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_CONFIG ); switch( $this->coupon['coupons_discount_type'] ) { case 'shipping': $discount_amount = ( $this->coupon['coupons_discount_amount'] * 100 ).'% '.MODULE_ORDER_TOTAL_DISCOUNT_COUPON_TEXT_SHIPPING_DISCOUNT; break; case 'percent': $discount_amount = ( $this->coupon['coupons_discount_amount'] * 100 ).'%'; break; case 'fixed': $discount_amount = $currencies->format( $this->coupon['coupons_discount_amount'] ); break; } $min_order = ( $this->coupon['coupons_min_order'] != 0 ? ( $this->coupon['coupons_min_order_type'] == 'price' ? $currencies->format( $this->coupon['coupons_min_order'] ) : (int)$this->coupon['coupons_min_order'] ) : '' ); //replace the variables with their proper values: $display = str_replace( ' ', $this->coupon['coupons_id'], $display ); $display = str_replace( '[discount_amount]', $discount_amount, $display ); $display = str_replace( '[coupon_desc]', $this->coupon['coupons_description'], $display ); $display = str_replace( '[min_order]', $min_order, $display ); $display = str_replace( '[number_available]', $this->coupon['coupons_number_available'], $display ); $display = str_replace( '[tax_desc]', $tax_group, $display ); return $display; } function is_errors() { if( count( $this->messages['error'] ) > 0 ) return true; return false; } function message( $message, $error_level = 'error' ) { $this->messages[$error_level][] = $message; } function get_messages( $error_level = 'error' ) { if( $error_level == 'debug' ) return $this->messages; return $this->messages[$error_level]; } }?> Quote Link to comment Share on other sites More sharing options...
Esquire Posted July 12, 2009 Share Posted July 12, 2009 The contribution works!!! One question though: how do I add CATEGORY SPECIALS to exclusion list? I am thinking that those are on sale anyway and would like to exclude those products from further discount. Thanks alot for the contribution!!! Quote Link to comment Share on other sites More sharing options...
gwynwyffar Posted July 13, 2009 Share Posted July 13, 2009 I've just installed DCC version 3.34 dated July 9 2009 by xinxi on a modified version of RC2.2a. All seems to be working properly with the exception of Max. Use. I have the coupons set to a max use of 1 (so one use per customer) however upon testing I find that I can reuse the coupon code multiple times. I've searched the forums and see lots of posts with people having the same issue, but I cannot seem to find the fix for this issue. Can anyone shed some light as to which version of the contribution this may have been corrected on, or how I can correct it? Quote Link to comment Share on other sites More sharing options...
sudd12 Posted July 14, 2009 Share Posted July 14, 2009 I get this error in Catalog -> Discount Coupons 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-6, 6' at line 1 select * from discount_coupons cd order by cd.coupons_date_end, coupons_date_start limit -6, 6 Does anyone knows what wrong? Quote Link to comment Share on other sites More sharing options...
Gems Posted July 14, 2009 Share Posted July 14, 2009 Hi, Hope all is well. I cant seem to download this contribution: http://www.oscommerce.com/community/contri...nt+coupon+codes i tried double clicking, and right clicking. Quote Link to comment Share on other sites More sharing options...
Gems Posted July 14, 2009 Share Posted July 14, 2009 Hi, Hope all is well. I cant seem to download this contribution: http://www.oscommerce.com/community/contri...nt+coupon+codes i tried double clicking, and right clicking. nm i got it.. Sorry Quote Link to comment Share on other sites More sharing options...
Cyberspiritual Posted July 15, 2009 Share Posted July 15, 2009 Hey guys, On my side I have been able to install the contrib (lot of errors in this contrib btw). But now when I click on create new coupon, nothing appens...so I can't create any coupon... please help... Quote Link to comment Share on other sites More sharing options...
sudd12 Posted July 16, 2009 Share Posted July 16, 2009 Problem solved. It seems that I am using an old version of oscommerce admin. The admin cant handle any empty databases. Quote Link to comment Share on other sites More sharing options...
pouyak Posted July 17, 2009 Share Posted July 17, 2009 Discount Coupon value gets added to the sub total rather then deduct from subtotal anyone knows how to fix this? Quote Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 17, 2009 Share Posted July 17, 2009 Hi Thanks for the contribution, it is very nice and flexible add on. I am having a problem with the tax being calculated correctly. My state has a 6 percent tax and must be calculated from the subtotal + shipping, before a discount is applied. Taxes are calculated properly when I do not submit a coupon code and works fine with Discount Loyalty contribution. Here is example of what happens in checkout_confirmation.php using a 5 percent coupon. Sub-total: 135.20 Shipping: 16.64 Tax: 8.70 Discount: 6.76 Total: 153.78 As you can see sub-total 135.20 + shipping 16.64 = 151.84. Then 151.84 x .06 tax rate = 9.11. When I use a coupon tax is 41 cents less. Please help! Thanks I am a pretty good code cut and paster and know a liitle programming. I have Discount coupon 3.34 Oscommerce 2rc2a Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
pouyak Posted July 17, 2009 Share Posted July 17, 2009 (edited) Hi Thanks for the contribution, it is very nice and flexible add on. I am having a problem with the tax being calculated correctly. My state has a 6 percent tax and must be calculated from the subtotal + shipping, before a discount is applied. Taxes are calculated properly when I do not submit a coupon code and works fine with Discount Loyalty contribution. Here is example of what happens in checkout_confirmation.php using a 5 percent coupon. Sub-total: 135.20 Shipping: 16.64 Tax: 8.70 Discount: 6.76 Total: 153.78 As you can see sub-total 135.20 + shipping 16.64 = 151.84. Then 151.84 x .06 tax rate = 9.11. When I use a coupon tax is 41 cents less. Please help! Thanks I am a pretty good code cut and paster and know a liitle programming. I have Discount coupon 3.34 Oscommerce 2rc2a I think is because you have add discount tax... anyways the number is coming from this (subtotal + shipping ) - discount = answer answer * 0.06 = your tax Edited July 17, 2009 by pouyak Quote Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 17, 2009 Share Posted July 17, 2009 I think is because you have add discount tax... anyways the number is coming from this (subtotal + shipping ) - discount = answer answer * 0.06 = your tax Hi Thanks for helping. The only Settings I know are these 2 screens. Admin>Modules>Order Total ---------------------------------- Enable discount coupon? true Sort Order 5 Display discount with minus (-) sign? false Display subtotal with applied discount? false Display tax in discount line? None Exclude product specials? false Random Code Length 6 Display discount total lines for each tax group? false Allow negative order total? false Use the language file to format display string? false Display Format for Order Total Line Discount Coupon applied Debug Modefalse Admin>Catalog>Discount coupons----------------------------------------Discount Coupons NOTICE: Click here to read the Discount Coupon Codes manual for help editing coupons. Coupon Code: save05 Description: Save 5 percent off products Discount Amount: .05 Discount Type: percentFor percentage or shipping discounts, enter a percentage as a decimal. Example: .10 for 10%Start Date: 7/16/2009 End Date: 7/20/2009 Max Use: 0 Min Order: 0 Min Order Type:Number Available: Please Help Thanks! Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
pouyak Posted July 18, 2009 Share Posted July 18, 2009 Hi Thanks for helping. The only Settings I know are these 2 screens. Admin>Modules>Order Total ---------------------------------- Enable discount coupon? true Sort Order 5 Display discount with minus (-) sign? false Display subtotal with applied discount? false Display tax in discount line? None Exclude product specials? false Random Code Length 6 Display discount total lines for each tax group? false Allow negative order total? false Use the language file to format display string? false Display Format for Order Total Line Discount Coupon applied Debug Modefalse Admin>Catalog>Discount coupons----------------------------------------Discount Coupons NOTICE: Click here to read the Discount Coupon Codes manual for help editing coupons. Coupon Code: save05 Description: Save 5 percent off products Discount Amount: .05 Discount Type: percentFor percentage or shipping discounts, enter a percentage as a decimal. Example: .10 for 10%Start Date: 7/16/2009 End Date: 7/20/2009 Max Use: 0 Min Order: 0 Min Order Type:Number Available: Please Help Thanks! which package did you install? the latest one? Quote Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 18, 2009 Share Posted July 18, 2009 which package did you install? the latest one? Hi I installed the lastest version of discount coupon. Thanks! Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 18, 2009 Share Posted July 18, 2009 which package did you install? the latest one? Hi Ot discount coupon codes 3.34 which is the latest version. Thanks! Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 18, 2009 Share Posted July 18, 2009 which package did you install? the latest one? Hi I found the file where the tax calculation is done. Looks like this might be towards the end of the code. Do you know of any freeware debuggers I could use to determine the values of the varibles. Stepping threw this code with debugger should help find the problem. I can't see the problem looking at it. Also: This may be caused by the installation of the contribution. The first code snippet directly below Maybe where problem is. //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 = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']); $this->info['subtotal'] += $shown_price; **************/ //end kgt - discount coupons Use above remark code if code after ELSE doesnot work for ideas Check with install instructions for this file. The instructions said to find: $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']; $this->info['subtotal'] += $shown_price; This is what was there: $shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']); $this->info['subtotal'] += $shown_price; Then it said to replace with code in the above snippet. In a previous post in this topic forum they said to replace as if it was the same as what instructions wanted you to find. Below is the entire code for catalog/includes/classes/order.php <?php /* $Id: order.php 1750 2007-12-21 05:20:28Z hpdl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2007 osCommerce Released under the GNU General Public License */ class order { var $info, $totals, $products, $customer, $delivery, $content_type; function order($order_id = '') { $this->info = array(); $this->totals = array(); $this->products = array(); $this->customer = array(); $this->delivery = array(); if (tep_not_null($order_id)) { $this->query($order_id); } else { $this->cart(); } } function query($order_id) { global $languages_id; $order_id = tep_db_prepare_input($order_id); $order_query = tep_db_query("select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); $order = tep_db_fetch_array($order_query); $totals_query = tep_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order"); while ($totals = tep_db_fetch_array($totals_query)) { $this->totals[] = array('title' => $totals['title'], 'text' => $totals['text']); } $order_total_query = tep_db_query("select text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_total'"); $order_total = tep_db_fetch_array($order_total_query); $shipping_method_query = tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_shipping'"); $shipping_method = tep_db_fetch_array($shipping_method_query); $order_status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . $order['orders_status'] . "' and language_id = '" . (int)$languages_id . "'"); $order_status = tep_db_fetch_array($order_status_query); $this->info = array('currency' => $order['currency'], 'currency_value' => $order['currency_value'], 'payment_method' => $order['payment_method'], 'cc_type' => $order['cc_type'], 'cc_owner' => $order['cc_owner'], 'cc_number' => $order['cc_number'], 'cc_expires' => $order['cc_expires'], 'date_purchased' => $order['date_purchased'], 'orders_status' => $order_status['orders_status_name'], 'last_modified' => $order['last_modified'], 'total' => strip_tags($order_total['text']), 'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title']))); $this->customer = array('id' => $order['customers_id'], 'name' => $order['customers_name'], 'company' => $order['customers_company'], 'street_address' => $order['customers_street_address'], 'suburb' => $order['customers_suburb'], 'city' => $order['customers_city'], 'postcode' => $order['customers_postcode'], 'state' => $order['customers_state'], 'country' => array('title' => $order['customers_country']), 'format_id' => $order['customers_address_format_id'], 'telephone' => $order['customers_telephone'], 'email_address' => $order['customers_email_address']); $this->delivery = array('name' => trim($order['delivery_name']), 'company' => $order['delivery_company'], 'street_address' => $order['delivery_street_address'], 'suburb' => $order['delivery_suburb'], 'city' => $order['delivery_city'], 'postcode' => $order['delivery_postcode'], 'state' => $order['delivery_state'], 'country' => array('title' => $order['delivery_country']), 'format_id' => $order['delivery_address_format_id']); if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) { $this->delivery = false; } $this->billing = array('name' => $order['billing_name'], 'company' => $order['billing_company'], 'street_address' => $order['billing_street_address'], 'suburb' => $order['billing_suburb'], 'city' => $order['billing_city'], 'postcode' => $order['billing_postcode'], 'state' => $order['billing_state'], 'country' => array('title' => $order['billing_country']), 'format_id' => $order['billing_address_format_id']); $index = 0; $orders_products_query = tep_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'"); while ($orders_products = tep_db_fetch_array($orders_products_query)) { $this->products[$index] = array('qty' => $orders_products['products_quantity'], 'id' => $orders_products['products_id'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'price' => $orders_products['products_price'], 'final_price' => $orders_products['final_price']); $subindex = 0; $attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']); $subindex++; } } $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1'; $index++; } } function cart() { global $HTTP_POST_VARS, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment, $comments, $customer_default_address_id; $this->content_type = $cart->get_content_type(); if ( ($this->content_type != 'virtual') && ($sendto == false) ) { $sendto = $customer_default_address_id; } $customer_address_query = tep_db_query("select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . (int)$customer_id . "' and ab.customers_id = '" . (int)$customer_id . "' and c.customers_default_address_id = ab.address_book_id"); $customer_address = tep_db_fetch_array($customer_address_query); if (is_array($sendto) && !empty($sendto)) { $shipping_address = array('entry_firstname' => $sendto['firstname'], 'entry_lastname' => $sendto['lastname'], 'entry_company' => $sendto['company'], 'entry_street_address' => $sendto['street_address'], 'entry_suburb' => $sendto['suburb'], 'entry_postcode' => $sendto['postcode'], 'entry_city' => $sendto['city'], 'entry_zone_id' => $sendto['zone_id'], 'zone_name' => $sendto['zone_name'], 'entry_country_id' => $sendto['country_id'], 'countries_id' => $sendto['country_id'], 'countries_name' => $sendto['country_name'], 'countries_iso_code_2' => $sendto['country_iso_code_2'], 'countries_iso_code_3' => $sendto['country_iso_code_3'], 'address_format_id' => $sendto['address_format_id'], 'entry_state' => $sendto['zone_name']); } elseif (is_numeric($sendto)) { $shipping_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int)$customer_id . "' and ab.address_book_id = '" . (int)$sendto . "'"); $shipping_address = tep_db_fetch_array($shipping_address_query); } else { $shipping_address = array('entry_firstname' => null, 'entry_lastname' => null, 'entry_company' => null, 'entry_street_address' => null, 'entry_suburb' => null, 'entry_postcode' => null, 'entry_city' => null, 'entry_zone_id' => null, 'zone_name' => null, 'entry_country_id' => null, 'countries_id' => null, 'countries_name' => null, 'countries_iso_code_2' => null, 'countries_iso_code_3' => null, 'address_format_id' => 0, 'entry_state' => null); } if (is_array($billto) && !empty($billto)) { $billing_address = array('entry_firstname' => $billto['firstname'], 'entry_lastname' => $billto['lastname'], 'entry_company' => $billto['company'], 'entry_street_address' => $billto['street_address'], 'entry_suburb' => $billto['suburb'], 'entry_postcode' => $billto['postcode'], 'entry_city' => $billto['city'], 'entry_zone_id' => $billto['zone_id'], 'zone_name' => $billto['zone_name'], 'entry_country_id' => $billto['country_id'], 'countries_id' => $billto['country_id'], 'countries_name' => $billto['country_name'], 'countries_iso_code_2' => $billto['country_iso_code_2'], 'countries_iso_code_3' => $billto['country_iso_code_3'], 'address_format_id' => $billto['address_format_id'], 'entry_state' => $billto['zone_name']); } else { $billing_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int)$customer_id . "' and ab.address_book_id = '" . (int)$billto . "'"); $billing_address = tep_db_fetch_array($billing_address_query); } if ($this->content_type == 'virtual') { $tax_address = array('entry_country_id' => $billing_address['entry_country_id'], 'entry_zone_id' => $billing_address['entry_zone_id']); } else { $tax_address = array('entry_country_id' => $shipping_address['entry_country_id'], 'entry_zone_id' => $shipping_address['entry_zone_id']); } $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $currency, 'currency_value' => $currencies->currencies[$currency]['value'], 'payment_method' => $payment, 'cc_type' => '', 'cc_owner' => '', 'cc_number' => '', 'cc_expires' => '', 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array(), 'comments' => (tep_session_is_registered('comments') && !empty($comments) ? $comments : '')); if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) { if (isset($GLOBALS[$payment]->public_title)) { $this->info['payment_method'] = $GLOBALS[$payment]->public_title; } else { $this->info['payment_method'] = $GLOBALS[$payment]->title; } if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) { $this->info['order_status'] = $GLOBALS[$payment]->order_status; } } $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => ((tep_not_null($customer_address['entry_state'])) ? $customer_address['entry_state'] : $customer_address['zone_name']), 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'email_address' => $customer_address['customers_email_address']); $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => ((tep_not_null($shipping_address['entry_state'])) ? $shipping_address['entry_state'] : $shipping_address['zone_name']), 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']); $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => ((tep_not_null($billing_address['entry_state'])) ? $billing_address['entry_state'] : $billing_address['zone_name']), 'zone_id' => $billing_address['entry_zone_id'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']); $index = 0; $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++) { $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']), 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id']); if ($products[$i]['attributes']) { $subindex = 0; reset($products[$i]['attributes']); while (list($option, $value) = each($products[$i]['attributes'])) { $attributes_query = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$products[$i]['id'] . "' and pa.options_id = '" . (int)$option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int)$languages_id . "' and poval.language_id = '" . (int)$languages_id . "'"); $attributes = tep_db_fetch_array($attributes_query); $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attributes['products_options_values_name'], 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']); $subindex++; } } //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 = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']); $this->info['subtotal'] += $shown_price; **************/ //end kgt - discount coupons Use above remark code if code after ELSE doesnot work for ideas Check with install instructions for this file. $products_tax = $this->products[$index]['tax']; $products_tax_description = $this->products[$index]['tax_description']; if (DISPLAY_PRICE_WITH_TAX == 'true') { $this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); if (isset($this->info['tax_groups']["$products_tax_description"])) { $this->info['tax_groups']["$products_tax_description"] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); } else { $this->info['tax_groups']["$products_tax_description"] = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); } } else { $this->info['tax'] += ($products_tax / 100) * $shown_price; if (isset($this->info['tax_groups']["$products_tax_description"])) { $this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price; } else { $this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price; } } $index++; } 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']; } //kgt - discount coupon if( is_object( $this->coupon ) ) { $this->info['total'] = $this->coupon->finalize_discount( $this->info ); } //end kgt - discount coupon } } ?> Please help Thanks! Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
Nitrocharged Posted July 20, 2009 Share Posted July 20, 2009 any one get this contribution works via Paypal? On checkout comfirmation page, I can see the discount code does works, however, when transfer to Paypal page, the total back to normal without discount applied... I solved this by going into the Paypal IPN module in the payment section and set the show items to 'aggregate' instead of 'individual' items. Quote Link to comment Share on other sites More sharing options...
Moparcj5 Posted July 27, 2009 Share Posted July 27, 2009 Hi I am still trying to locate the code to make my taxes right Post #2486 toward top of page 125. I need it to do: (subtotal + shipping) * tax rate = tax amount; subtotal + shipping + tax amount - discount = total Instead only when using coupon: (subtotal - discount + shipping) * tax rate = tax amount; subtotal + shipping + tax amount - discount = total This contribution Ot discount coupon codes 3.34 Please Help point me to what file I need to change and if so kind where. I appreciate any help. Thanks Joey Quote I have installed: Oscommerce version 2.2rc2a, STS version 4.5.8, Header Tags SEO version 3.1.5, SEO Assistant version 2.1 Thanks Joey Link to comment Share on other sites More sharing options...
agoranet Posted July 27, 2009 Share Posted July 27, 2009 I am doing a new install of both osCommerce (2.2a) and this contribution so I just did a full FTP of files for both. It appears as though some of the main definitions, e.g. define('FILENAME_LOGIN', 'login.php'), are missing from the contribution's version of the include files so it broke my osCommerce installation. Am I missing something obvious? I got around this particular missing entry by hand editing filenames.php but now I'm hitting others and wondering if I'm going to have to edit each file in the installation. Thanks for any help. Lorie Quote Link to comment Share on other sites More sharing options...
STRunner Posted July 27, 2009 Share Posted July 27, 2009 (edited) hi, first sorry for my (perhaps) bad english. i have a problem with the discount coupons 3.34. if i enter a coupon code which i created a few minutes ago, the error "The coupon code you have entered is not valid." appears. i have read about the date probelm, and chnged it to dd/mm/yyy, like it is written in the discount coupon in the admin panel. perhaps i have to change it in another file,too? further, the buttons which are attached in the contrib (category_exclusions etc.) doesn't appeat in my admin panel. it woul be great if you could help me!!! i attached you a picture how you can see my admin panel: Edited July 27, 2009 by STRunner Quote Link to comment Share on other sites More sharing options...
TAOL Posted July 28, 2009 Share Posted July 28, 2009 I am doing a new install of both osCommerce (2.2a) and this contribution so I just did a full FTP of files for both. It appears as though some of the main definitions, e.g. define('FILENAME_LOGIN', 'login.php'), are missing from the contribution's version of the include files so it broke my osCommerce installation. Am I missing something obvious? I got around this particular missing entry by hand editing filenames.php but now I'm hitting others and wondering if I'm going to have to edit each file in the installation. Thanks for any help. Lorie Hi, I'm this or a similar problem also so any help would be appreciated. Once I've done a new install of both osCommerce and this contribution it works fine until I exit the admin console. I can't then get back into the admin console.. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
STRunner Posted July 28, 2009 Share Posted July 28, 2009 i solved the problem. Quote Link to comment Share on other sites More sharing options...
agoranet Posted July 28, 2009 Share Posted July 28, 2009 Hi, I'm this or a similar problem also so any help would be appreciated. Once I've done a new install of both osCommerce and this contribution it works fine until I exit the admin console. I can't then get back into the admin console.. Thanks in advance. yes - I had to hand edit the database_tables.php and filenames.php files in admin/includes and /includes to get it to work. It would be nice to have it fixed but I also want to make sure I'm not going to hit anything else. Thanks! Quote Link to comment Share on other sites More sharing options...
vegasbeach Posted July 29, 2009 Share Posted July 29, 2009 Hello, I just installed the newest version: 3.34 All is great except the number used is always at 0 - never updated. Also the max use - set to 1 - never changes. Is there some code change not implimented into the current package? i've gone over code changes twice. Everything is in place. I use standard paypal checkout if that matters. Quote Link to comment Share on other sites More sharing options...
Nitrocharged Posted July 29, 2009 Share Posted July 29, 2009 Did you update the database file? Hello, I just installed the newest version: 3.34 All is great except the number used is always at 0 - never updated. Also the max use - set to 1 - never changes. Is there some code change not implimented into the current package? i've gone over code changes twice. Everything is in place. I use standard paypal checkout if that matters. 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.