Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

Hi Kristen you were right I had missed adding the first new element of code - this i have now done but get this error

 

Parse error: syntax error, unexpected T_IF, expecting ')' in /home/sherpas1/public_html/catalog/includes/classes/order.php on line 168

 

I have looked through the other amendments but cannot see where I might have gone wrong.

 

 

Line 162-168:

 

						  'tax_groups' => array(),
  //kgt - discount coupons
									  'coupon' => (isset($GLOBALS['coupon']) ? $GLOBALS['coupon'] : ''),
									  'applied_discount' => array(),
									  //end kgt - discount coupons					'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));

  if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {

 

When you insert code with comments, you need to be sure that existing code does not appear on the same line. In this block, you have left the last line of the discount codes comment, "//end kgt - discount coupons" on the same line as existing code, "'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));". The existing code must be on it's own line, since by adding a comment before it on the same line, you have effectively commented out that code.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Line 162-168:

 

						  'tax_groups' => array(),
  //kgt - discount coupons
									  'coupon' => (isset($GLOBALS['coupon']) ? $GLOBALS['coupon'] : ''),
									  'applied_discount' => array(),
									  //end kgt - discount coupons					'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));

  if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {

 

When you insert code with comments, you need to be sure that existing code does not appear on the same line. In this block, you have left the last line of the discount codes comment, "//end kgt - discount coupons" on the same line as existing code, "'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));". The existing code must be on it's own line, since by adding a comment before it on the same line, you have effectively commented out that code.

 

Hi Kristen

 

Thanks for all your help and your patience - that has done the trick - several test purchases have all gone through smoothly. Excellent

 

J

Link to comment
Share on other sites

just a suggestion on future releases: perhaps you could include a function that allows you to add products to a "non-discountable" list. reason being is that some items on my site have less than a 10% margin, and if i randomly give out 10% discounts to ppl, i'd actually be losing money...

Link to comment
Share on other sites

I have a customer that in some instances the coupon code will make the checkout amount $0

This is expected and wanted behavior.

 

The problem is a couple of things.

When the user puts in the coupon code the will end up with a $0 amount

they still have to enter a CC# (thats not the BIG issue)

 

THen when the user clicks to complete the process it comes back with a CC error.

Im not sure what do to to handle this.

 

I really need some help on this one. :(

Link to comment
Share on other sites

OK heres a theory on how i might get around it but may still need some help on it.

IF i can move the coupon entry piece to the delivery page OR make it its own step in the checkout process. then if the total amount = 0 then i could make it SKIP the paypamt page alltogether which would solve my problem. this could also be a perm. addition to the contrib for later users because, you never know what people need.

 

THanks for any help.

Link to comment
Share on other sites

These order totals don't add up at all! Did you upgrade to the latest version or did you install it from scratch? If you upgraded, from which version did you upgrade? Double check that you've made the correct changes to includes/classes/order.php, especially from around line 252 to the end of the file.

 

 

I installed from scratch from the latest version. I check the order.php file now.

Link to comment
Share on other sites

Hi, I have a question on moving the input box of coupon code from checkout_payment.php to checkout_shipping.php. The reason is I have PayPal Express Checkout and it will skip checkout_payment.php and go straight to the order_confirmation.php.

 

I have tried moving the coupon input box code to checkout_shipping.php but when I input a discount code in there it's not picking up at all. It seems the input box only works on the checkout_payment.php page.

 

May I know is there a way to move the input coupon code box from checkout_payment.php to checkout_shipping.php? Are there any files that I need to edit as well?

 

Thanks a lot!

Link to comment
Share on other sites

Thank you very much!

 

I should have stated in my earlier post that there are 2 scenarios:

 

Scenario 1: When a customer picks PayPal Express Checkout, my original code will skip checkout_payment.php automatically since the customer has already chosen PayPal as his/her payment option. That's why I need to move the input for discount code to the checkout_shipping.php or else the customer has no place to put in the code.

 

PayPal Express Checkout has this strange requirement that I need to put the Express Checkout option before showing checkout_shipping.php. This is how it is structured and I cannot change it, unfortunately.

 

Scenario 2: When a customer wants to pay by "cash on delivery" or other options, my original code needs checkout_payment.php to show up since this is where the customer picks his/her payment options.

 

Both scenarios will need to show checkout_shipping.php. Therefore, if I can move the input for discount code up one page to checkout_shipping.php, it will be great.

 

Thanks again for any help!

Link to comment
Share on other sites

OK heres a theory on how i might get around it but may still need some help on it.

IF i can move the coupon entry piece to the delivery page OR make it its own step in the checkout process. then if the total amount = 0 then i could make it SKIP the paypamt page alltogether which would solve my problem. this could also be a perm. addition to the contrib for later users because, you never know what people need.

 

THanks for any help.

 

 

This was originally written with the code box on the shipping page, but was moved to payment since some people may have virtual products. There's absolutely no reason why the coupon box can't be on the shipping page.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi, I have a question on moving the input box of coupon code from checkout_payment.php to checkout_shipping.php. The reason is I have PayPal Express Checkout and it will skip checkout_payment.php and go straight to the order_confirmation.php.

 

I have tried moving the coupon input box code to checkout_shipping.php but when I input a discount code in there it's not picking up at all. It seems the input box only works on the checkout_payment.php page.

 

May I know is there a way to move the input coupon code box from checkout_payment.php to checkout_shipping.php? Are there any files that I need to edit as well?

 

Thanks a lot!

 

 

For every box in the checkout, there's code that must process it. You can't just move a box and expect it to work. The code that processes the coupon box is in checkout_confirmation.php.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

For every box in the checkout, there's code that must process it. You can't just move a box and expect it to work. The code that processes the coupon box is in checkout_confirmation.php.

 

Thank you for your reply! I have very limited knowledge on php and I switched the additional codes from Discount Coupon Codes around to no avail.

 

It will be greatly appreciated if you can show me where I should put the codes in checkout_confirmation.php if I want the code to process the input code from checkout_shipping.php.

 

I have downloaded the very first version of this contribution to see how the input code got processed under checkout_shipping.php, but when I read the instructions the input code box is on the checkout_payment.php page instead of checkout_shipping.php page.

 

Many thanks!

Link to comment
Share on other sites

Thank you for your reply! I have very limited knowledge on php and I switched the additional codes from Discount Coupon Codes around to no avail.

 

It will be greatly appreciated if you can show me where I should put the codes in checkout_confirmation.php if I want the code to process the input code from checkout_shipping.php.

 

I have downloaded the very first version of this contribution to see how the input code got processed under checkout_shipping.php, but when I read the instructions the input code box is on the checkout_payment.php page instead of checkout_shipping.php page.

 

Many thanks!

 

The first version on the contributions site wasn't the first version of this code. PM me or email with with your email address and I will send it to you.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

kgt - What is considered a virtual Product?

The client i am doing this for is useing the cart for Online based learning products.

 

Thanks

 

 

This is what I am talking about:

 

http://www.oscommerce.info/kb/osCommerce/A...nfiguration/162

 

If your customers order only downloadable products (virtual - there's no real physical product to be handled or shipped) then the shipping page is by default skipped in the checkout.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

The first version on the contributions site wasn't the first version of this code. PM me or email with with your email address and I will send it to you.

 

Thanks a lot! I have already PM you with my email address. Please let me know if you do not receive it.

Link to comment
Share on other sites

This is what I am talking about:

 

http://www.oscommerce.info/kb/osCommerce/A...nfiguration/162

 

If your customers order only downloadable products (virtual - there's no real physical product to be handled or shipped) then the shipping page is by default skipped in the checkout.

 

then I would need a coupon PAGE all in itself.

say before the shipping page..

 

Then I need to get the total amount before the next page is displayed.

For some reason im not getting it passed.. It looks like the way it works right now is that you are Posting from the payment page to the confirm page with the coupon code.

Edited by rayge
Link to comment
Share on other sites

then I would need a coupon PAGE all in itself.

say before the shipping page..

 

Then I need to get the total amount before the next page is displayed.

For some reason im not getting it passed.. It looks like the way it works right now is that you are Posting from the payment page to the confirm page with the coupon code.

 

 

On the payment page, you can make it work the way CCGV does. Next to the coupon box, have a 'Redeem Coupon' button that will go ahead and post checkout_payment.php. You'd probably need to use the onclick event for the button to bypass the javascript checks for the payment module. In checkout_confirmation.php, process the coupon and then check the order total. If order_total > 0, redirect back to checkout_payment.php. If order_total = 0, then display the confirmation screen.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

When i simply tested it without the checkform JS it still comes back to the payment page.. Im assuming its checking the CC in some fashon on the COnfirm page.

 

 

It could be getting redirected because there is no selected payment module. If the CC is the selected payment module, then yes, there will be validation performed in checkout_confirmation.php (actually performed in the payment module you're using). So you need to make sure your payment module doesn't perform validation if the order total is zero.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

It could be getting redirected because there is no selected payment module. If the CC is the selected payment module, then yes, there will be validation performed in checkout_confirmation.php (actually performed in the payment module you're using). So you need to make sure your payment module doesn't perform validation if the order total is zero.

 

Actually its getting redirected because it is defaulting to the detected payment method..

even if i set an item to $0 and have it skip shipping AND payment pages

Then comment out the code on the confirm page that redirects them to the payment page related to payment validation,

it still shows the authorize.net as the payment method.. therefore it still trys to process through authorize.net

 

Any other ideas?

Edited by rayge
Link to comment
Share on other sites

The first version on the contributions site wasn't the first version of this code. PM me or email with with your email address and I will send it to you.

 

Thanks a lot! Kristen. I got the 2 files and followed your instructions in the email by taking out the codes in checkout_confirmation.php and added relevant codes in checkout_shipping.php. Now checkout_shipping.php recognizes bad codes and gives relevant errors.

 

The only thing that is still not going through is the discount itself cannot be passed to the ultimate total on the checkout_confirmation.php page, i.e. even thought I punched in the correct code, there was no discount applied to the final total.

 

Is there anything else I need to check?

 

Many thanks again!

Link to comment
Share on other sites

Actually its getting redirected because it is defaulting to the detected payment method..

even if i set an item to $0 and have it skip shipping AND payment pages

Then comment out the code on the confirm page that redirects them to the payment page related to payment validation,

it still shows the authorize.net as the payment method.. therefore it still trys to process through authorize.net

 

That's why I think you need to modify the payment module to NOT process when the order total is zero.

 

Another option may be to create a sort of "dummy" payment module (similar to the COD payment module). The COD payment module doesn't really do anything - it's a placeholder for a transaction that will occur after the order is submitted. In checkout_confirmation.php, if the order total is zero, make the dummy payment module the payment method. Looking at the code in checkout_confirmation, I think it's doable.

 

The payment object must be assigned before the order object, but you wouldn't know that you need to reassign the payment object to the dummy module until the order object (that contains the order total) is assigned. Also, the coupon code must be performed using the order object before you'll know the order total is zero. You may be able to do something like this:

 

// load the selected payment module
 require(DIR_WS_CLASSES . 'payment.php');
 $payment_modules = new payment($payment);

 require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 //kgt order total check
 if( $order->info['total'] == 0 ) { //we need to reassign the payment module and recreate the objects
$payment_modules = new payment('cod');  //recreate the payment module 
$order->info['payment_method'] = 'cod'; //reset the order payment method
 }
 //end kgt order total check

 $payment_modules->update_status();

 if ( ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) || (is_object($$payment) && ($$payment->enabled == false)) ) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL'));
 }

 if (is_array($payment_modules->modules)) {
$payment_modules->pre_confirmation_check();
 }

 

 

As long as you're not using the COD module, you should be fine just editing it:

1. Change includes/languages/english/modules/payment/cod.php to match the verbiage you want.

2. Change the selection() function in includes/modules/payment/cod.php to return false (so it doesn't display as a payment option on checkout_payment.php but it's still recognized as an installed payment module):

 

	function selection() {
  return false
}

3. Install the COD module and give it a shot.

 

 

Footnote: I have no idea if any of this will actually work. ;)

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Does this have the capability to offer free shipping with a purchase of a certain $ amount? I am needing to accept vouchers from some customers and offer free shipping to others without overloading the site with too many contributions. Thanks!

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