Disabling Javascript Merging in Magento

If you have ever written Javascript for Magento, you have probably been frustrated by the fact that Magento merges all of its JS files before outputting them to the front end. This makes debugging difficult for a few of reasons:

  • It makes it more difficult to see if your JS file is even being loaded
  • When Firebug (or your JS debugger of choice) logs errors to the console, it’s impossible to match up the line numbers Firebug reports with the line numbers in the file
  • If you want to use Firebug’s debugging or profiling tools, you’re greatly impaired by having all the JS in one file.

A few months ago, one of our developers stumbled across the ability to disable the JS merging in Magento: Go to System > Preferences > Developer > Javascript Settings tab > Set “Merge JavaScript Files” to “No”.

I hope this helps in your Magento Javascript debugging!

Viewing Error Backtraces for Ambiguous Error Messages

There are many times when working with the Magento front end that I get a very ambiguous error message.

I usually just search the entire codebase for the error message code, locate the place where the exception is getting caught, and then temporarily modify the code to Mage::log() the following data: $e->getMessage(), $e->getTraceAsString(), etc…

I just came across an exception handler in the Mage_Checkout_MultishippingController class that passed the generic exception message as well as the Exception class itself to Mage::getSingleton(‘checkout/session’)->addException(). Here’s the code (from line 219 of the containing file):

        catch (Exception $e) {
            Mage::getSingleton('checkout/session')->addException(
                $e,
                Mage::helper('checkout')->__('Data saving problem')
            );
            $this->_redirect('*/*/addresses');
        }

I dug into the Mage::getSingleton(‘checkout/session’)->addException() class and realized that it logged the exception code to the var/logs/exception.log file (it only logs the exception if logging is enabled in System > Preferences > Developer). This means that instead of locating and hacking up core files to see exceptions that are thrown, in a lot of cases, you can just monitor the contents of the exception.log file.

If you’re developing on a Mac machine, you can monitor the contents of the exception.log file using the Console app. If you’re on a Linux box, you can use “tail -f var/log/exception.log” to monitor the contents of this file.

Hopefully this helps you in your debugging efforts!

The Evaluation Process: An Introduction to the Perceived Cost/Benefit Relationship

Before I drill down into the actual Value Presentation, it is important to have a complete understanding of the relationship between Perceived Value and Perceived Cost, which I briefly mentioned in the previous article on Traffic Quality.

We are evaluating things all the time.  We don’t even recognize much of the evaluation that takes place.  It’s usually automatic, subconscious.

This process of evaluation can be broken down into the rising and falling of two perceptions:  Perceived Cost and Perceived Benefit.  To be clear, the cost of something is not just money.  Cost is the receipt of something negative or the release of something positive whereas Benefit is the release of something negative or the receipt of something positive.

When you buy insurance, you give up something positive (your money, your mental energy to think through all the insurance options, and your time talking to the pesky insurance agent), which altogether represents your Cost.  How valuable that Cost is to you depends on your perception, which is why Perceived Cost is what truly matters.  If you sacrifice the Cost, you lose something negative (a certain degree of risk in your life) and you gain something positive (peace of mind), which altogether is your Benefit.  How valuable that is, again, depends on your perception and subjective evaluation of that Benefit.  I’m sure the insurance agents reading this are howling at how much I just oversimplified their jobs.  My apologies.

This is nothing new, though.  This is elementary sales, which is why I’m not going to take any more of my or your time regurgitating it.  I’ll tell you about something unique.

Any time a value presentation is made, be it a candy bar in the checkout rack at a grocery store, a pair of earrings online, or a proposal to marry, there is an initial phase when you open your mind “file cabinet” and pull the “folder” associated with whatever value is being presented.  As you open this folder, certain things will jump out at you, influencing your initial perceived cost and benefit of the value presented.  What is in that folder, what items you pull first, and how much each item affects you depends on two things:

1.  Your history with the value presented

2.  How it is initially presented

This initial reaction to the value presentation is the “First Impression” Phase of the value presentation, which is discussed in greater detail in the next article in the series.

