SimpleMarket the number of item in cart not updating

Hello there,

I'm using SimpleMarket with MarketPress as my parent theme and I have created some template files in my child theme for customization. I would like to ask about a MarketPress function, mp_items_count_in_cart, which is used to display the # of items in the shopping cart. I have put the shopping cart widget and the code mp_items_count_in_cart the sidebar.php in my child theme folder then I tested it by adding a product. The shopping cart works perfectly by showing the product in the cart instantly at the moment I click 'add to cart', but the number from mp_items_count_in_cart is not updating. It only updates when I manually refresh the page.

May I ask if anyone knows the solution to fix this? I think it is the SimpleMarket theme problem rather than MarketPress because when i'm looking at the GridMarket theme the number works and updates instantly.

Thank you very much and any help would be appreciated!

- littlemkv

  • aecnu
    • WP Unicorn

    Greetings littlemkv and Rob,

    Though it took me a bit to set the whole thing up I found that the quantity does indeed refresh immediately when clicking the product unless I am missing something, but see for yourselves:

    Of course this is hosted on my WPMU configured high performance test production server but it works flawlessly as you can see.

    Please test and let me know if I am indeed missing the boat on this issue.

    If I am on the right track then we need to dig to see why you folks are having this problem.

    Please advise.

    Thank you both for being WPMU Dev Members!

    Cheers, Joe

  • digitsoft
    • The Crimson Coder

    @joe - you're a trip with the server plug :slight_smile: What littlemkv and me are talking about is adding code like this in the sidebar (like with a text widget and a php plugin for an existing theme):

    echo 'Count: '.mp_items_count_in_cart();

    I could be wrong as well, but I believe that's what they're trying to do.

  • aecnu
    • WP Unicorn

    Greetings Rob,

    Are you referring to the popup? .... lol

    Though it may not be relative in this case, as you well know my friend and probably agree hosting is the most important part of the equation to a good running site (WordPress or not) and many people think $4 hosting with the likes of Host Gator is good hosting and should be able to handle a lot of traffic in which we both know that it is ridiculous.

    They normally configure their php.ini too light for working with WordPress and all other kinds of anomalies are caused by these simple inconsideration's in their plans.

    But I am proud to have developed and maintain screaming configurations as you have probably noticed the sites on them are extremely fast.

    I still look forward to your future critique of the site and yesterday I added the CPanel option and static IP options - working it though is slow due to my WPMU Dev duties which actually come before my personal duties at this time - unless there is a crisis of course but those are extremely rare - thank goodness.

    Back to this issue at hand, aha! so this appears to be custom coding rather then stock using the Simple Market themes included widgets etc. Then if this is indeed the case my apologies and I am on the wrong trail and your advice was correct.

    Now waiting for a response from littlemkv to see what is going on.

    Cheers, Joe

  • littlemkv
    • Flash Drive

    Hi Joe and digitsoft,

    Thank you for your help in looking into the problem. Yes digitsoft is correct on what I'm trying to achieve here, I'm trying the display the number of items in the cart by something like this:

    echo 'Count: '.mp_items_count_in_cart();

    So as I mentioned previously: "The shopping cart works perfectly by showing the product in the cart instantly at the moment I click 'add to cart', but the number from mp_items_count_in_cart is not updating. It only updates when I manually refresh the page." I believe it should update instantly because that's how GridMarket theme shows.

    Thank you all again for answering my questions in the weekend!


  • littlemkv
    • Flash Drive

    Thank you and I managed to add my own code to make the ajax works. Have to customize quite a bit in the marketpress files.

    I think this theme should support that mp_items_count_in_cart function in ajax form, since this is what people in online shopping expected to see.

    Thanks all for the help!

  • Joseph
    • New Recruit

    I know this is kind of old, but in my various searches I came across this, so maybe someone else will too.

    First, I created a PHP file in my custom theme called "mp_items_count_in_cart.php". The only thing in it is:

    	include "../../../wp-load.php";
    	echo mp_items_count_in_cart();

    This should simply display the number when you navigate to this file in the browser.

    Then, in the theme file where I wanted the number to appear, I created a span with the ID "mp_items_count_in_cart" where I want the number to appear.

    Then, I added this script to the theme file that would also serve the Add To Cart button:

    jQuery(document).ready(function($) {
    		$('span#mp_items_count_in_cart').load( "<?= get_template_directory_uri() ?>/mp_items_count_in_cart.php" );

    Basically, it activates when you click on any Add To Cart button, as specified in 'input.mp_button_addcart', and loads the contents of the PHP file created above into the span specified above.

    If there is a better way to do this, please share.

    Tested on Marketpress v2.9.5.2, WP v3.9.2

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.