CS-Cart Customization: Product Downloads Counter

Notice: This post is aimed at experienced users. It applies to CS-Cart v.3.0.x.

I have already written posts about the CS-Cart shopping cart, here is a new one!

Here is a scenario:

You sell downloadable digital products in your CS-Cart store.

You want to know how many times a user downloaded a file.

You need to keep records of when the customer first and last downloaded the product.

CS-Cart lets you sell digital and downloadable products very easily. It keeps also track of how many times a user “clicked” on the download link (but does not tell you if the file was correctly sent to the user, which might cause an issue if you want to fully refund not-downloaded orders)

Make these modifications to put things in the right way:

1- Edit: <CS-CART_ROOT>/controllers/customer/orders.php

and replace the ‘get_file’ mode block (lignes 403 to 435, may vary upon versions) with the following block:

} elseif ($mode == 'get_file') {

	$field = empty($_REQUEST['preview']) ? 'file_path' : 'preview_path';

	if (($field == 'file_path' && !empty($_REQUEST['ekey']) || $field == 'preview_path')) {

		if (!empty($_REQUEST['ekey'])) {

			$ekey_info = fn_get_product_edp_info($_REQUEST['product_id'], $_REQUEST['ekey']);

			if (empty($ekey_info) || $ekey_info['file_id'] != @$_REQUEST['file_id']) {
				return array(CONTROLLER_STATUS_DENIED);
			}

			// Increase downloads for this file
			$max_downloads = db_get_field("SELECT max_downloads FROM ?:product_files WHERE file_id = ?i", $_REQUEST['file_id']);
			$file_downloads = db_get_field("SELECT downloads FROM ?:product_file_ekeys WHERE ekey = ?s AND file_id = ?i", $_REQUEST['ekey'], $_REQUEST['file_id']);

			if (!empty($max_downloads)) {
				if ($file_downloads >= $max_downloads) {
					return array(CONTROLLER_STATUS_DENIED);
				}
			}

		}

		$file = db_get_row("SELECT $field, file_name, product_id FROM ?:product_files LEFT JOIN ?:product_file_descriptions ON ?:product_file_descriptions.file_id = ?:product_files.file_id AND ?:product_file_descriptions.lang_code = ?s WHERE ?:product_files.file_id = ?i", CART_LANGUAGE, $_REQUEST['file_id']);

		if (!empty($file)) {
			if(fn_get_file(DIR_DOWNLOADS . $file['product_id'] . '/' . $file[$field]) != false)
			{
				db_query('UPDATE ?:product_file_ekeys SET ?u WHERE file_id = ?i AND product_id = ?i AND order_id = ?i', array('downloads' => $file_downloads + 1), $_REQUEST['file_id'], $ekey_info['product_id'], $ekey_info['order_id']);

			}
		}
	}

	return array(CONTROLLER_STATUS_DENIED);

2- Edit <CS-CART_ROOT>/core/fs.fs.php and change the line 332 (where the fn_get_file function calls the “exit;”) to the following:

			return false;

These modifications, make sure the file is sent to the user before increasing the download counter.

Now, lets make the download counter visible in your administration panel.

1- Edit <CS-CART_ROOT>/skins/<ACTIVE_ADMIN_SKIN>/admin/views/orders/details.tpl

After line 343, inside the TR tag, add the column header:

<th>{$lang.downloads_count}</th>

Now, after line 354, add the download counter value:

<td>{$file.downloads}</td>

Save your file and refresh your CS-Cart cache by opening your store’s administration panel and then adding &cc to the end of the page url (if you are on the admin index, also add a “?”)

example: https://www.examplestore.com/administration.php?&cc

Now, go to a confirmed/processed order and on the downloads tab you will have:

CS-Cart download counter in administration panel

In the next post, I will write about how to keep track of first and last download times to let you know more about your customers.

 

[Solved] Joomla 3.0 admin radio switch buttons do not display their state

If you are using Joomla 3.0 with the ISIS administrator template, and have installed some modules and themes like JA T3 Framework or GANTRY Framework, you might notice that radio switch buttons in your administration panel do not show their state.

Here is a screenshot of how settings “Hide / Show” buttons might show:

Joomla Settings Switch buttons no state

This can be fixed easily:

Edit the file:

 JOOMLA_ROOT/administrator/templates/isis/js/template.js 

Change the line (around 35) from:

 $(".btn-group input[checked=checked]").each(function() 

to

 $(".btn-group input:checked").each(function() 

Here is what you will have once you reload your admin page:

Joomla ISIS template radio switch working correctly

The issue resides in the method the function checks if a radio button is checked or not. This update is needed in Joomla ISIS template so that the “:checked” selector is used.

Alternative PHP Cache, APC, on GoDaddy Hosting

As I said earlier, Godaddy is implementing APC ( a great cache functionality) on its shared hosting plans. In a recent contact I had with them, it looks like the launch day is tomorrow.
Godaddy.comTill now, Godaddy disabled (by default) this extension for clients using actually Zend and Ioncube; good choice; as these 3 extensions represent an incompatibility risk.

If you want to benefit from the “awaited” great performance boosts with APC, you need to disable Zend and Ioncube extension and enable APC.

Enable APC on Godaddy.com Hosting

Here is how to do it:

Open your working php.ini/php5.ini file (it might be in a subfolder or on your root folder)

If you have Zend or Ioncube extensions enabled, and you are sure your sites will work without them, disable these extensions by putting a semicolon (;) in front of each line about them.

If you see “apc.enabled=0” somewhere, comment this line with a semicolon (;) too.

Godaddy Optimized php(5).ini

Here is a nice PHP5.INI (for Godaddy Linux hosting plans using FastCGI PHP 5.3)

Save it as php5.ini and place it in the public root of your server (/html folder). Careful to backup your current php5.ini.

cgi.fix_pathinfo = 1
cgi.check_shebang_line = 0
;register_argc_argv = false
default_charset= "UTF-8"

; Enable GZIP compression at the default level
zlib.output_compression = On
zlib.output_compression_level = 6

; Disable PHP magic quotes
;magic_quotes_gpc = Off
;magic_quotes_runtime = Off
;magic_quotes_sybase = Off

register_globals = off
allow_url_fopen = on

max_upload_filesize = 6M
upload_max_filesize=6M
memory_limit=48M
max_execution_time=30

expose_php = Off
max_input_time = 60
variables_order = "EGPCS"
extension_dir = ./
upload_tmp_dir = /tmp
precision = 12
SMTP = relay-hosting.secureserver.net
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

date.timezone="Europe/Paris"

allow_call_time_pass_reference = on

; Load PDO MySQL extension
extension=pdo.so
extension=pdo_mysql.so

;APC
extension="apc.so"
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.enable_cli=1

; Only uncomment zend optimizer lines if your application requires Zend Optimizer support
[Zend]
;zend_optimizer.optimization_level=15
;zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
;zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
;zend_extension=/usr/local/Zend/lib/Optimizer-3.3.3/ZendExtensionManager.so
;ZEND GUARD (because we use PHP 5.3)
;zend_extension=/usr/local/Zend/lib/Guard-5.5.0/php-5.3.x/ZendGuardLoader.so
;zend_extension_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3/ZendExtensionManager_TS.so
; -- Be very careful to not to disable a function which might be needed!
; -- Uncomment the following lines to increase the security of your PHP site.
;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru,
; phpinfo, exec, system, dl, fsockopen, set_time_limit,
; popen, proc_open, proc_nice,shell_exec,show_source,symlink"

Now you have APC enabled by default!

Check if APC is installed on your Godaddy account

You can check it by opening a php file containing phpinfo() function.

Here is an example:

Save the code below in a file named: phpinfo.php

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

Now you can put this file next to your websites files (careful not to overwrite existing files) and browse to this file with your web browser. Search in the page for “APC”, you will know now…

Keep in mind that these settings apply if you have your hosting with any of Godaddy Resellers, like “DomainsPricedRight.com”

 

Optimize your CS-Cart store

Speed up CS-Cart

Faster websites get better SEO scores and get better indexes in search engines, a Google employee once said “Website should be fast”, your visitors will agree, trust me.

 

CS-Cart more salesFaster and optimized eCommerce websites do sell +40% more than slower ones, just because they are faster. You “will” agree once you see the money come 😉  trust me.

 

In the continuity of my “Website optimization” posts, this time we will see how to optimize CS-Cart, but hints and methods written here are useful for all other platforms, just you will need to adapt, easily.

E-Commerce Optimization

I assume you already know about the ROCK SOLID eCommerce software “CS-Cart”, if not, you are missing BIG!

odience.net|works sponsored this post and asked me to optimize their online marketplace which is based on CS-Cart.

The outcome? A faster CS-Cart store which loads in less than 5 seconds and gets a performance grade of 94/100 and on some pages 99/100 (check for yourself at Pingdom), this literally “ROCKS”.

UPDATE: Based on my work 😉 , odience.net|works made a package that CS-Cart users can use to speed-up their stores. Will be available soon!

Now we will see in this post, how you can optimize your site load times and speed.

A little bit more than “few” technical knowledge is required if you want to read on, but you never know, maybe you will learn on the way 😉

I will expose different steps and aspects of optimization which are also applicable with other websites as we saw in my previous posts.

 

Time Matters

From an optimization point of view, even 0.1 second in load time matters so let’s get started.

 

Optimize Cache, Server side:

CS-Cart integrates a built-in cache, but that needs lots of modifications to be “robust” and “reliable”.

Here are some issues with CS-Cart’s cache:

  • It “kind of” compresses the JavaScript files but doesn’t combine them! So you find your self serving multiple files which is BAD for load time.
  • It does not cache external JS files you include with the {script} tag. OK, this might be “over doing” but it might be interesting as for serving “hosted” Google Analytics JS on CS-Cart…
  • It “combines” the CSS files but does not compress them, so you will be sending the user a quite BIG file; and that is BAD for page speed too.
  • It does not compress nor clean the HTML output, and again, BAD for speed.
  • It does not serve files with the right expires header so no one know when to refresh the content! How a browser is supposed to know what and when to cache?

Well, what to do, is to optimize this caching to the maximum and make the page generation faster and faster.

So for example the same time CS-Cart “combines” CSS files, let’s tell it to “compress” the output CSS file. When it compresses JavaScript files “independently” let’s ask for a combined and compressed output file, in the mean while, cache external JS files to limit multi-domain requests for the user.

Backup AlertThese steps are quite complex, and need core modification, so you must be careful when updating/upgrading your CS-Cart installation to keep a backup of your MODs.

SMARTY

smarty logoIf you don’t know it already, CS-Cart runs Smarty for its template engine. Smarty is basically great from an ease of use point of view, but unfortunately, Smarty v2 is not optimized for speed. Well, Smarty did great on its Smarty v3 on speed optimization, and included multiple cache handlers like eAccelerator, APC and others.

APC

Alternative PHP Cache LogoI have to mention that APC caching improves A LOT your site performance, but, Smarty v2 does not contain an APC cache handler, so I made an APC cache handler for Smarty v2, and thus for CS-Cart 3, which makes your content load directly from “RAM” instead of Hard Drive. This means “very fast”.

CS-Cart Core Optimizers

You can download these “Optimizers” from my Downloads page  odience Market, instructions included.

 

Optimize Cache, Client side:

To tell the browser which files to cache and which ones to not, your server must send correct “Expires headers”.

Unfortunately CS-Cart does not set theme correctly. This causes your client’s browser NOT to cache and ask for every page element at each request. Seriously, you DO NOT WANT THIS, because, wait for it…. BAD for speed!

You will need to edit your HTACCESS file(s) to send correct “cache” headers to the user directly from your server.

CS-Cart Optimized HTACCESS

You can download a sample of the “CS-Cart Optimized HTACCESS” from my Downloads page and for the full version, check odience Market, instructions included.

 

Combine JavaScript files:

Merge JS and CSS files

As I wrote before, CS-Cart just “compresses” JavaScript files and it does NOT combine the files. You need to combine the compressed JavaScript files to use less bandwidth and send the file FASTER to the user, because JavaScript files are “VERY DANGEROUS” for page speed.

A JavaScript file  literally blocks all other elements from loading until itself gets fully loaded, so you want it to be “alone” and to finish loading, wait for it …. …. …. FAST!

CS-Cart JS Optimizer

Get the “JavaScript Combine&Compress Smarty output filter”; that I wrote; from odience Market, instructions included.

 

Compress CSS files:

Compress content

There are lots of great Open Source projects (ex. Minify) which allow great CSS optimization, combination and compression. I don’t know why CS-Cart does not integrate one such library?

Well, all that said, you need to compress CSS files, and more precisely, Minify them to let users receive just what they need to “style”, nothing more nothing less.

Use less files, Use more SPRITES:

CSS Sprites example

CS-Cart uses a lot of small icons for its base skin.

If your current skin is using more than 20 different icons (not product images, just icons, ex. account icon, cart icon, live help icon, menu drop down arrows,…) you should think about combining them into a single file to decrease the number of requests a visitor’s browser makes to your server. This combination reduces significantly your page load time and speeds up your CS-Cart store. So, go ahead  and combine your small icons into one or two bigger image sprites to reduce file requests as these requests are BAD for speed.

There are some free tools which help you automate and simplify sprites generation:

CS-Cart Sprites based Basic skin

Still not finished, but I am working on creating a sprites based “Basic” skin for CS-Cart, help is much appreciated.

 

Use a CDN for your static contents:

CDN77.com Europe Pops

CDN, CDN, CDN! (It stands for Content Delivery Network if your are new :D)

If you got the $$$ to run with the big guys, go with AKAMAI, Amazon and other big Content Delivery Networks.

But! You can set your FREE CDN too! just serve your static content from a different sub-domain (or domain), for exemple:

Serve images from

https://staticimg.yourdomain.com/images/

while serving your mains website from

https://www.yourdomain.com/

This allows “parallel” downloads which will increase significantly page speed.

Well, serving JavaScript and CSS files from a CDN is something to think twice about, because CS-Cart generates your CSS and JS files every time you refresh the cache so if you are on a CDN, that would happen slower than you expect.

To make CS-Cart “CDN-compatible” you will need to make few changes to your skin’s files. If you focus on moving only your images to the CDN, it would be quite easy, though you should also think about the Addons and their images.

Basically, by overriding the $images_dir SMARTY variable at the right moment, you can tell CS-Cart to go get the images from a CDN, though some minor modifications should be done on core smarty plugin files to let CSS files compile correctly.

Another great idea to setup a CDN for CS-Cart is to mount your CDN space as a partition (mount point) on your server and symlink your static directories (images, css, js, cache) to the mount point, this reduces all synchronisation lags, and saves you from changing core files.

CDN CS-CartBut, a better idea, is to use a “Mirror CDN” like CDN77.com!

 

I already tested CDN77.com and the service is great. They offer a 14 days free trial, which lets you know if you are ready for CDN.

I really recommend them because of the number of pops (servers worldwide) and their affordable price ($4.90 /100GB of data, THIS IS VERY LOW!). So, if you need a CDN, sign up for CDN77.com and make your CS-Cart s

ite faster!

Let me explain on how to use a mirror CDN for your CS-Cart ecommerce software:

  1. Open an account on CDN77.com
  2. Create a new CDN
  3. If you need SSL (I recommend it if you have a secure store)
  4. Choose Free SSL (shared)
  5. or choose a custom SSL (ex.: “https://cdn1.gibni.com/” for 39$/month)
  6. Let 4 minutes pass by, for the CDN to be setup of course!
  7. Modify your CS-Cart store to serve images (you can do it even for CSS and JS, but not really needed, as you would have less than 5 JS and CSS files; it’s up to you!)
  8. Enjoy your Free CDN! (Yes, as simple as that, weird huh?)

 

Use a cookie-less domain for static components:

CS-Cart Cookie

Sites setting cookies will send/set the cookie file (0.8 – 1.5 KB) for each requested component (even for static images and css/js files).

These static contents do not require a cookie file, so by using a subdomain, or another domain (like a CDN), you will be able to get this point fixed and make your static components “cookie-less”, i.e. about 1K size reduction per element, so again, read the previous section about CDN to setup one for your images (at least).

 

Optimize your server with HTACCESS and PHP.INI tweaks:

Php.ini and Htaccess optimization for CS-Cart

To oil the gears of your server, you might need to have a look at your .htaccess and php.ini (php5.ini) files.

 

Some stuff you could do:

  • Set Expires headers based on file types,
  • Tell the browser to cache CSS and JS files,
  • Unset ETags,
  • Set Gzip/Deflate compression for your HTML/PHP files,
  • Secure access to your server and store,
  • Secure file requests and prevent file request attacks
  • Make sure downloadable files are downloadable! weird, huh?!
  • Add the “missing” trailing slash in your URLs,
  • Rewrite requests to WWW,
  • Force secure connections through HTTPS
  • Install a Virtualized Software Firewall through HTACCESS to protect yourself from hackers
  • Protect  your server and store from unauthorized queries and requests
  • Speed up the server with the PageSpeed Apache module
  • and so on…

Specially with PHP.INI (PHP5.INI) you could:

  • Set a default FROM address directly on the server to get your emails “delivered”
  • Increase execution times and upload file sizes to optimize performance and ease file uploads
  • Activate ZEND extensions to boost your server
  • and so on…

CS-Cart optimized PHP.INI & HTACCESS

Check the optimized PHP5.INI file (created and tested on Godaddy.com’s Shared hosting) and a tweaked (basic) HTACCESS for CS-Cart at my Downloads page.

 

Conclusions

There is a lot to do for a better web, by optimizing your websites and e-shops, you use less bandwidth and energy. Apart from making better sales and getting better SEO scores, you make a greener world. Do not hesitate about optimization.

GoDaddy Down

Godaddy.comWell, there are lots of news about GoDaddy.com being down, now more than 4 hours, but the question is: How Godaddy.com will compensate the losses?!

People hosting their websites on Godaddy.com servers, and its resellers, lost lots of money in this outage.

“Over 50 local Myrtle Beach hotels that use GoDaddy services through Fuel Interactive could be impacted by as much as $30,000 an hour, collectively, for each hour the sites are down.” says Wmbfnews. (1)

On the other hand, Disa Johnson says that Godaddy didn’t resolve the issue by themselves. It was the hacker who “had a heart” and let go!!!! (2)

How can making troubles for others be called “having a heart”??

Just search about this outage on Google News and Twitter (@Godaddy) and you will see that millions of websites were affected…

1- http://www.wmbfnews.com/story/19505927/hack-of-godaddy-sites-impacts-myrtle-beach-area-businesses
2 – http://airdisa.tumblr.com/post/31297877089/godaddy-dns-tangodown

SOLVED : Can't update to Joomla 1.7?

To Joomla 1.7…

If you are running a Joomla! website, you’ve already heard about the Joomla 1.7 upgrade. It’s recommended to upgrade to this version specially if you run Joomla 1.6.

 

Basic steps to update/upgrade to Joomla 1.7:

 

In some situtations, you might have trouble upgrading Joomla with the built-in “Joomla Updater”.

Joomla 1.7 Upgrade errors:

  • “Update: :Collection: Could not open http://update.joomla.org/core/list.xml”

    To solve this errror, you need to “allow fopen” on your server:

    1. Create a php.ini file in your Joomla site’s root. This file should contain the following line:
         
      allow_url_fopen = on
    2. Make sure that the file is having the 644 permissions at least.
    3. Check if fopen is allowed by running a simple php file inside your Joomla root directory containing the following line:
      <?php phpinfo(); ?>

      and look for “allow_url_fopen”, it should say “ON”

    To upgrade to Joomla 1.7 on a Godaddy hosting running PHP5, you should create a “php5.ini” instead of the php.ini stated above.

  • Joomla updates do not appear, and Joomla says there is no upgrade available at the moment?

    If you run Joomla 1.6.x,

    1. Go to the “Extension Manager”, hit the “Manage” tab, click the “Refresh Cache” button.
    2. Go back to “Update” tab, click “Purge Cache”
    3. Click on the “Find updates” button,
    4. Joomla should appear as an update option, check it and click the “Update” button.
  • Fatal error: Cannot instantiate abstract class JDatabaseQuery in mysite/plugins/system/jat3/jat3/core/joomla/modulehelper.php on line 292

    When you run a JoomlaArt template, as of today, you will get an error after upgrading to Joomla 1.7.

    As the error message says it, the error is on line 292 of the above file. With your FTP client, or web file manager, navigate to the file mentioned above and edit the file.

    On line 292, comment out this:

    $query = new JDatabaseQuery;

    and insert this line below it:

    $query = $db->getQuery(true);

    so the final result at lines 292 and 293 looks like this:

    //$query = new JDatabaseQuery;
    $query = $db->getQuery(true);
  • Fatal error: Cannot instantiate abstract class JDatabaseQuery in mysite/plugins/system/jat3/jat3/core/menu/base.class.php on line 329

    If you use the mega menu of JoomlaArt, you need to do the same proccess for the file base.class.php

    That is, the lines 329 and 330 should be as follows:

    //$query = new JDatabaseQuery;$query = $db->getQuery(true);

Add a Google +1 button to your PrestaShop store for Free!

Today I’m going to give you some great news.

 

Online stores, e-commerce software…

More than 50 thousand online stores run on PrestaShop, an online e-commerce software. There are lots of advantages using this software, e.g. it’s open source, it’s got a huge community of developers and users, lots of modules and themes are being added to it regularly…

 

PrestaShop’s Drawback

But the main drawback of PrestaShop is that most of its modules are not free and to run a decent business you gonna spend a lot of money over the modules. Well, I would recommend to buy the modules you need without hesitation, because it is an investment in your business, but I know that you are looking for the Free ones at first.

 

Google +1

You’ve certainly heard of the “+1” button from Google, and it would be nice to add it to your shop so that your users can recommend your products on Google.

There are modules on the PrestaShop’s market to allow you putting a “Google +1” button to you store, and they are priced at around 40€ (about 50USD).

 

Free Google +1 for PrestaShop

oGooglePlusOne module Logo

The great news is that odience.net offers a “Google +1” button for PrestaShop, completely FREE! and that saves you about 50USD!

 

As you know, you can donate to thank the developer 😉

 

I got a copy of the oGooglePlusOne module from odience.net and tested it on one of my e-commerce websites. It is complete and integrates itself automatically! Go to odience.net and grab yourself a Free copy of oGooglePlusOne for Prestashop!

 

Don’t forget to say Thank You and send a donation if you think it’s worth it.

Embed Images in PHPMailer

I’ll keep this one short and fast:

PHPMailer has lots of features, even if it’s a bit old.

One great feature is that it allows you to embed images inline within your e-mail’s body. In most email clients, the inline embedded images are shown in their right place just as on a web page and are “also” in the attachements list.

To be able to use this feature, proceed as follows:

1- Instantiate PHPMailer:



$mail = new PHPMailer(true);

$mail->CharSet='UTF-8';

...

...

//Path to image file (use full path)

$filepath= '/path/to/file/logo_mail.jpg';

//File token ID, use unique interger.

$filecid = 1001;

//File name which will be in the mail, overrides default filename.

$filename= 'shop-logo.jpg';

//Encoding

$encodingtouse = 'base64';

//File type MIME

$filemime = 'image/jpeg';

//EMBED IT

$mail->AddEmbeddedImage($filepath, $filecid, $filename, $encoding, $filemime);

//Message Html Body

$mail->MsgHTML(file_get_contents('/path/to/contents.html'));

2- In your /path/to/contents.html file, which is your mail template message, you can include the inline image. Use this syntax for the <img> tag:

<img src=”cid:1001” alt=”shop logo used in emails” width=”182″ height=”75″ />

Note the CID here, it should be the same as the one you defined for your embedded inline image.

Tested and working with PHPMailer 5.1 on GMAIL, Yahoo!Mail and Mac Mail application

 

ref: http://www.sitepoint.com/forums/php-34/embed-images-phpmailer-586789.html

[SOLVED] Could not instantiate mail function in PHPMailer

(This article has an advanced technical level, written for people with PhpMailer experience.)

PHPMailer 5.1 in PrestaShop 1.4

Trying to integrate PHPMailer in Prestashop and use it instead of SWIFT Mailer 3 (which is the default mailer script included with Prestashop 1.4), I spent hours to no avail and was getting the Could not instantiate mail function error.

mail() function

The mail() function by itself  was working correctly before and after loading Prestashop and every passed argument seemed to be correct. I did get the “Bad parameters to mail() function, mail not sent” error for mail() too.

Debugging and Abracadabra!

I’ve done lots of debugging and found in my case that the following functions were causing the error, when passing the $Subject parameter to mail():

SecureHeader();
EncodeHeader();

To solve the “Could not instantiate mail function” error in PHPMailer, I removed the above 2 functions from the mail() function arguments.

Just be careful to remove these functions correctly from all places in your class.phpmailer.php.

I recommend using the PHP function

mb_encode_mimeheader()

http://php.net/manual/en/function.mb-encode-mimeheader.php

because it encodes your stuff correctly for the headers in emails.

To be more clear,

1- open the PHPMAILER class file (class.phpmailer.php)

2- Locate:

protected function MailSend($header, $body)

function and in its body,

3- In every call to mail(),

replace this:

@mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);

by this:

@mail($val, mb_encode_mimeheader($this->Subject,$this->CharSet, 'B', ''), $body, $header, $params);

 

This way you are sure to correctly encode your subjet.

Remember to set the correct Charset for your PHPMAILER instance. That is, when calling PHPMailer, just after:

$mail=new PHPMailer(true);

add:

$mail->CharSet = 'UTF-8';

(or any other charset you need).

This solved my “Could not instantiate mail() function in PHPMailer issue. I hope it helps you out if you got this issue too.

Evenmore:

I’ll write more about PHPMailer and PrestaShop later,

In my next post, learn how to correctly include inline images in PHPMailer email to display in GMAIL, YAHOO, Mac Mail app and other email clients correctly as inline images.

Bug Prestashop, la liste des magasins n'apparait pas

Cette article est sponsorisé par odience.net¦works

En plein developpement

En plein développement de plusieurs modules PrestaShop, j’ai rencontrer plusieurs souci dans les code du package PrestaShop. Ce qui m’étonne, c’est qu’il y a beaucoup de gens qui utilise PrestaShop, même si c’est du gros n’importe quoi en terme de codage et programmation.

 

Alors pourquoi je créer des module?

Tout simplement parcequ’il y a de la demande.

(Restez connecté pour avoir des nouvelles de mes modules:

Ces modules sont créer pour odience.net et seront sont disponible sur odience.net)

Retour à nos moutons

Je vous explique un bug que j’ai trouver aujourd’hui et la solution.

Le problème est ceci:

La variable SMARTY qu’utilise PrestaShop pour stocker les informations des magasin est nomée “$stores”. On peut y acceder et donc afficher les details de nos magasin un peu partout dans les pages et les modules sans diriger le visiteur sur la page de “nos-magasin”.Module Contact PrestaShop avec formulaire de contact et carte google maps

Quand vous changez la configuration de l’affichage simplifié dans le Back Office, la variable $stores devient VIDE partout sur votre boutique. Donc vous ne pouvez plus afficher les details comme un numéro téléphone ou une photo tiré directement de la variable $stores.

Ceci est du au faite que une fois la configuration dans le Back Office modifié, PrestaShop relance une requete vers la base de donnée pour recréer $stores, mais cette fois il relance la requete en cherchant a calculer un distance! Donc la variable $stores reste vide.

Essayez d’ouvrir votre boutique en ligne en ajoutant “?all=1” à la fin de votre URL et vous verrez que la variable $stores fonctionne correctement et affiche bien les infos de vos magasins.

Remède, Solution

Le remède a ceci est de modifier le fichier

PSdir ->controllers -> StoresController.php

qui gère la variable $stores.

 

Au environs de la ligne 73, on ajoute une nouvelle requete SQL qui remplit la variable $stores avec la liste de tous nos magasins, et une deuxième requete SQL qui servira a calculer la distance en cas de recherche.

$stores = Db::getInstance()->ExecuteS(' SELECT s.*, cl.name country, st.iso_code state FROM '._DB_PREFIX_.'store s LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) WHERE s.active = 1 AND cl.id_lang = '.(int)($cookie->id_lang)); $results = Db::getInstance()->ExecuteS(' SELECT s.*, cl.name country, st.iso_code state, ('.(int)($multiplicator).' * acos(cos(radians('.(float)(Tools::getValue('latitude')).')) * cos(radians(latitude)) * cos(radians(longitude) - radians('.(float)(Tools::getValue('longitude')).')) + sin(radians('.(float)(Tools::getValue('latitude')).')) * sin(radians(latitude)))) distance, cl.id_country id_country FROM '._DB_PREFIX_.'store s LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) WHERE s.active = 1 AND cl.id_lang = '.(int)($cookie->id_lang).' HAVING distance < '.(int)($distance).' ORDER BY distance ASC LIMIT 0,20');

A savoir que la variable $results sera vide si il n’y a pas de demande de recherche de distance et donc StoresController.php ne genèrera pas de fichier XML servant a la mise en place d’une carte Google Maps dans le Store Locator. Pour assurer que le fichier XML sera créer seulement si $results contient quelque chose, je fait une verification avec:

if (!empty($results))

Téléchargez, tout simplement

Vous pouvez télécharger la version corrigée de ce fichier dans la page téléchargement de Gibni.com (nom du fichier: StoresController-1.4.Amir.zip)

 

Pour l’utiliser,

1- Allez dans:

DossierPrestaShop/controllers/

2- Renommez votre present fichier StoresController.php en StoresController.php.bak,

3- Placez le fichier php que vous avez télécharger et décompresser dans le même dossier.

 

Maintenant la variable $stores est de nouveau accessible, quelconque la configuration dans le Back Office de PrestaShop.

Je souhaite un grand succès à la communauté PrestaShop et j’espère qu’un jour ils auront du code concrete, correcte, scientifiquement étudié et structuré.


Cette article est sponsorisé par odience.net¦works