Get cart content outside of Magento but on same domain

和自甴很熟 提交于 2019-12-01 21:49:58
Vladimir Ramik

Here's a working standalone file:

<?php
    require_once( 'app/Mage.php' );

    umask(0);
    Mage::app('default');

    // This has to run to authenticate customer and checkout session calls.
    Mage::getSingleton('core/session', array('name' => 'frontend'));

    // Get any customer model you desire.
    $oSession = Mage::getSingleton( 'customer/session' );
    $oCustomer = $oSession->getCustomer();
    $oCheckout = Mage::getSingleton( 'checkout/session' );
    $oQuote = $oCheckout->getQuote();

    var_dump( $oCustomer );
    var_dump( $oSession );
    var_dump( $oQuote );
    var_dump( $oCheckout );

    $oCart = $oQuote->getAllItems();
    if( !empty( $oCart ) )
    {
        foreach ( $oCart as $oItem ) 
        {
            $sName  = $oItem->getProduct()->getName();
            $fPrice = $oItem->getProduct()->getPrice();
            var_dump( $sName );
            var_dump( $fPrice );
        }
    }
?>

More reference for other domains:

How to access Magento customer's session from outside Magento?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!