Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
I have this scenario: I only have one item to sell(no option of buying more), and I really don't need all the cart functionality(update, delete).

Therefore, I would like when the user populates the input fields(custom options textboxes) to be sent directly to checkout page, where the summary will be shown, along with an option to enter custom coupon codes.

I think I have it working, it redirects to PayPal and it seems ok, but one thing is bugging me.
In the CouchCart tutorial, it says that two templates are needed for everything to work:
$pp['tpl_cart'] = 'cart.php';
$pp['tpl_checkout'] = 'checkout.php';

In my case, I just have the cart.php, but with the added checkout functionality?
Can I leave it this way?

Edit: Or maybe to have checkout.php(with the same code as cart.php) available for couch, but not using it directly from the website?

Thanks,

Mirko
Hi Mirko,

Only the cart template is essential for the cart to work.
You can safely skip the checkout template and put everything in the cart template.

Do let us know if you happen to need any help.
Thanks KK, glad that you clarified this to me. I was confused, because the tutorial says that it needs two templates, but my logic was telling me that it could all be done with cart.php!

I have one more question, is it possible to not store any data in session variables(regarding my one product)?

For example, someone visits the website, enters the info and presses "buy now", then for some reason, the customer closes the browser and returns in a few hours.
He/She does the same process again, but only this time the price will be doubled, because the last added product is still in the cart.

Basically, I would need to clear the cart, not only after redirecting to PayPal, but on every time cart.php page is leaved.
Is this behaviour possible?
Mirko, while there is a tag (cms:pp_empty_cart) that'll allow you to empty the cart at whatever point you wish - I think a better solution would be to simply not allow the visitor to add the item again if the item is already present in the cart.

There was a related question asked just a couple of days back (viewtopic.php?f=2&t=8113} where we did the same thing (the trigger was different - the item had to be out of stock).

I think we can use the same technique in your case too.

Taking the example of the sample Cart application that is described in the docs, following is the original portion of the 'index.php' template that displays the products (excerpted for clarity) -
Code: Select all
<div class="product-details">
    <cms:pp_product_form class="cart-form">
        ..
        ..
        <div class="purchase-box">
            <label class="quantity-label">Qty:</label>
            <input class="product-quantity" type="number" name="qty" min="1" step="1" value="1" title="Quantity">
            <input class="button product-add" type="submit" value="Add to Cart">
        </div>
        ..
        ..
    </cms:pp_product_form>
</div>

We can change it to the following to conditionally show the 'Add to cart' button only if there are no items in the cart -
Code: Select all
<div class="product-details">
    <cms:pp_product_form class="cart-form">
        ..
        ..
        <div class="purchase-box">
            <cms:if "<cms:pp_count_items />" >
                <label class="quantity-label">Already in cart</label>   
            <cms:else />
                <label class="quantity-label">Qty:</label>
                <input class="product-quantity" type="number" name="qty" min="1" step="1" value="1" title="Quantity">
                <input class="button product-add" type="submit" value="Add to Cart">
            </cms:if>   
        </div>
        ..
        ..   
    </cms:pp_product_form>
</div>

Does this help?
Thanks for the reply, but I am afraid that it won't cut it in my case :(

The main problem will still be there, eg; customer enters the details, goes to the checkout page, and then for some reason closes the browser.
He returns(product is added to the cart), but he whishes to enter new product info, and there is no "Buy now" button, because the product is added to the cart.

One very important thing in my case is that I don't use the cart functionality, update quantity, remove item, etc. It is only one product, customer fills the product options textboxes, it takes them to cart/checkout page with just a summary, coupon codes and the PayPal button.
There is no remove item, update, quantity options here.

I would need a way to clear the cart once the user leaves cart.php page.
Maybe to use empty cart tag on all other pages, except cart.php?
Is the site online? Can I see it in action?
Unfortunately no, I am still waiting for the client to buy the domain. Maybe, I can put it up on my test domain.
That'd be perfect. Please put the site on a test domain and grant me temp access.
Thanks.
Thanks for the creds, Mirko.

I had a look at your site and the use-case is this -
You have only one product but it has many variations (text fields).
What you want is that only one line-item should ever be present in the cart (remember that the same product added to the cart with a different variation counts as a separate line-item) and that its quantity should never exceed 1.

Basically, the last item added to the cart should remove all other items from the cart first and have a quantity of 1.

OK, what we can use for this (pretty unusual) condition is the 'pre_calc()' function in cart_ex.php.
This function gets called anytime the cart is modified and is meant to adjust the cart-items' quantities and prices (discounts).

For our purpose, we'll make it enforce the 1 item restriction that we have.

This is how I did it.
I replaced the original 'pre_calc()' function with the following version -
Code: Select all
function pre_calc(){

    if( count($this->updated_rows) ){ // something changed in the cart
        foreach($this->updated_rows as $key=>$orig_qty){
            $tmp = $this->items[$key]; // save the currently added item
            $tmp['quantity']=1; // set its quantity to 1
            $this->items = array(); // empty the cart
            $this->items[$key] = $tmp; // add the item saved above to the cart
            break;
        }
    }
}

The cart is now working the way you needed.
Hope this helps.
Great, thanks a lot!! It is working now the way I need it.
I must admit that it is, as you say, a pretty unusual scenario ;) Hopefully, if someone finds that they are in a same position, this thread will come in handy.

Thanks
10 posts Page 1 of 1
cron