When enabling Ajax Cart a conflict with LiteMage can cause a blank page to be served. The following is a step-by-step example for troubleshooting this issue.
var/log/system.log
, you will see errors like: 2016-04-04T14:12:24+00:00 ERR (3): Warning: simplexml_load_string(): <!--Litemage esi started cart_sidebar--></!--Litemage> in /home/user/public_html/app/code/local/Magestore/Ajaxcart/Helper/Data.php on line 29
These errors are caused by the following code block in Magestore/Ajaxcart/Helper/Data.php
:
/** * get Mini cart block class * * @return string */ public function getMiniCartClass() { if (!isset($this->_cache['mini_cart_class'])) { $minicartSelect = ''; if ($minicartBlock = Mage::app()->getLayout()->getBlock('cart_sidebar')) { $xmlMinicart = simplexml_load_string($this->toXMLElement($minicartBlock->toHtml())); $attributes = $xmlMinicart->attributes(); if ($id = (string)$attributes->id) { $minicartSelect = "#$id"; } elseif ($class = (string)$attributes->class) { $minicartSelect = '[class="' . $class . '"]'; } } $this->_cache['mini_cart_class'] = $minicartSelect; } return $this->_cache['mini_cart_class']; }
Looking more closely at the getMiniCartClass()
function we see:
$xmlMinicart = simplexml_load_string($this->toXMLElement($minicartBlock->toHtml())); $attributes = $xmlMinicart->attributes();
At this point in the code, the value of $minicartBlock
is already a hole-punched ESI block, so the function toHtml()
will return something like <esi:include …>
which will not be understood by the toXMLElement()
function.
?LITEMAGE_DEBUG=NOCACHE
to the current URL so you can see the original page without LiteMage.getMiniCartClass()
function in Magestore/Ajaxcart/Helper/Data.php
, replacing $this->_cache['mini_cart_class'] = $minicartSelect;
with code containing a marker like
$this->_cache['mini_cart_class'] = 'LMDD_' .$minicartSelect . '_LMDD';
Open another browser window and view the same URL as before. Once again look at the source code for this page but this time search for our marker LMDD_
.
You should find something like
LMDD_[class="login_scroll"]_LMDD
Check a few more URLs with ?LITEMAGE_DEBUG=NOCACHE
to confirm that you always get this same string.
Now we can go back and modify the getMiniCartClass()
function again, this time commenting out the original logic and putting in the value directly.
public function getMiniCartClass() { if (!isset($this->_cache['mini_cart_class'])) { /* $minicartSelect = ''; // this will not work with LiteMage if ($minicartBlock = Mage::app()->getLayout()->getBlock('cart_sidebar')) { $xmlMinicart = simplexml_load_string($this->toXMLElement($minicartBlock->toHtml())); $attributes = $xmlMinicart->attributes(); if ($id = (string)$attributes->id) { $minicartSelect = "#$id"; } elseif ($class = (string)$attributes->class) { $minicartSelect = '[class="' . $class . '"]'; } } */ $minicartSelect = '[class="login_scroll"]'; $this->_cache['mini_cart_class'] = $minicartSelect; } return $this->_cache['mini_cart_class']; }
?LITEMAGE_DEBUG=NOCACHE
. The page should now be displaying correctly.
Note: Enabling mini compare will cause a similar problem and break ESI. You can fix this by following the same steps as above to modify public function getMiniCompareClass()
.