Magento购物车/会议数据在magento之外

Dav*_*ave 1 session magento cart

这可能会让我有点困惑,因为我已经尝试了一切来使这项工作.我想要的只是我的品牌网站(domain.com)中的一个链接,它显示我的magento 1.5.1购物车(domain.com/shop)中的数量我很容易提取产品数据和导航块,但不管我做什么,购物车数量从外面的magento总是0.我尝试的主要方式是在我的品牌网站上:

    require_once $_SERVER['DOCUMENT_ROOT'].'/shop/app/Mage.php';
    umask(0);
    Mage::app();        
    Mage::getSingleton('core/session', array('name'=>'frontend'));
    // trying everything 
    Mage::getSingleton('checkout/cart')->getItemsCount(); // returns 0
    Mage::helper('checkout/cart')->getItemsCount(); // returns 0
    Mage::getSingleton('customer/session')->isLoggedIn(); // returns blank
    Mage::helper('checkout/cart')->getCart()->getItemsCount(); // returns 0
    Mage::helper('checkout/cart')->getCart()->getQuote()->getItemsCount(); // returns blank
Run Code Online (Sandbox Code Playgroud)

然后,当这些都不起作用的时候,我在Magento中创建了一个模板,只是为了给我一个推车数量作为一个块,它返回块很好但在购物车中仍为零!

    $block = $this->layout->createBlock('core/template');
    $block->setTemplate('page/html/cartForBrand.phtml');
    return $block->renderView();
Run Code Online (Sandbox Code Playgroud)

并且magento中的块很简单

    Mage::getSingleton('core/session', array('name'=>'frontend'));
    $cart = Mage::getModel('checkout/cart')->getQuote()->getData()['items_qty'];
Run Code Online (Sandbox Code Playgroud)

我见过很多人都有类似的问题:/ session_cookie_management,.domain.com cookie_domain(即使这是特定于子域​​名的),我已经阅读并尝试了我能找到的所有内容,为期2天.不断删除会话和缓存目录,并清除缓存和cookie,禁用magento缓存.

这是我使用它多年后在网站上发布的第一个问题,我已经坚持了3天!拉出我的头发!

Vin*_*nai 7

我复制了你的代码并在Magento 1.5,1.6和1.7上进行了测试.
我将代码放在Magento根目录中名为test.php的PHP文件中.这是我使用的代码:

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
Run Code Online (Sandbox Code Playgroud)

Magento实例使用本地测试主机名magento15.dev,magento16.dev和magento17.dev.

我请求相应的Magento实例并将产品放入购物车(使用可配置和简单的产品进行测试),然后更新购物车中的产品数量.

在每个步骤之间,我在浏览器中重新加载了test.php文件.
结果总是一样的:它按预期工作.每次调用都返回与Magento站点相同的值.

所以这意味着您的代码是正确的,它可能是您的域和/或设置(当您请求测试脚本时,浏览器是否发送Magento前端cookie)?