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.

Unique items in mini cart, not total quantity

sccr410sccr410 Member
in Help edited June 2012
http://www.ashwebdev.com/oasisstone/products/blue-hickory-natural/

We are using the quantity field as a way to input square feet for coverage of stone and other yard materials. It will be common for someone to add 500 sq ft, which adds 500 to the quantity. In the upper right, it says you have 500 items in your shopping cart. Is there a way to have that reflect the number of unique items in cart instead of total quantity of items in cart?
Tagged:
Comments
  • fredfred FoxyCart Team
    You'll need to write some custom Javascript in order to do this, so have a look at:
    http://wiki.foxycart.com/v/0.7.2/advanced/javascript

    The information you need is definitely in the JSON cart returned by FoxyCart, you'll just need to do some legwork to get it onto your page. You can display the total price without writing extra code, but it'll take a little more effort to do what you want.

    It looks like you're using FoxyShop, so @sparkweb may have some great ideas to contribute as well. Site looks nice, by the way!
  • fc_adamfc_adam FoxyCart Team
    The other option would be to change the way you handle your add to carts, so instead of setting the quantity to 500, you'd leave it as 1 and add the 500 sq ft figure as a product attribute in the add to cart, and also change the price to represent what 500 sq ft would cost. This would still require some javascript, but you wouldn't need to change the default functionality of the cart.
  • sccr410sccr410 Member
    edited June 2012
    500 is a random number. Users can enter any number they want. So how would I setup a product like that? We can't set predefined pricing for every single numerical value.

    I'm quite lost based on the docs about how to use the JSON stuff to get the number of unique products - just didn't make much sense to me where to start.
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    As I mentioned, it would require a little bit of javascript to make it work, but this is how you'd do it.

    Currently, you'd have a form that has an open quantity field and a hidden price field. Quantity x price = total. Easy. This would leave you with:
    Product Name - 500 - $1000 ($2 per)


    With what I suggested, it's a little bit more complex. What you'd have is an open fake quantity field (one that's given a name like 'SqFt'), a hidden FoxyCart quantity field with a value of 1 (that has a name of 'quantity'), a hidden price field, and finally a hidden field for a product attribute of 'Price Per' or similar.

    Then with some javascript, you'd add an onChange event to the fake quantity field. When that changes, you'd grab the price per from the hidden input, and multiply that by the value of the 'SqFt' open fake quantity field. This would give you your total price, which you'd in turn insert into the hidden price field.

    Then on submission, the customer would see:
    Product Name - 1 - $1000 ($1000 per)
    Sq Ft: $500
    Price Per: $2
  • Thank you Adam for the thorough explanation, that does make sense. This is why I love using FoxyCart :)

    I think the JSON method is going to be the right approach since I am using FoxyShop and your suggestions would require building a custom add to cart button. Either I get the JSON working, or hack FoxyShop and the JSON method sounds easier - should I figure out where to get started.
  • fc_adamfc_adam FoxyCart Team
    For your previous question, to access the json cart object it's simply fc_json. Total products are available as fc_json.product_count
  • product_count still comes back as 500 in the FC object in firebug.

    Still completely perplexed on how to do this one.

    http://www.ashwebdev.com/oasisstone/products/blue-hickory-natural/

    I include foxycart.js now.
    var total = 0;
    	  for(var prop in FC.json.products) {
    	    if (obj.hasOwnProperty(prop)) {
    	      total++;
    	    }
    	  }
    	
    	$('#fc_total_products').text(total);
    
    <a href="https://oasisstone.foxycart.com/cart?cart=view"; class="foxycart"><span id="fc_total_products">0</span> items in cart</a>
    

    Adding foxycart.js however breaks colorbox. This seems like it should be so simple! Docs are completely confusing me right now.
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    You don't need to add the foxycart.js if you already have the FoxyCart files included as provided in the sample code.

    Ah sorry, so what you're wanting to do is have the product total up the top show the unique products.

    Try this out on your page: http://pastie.org/private/zoivxczgvtcmbyisqq1cww
    Make sure you include it after the FoxyCart includes.
Sign In or Register to comment.