prestashop 1.4 code analysis:FrontController

1 Comment

the most important stuff I will only love in prestashop 1.4 is nothing but the very important FrontController.php.

Analysis

At first let’s just take a look at the mode of loading files in prestashop 1.4. If you “new” a class, at first the codes would search for the class file of the same name in controller, and such a way looks pretty much the same as that in the previous version. If the file could not be found there, the codes will then carry on the search in override, this folder that allows classes to be user-defined. If the file still could not be found, the codes will use exec to create a new class of the request-typed name in turn to load the names of those classes under classes plus the core classes. So, for the real FrontController.php, you have to find and get it under classes, also the corresponding name of the class will be FrontControllerCore.

If it is said that the most important stuff is init.php before, then FrontController.php in prestashop 1.4 has taken over all the work previously done by init.php. Moreover it has replaced all the other three files header.php, index.php and footer.php to carry out all of their original work, even including pagination and merchandise ordering. In a few words, just somewhat like the dispatch of zend framework, FrontController.php is a signal to have all the work start off.

	public function run()
	{
		$this->init();
		$this->preProcess();
		$this->setMedia();
		$this->displayHeader();
		$this->process();
		$this->displayContent();
		$this->displayFooter();
	}

Regarding such a style that is so similar to zend, I would doubt that if prestashop’s CTO has already been changed.

		if ($this->ssl AND !(isset($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) == 'on') AND Configuration::get('PS_SSL_ENABLED'))
		{
			header('HTTP/1.1 301 Moved Permanently');
			header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
			exit();
		}

Automatic 301 in function init, the very new function added in prestashop 1.4. Now it looks like that the maindomin module I’ve written before has got totally f**ked up.

$page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name;

