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.

Adding items to Cart using API call

Hi FC,

Got couple of questions...


A. I would like to be able to add items to cart programmatically.

My workflow is as follows:

1. Client configures an item by going through wizard steps
2. Client reaches the last page of the wizard, clicks FINISH button and I send a request to the server
3. If all goes well, I would like to add the configured item to the cart in 'success' phase of JQuery's $.ajax (and see the "sliding" screen and the cart

B. How do I disallow quantity modification in the Foxy Cart interface? I'd like to set it to 1, and preferably - remove the quantity input field altogether.

Thanks!
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @temuri416,

    You can use JSONP to add the product using javascript - check out details of that on our wiki here: http://wiki.foxycart.com/static/redirect/jsonp
    B. How do I disallow quantity modification in the Foxy Cart interface? I'd like to set it to 1, and preferably - remove the quantity input field altogether.
    You can set quantity_min and quantity_max values to only allow the customer to change the quantity to within a certain range. If you wanted to not allow quantity changes at all - you could hide the input using CSS or or alter the Twig template for the cart include template.
  • temuri416temuri416 Member
    edited March 2016
    Thanks!

    Another question... Here's what I am trying to do:

    $('#addProduct').on('click', function() {
    FC.client.request('https://'+FC.settings.storedomain+'/cart?name=My+Product&price=20');
    });
    $('#submitCart').on('click', function() {
    FC.client.submitCart();
    });
    I have two buttons - #addProduct and #submitCart. Adding works fine, but when I click #submitCart I get the following JS error:

    TypeError: data is undefined
    ...d=function(params){var data=params.data;return"checkout"==data.cart||"updateinfo...
    The idea is to add a product with one button and then submit cart with another - *skipping* the sliding sidecart.

    What am I missing there?

    Cheers!
  • fc_adamfc_adam FoxyCart Team
    @temuri416,

    If you don't want our Sidecart functionality at all - you can turn that off in your store's configuration in the administration. Under "Customize your cart type" set it to "Full Page".

    For the checkout link - you'd simply set it up as a normal link in your HTML and have the link as https://YOURSTORE.foxycart.com/cart?cart=checkout. That link (once updated for your own FoxyCart subdomain) will send the customer on to the checkout.
  • @fc_adam,

    I've disabled Sidecart and placed a link to /cart?cart=checkout. Clicking it skips showing cart contents and proceeds to payment screen.

    Now, I would like to be able to send my customers directly to payment page - without having them to click "PAY" button or doing things like $('#submitCart_HIDDEN_BUTTON').trigger('click').

    I thought that this would do it:

    $.ajax(.....,
    success: function() {
    FC.client.submitCart();
    }
    But it does nothing at all.

    So, the question is - how can I submit cart contents programmatically, using FC API? I've managed to add items to cart via API, I should also be able to submit it via API, right?

    Cheers!

  • fc_adamfc_adam FoxyCart Team
    edited March 2016
    @temuri416,

    The cartSubmit() function relies on it being passed a link or form element - it's used for handling when products are added to the cart. For your use though, no need to use any special calls - if you want to redirect the customer you can simply do so using javascript:
    window.location.href = "https://YOUR STORE.foxycart.com/cart?cart=checkout&" + FC.session.get();
  • @fc_adam,

    I've disabled Sidecart and use this code to add item:

    FC.client.request('https://'+FC.settings.storedomain+'/cart?name=Tomato&price=123&quantity_min=1&quantity_max=1&' + FC.session.get())
    However, checkout page allows item to be removed or its quantity set to 0. You can't set it to > 1 though.

    Since that checkout page is on FoxyCart side, I can't do this:

    FC.client.on('cart-item-remove', function(params, next)) {
    // stop action.
    });
    What's the best way of preventing user from removing my Tomato from the cart?

    Thank you!
  • fc_adamfc_adam FoxyCart Team
    @temuri416,

    You can use our events on the cart, checkout and receipt just like you can on your own site. You would just need to add your custom code to the relevant template. You can either do that by editing the respective template within the administration or by adding custom footer code through the "Add custom header and footer code to your templates" on your store's configuration page.

    You could also use custom CSS to hide the remove links and the quantity inputs - which would stop a customer from being able to alter the quantity or remove the item. You can add custom CSS to the individual templates, or to the header code option in the "Add custom header and footer code.." configuration.
  • @fc_adam

    It's amazing how flexible FoxyCart is.

    thanks!
Sign In or Register to comment.