Important Note This tutorial assumes you have already created a pull zone AND enabled shared ssl for that zone. This CDN implementation pushes only product images to CDN without css, js and other files NOT being part of products.
NOTE: Domains in the steps below are placeholders.-
origin.domain.com
should be replaced by your actual origin domain (plainly withouthttp://
)-
foo.bar.netdna-cdn.com
should be replaced with your own cdn url. (temp cdn url also withouthttp://
)- shared ssl url
foo-bar.netdna-ssl.com
replace with your own (withouthttps://
).
The Process
-
Create a backup of file
/classes/Link.php
or copy it to a file called/classes/Link.php.bckp
-
Open file
/classes/Link.php
-
Find the following lines:
public function getCatImageLink($name, $id_category, $type = null) { $uri_path = ($this->allow == 1) ? (__PS_BASE_URI__.'c/'.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg'); return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path; }
-
Replace these lines with the following:
public function getCatImageLink($name, $id_category, $type = null) { $uri_path = ($this->allow == 1) ? (__PS_BASE_URI__.'c/'.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg'); if ($_SERVER['HTTPS'] != 'on') { return str_replace("origindomain.com","foo.bar.netdna-cdn.com",$this->protocol_content.Tools::getMediaServer($uri_path).$uri_path); } else { return str_replace("origindomain.com","foo-bar.netdna-ssl.com",$this->protocol_content.Tools::getMediaServer($uri_path).$uri_path); } }
-
Find the following lines:
else $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg'; } return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path; }
-
Replace these lines with the following:
else $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg'; } if ($_SERVER['HTTPS'] != 'on') { return str_replace("origindomain.com","foo.bar.netdna-cdn.com",$this->protocol_content.Tools::getMediaServer($uri_path).$uri_path); } else { return str_replace("origindomain.com","foo-bar.netdna-ssl.com",$this->protocol_content.Tools::getMediaServer($uri_path).$uri_path); } }
- You can check if your PrestaShop is using CDN by loading it in a browser and viewing the source code of the page (CTRL + U).
- Restoration to a state without CDN implemented is done simply by copying file
/classes/Link.php.bckp
back to/classes/Link.php
.
We hope this article was helpful. As always, If you have any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!