The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

one item max per cart

I need to restrict the number of items in the cart to one unique SKU with quantity of one "1".

I have been using the following code to reset/delete the cart every time an item is added;

var FC = FC || {};
FC.onLoad = function () {
FC.client.on("sidecart-show", function (params) {
FC.client.request('').done(function(dataJSON) {
console.log( dataJSON.items );

This works until the user clicks Proceed to checkout then the cart shows empty. Does anyone know a better way or event handler? I am new to foxycart and just getting to know the options available. Thank you.
  • fc_marijafc_marija FoxyCart Team
    Hello @kingkong -

    If I'm understanding your needs correctly, you can pass the empty parameter along with your add-to-cart. From our docs:

    This will clear the contents of the cart. If products are added in the same request, the cart will be emptied and then the products will be added.

    true: Empties the cart, including all custom session values, coupons, customer address and prepopulation values, shipping selections, etc.
    reset: Does all of the above but also resets the cookie. The use case for this is uncommon, so in general you should use the true instead of the reset value.
    For an add-to-cart link, it'd look something like this:

    For an add-to-cart form, you'd add this to your form element:
    <input type="hidden" name="empty" value="true" />
    Hope that helps.
  • kingkongkingkong Member
    edited February 2019
    Yes, that did work. To go straight to the checkout I added:

    input type="hidden" name="cart" value="checkout"
Sign In or Register to comment.