If, at any point, you determine that continuing to give attention to the value presentation isn’t worth the time and energy required to do so, you direct your attention elsewhere and you close the folder and refile it.  This is the act of saying “no” to a transaction.  It might be no for now or no never, but for whatever reason, you decide you are not going to complete the transaction.  We will delve more deeply into what happens when you refile the corresponding folder, but for now, simply understand that the moment you say “no,” the value presentation is over.

A complete and successful value presentation consists of a few vital constituents:

1.  Perceived Benefit Surplus (at which your perceived benefit exceeds your perceived cost)

2.  Commitment (at which you decide to commit to the transaction)

3.  Transaction (at which you consummate the commitment by giving the cost and receiving the benefit or initiating the contract committing both/all parties to do so)

Calls to action (CTAs) will not succeed if the Point of Perceived Benefit Surplus has been reached.  Naturally, visitors will reach that point at different times and for different reasons, which is why it’s typically an effective strategy to give visitors the opportunity to purchase at all times.  You never know when they’ll be ready to bite… I mean, buy.  However, excessive and glaring CTAs can have a negative effect on a visitor’s perceived benefit as they begin to get the feeling that you’re just trying to sell them on something rather than genuinely build value into their life.

It’s also important to note here that the point at which a visitor makes a commitment to the transaction is not the same point at which they complete the transaction.  The time between the commitment and the transaction should be as short and simple as possible.  The more complex and time-consuming it is, the more chance the frustration  of the transaction process or the “cold feet” effect could keep it from happening.  Consider how many wedding engagements do not result in the “sealed deal” of an actual marriage.  Have you ever heard of a wedding being called off because of how frustrating the wedding planning process was?  That’s precisely the same reason you should make it as easy and quick as possible to go from commitment to transaction.  (by the way, I’m not promoting the idea that you should get married the day after you’re engaged to make sure the marriage actually happens… if you’re that uncertain about your future spouse’s commitment, maybe it’s time to slow down and consider NOT sealing the deal.  🙂  )

It’s very important to realize that people continue to evaluate the object even after the commitment and transaction.  Most people consider their business a success if they can get people to pay them money for whatever it is they sell.  I think that’s near-sighted.  Businesses that are built to last give as much attention to the post-transaction evaluation process as they do to the pre-transaction evaluation process.  If you’re just trying to get people to buy your stuff, you’re a con artist.  It’s not about building value into their lives.  It’s about making money…  Had a bit of a soap box moment there.

But even from a purely sustainable basis, you have to think about how your customers/clients will evaluate your offering once they are experiencing it, and even as they reflect on the experience.

Consider the purchase of a candy bar.  You are waiting in line at the grocery store.  It’s late.  You haven’t cooked dinner yet, and you’re hungry.  You see that familiar brown-packaged candy bar with the blue letters and the white secondary color, and you hear those familiar words “Hungry?  Why wait…”  And you grab the candy bar as your perceived benefit rises far above the perceived cost of the nutty, nougatty, caramelly deliciousness.  You begin to get impatient because all you want to do is tear off the glossy covering and devour the bar in four equal bites, but your social cost of embarrassment rises above the perceived value of eating first, paying later, so you do not take that action.  The line is horrendously long, and as you wait interminably, a new thought suddenly comes to your mind…  All those calories will go right to your butt.  You know this.  Past consumptions of equal quality and deliciousness have proven it.  Your brain begins to open up all of the corresponding stigmas associated with gaining weight, and as your mind descends into the depths of the health and social repercussions of partaking in the excellence in your sweating hand, you quickly close that mind folder and tightly squeeze the snack to ensure it cannot escape.  This action causes the exterior chocolate covering of the bar to cave in.  You’ve damaged the candy bar.  Now it’s official.  You absolutely cannot put it back now.  Your moral fiber rears its head at the thought of switching to an uncrumpled version.  The moral cost of such a heinous act is far greater than the 50 cents required to buy it.  Your appetite laughs to itself as it has successfully used your moral compass for its own devices…

Have I said enough?  I hope you can see how complex a seemingly simple evaluation process can be.  And you haven’t even purchased the candy bar yet!  What would happen if you got to the checkout lady, and she made a comment about how obese you are and how the candy bar “aint going to help that situation?”  Or after the transaction, what would happen if you bit into the candy bar and discovered a grub worm inside?  Your actions and perceptions about that candy bar would likely change significantly.

