Magento

How to fix Fooman speedster in Magento 1.3.2.4: Fatal error: Uncaught exception ‘JSMin_UnterminatedStringException’

After installing Fooman Speedster on Magento version 1.3.2.4, got several javascript errors. Both admin menu and front-end menu stopped to work.

I got the following error:

Fatal error: Uncaught exception 'JSMin_UnterminatedStringException' with message 'Unterminated String: '\'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,})/i.test(v)'

How have I fixed it?
First, I opened the following url for which I was getting this error, copied from Firefox’s Firebug extension.


http://127.0.0.1/magento/skin/m/1264961510/js/prototype/prototype.js,/js/prototype/deprecation.js,/js/prototype/validation.js,/js/scriptaculous/builder.js,/js/scriptaculous/effects.js,/js/scriptaculous/dragdrop.js,/js/scriptaculous/controls.js,/js/scriptaculous/slider.js,/js/varien/js.js,/js/varien/form.js,/js/varien/menu.js,/js/mage/translate.js,/js/mage/cookies.js,/js/sb/src/js/lib/yui-utilities.js

Obviously you should see the same error till now.

Now, I removed one js file and requested the above URL, how? say you would want to remove validation.js, then URL should be


http://127.0.0.1/magento/skin/m/1264961510/js/prototype/prototype.js,/js/prototype/deprecation.js,/js/scriptaculous/builder.js,/js/scriptaculous/effects.js,/js/scriptaculous/dragdrop.js,/js/scriptaculous/controls.js,/js/scriptaculous/slider.js,/js/varien/js.js,/js/varien/form.js,/js/varien/menu.js,/js/mage/translate.js,/js/mage/cookies.js,/js/sb/src/js/lib/yui-utilities.js

Notice I have removed /js/prototype/validation.js,

Ok, now there is no more error. So, the error is somewhere in the validation.js. In Magento 1.3.2.4, open the /js/prototype/validation.js and need to replace Line no 431

return Validation.get('IsEmpty').test(v) || /^[a-z0-9,!\#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})/i.test(v)

with

 return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v)

Should work fine now.

Thanks!

How to edit default email templates in Magento?

To change default email template, we need to edit html files in app\locale\en_US\template\email

If you are using other languages than en_US then open corresponding folder to make changes.

You also need to edit few more files, in order to get rid of these type of things:

{{layout handle="sales_email_order_items" order=$order}} 

so, make changes of files in app\design\frontend\your_theme\default\template\email otherwise you would see default email template.

phpmyadmin

How to import / recover magento categories and products from the old store?

Well, I was really looking for a good way to import categories in magento, we know we can export and then import products gracefully from our old store but not categories. So, what you need to do is, you need phpMyAdmin to export and import tables or similar tool, though I would recommend phpMyAdmin.

  1. Step 1: Select the old database from where you would like to recover categories and products and click on export, please check the attached image file, you need to Disable Foreign Key checks and Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT.

  2. Step 2: Now, select all tables prefix with catalog and eav
  3. Step 3: finally Save as file
  4. Step 4: Install a fresh magento version, I have tested with version 1.4.0.1, so I would recommend install the same version as the old one. Say, old magento store version was 1.4.0.1 then install a fresh copy of the same version.
  5. Step 5: Now, select the fresh database in phpMyAdmin which you have just installed and import the same old SQL file which you had exported in Step 3

If you don’t see any errors then look at new magento store, hope you would see all the products and categories.

You might not see new categories at the frontend, login to admin panel and enable Use Flat Catalog Category / Product.

Don’t forget to use the old media directory and ReIndex Data (System -> Index Management) :)

This method will be helpful if you would like to recover categories and products from the old corrupted database. This sometime happens we can not fix the old database even if you use the old database and install fresh magento.

Let me know whether you have successfully recover the old database or not.

How to fix Mage registry key “XXXXXX” already exists?

I got the following error message in a magento store after upgrading from 1.4.0.1 to 1.4.1.1. Though I moved products and categories from old site. And this lead me to see the error in the report directory:

Mage registry key "_resource_singleton/customer/customer_address" already exists

To fix this quickly, first, I simply commented a line in app/Mage.php file, line No.192

public static function register($key, $value, $graceful = false)
    {
        if (isset(self::$_registry[$key])) {
			if ($graceful) {
                return;
            }
            //self::throwException('Mage registry key "'.$key.'" already exists');
        }
        self::$_registry[$key] = $value;
    }

Above trick will resolve the issue quickly. Though I would not recommend. So, I restored the file as it was before. Then I looked at eav_entity_type table. And noticed in entity_model field value is customer/customer_address where entity_type_code is customer_address. This value should be customer/address, changed it, wow, started to work perfectly again!

So, if you see the similar error and don’t know how to fix in database then commenting the mentioned line will definitely help.

Let me how you have fixed :)

admin-debug

Develop magento theme- convert psd to magento

