0

So I'm trying to get my front-end static website to work with Magento backend. (I'm not that great at php)

My setup:

www.mywebsite.com/shop2 <-Magento

www.mywebsite.com/index.php <-Static front end

I have a file located at www.mywebsite.com/test.php that correctly displays the contents of my magento cart using the following code:

<?php

require_once(dirname(__FILE__).'/shop2/app/Mage.php');

$app = Mage::app();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));

$block = $app
->getLayout()
->getBlockSingleton('checkout/cart_sidebar')
->setTemplate('checkout/cart/sidebar.phtml');

echo $block->toHtml();

?>

However, when I insert the above code into my www.mywebsite.com/index.php sidebar area, it doesn't update with the cart contents of the website.

Any ideas why this would work in the test.php and not in my main index.php website?

That1Guy
  • 7,075
  • 4
  • 47
  • 59
  • 1
    What does it do? PHP error? Renders a cart with no items? Does your code finish execution? etc. – Alana Storm Dec 08 '13 at 19:35
  • Hi Alan! it renders the cart with no items, even though the test.php running at the same folder level shows the cart items. –  Dec 08 '13 at 19:40

2 Answers2

0

Making two PHP application communicate with one another, or making one run in the context of the other, is never a straight forward process. My first guess on this would be the application your index.php bootstraps (even if it's just a simple framework for your webpage) initializes session storage before Magento has the opportunity to.

Then, when you bootstrap your Magento environment

require_once(dirname(__FILE__).'/shop2/app/Mage.php');

The PHP sessions have already been started. This means a Magento sessions never loads, and the user session is how Magento persists the cart information.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • Thanks for the reply Alan. I've added to the top of the page, above the statement. Beyond this, is there anything I can do? –  Dec 08 '13 at 19:56
  • @user2487746 Beyond the scope of what I can help remotely with in a Stack Exchange answer. You might try stopping the session before restarting it, or the session might not be working for some other reason. – Alana Storm Dec 08 '13 at 19:58
  • Thank, I'll think it over –  Dec 08 '13 at 20:03
0

I was able to import the test.php file which has my cart information using the following. For my purposes, it works alright now.

How to load an external webpage into a div of a html page

Community
  • 1
  • 1