Here at Cadence Labs, we’ve done a number of Magento-WordPress integrations using the MWI plugin (see our full article here: https://www.cadence-labs.com/2015/02/use-magento-theme-wordpress/ ). One error we run into with more complex builds is:
PHP Fatal error: Mage_Core_Model_Session_Abstract::getMessages() [mage-core-model-session-abstract.getmessages]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Mage_Core_Model_Message_Collection” of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in {magento_path}/app/code/core/Mage/Core/Model/Session/Abstract.php on line 215
What’s happening is that WordPress is loading the core message session information before the class definition for Mage_Core_Model_Message_Collection has been defined. What we need to do is tell Magento to ignore the core message queue if we’re running inside a WordPress page/post.
The Fix
Create a local copy of Mage_Core_Model_Session_Abstract:
mkdir -p app/code/local/Mage/Core/Model/Session
cp app/code/core/Mage/Core/Model/Session/Abstract.php app/code/local/Mage/Core/Model/Session/Abstract.php
In our new local copy, we’re going to modify the function getMessages() to look like the below:
/**
* Retrieve messages from session
*
* @param bool $clear
* @return Mage_Core_Model_Message_Collection
*/
public function getMessages($clear=false)
{
if (isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], '/YOUR_WORDPRESS_PATH')) {
return Mage::getModel("core/message_collection");
}
if (!$this->getData('messages')) {
$this->setMessages(Mage::getModel('core/message_collection'));
}
if ($clear) {
$messages = clone $this->getData('messages');
$this->getData('messages')->clear();
Mage::dispatchEvent('core_session_abstract_clear_messages');
return $messages;
}
return $this->getData('messages');
}
You can see, what we’re doing is telling Magento to not attempt a read from the Session (for core messages only) in the event we’re on a wordpress page.
Change /YOUR_WORDRESS_PATH to the subdirectory where WordPress is installed.
** Author’s note: If you are running Magento in a subdirectory (WordPress in the base) you’ll need to create a Magento module to make this work. We currently don’t have the tutorial online yet, but hope to provide it in the coming days.