The $page_name variable in function init has achieved a judgment in different pages and different modules in a very convenient way. You know in previous versions I still have to make judgments in header.tpl.

		Tools::addCSS(_THEME_CSS_DIR_.'global.css', 'all');
		Tools::addJS(array(_PS_JS_DIR_.'tools.js', _PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js'));

All above is from function serMedia. The advantage for doing so is achieving the unified management of both css and js, thereby it is available to do CCC (Combine, Compress and Cache) in prestashop, function productSort and pagination just take over the work previously done by sort and pagination while there is no significant change with respect to other aspects, as the main function is still copied from the past init.php, even the naming of each variable is still global rather than global class in the oriented object.

Customization

In folder override/classes everyone can see a file named _FrontController.php, which is actually an example of user-defined FrontController.php. Now if you delete that underscore in the file name and visit the page again, then you will see the debug information. What has to be noted here is that there are two additional files named mysql and module in the same folder. If some change were applied to FrontController.php only, it would lead to the termination problem due to some error message. Thus it is necessary to change Line 148 in _FrontController.php below:

error_reporting(E_ALL | E_STRICT);

Into:

error_reporting(7);

In regard to“7” above, if someone might not understand what it means, please refer to the relevant parts in the handbook for further study.

In order to customize FrontController.php, just create a new file named FrontController.php under folder override/class, and then write a class named extends FrontControllerCore and then it will be fine. The method can be taken to overlay the one in core directly.

class FrontController extends FrontControllerCore
{
	function setMedia()
	{
		parent::setMedia();
		Tools::addCSS(_THEME_CSS_DIR_.'addition.css');
	}
 
	public function displayFooter()
	{
		global $cookie, $smarty;
		if (!self::$initialized)
			$this->init();
 
		self::$smarty->assign(array(
			'HOOK_RIGHT_COLUMN' => (($smarty->get_template_vars('page_name') == 'category') ? '' : Module::hookExec('rightColumn', array('cart' => self::$cart))),
			'HOOK_FOOTER' => Module::hookExec('footer'),
			'content_only' => (int)(Tools::getValue('content_only'))));
		self::$smarty->display(_PS_THEME_DIR_.'footer.tpl');
		//live edit
		if ($cookie->live_edit AND $ad = Tools::getValue('ad'))
		{
			self::$smarty->assign(array('ad' => $ad, 'live_edit' => true));
			self::$smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
		}
		else
			Tools::displayError();
	}
}

In the example above, both methods namely setMedia and displayFooter have been overwritten.

When setMedia is being rewritten, such a method of original FrontController is executed and a new css is also loaded in the original css.

When displayFooter is being rewritten, such a process is actually copying the original codes to here to achieve the rewriting, and the only change can be nothing but just adding a judgment. If pagename were category, then column on the right-hand side would never be outputted so as to make a bigger space for category list.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

Upgrade Guide for prestashop 1.4

No Comments

Due to the real power of version 1.4, many people in b2c just wish to have their original prestashop upgraded to this new version. In fact, all upgrades above version 1.2 have been well done enough, so just following the upgrade steps as before is fair enough. However, there are lots of changes that have been made to version 1.4, so as I see it, it is necessary to put an instruction here in order to guide everyone for their upgrades to version 1.4.

1.Backup your database and hopefully your database version is 1.1-1.3, as the upgrade program will not support any lower versions than that. Besides, I don’t believe there could still be anybody still using the version below 1.0, whose bugs are too many to make its clients make payments normally.

2.Do not transfer your prestashop to the server until its local upgrade is complete. So please make sure you have created your local database in advance.

3.Install a brand new prestashop 1.4, and then copy settings.php from your old website into this new version, meanwhile update all the collection information for your database.

4.Open prestashop 1.4 in your local drive and find out the Upgrade option in the setup program. Then click and follow the steps in it for the rest of your upgrade work.

5.Check if the database upgrade has been complete. (You know, I used to try 3 times to barely have mine done successfully…)

6.Test your module and template of old versions in the local drive, since there would be more steps to be taken for upgrading to 1.4, unlike being that simple and easy to upgrade from 1.2 to 1.3 before. What is more, even smarty has been already upgraded to v3 while jQuery has also been of version 1.4 now.

There is one more thing that has to be mentioned here. If your old module uses many Smarty codes, then please upgrade it to the v3 environment as soon as possible. Moreover, both smarty v2 and v3 will be supported at prestashop 1.4 whereas version 1.5 may support v3 only. Be better a little loss than a long sorrow, please think about it now.

Also, there is basically no need to rewrite the module as it still works for the new version. So far no old modules that do not support the new version have been found yet.

7.Upload your prestashop of the new version. You had better create a new database and a new folder to give it a test at first. Once the test is successful you may move on to file transfer.

8.In addition to the issue regarding the path configuration in settings.php, which has been mentioned in my previous articles, prestashop 1.4 has got the function of automatically directing any visit to those non-primary domains to the primary domain. By such a function, data of the primary domain are recorded in the database, and all visits to non-primary domains will be directed by 301 to the primary domain. Therefore your local installed prestashop 1.4 might contain some domain information like localhost, which can be set in Backoffice >> Preferences >> SEO.

9.Finally, don’t forget copy all pictures in your img folder into your new website.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

Prestashop 1.4: New World, New Hope

No Comments

Prestashop 1.4 version has been released last Friday, after try the function, I have got a conclusion by one sentence: prestashop has started to keep abreast of other mature shopping systems.

New additions of one step checkout and guest pay are always the most common thing in customized development. And I also have lots of customers who need function in this regard. Furthermore, filtering of assortment product on the left side is the basic function of improving user experience in e-commerce field.

Do you still remember speed problem about the previous version? Actually, it is chaotic about js and css. It will take a long time to open the prestashop site in abroad server, just due to the numerous static resources, so we cannot do any optimization. The quote of js and css is everywhere, each module can cite css and js into our own tpl, which adverse the optimizing of speed. However, 1.4 version has totally solved this problem. First of all, it has combined the management of js with css, after that, it can achieve minimization, compression, etc. And it’s much more convenient, the requirement of http can be reduced a lot. In addition, 1.4 module has turned css into separate file, so global is not the one to dominate the whole world.

Cms is always the disadvantage of prestashop, however, 1,4 version has the ability of cms classification management, which is more convenient. Although it cannot beat prestashop+wordpress, compared with before, this is really a good improvement.

Webservices, for average user, it has not any value of practical use. But if you decide to make station cluster, it is really a convenient stuff. And I always hold the statement that it is suitable to apply prestashop into station cluster, because shift and copy is that commodious, and the running speed is much better compared with established brander shopping system. Recently, I devoted myself to sem, so what I thought about tends to sem a little.

At present, module is controlled in the official method, which is different like before, that is just creating an assortment automatically after writing one, and modules which don’t obey the official rules will be named as “other modules”.

In code aspect, please pay attention to two new folder: controllers and override. Previously, primary control routines are all in the files of root directory, but this part of file has been transferred into controllers. For prestashop which is facing the objectivity, of course it has free play space about customizing for programmers, override is exactly for this purpose, creating a file which has the same name as documents in controllers, and system will invoke files in overrides automatically.

The last but not the least, it’s about the development direction of prestashop. Before 1.2 version, prestashop didn’t have any official stuff, and there is only a link in the backend. Now official website of prestashop has established addons.prestashop.com, which is kind of like app store, and 1.4 version is combined with prestashop very closely. In submenu of modules, there is a special item – My Account, that is to say, you can land the official addons platform as well as accounts on addons directly.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

New module named Recent orders

No Comments

A module of prestashop, display the order’s product name and customer address(just city, state and country) in your left or right column.

It’s have 3 dispaly mode: auto, fake date and mixed.

Auto is default setting, which can display the real orders in database.

If your shop dont have so much orders, fake data mode can display orders you added below.

Mixed will display 2 mixed data.

Also, it’s have options to dispaly how many orders do you want do display.

Project home page http://phpskill.com/prestashop-shard-modules/71-recent-orders.html

Show case

Configuration page

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

Add phone number validator to prestashop registration form

No Comments

Add

elseif(!Tools::getValue('phone') || !Tools::getValue('phone_mobile'))
$errors[] = Tools::displayError('Error phone number');

to behind of #54 line of authentication.php

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

how to expend prestashop catgory list on left colume automatic

No Comments

Sometimes the visits need to click the plus button to see the sub catgories, i think it not good for user experience.

<script type="text/javascript">
$(function (){
toggleBranch($('ul.tree span.grower'));
});
</script>

You can put those code in your header.tpl of theme folder, and also, can put

toggleBranch($('ul.tree span.grower'));

at end of themes/YOUR THEME NAME/js/tools/treeManagement.js, so it looks like

$('ul.tree.dhtml').removeClass('dhtml');
toggleBranch($('ul.tree span.grower'));
}});
Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

