According to X-Cart's help wiki: "Setting up a CDN for your medium to large X-Cart site will help improve its loading times across the world by delivering static content from the [StackPath] server located closest to your customer."
In each section of this tutorial, swap site.company.stackpathdns.com in the code with your CDN URL and yourdomain.com
with your actual domain name. Also, replace ideal_comfort
in the code with the name of your skin if you're not using the Ideal Comfort skin.
This tutorial assumes a site is created and is for X-Cart 4.4 and later.
Fixed Skin Path
-
Open the core X-Cart file called
smarty.php
.It's located in root directory of X-Cart.
-
Find these two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
-
Replace them with this code:
// WCM - StackPath Integration if ($_SERVER['HTTPS'] != 'on') { $smarty->assign("SkinDir","http://site.company.stackpathdns.com/skin/ideal_comfort"); $smarty->assign("ImagesDir","http://site.company.stackpathdns.com/skin/ideal_comfort/images"); } else { $smarty->assign("SkinDir",$xcart_web_dir."/skin/ideal_comfort"); $smarty->assign("ImagesDir",$xcart_web_dir."/skin/ideal_comfort/images"); }
- Verify StackPath is properly integrated.
Dynamic Skin Path
If you want your skin path assigned dynamically, follow the steps in this section.
-
Open the core X-Cart file called
smarty.php
.It's located in root directory of X-Cart.
-
Find these two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
-
Replace them with this code:
// WCM - MaxCDN Implementation if ($_SERVER['HTTPS'] != 'on') { $smarty->assign('ImagesDir', "http://site.company.stackpathdns.com" . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', "http://site.company.stackpathdns.com" . $smarty_skin_dir); } else { $smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir); }
-
Open
/include/templater/plugins/function.load_defer_code.php
and find this line:$cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type;
-
Replace it with this code:
if ($_SERVER['HTTPS'] != 'on') { $cacheWebFile = "http://site.company.stackpathdns.com/var/cache" . '/' . $label . '.' . $md5Suffix . '.' . $type; } else { $cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type; }
-
Open
/include/func/func.files.php
and find this line:global $config, $sql_tbl, $xcart_dir, $current_location;
- Add this new code below it. (DO NOT replace.)
if ($HTTPS) $current_location = $current_location; else $current_location = 'http://site.company.stackpathdns.com';
-
Open
/include/templater/plugins/function.get_category_image_url.php
and find this line:return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));
-
Replace it with this code:
return return str_replace("domain.com ","site.company.stackpathdns.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));
- Open
/skin/common_files/modules/Banner_System/banner_rotator.tpl
and find this line:src="{$content.image_path|amp}"
-
Replace it with this code:
src="{$content.image_path|amp|replace:'domain.com':'site.company.stackpathdns.com'}"
- Verify StackPath is properly integrated.