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.

Console.log(FC) when including Foxycart.js

austinbizmartaustinbizmart Member
in Help edited March 2014
Hi guys,

What's happening is really weird.

I'm on my company's website and I use foxycart.js to access FC.json.product_count property.
When displaying it on our page, it doesn't print any value but when using console.log(FC) and expanding the contents of FC, I'm able to see the session_id, session_name and json object with the correct information.

Any advice, something I could be missing?
I guess I can request a json object but by instantiating the FC, I should be able to access the cart contents right?

Comments
  • fc_adamfc_adam FoxyCart Team
    @austinbizmart,

    Without seeing your site, it's hard to really diagnose - but at a guess, you may be trying to access the FC.json object before it's actually initialised on the page. You'll need to wrap it in a cart.ready event call as described on this page: http://wiki.foxycart.com/static/redirect/javascript

    Are you seeing any errors in the console at all?
  • austinbizmartaustinbizmart Member
    edited March 2014
    Thanks @fc_adam,
    You mean a jquery $( document ).ready() event, I wrapped FC.json inside, but it is still empty though I see now the session_id.
    I don't see cart.ready event call on that page.

    Btw, I'm only using foxycart.js

    There is no error in console.log, right now it's on my dev machine.
  • fc_adamfc_adam FoxyCart Team
    @austinbizmart,

    Sorry - no, I didn't mean document.ready - fcc.events.cart.ready - it's just referenced as 'ready' on that page, right down the bottom in the 'Adding your own events' section.
  • @fc_adam,

    That did it, thanks a lot.
    fcc.events.cart.ready.add(function() {
            console.log(FC.json.product_count);
        });
    
Sign In or Register to comment.