Magento Cookbook - Teaching Old Dogs New Tricks, Easy Hacks to Make Magento Work Right

Magento Tricks and Hacks For Developers

In this posting, we will show you some cool and interesting hacks for developers.  These all require SSH access and R/W access to the Magento PHP code.  We have been developing custom templates and shopping carts and this is how we do it.   Magento pricing for standard carts is available here.

1) Dump Session Variables into your Magento 1column view (Magento 1.9 Trick) Put this into your 1-column phtml template file.
...
<div class="col-main">
      <pre> <?php var_dump($_SESSION); ?> </pre>
      <?php echo $this->getChildHtml('global_messages') ?>
      <?php echo $this->getChildHtml('content') ?>
</div>

...
...
<pre> <?php var_dump($_SESSION["checkout"]); ?> </pre>
<hr>
<pre> <?php var_dump($_SESSION["core"]["messages"]); ?> </pre>
<hr>
<pre> <?php var_dump($_SESSION); ?> </pre>
<hr>
<?php
   $session =  Mage::getSingleton("core/session"); 

   var_dump($session);
   Mage::register('messages_collection', 
     Mage::getSingleton('adminhtml/session')->getMessages(true));
    $_messages = Mage::registry('messages_collection');
    $_messages = $_messages->getItems();
    $_messagesData = array();
        foreach ($_messages as $_message) {
        $_messagesData[] = array(
          'type' => $_message->getType(),
          'text' => $_message->getText()
        );
        echo $_message->getText();
    }
?>


2) The following is a cheap work-around hack to fix Magento's broken user feedback mechanism.  Getting the checkout and shopping cart messages out and showing them. Use this with Magento 1.9 and it's broken messaging system.  getGroupedHTML() does not work at all, furthermore  $this->getChildHtml ('global_messages') does not work either.

<hr>
<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
<hr>
<pre> <?php var_dump($_SESSION["checkout"]); ?> </pre>
<hr>
<pre> <?php var_dump($_SESSION["checkout"]["messages"]); ?> </pre>
<hr>
<?php
      $mess = new Mage_Core_Model_Message_Collection;
      $msgobj = new Mage_Core_Model_Message_Collection();
      $msgobj = $_SESSION["checkout"]["messages"];
      $lastmsg= $msgobj->getLastAddedMessage();
      echo var_dump($lastmsg);
      echo $lastmsg->getCode();
?>

Output looks like this, and is purely for debugging:
object(Mage_Core_Model_Message_Error)#90 (6) { ["_type":protected]=> string(5) "error" ["_code":protected]=> string(33) "Coupon code "ppppp" is not valid." ["_class":protected]=> string(0) "" ["_method":protected]=> string(0) "" ["_identifier":protected]=> NULL ["_isSticky":protected]=> bool(false) } Coupon code "ppppp" is not valid.


Comments

  1. I was in need of helping material while preparing for Cisco exam and then finally I got Pass4sure Cisco dumps. There are many positive aspects of this material that I can talk about. I got every bit of knowledge about my syllabus topics from Cisco questions and answers. I appreciate the efforts done by experts at Dumpspass4sure.

    ReplyDelete

Post a Comment

Popular posts from this blog

Microsoft Visio 2010 Premium Product Keys

Mercedes Benz Diesel CDI EGR Emulator Circuit Diagrams

Fix: The Diagnostic Service Host service failed to start due to the following error. [ solved, no kidding ]