Check if the shopping cart is empty

Discussion in 'aMember Pro v.4' started by gogoseo, Jan 5, 2013.

  1. gogoseo

    gogoseo Member

    Joined:
    Nov 17, 2012
    Messages:
    36
    Is there a way to check if the shopping cart is empty?

    I have an integration with wordpress and i want to display my simple custom "Cart" button on the page only it there are some items in the cart already..
  2. gogoseo

    gogoseo Member

    Joined:
    Nov 17, 2012
    Messages:
    36
  3. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You can do this only if you are able to include ammeber's bootstrap:
    PHP:
    include "/amember/bootstrap.php";
    $cart Am_Di::getInstance()->session->cart;
    if(
    $cart && $cart->getItems()){
    // Cart have items;
    }
  4. gogoseo

    gogoseo Member

    Joined:
    Nov 17, 2012
    Messages:
    36
    Hmm...
    im using this in Wordpress(Catalyst hooks) so i tried this (which i think is bootstrap.php equivalent..)

    $cart = am4PluginsManager::getAPI()->session->cart;
    print_r($cart);

    And nothing gets printed..
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    No Am_Lite is simplified API You can't get access to session from it.
  6. gogoseo

    gogoseo Member

    Joined:
    Nov 17, 2012
    Messages:
    36
    I tied to include bootstrap.php into wordpress (in functions.php) and i get this error:
    "Script Error
    An internal error happened in the script, please contact webmaster for details"

    Maybe some conflict with Am_Lite ?
    Is there a way to access the session directly?
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    No you can't access session directly. cart is an object so cart class must be defined before you will be able to load it from session.
    Try to move bootstrap.php include before any output Error can be generated if you place it after html code (amember will be unable to start session then)
  8. gogoseo

    gogoseo Member

    Joined:
    Nov 17, 2012
    Messages:
    36
    I know that there is a plugin for wordpress that works with cart. So there must be a way to access the session somehow.

    I tried to hook the bootstrap.php in Catalyst custom-functions.php and created a hook:

    //include za bootstrap for cart session check
    add_action('init', 'process_amember_session');

    function process_amember_session(){
    include_once ("/home/trusteds/public_html/amember/bootstrap.php");
    }

    ...and this works if im on /amember/... sites(with head and footer generated from WP Catalyst), but as soon as i get back to "normal" wordpress sites(like the domain root) i get the error message.

Share This Page