Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, June 29, 2010

Magento - Change Price Labels

Magento by default labels the prices as "Regular Price" and "Special Price". I could not find any simple or straightforward method of changing these labels in the back-end admin.

It turns out that this is driven from the template's Price PHP file app/code/design/frontend/MYTHEME/template/catalog/product/price.phtml which reads the label values from the locale files and displays it.

So the simple solution is to change the label values in app/locale/en_US/Mage_catalog.cvs:
"Special Price:","Special Price:" 
to
"Special Price:","Our Special Price:" 

and

"Regular Price:","Regular Price:" 
to
"Regular Price:","Suggested Retail Price:" 

However, the recommended upgrade-proof method would be to create a new locale specific translation file containing only the above desired changes and save it as: app/design/frontend/MYTHEME/locale/en_US/translate.csv.

And don't forget to clear the cache after doing any of the above changes or they may not be visible on the front-end!

Similarly you can change any labels that you desire. Note that this is case-sensitive and needs to be done very carefully.

Magento - Ampersand in Category name not showing properly

Quite a few Categories added to a test install of Magento shopping cart had the ampersand character in the name. The Category page was displaying the ampersand in the name as & a m p ; which is the special HTML entity for the ampersand character.

I fiddled around with the settings in the back-end admin but there was no solution like the one I had stumbled upon for a similar problem in Product names here.

After a lot of fiddling, it turned out that this was happening because the category view PHP file for the theme I was using had compatibility issues with the instaleld cart version. The solution was to modify the app/design/frontend/MYTHEME/template/catalog/category/view.phtml as follows:

Search for occurrences the line:
<h2><?php echo $_helper->categoryAttribute($_category, $this->htmlEscape($_category->getName()), 'name') ?></h2> 

Replace with this line:
<h2><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h2> 


Explanation:
We are changing the theme view code to not translate any characters in the name that may have a HTML Special Entity representation. So these will remain as they are and you will not see the names going haywire!

Note that this may need to be done in a different file depending on which of the files are causing this problem. The errant file could be an incompatible older version of a plug-in as well.

Magento - Invalid argument supplied for foreach in toolbar.phtml

After adding a new theme and uploading a big number of records to a fresh Magento install, I see the following error in the log files:

Invalid argument supplied for foreach() in /home/content/07/6268407/html/app/design/frontend/MYTHEME/template/catalog/product/list/toolbar.phtml on line 63

After much digging around, I realized that this error is due to change in Magento on how the pagination works now in 1.4 as compared to earlier versions. The theme I used was clearly not compatible with Magento1.4 and hence this issue. To resolve this problem, here are the steps I took:

1. Create Template file for Pagination
Create a new file for handling pagination according to the new way. Create a new file called pager.phtml in the /template/catalog/product/list/ folder inside your theme folder. Now write the below code into this new file:
<?php if($this->getCollection()->getSize()): ?>
        <?php if($this->getLastPageNum()>1): ?>
        <td class="pages">
            <strong><?php echo $this->__('Page:') ?></strong>
            <ol>
            <?php if (!$this->isFirstPage()): ?>
                <li><a href="<?php echo $this->getPreviousPageUrl() ?>"><img src="<?php echo $this->getSkinUrl('images/pager_arrow_left.gif') ?>" alt="<?php echo $this->__('Previous Page'); ?>" /></a></li>
            <?php endif ?>
            <?php foreach ($this->getPages() as $_page): ?>
                <?php if ($this->isPageCurrent($_page)): ?>
                    <li><span class="on"><?php echo $_page ?></span></li>
                <?php else: ?>
                    <li><a href="<?php echo $this->getPageUrl($_page) ?>"><?php echo $_page ?></a></li>
                <?php endif ?>
            <?php endforeach;; ?>
            <?php if (!$this->isLastPage()): ?>
                <li><a href="<?php echo $this->getNextPageUrl() ?>"><img src="<?php echo $this->getSkinUrl('images/pager_arrow_right.gif') ?>" alt="<?php echo $this->__('Next Page'); ?>" /></a></li>
            <?php endif ?>
            </ol>
        </td>
        <?php endif; ?>
