Jump to content

Magento & Processwire together


pandaman
 Share

Recommended Posts

A new client asked for a an e-commerce (and we usually use Magento), but with a lot of customizations, blog, posts and other cms stuff.

Magento sucks for these kind of operations, and i'd like to integrate Processwire in this adventure.
In the last months i appreciated a lot PW and i made all my sites with it.

So i'd like to have a regular cms part, with pages, news, etc... and the shop part, sharing the same html layout.

Have you ever tried to work with this 2 solutions together?
Any advice to avoid conflicts?

  • Like 1
Link to comment
Share on other sites

Hi @pandaman For one of my customers I made some basic experiments to connect the both systems together. Your arguments are valid. I also told him to combine the best of two worlds and let each system do what it's best for.

What I can say right now, it is possible, but there might be pitfalls, that I didn't discover yet. One problem was the session management which caused conflicts so you have to modify it.

Right now I have the following working solution (PW 3 and Magento 2.1):

I installed Magento 2.1 in a "store" directory that lies right beside site and wire directories.

I made a magento2-bridge.php in site/templates/

<?php

namespace ProcessWire;

require $_SERVER['DOCUMENT_ROOT'] . '/store/app/bootstrap.php';

use Magento\Framework\App\Bootstrap;


class StoreApp
{
	private static $instance;


	public static function get_instance() {
		if ( ! isset(self::$instance) && ! (self::$instance instanceof StoreApp) ) {
			self::$instance = new StoreApp();
		}
		return self::$instance;
	}


	public $helper;
	public $quote;
	public $session;
	public $cart;
    public $customer;

	private function __construct()
	{
		$bootstrap = Bootstrap::create(BP, $_SERVER);

		$obj = $bootstrap->getObjectManager();

		$state = $obj->get('Magento\Framework\App\State');
		$state->setAreaCode('frontend');

		$this->customer = $obj->get('Magento\Customer\Model\Session')->getCustomer();

		$this->quote = $obj->get('Magento\Checkout\Model\Session')->getQuote();
		$this->helper = $obj->get('\Magento\Checkout\Helper\Cart');
		$this->session = $obj->get('Magento\Checkout\Model\Session');
		$this->cart = $obj->get('\Magento\Checkout\Model\Cart');
	}
}

I had to modify the session management in Magento, so it stores its session variables in ProcessWires directory.  I hope I remember this correctly:

Change the Cookie Path in Magento @ Stores -> Configuration -> Web -> Defaut Cookie Settings to "/" (without the quotes)
Change the save_path for sessions under store/app/etc/env.php

'session' => 
  array (
    'save' => 'files',
    'save_path' => $_SERVER['DOCUMENT_ROOT'].'/site/assets/sessions',

At some point I changed the sessionAllow parameter of ProcessWire, but I don´t know if this is needed anymore. But for completeness, here is the code I used:

    $config->sessionAllow = function () {

        if (strpos($_SERVER['REQUEST_URI'], '/processwire/') === 0) {
            return true;
        }

        return false;
    };

Then in my site/templates/home.php I have the following code, to get data from Magento (like Customer data, what is in the cart, product information):

require_once __DIR__ .'/magento2-bridge.php';
$store = StoreApp::get_instance();

$quote = $store->helper->getQuote();
$quoteitems = $quote->getAllItems();

$customer = $store->customer;
bd($customer->getName());


foreach ($quoteitems as $item) {
    // Code to get contents per product
    bd($item->getName());
    bd($item->getQty());
}

If you are wondering what bd() means. It is a debugging output from Tracy Debugger for ProcessWire (recommended install).

Why do I share this information here although it was very time-consuming and expensive to figure this out? Because I had great support from the PW community and want to give something back.

If you make any progress with this, please try to do the same and share your findings with our lovely community.

  • Like 13
Link to comment
Share on other sites

14 hours ago, louisstephens said:

Have  you tried padloper for processwire? I have not used it yet, but it looks very promising, and would probably cut down on trying to make magento work with processwire.

https://www.padloper.pw

Because a real e-commerce, with prices different for each group of customers, offers, world VATS managing, etc deserves a SOLID solutions, and we always worked with Magento.

 

Link to comment
Share on other sites

Quote

Why do I share this information here although it was very time-consuming and expensive to figure this out? Because I had great support from the PW community and want to give something back.

I can't thank you enough @jmartsch  !!!

These are the kind of problems I'm sure I would encounter doing this job. It's a great start!
If I find any problem dealing with this job, I'll let you know...
Thank you again ;)

  • Like 1
Link to comment
Share on other sites

@pandaman i've never used magento but i've used one approach in other projects that could maybe also be interesting for you:

the project was a step-by-step move from joomla to processwire and we changed only one part to processwire and had the joomla site running side-by-side. not sure if something similar could work in your scenario but that's what i did:

my pw site did a request to the joomla site and fetched its HTML. this way all the html + design came from the joomla site and i could manage the menu etc from within the joomla admin. i then used something like http://simplehtmldom.sourceforge.net/ and replaced the content dom element by the pw-content.

so basically the wrapper came from joomla and the content from PW. of course the html fetching was cached, because otherwise that would be terribly slow. also the script and image paths can be tricky. but maybe it's something you want to consider...

said that, i admit that this can be a quite hacky solution. but sometimes quick hacks are not the worst solution :)

Link to comment
Share on other sites

Programmers in my company have combined my old cms with the new magento 2 review extension [spurious link removed] This was an excellent solution for my site. And in general use these extensions the best option for business. Recently, I think to switch to Magento CMS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...