• Hi,

    I’m trying to implement an ajax add to cart function.
    What I do not understand is, that the form to send an item to the cart hat
    $action_url = get_permalink();
    as its action-url.

    Usually there is a script.php which handles the requests and returns some information.
    I think this is handeled in backend.php in the function request().

    I have no clue how to trigger this function.

    Thanks for any ideas.

    https://www.ads-software.com/plugins/simple-cart-buy-now/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author bluey80

    (@bluey80)

    So, right now there is no AJAX. When you click add to cart, it uses $action_url = get_permalink so the action url is the url you are current on. This way you load the same page (again). This time with some POST variables that SCABN parses to add to the shopping cart. The ‘add to cart’ functionality is really on every page with the SCABN shopping cart.

    Not that this is the right way to do things. Ideally, SCABN would just be a set of REST queries and then AJAX handles all the add to cart, display cart, etc. I’ve played around a little bit with this, but haven’t gotten very far.

    If you want work on this and get your improvements back in SCABN, please let me know. I’d probably put SCABN up on github and have you do pull requests unless you prefer something else.

    (see https://code.tutsplus.com/tutorials/a-primer-on-ajax-in-the-wordpress-frontend-understanding-the-process–wp-27052 for some basic wordpress ajax stuff. Once setup, those new urls would be the actions for the AJAX instead of the get_permalink().

    Please let me know if you have more questions / how the AJAX stuff is going.

    Thread Starter Ploeve

    (@ploeve)

    Right now I’m already pulling the cart with ajax.
    The push of new items is still not working correctly.

    The first push is done, but then it skips because of this line:

    if ( isset($_REQUEST[‘randomid’]) && $_REQUEST[‘randomid’] == $cart->random() )

    the random ID of the form stays the same, is that a problem?

    thanks

    Thread Starter Ploeve

    (@ploeve)

    Got it working.
    That was the problem.
    The random-ID needs to be updated on each update of the cart.

    Something like:
    myForm.find(“input[name=randomid]”).val(obj.randid);

    Next challenge will be a manual checkout.

    thanks

    Plugin Author bluey80

    (@bluey80)

    The cart stores a random number that gets updated after every action. The purpose of this is to catch reload and other events from triggering extra add to carts. (Maybe this is unnecessary with AJAX requests). So, yes, you need to get the random id before doing an submission of changing the cart. Glad you got it working.

    Plugin Author bluey80

    (@bluey80)

    If you get your AJAX code working and want it incorporated into SCABN, you can do a pull request against https://github.com/IguanaBen/scabn

    Thanks!

    Hi
    I like simple plug
    Decided issue with AJAX as follows:
    add in the link ID record (data-ID = “…”) and javascript transfer it on to the server function, which adds an item.

    Plugin Author bluey80

    (@bluey80)

    I’m starting to work on a more AJAX version of SCABN, which should be faster and also make it easier to integrate with other payment platforms. If anyone wants to help with this development, or has some AJAX code working that they’d like to contribute, but please let me know. Or put a pull request at https://github.com/IguanaBen/scabn (ajax branch)

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Ajax Add to cart’ is closed to new replies.