The more you can accurately analyze that process, the better you will be at presenting and delivering value to your customers or clients.  As this series progresses, we will break down and analyze each phase of the evaluation process.

Feel free to ask questions and make comments in the comment section.  I am very actively involved with comments for these articles, so I will respond!

Editing Magento’s Footer Links

To follow up on our post about editing Magento’s top links, I thought I might as well write an article about editing the footer links while I’m at it.  I’d recommend reading our post about using a local.xml file before getting started on this post.  This post might not make much sense until you read it. [NOTE: This specific example assumes you are using the blank theme. Layout handles may differ from theme to theme.]

In local.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="footer_links">
            <!-- Add custom links. Pretty self-explanatory.
            Dig into app/code/core/Mage/Page/Block/Template/Links.php for more info -->
            <action method="addLink" translate="label title">
                <label>About Us</label>
                <url>about</url>  <!-- can use a full url if not using urlParams below -->
                <title>About Us</title>
                <prepare>true</prepare> <!-- set true if adding base url param -->
                <urlParams helper="core/url/getHomeUrl"/> <!-- base url - thanks @Russ! -->
                <!-- there are a few param you can send to do different things in <urlParams> 
                         dig into app/code/core/Mage/Core/Model/Url.php, around line 803 -->                   
 
                <!-- below adds #add-fragment to the end of your url -->
                <!-- <urlParams><_fragment>add-fragment</_fragment></urlParams> -->
 
                <!-- below adds ?add-query to the end of your url -->
                <!-- <urlParams><_query>add-fragment</_query></urlParams> -->
 
                <!-- below gives you a new session id (i think...)-->
                <!-- <urlParams><_nosid>true</_nosid></urlParams> -->
 
                <!-- below replaces double quotes, single quotes, greater than, and less than signs 
                         to their respective url escaped replacements (%22, %27, %3E, %3C) -->
                <!-- <urlParams><_escape>i'm-a-blog-url</_escape></urlParams> -->
 
                <position>1</position>
                <liParams/>
                <aParams>class="top-link-about-us"</aParams>
                <beforeText></beforeText>
                <afterText></afterText>
            </action>
 
            <!-- Remove 'Site Map' Link - Default Position: 10
            Original link adding in catalog.xml -->
            <action method="removeLinkByUrl"><url helper="catalog/map/getCategoryUrl" /></action>
 
            <!-- Remove 'Search Terms' Link - Default Position: 20
            Original link adding in catalogsearch.xml-->
            <action method="removeLinkByUrl"><url helper="catalogsearch/getSearchTermUrl" /></action>
 
            <!-- Remove 'Advanced Search' - Default Position: 30
            Original link adding in catalogsearch.xml-->
            <action method="removeLinkByUrl"><url helper="catalogsearch/getAdvancedSearchUrl" /></action>
 
            <!-- Remove 'Contact Us' link - Original link in contacts.xml
            <!-- Best bet to go to Magento's Admin > System > Configuration > (left sidebar) Contacts
            > Contact Us Enabled = NO -->
            <!-- You can pass the full url, which is a hassle if you have dev and stage sites -->
            <action method="removeLinkByUrl"><url>http://YOUR_SITE.com/contacts/</url></action>
            <!-- see comments below for making a custom helper to remove contacts link
            no matter what your base url is  -->
	</reference>
 
        <!-- By default, Magento sets a static footer block. Find it in the admin under
        CMS > Static Blocks.
	<reference name="footer">
            <!-- Remove Magento's default static block and use the 'addLink' method above
            to add your custom and inline links.  I use the 'unsetChild' method as often as
            possible as opposed using the more final <remove name="cms_footer_links"/>
            just in case I want to add the block somewhere else -->
            <action method="unsetChild"><name>cms_footer_links</name></action>
 
            <!-- Remove all the other Magento links - "Site Map, Search Terms, Advanced Search, and
            Contact Us" -->
            <action method="unsetChild"><name>footer_links</name></action> <!-- Magento 1.4.x -->
	</reference>
</default>
</layout>

If all else fails, you can edit template/page/template/links.phtml. However, if you can make all your changes in local.xml, your life will be so much easier when it comes to upgrading Magento and making future edits.

Contact Us