lrkwz
lrkwz

Reputation: 6513

Is it possible to get the magento cart summary (total and #items) for external use?

I whish to use magento also from and external (java springframework based) brand site.

Users will see a "buy" button. I would also like to let the user see the summary of cart info (total + number of items in cart) in the header of each external page. The checkout process will proceed on magento as usual.

Magento offers a soap api.

I cannot understand how to handle the switch from my site back to magento when the user wants to checkout and pay.

Scenario 1

  1. the user surfs my java web site and eventually clicks a"buy" button (in this scenario this is simple REST link to magento instance http://yourdomain.com/checkout/cart/add/product/{ID} ... shoppingCartId is created on magento's site )
  2. the cart summary is retrieved throught a server-side java call to magento's web service (cart.list and cart.total i presume) -> Q. which shoppingCartId should I use?
  3. a simple link sends the user to magento's site straight into the cart page

Scenario 2:

  1. the user surfs my java web site and eventually clicks a"buy" button (this is a server-side java call to magento's web service cart_product.add; shoppingCartId is created throught web service and stored into the java session)
  2. the cart summary is retrieved throught a server-side java call to magento's web service (cart.list and cart.total i presume), shoppingCartId is retrieved from java session
  3. a simple link sends the user to magento's site straight into the cart page, the shoppingCartId was stored into the java session, I imagine that a new cart empty will be shown to the user: Q. Is there a REST link to a specific cart (ie.e using shoppingCartId as a parameter)?

Upvotes: 1

Views: 2217

Answers (1)

MagePsycho
MagePsycho

Reputation: 2004

You can use the following code in order to use the magento data(for example cart) externally:

<?php
/**
 * @author      MagePsycho <[email protected]>
 * @website     http://www.magepsycho.com
 * @category    using Magento Externally
 */
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));

#Get total items and total quantity in cart
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

#Get subtotal and grand total price of cart
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();

Hope this helps you. Cheers!!

Upvotes: 2

Related Questions