Magento cart / session data outside magento

后端 未结 5 731
栀梦
栀梦 2021-01-25 04:55

This might get a little confusing as I have tried everything to make this work. All I want is a link in my brand site (domain.com) which shows the qty in my magento 1.5.1 cart (

相关标签:
5条回答
  • 2021-01-25 05:41

    I copied your code and tested it on Magento 1.5, 1.6 and 1.7.
    I placed the code in a PHP file called test.php in the Magento root directory. This is the code I used:

    umask(0);
    require_once 'app/Mage.php';
    Mage::app();
    
    Mage::getSingleton('core/session', array('name'=>'frontend'));
    
    var_dump(array(
        "Mage::getSingleton('checkout/cart')->getItemsCount()" =>
        Mage::getSingleton('checkout/cart')->getItemsCount()
    )); // returns number of items (w/o qty)
    var_dump(array(
        "Mage::helper('checkout/cart')->getSummaryCount()" =>
            Mage::helper('checkout/cart')->getSummaryCount()
    )); // returns number according to configuration
    var_dump(array(
        "Mage::getSingleton('customer/session')->isLoggedIn()" =>
        Mage::getSingleton('customer/session')->isLoggedIn()
    )); // returns bool true|false
    

    The Magento instances use the local test host names magento15.dev, magento16.dev and magento17.dev.

    The I requested the corresponding Magento instances and placed a product in the cart (tested with a configurable and a simple product), and then updated the quantity of the product in the cart.

    Between each step I reloaded the test.php file in the browser.
    The result is always the same: it works as expected. Each call returns the same values as on the Magento site.

    So this means your code is correct, it might be your domain and/or setup (is the browser sending the Magento frontend cookie when you request your test script)?

    0 讨论(0)
  • 2021-01-25 05:47

    If all you want is the qty why instantiate magento at all. Just set a client side cookie (ie cart_qty) and then read this cookie on your main site header.

    0 讨论(0)
  • 2021-01-25 05:49

    Your code is good, but by default Magento's "frontend" cookie isn't accessible outside of Magento (and so you can't access session data). You'll need to change the cookie's path in Admin > System > Configuration > Web > Session Cookie Management > Cookie Path. Try setting that to /

    0 讨论(0)
  • 2021-01-25 05:54

    In Your Code: Instead of:

    Mage::app();
    

    use

    Mage::app()->loadArea('frontend');
    

    & u will get your output...

    0 讨论(0)
  • 2021-01-25 05:59

    Think you forgot:

    Mage::app()->setCurrentStore(1);  // replace 1 with your store id
    

    after

    Mage::app()
    
    0 讨论(0)
提交回复
热议问题