Using Magento Cart Outside Magento

I would like to get a Cart block outside of Magento. Here is my code.

<?php require_once ( $_SERVER['DOCUMENT_ROOT']."/app/Mage.php" ); umask(0); Mage::app('base','website'); echo Mage::app()->getLocale()->getLocaleCode(); //Solution Mage::getSingleton('core/translate')->setLocale('de_DE')->init('frontend', true); Mage::getSingleton('core/session', array('name'=>'frontend')); $block = Mage::getSingleton('core/layout') ->createBlock("checkout/cart_sidebar", "sidebar") ->setTemplate("checkout/cart/sidebar.phtml"); echo $block->toHtml(); ?> 

I only have a problem that the output ist only in English and the translation does not work.

thanks for the help

+4
source share
2 answers

Any reason why you aren’t just specifying a store code that has the locale set in your call in Mage :: app ()?

Not related to your problem, but you may also be interested in a more robust approach to uploading a block to another website.

0
source

With this, you can get all the basket data from the side magnet. Now you can provide any template you want with these elements.

 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 ); } } 

? >

0
source

Source: https://habr.com/ru/post/1386319/


All Articles