<?php endif ?>

2. Call this Pagination code in Layout
Edit the catalog layout xml file to include this new pagination code. Open the file catalog.xml in the /layout/ folder inside your theme folder. Now search for this line of code:
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

Below this line, add the following new line to call the pager file that you created in step 1 above:
<block type="page/html_pager" name="product_list_toolbar_pager" template="catalog/product/list/pager.phtml" />

3. Call this Pagination code in Toolbar
Edit the toolbar html file to include this new pagination code. Open the file toolbar.phtml in the /template/catalog/product/list/ folder inside your theme folder. Now search for the below block of code approximately around lines 42 - 63:
<?php if($this->getLastPageNum()>1 && is_array($this->getPages())): ?>
...
...
...
<?php endif; ?>

Now replace this block of code with the following single line of code:
<?php echo $this->getPagerHtml(); ?>


If you follow these 3 steps to the 'T' it should definitely resolve your problem!

To find out details of errors, please go through this post on Debugging Magento.

Monday, June 14, 2010

Fix Magento Error Message “Exception printing is disabled by default for security reasons”

Sometimes when Magento exceptions out, it gives the message:
“Exception printing is disabled by default for security reasons”
To remove this message, follow the steps below:

Step 1:
Copy the file errors/local.xml.sample and name it as errors/local.xml

Step 2:
Modify the configuration to suit your needs - the xml is very well commented and self-explanatory. For leaving the error log files on the server for future reference as well as email it to the store admin, the config should be setup as below:

<config>
    <skin>default</skin>
    <report>
        <!--
            "action" can be set to "print" to show exception on screen and "email"
            to send exception on specified email
        -->
        <action>email</action>
        <!--
            in "subject" you can set subject of email
        -->
        <subject>Store Debug Information</subject>
        <!--
            "email_address" admin email address
        -->
        <email_address>storeadmin@mystore.com</email_address>
        <!--
            "trash" is handle about trace info
            value "leave" is for store on disk
            value "delete" is for cleaning
        -->
        <trash>leave</trash>
    </report>
</config>

For more Magento debugging tips, check out my article Debugging Magento.

Debugging Magento

Magento some times errors out with the below message which gives no clue as to what might have gone wrong:

There has been an error processing your request
Exception printing is disabled by default for security reasons.
Error log record number: XXXXXXXXXX

If you have access to the files on the server, then go to the folder /var/report/ and look for the file named with the above number and open it up - you will see a "stack trace" of the error!

In case you do not have access to these files, fear not! You can enable the printing of the logs on the front-end. Open the file index.php and uncomment line 71 to display the errors:

ini_set('display_errors', 1);

But remember - do not keep this on for a long time as the error messages will be visible to the world.

Friday, May 21, 2010

Import Products and Categories into Magento

Of the few shopping carts that I was playing around with, I found Zen Cart and Magento to be the best. Simplicity of the Zen Cart was very alluring and Magento was attractive for its features based on the solid framework.

However, for a new store, importing all the products and categories for the initial setup is a major area for complaint. I wonder, how such a simple and important features gets left out of such a thought out & planned product?!

The developer community has provided plug-ins for Zen Cart and Magento Extensions to solve this problem to some extent. However I still feel that the ones available for free are not so well integrated and do not provide a very clean solution. A better integrated & cleaner solution should come in pre-packaged with the cart.

The solution should take care of and provide the following features:
  • Import Category hierarchies
  • Import Product Images & gallery if required
  • Associating of Related, Cross Sell & Up Sell products

*** Sighhh **** well, so much for wishes - for now, use what you get to be as close to the end goal as possible and mash-up the required functionality with it.

LinkWithin

Related Posts Plugin for WordPress, Blogger...