Well, if you are using version 1.4.x then follow the following steps:

  1. First keep your design ready. you may use Photoshop or open source Gimp
  2. Identify the default theme which can be used to develop your own theme, say, if your design is similar like magnto default theme then its better to follow default theme than modern theme.
  3. Now go to admin panel, System-> Configuration->Current Configuration Scope:Main website->Advanced:Developer->Debug:Template Path Hints : YES and Save the button
  4. Also, Flush Magento cache then refresh cache and finally disable cache status as we can see in this image System -> Cache Management -> Disabled
  5. Now, look at frontend you would see something like below
  6. As I am developing theme based on default theme, so create a new directory in
    \app\design\frontend\default

    , so if your new directory name is newtheme, then it will look something

    app\design\frontend\default\newtheme
  7. Copy all files from
    app\design\frontend\default\default

    to

    app\design\frontend\default\newtheme
  8. Similarly create a new directory in
    skin\frontend\default\newtheme

    and copy all files from

    skin\frontend\default\default
  9. Before I go ahead, lets activate our theme, go to admin System-> Design ->Add design change-> Custom Design: Select Default:newtheme and Save
  10. Well, Look at frontend carefully, this page is showing which template files are being used to show this page. Now if you need to change header then you need to change:
    frontend\base\default\template\page\html\header.phtml

    file

  11. But we will not change anything in
    app\design\frontend\base\

    directory, rather copy that header.phtml file and save it in

    app\design\frontend\default\newtheme\template\page\html\header.phtml

    create all necessary directories :)

  12. Refresh the frontend, you would see header template hints has changed to
    frontend\default\newtheme\template\page\html\header.phtml

    file

  13. Play with
    skin\frontend\default\newtheme\css\styles.css

    to change color scheme

To develop version 1.3 theme procedures are more or less same, but need to copy whole default directory to newtheme directory. You would see many files.

If you need professional help to convert PSD to Magento template, or upgrade (rebuild) theme then please visit PSDtoMagento.NET to get a reasonable quote.

how to upgrade magento theme from 1.3 to 1.4

First of all it is advised to redevelop your theme from scratch rather than fixing bugs on existing theme, it would be easy to redevelop than fixing. In case of earlier versions we copied all files from existing theme to develop new one, but in case of 1.4 you can only copy those files which are needed to change. Less files, less coding, mange easily.

Almost all template contents were changed: either full re-factoring or just accessibility improvements. As well the difference between different themes was unified.

It is worth of starting from scratch (and it should be the easiest way). Just don’t copy the entire theme, as it used to be done before… Override only templates/layouts you need. Less code = less maintenance.

Source

If you need professional help to develop magento theme, you may visit PSDtoMagento.NET

How to upgrade magento from ver.1.3.x to ver.1.4.x

Today, I am going to explain how I have upgraded magento from version 1.3.0 (pretty old :) ) to version 1.4.1.0 using the same old database.

As we know its a pain while we upgrade magento each time from one version to another.

Well follow the steps as written below, hope your magento site will run without any errors.

  1. First of all, take backups, and run magento on testing server/ local machine, in my case it was version 1.3.0 and installed directory was “old_magento”
  2. Now unzip fresh version of magento 1.4.1.0 in a separate directory, say, “new_magento” directory
  3. Copy all directory/files from new_magento to old_directory, obviously replace everything with new files
  4. Now run this old_magento directory (http://127.0.0.1/old_magento), this will take time as it will reconfigure your database.
  5. In order to avoid time-out error, increase php execution time, I set it to 3600 seconds, memory 2048, I had around 1000 products with many custom attributes, categories and product images
  6. After successful database upgrade, site should run, but we may see some php fatal errors on both admin panel and frontend respectively given below
    Fatal error: Undefined class constant 'Mage_Customer_Model_Group::ENTITY' in xxx\app\code\core\Mage\Core\Model\Config.php  on line 1206
    
    Fatal error: Call to a member function toHtml() on a non-object in xxx\app\code\core\Mage\Core\Model\Layout.php on line 529
  7. Now delete everything from old_magento directory except media directory, rename media to media_old
  8. Again copy fresh files / directories from new_magento to old_magento directory, rename directories media to media_temp and media_old to media
  9. Run again (http://127.0.0.1/old_magento your path may be different)
  10. Now you would see magento installation screen, use old database name, user and password etc properly.
  11. This installation should not take too much time, after installation go to frontend and admin panel

This trick worked for me smoothly with 1000 records, although you have to check your custom theme so that it becomes compatible with version 1.4.x that is another story :)

How to add static CMS block in Magento?

If you want to add CMS block in Magento then there are several ways to accomplish the task.

if your block Identifier name is ‘new_block’,

Insert CMS static block directly through PHP in .phtml file:

<?php
echo getLayout()->createBlock('cms/block')->setBlockId('new_block')->toHtml()
?>

Insert CMS static block through Magento admin control panel CMS:

 {{block type="cms/block" block_id="new_block"}}

Insert CMS static block through XML:

<block type="cms/block" name="block_name" after="cart_sidebar">
 <action method="setBlockId"><block_id>new_block</block_id></action>
</block>

PS: block_name may be anything as you wish.

Move magento site from development to production

How to move Magento site from demo to root directory?

if you would like to move Magento from development directory to main directory then its quite easy.

  1. Copy all files and folder and paste at desired location. eg. public_html/magento/ and paste to root directory public_html/
  2. Now open database, look at core_config_data table, edit only 2 values: web/unsecure/base_url and web/secure/base_url
  3. if previous value was something like : http://127.0.0.1/magento/ then new value will be http://127.0.0.1/
  4. that’s all!

:D

After updating Manage Stores magento shows 404 Page error

If you see 404 Page not found error in magento version 1.4 after updating or changing magento stores, there is a simple solution as given below:

Open index.php file and replace

Mage::run($mageRunCode, $mageRunType);

with

Mage::run('default');

You should be able to login to Admin control panel, restore old configuration in Manage Stores and again change index.php file, replace

Mage::run('default');

with

Mage::run($mageRunCode, $mageRunType);

Although, you may not see

Mage::run($mageRunCode, $mageRunType);

, this line may be different if you are not using Magento 1.4

In that case search

Mage::run('

and replace the line with

Mage::run('default');