The CDN of extjs

No Comments

Google javascript CDN is very good, but it’s not support extjs.

We dont know why, but the good news is, extjs buy the CDN service for themself.

<script type=”text/javascript” src=”http://extjs.cachefly.net/ext-3.0.3/adapter/ext/ext-base.js”></script>
<script type=”text/javascript” src=”http://extjs.cachefly.net/ext-3.0.3/ext-all.js”></script>
<link href=”http://extjs.cachefly.net/ext-3.0.3/resources/css/ext-all.css” rel=”stylesheet” type=”text/css” />

Include all css and images, very cool.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

How to reset the administrator password of prestashop

No Comments

The administrator password of prestashop use md5 for password encryption, it’s use a long string called “cookie key” plus your password to generate password data.

We need copy the cookie key in config/setting.inc.php.

My cookie key is _COOKIE_KEY_ = Q8ofSVQ9j6biVE2TnsFkKrhGZL04s3ahUzYLUWYHxL3N686JLSBiX7uL

So for me:

UPDATE `prestashop`.`ps_employee` SET `passwd` = md5('Q8ofSVQ9j6biVE2TnsFkKrhGZL04s3ahUzYLUWYHxL3N686JLSBiX7uL' + '123456') WHERE `ps_employee`.`id_employee` =1 LIMIT 1

ps_employee is administrator table name, if you set other table prefix, need change herer.

id_employee = 1 This is the first administrator, if you want change other one, just replace the id here.

Still cant open bankend? See here

Hope this article can help you, thanks.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

Solution on google map v3 in tabs

No Comments

If you want put google map in tabs view, sometimes cant display as well.

My HTML is:

<div id=”tab_gmap”>
<div id=”googlemap”></div>
</div>

First, need bind google map initialization in tabs title click event, so

jQuery("a.tabs").click(function (){
    //google maps init;
});

Second step, we need reset some attributes of map div.

jQuery("a.tabs").click(function (){
   jQuery("#tab_gmap").css({'display':'block'});
   jQuery("#googlemap").css({'width':'100%', 'height':'100%'});
 
   //google maps init;
 
});

Hope this article can help you, thanks.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

A bug in the gsitemap module of prestashop 1.2.5

No Comments

I dont know if the prestashop company already fix this problem in 1.3.x version, but i think 1.2.5 is a most useful version, and many website master dont want change it.

gsitemap, is the name of google sitemap module in prestashop, will generate twice main domin in 1 url at same time when site have 2 or more languages.

The URL like http://phpskill.com/abc under the defualt language is good, but for second language, this url will become http://phpskill.com/lang-nl/phpskill.com/abc.

So, open modules/gsitemap/gsitemap.php?change the line 86?113?147?165, replace the last “$tmplink” to str_ireplace(‘/’.$_SERVER['HTTP_HOST'].’/', ”, $tmpLink).

Hope this article can help you, thanks.

Share and Enjoy:
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • RSS
  • HelloTxt
  • MyShare
  • MySpace
  • Add to favorites
  • PDF
  • Print

Older Entries