cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Magento2 Header and Footer in an external PHP

Calling Magento2 Header and Footer in an external PHP

I am using magento2 for one of our eCommerce project. My store is running on our domain say example.com. I need to run a php file inside this domain (say example.com/sdk/sdk.php. My sdk.php needs to access Header & Footer from the magento (example.com). Header should have the state (Login, Carts).

 

The problem here is - we don't have to create any Magento Plugin for this. This is an independent PHP.

 

I found some examples of doing this in older magento version but I am not finding anything in Magento2.

Hitesh
4 REPLIES

Re: Calling Magento2 Header and Footer in an external PHP

Hello,

 

https://fishpig.co.uk/magento/wordpress-integration/

 

There is one module to use magento 2 header and footer calls into a wordpress blog.

 

 

you need to check this module.

 

Hope it will help you.

Re: Calling Magento2 Header and Footer in an external PHP

Thanks Sunil for your response. Though I am not able to figure out how and where this is used in the plugin. 

Do you know if we can write a simple script. I found following for Magento 1. But thats not good for Mangento 2. Any help ?

$mageFilename = 'app/Mage.php';
echo $mageFilename;
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app()->loadArea('frontend');

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
echo $headBlock->toHtml() . $headerBlock->toHtml();
Hitesh

Re: Calling Magento2 Header and Footer in an external PHP

Hello @hitesh_mathpal

 

https://www.cadence-labs.com/2017/04/magento-2-load-block-layout-external-file/

 

 

check above link for same.

 

If the help you then give kudos or mark as solution.

Re: Calling Magento2 Header and Footer in an external PHP

Hi @hitesh_mathpal,

 

Maybe you can use the API? But you should handle the cart staus on your side.

Here you'll find the list of API endpoints: https://devdocs.magento.com/guides/v2.2/rest/list.html#cms

 

Maybe the problem is that you want to maintain the header working with your store (cart state) but you don't want to customize that part.

I guess it will be easier if you can create a custom module that loads into a block and then you can use the layout logic of Magento.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"