Your account is limited to posting only in the Pre-Sales Questions forum.
Support forum access is limited to members with a purchase history.

If you are working on behalf of another member, please contact us with the name of the license holder and we will upgrade your account.
   
 
Using coupon codes “on-the-fly”
Posted: 11 May 2010 03:02 PM   [ Ignore ]
Is a Really Great Dancer
Avatar
RankRank
Total Posts:  100
Joined  2010-04-26

I would like to let customers enter their coupon codes on the cart_items_info screen.

When I add the add_coupon_form inside the cart_items_info section, I can no longer update the cart (i.e. change quantity of items or delete items). If I change the qty or try to delete the items, the page refreshes, but the quantities do not change.

Here’s a simple breakdown of my code:

{exp:cartthrob:cart_items_info}

     
...code to display itemsqtyetc.

     
{exp:cartthrob:add_coupon_form}
          
<class="inline">
          <
label for="coupon">Coupon Code</label>
          <
input type="text" name="coupon_code" />
     
{/exp:cartthrob:add_coupon_form}

     
<input type="image" src="/img/s/updateCart.jpg" value="Update Cart" /><a href="{path=store/storeList}"><img src="/img/s/continueShopping.jpg" alt="Continue Shopping" /></a><a href="{path=store/checkout}"><img src="/img/s/checkout.jpg" alt="Checkout" /></a>

{/exp:cartthrob:update_cart_form} 
 Signature 

Jason Turcotte
Turcotte Data & Design
http://turcottedata.com

Profile
 
 
Posted: 11 May 2010 03:13 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRank
Total Posts:  3369
Joined  2009-05-29

You can’t have a form within a form, HTML won’t allow it. So, unfortunately, you’ll have to separate them.

Profile
 
 
Posted: 11 May 2010 04:49 PM   [ Ignore ]   [ # 2 ]
Is a Really Great Dancer
Avatar
RankRank
Total Posts:  100
Joined  2010-04-26

Gah! (duh!)

Thanks. smile

It seems however, that the coupon code “logic” should be part of the cart processes rather than a whole separate process. After all, it does affect the price of the cart.

[ Edited: 11 May 2010 04:52 PM by JasonTurcotte ]
 Signature 

Jason Turcotte
Turcotte Data & Design
http://turcottedata.com

Profile
 
 
Posted: 19 May 2010 12:37 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29

You could do this with AJAX pretty easily.

We DO have it set up to take a coupon within the checkout form. We’ll consider adding it elsewhere.

 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile
 
 
Posted: 19 May 2010 02:51 PM   [ Ignore ]   [ # 4 ]
Is a Really Great Dancer
Avatar
RankRank
Total Posts:  100
Joined  2010-04-26

Any examples using AJAX you could point me to? Not a huge AJAX guy here.

 Signature 

Jason Turcotte
Turcotte Data & Design
http://turcottedata.com

Profile
 
 
Posted: 19 May 2010 03:47 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29

This makes use of jQuery to fill & submit a hidden form, then update DIVs with content pulled from other templates. In this case we have additional templates for cart_total, and for items_in_cart

{exp:cartthrob:add_to_cart entry_id="5" }
<html>
<
head>
    <
title>Ajax Add Coupon Example</title>

[removed][removed]
[removed][removed]
[removed]
jQuery
(document).ready(function($){

    
// bind to the change event of the state select in the checkout form
    
$('#add_submit').click(function(){

        
// display a message indicating that we're updating the tax cost
        
$('#cart_total').html'Updating...' );
        $(
'#items_in_cart').html'Updating...' );

        $(
'#coupon_code').val( $("#add_coupon_code").val() );

        
// use the jquery form plugin method ajaxSubmit to send the form
        
$('#my_form').ajaxSubmit({
            success
: function(data{
                
// load the updated tax value back into the page
                
$('#cart_total').load('{path=includes/cart_total}');
                $(
'#items_in_cart').load('{path=includes/items_in_cart}');

            
}
            
        }
);
    
});
});
[removed]
</head>
<
body>
    <
h1>Ajax Add Coupon Example</h1>
    <!-- 
somewhere in your pagehave this hidden formwhich will be used for ajax submissions-->
    <
div style="display:none;">
        
{exp:cartthrob:add_coupon_form
            id
="my_form"
            
}
            
<input type="text" id="coupon_code" name="coupon_code" />
        
{/exp:cartthrob:add_coupon_form}
    
</div>
    
    <
div>
    <
h2>Items in cart</h2>
    <
div id="items_in_cart">
    
{exp:cartthrob:cart_items_info}
        {title} {item_price} x {quantity}
<br />
        
discount{cart_discount}
    {
/exp:cartthrob:cart_items_info}
    
</div>
    <
br /><br />
    
    
Coupon Code: <input type="text" name="add_coupon_code" id="add_coupon_code" size="15" value="5_off" /> 
    <
input type="submit" id="add_submit" value="Update Coupon Code">

    <
br />
    <
br />

    
Cart Total with Tax Shipping: <div id="cart_total">{exp:cartthrob:cart_total}</div>

</
body>
</
html
 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile
 
 
Posted: 19 July 2010 09:13 AM   [ Ignore ]   [ # 6 ]
Wallflower
Rank
Total Posts:  13
Joined  2010-06-03

I’d second a call for this to be updateable via the update_cart_form tags, as the shipping option is. Makes sense for me to be able to have this all in the same form on the basket page.

Profile
 
 
Posted: 19 July 2010 03:33 PM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8342
Joined  2008-09-29

Agreed.

 Signature 

NOTE: If I say “I will look into x” and you PM me information, please do not hesitate to contact me again about it, if I do not respond in several hours, or at most a day. Please feel free to remind me as you see fit

Profile