How to integrate Hostry CDN with X-Cart

x-cart.com

In this case, during CDN implementation “ideal_comfort” default skin is applied, so if you have another skin, you will need to modify the code below to match the name of your skin.

X-Cart 4.4.x (and later versions) + CDN implementation – fixed path to skin
Open the core X-Cart file smarty.php that can be found in root directory of X-Cart.

Find the following lines:

$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
Replace these lines with the following:
// WCM - CDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign("SkinDir","http://cdn.your-domain.net/skin/ideal_comfort");
$smarty->assign("ImagesDir","http://cdn.your-domain.net/skin/ideal_comfort/images");
}
else
{
$smarty->assign("SkinDir",$xcart_web_dir."/skin/ideal_comfort");
$smarty->assign("ImagesDir",$xcart_web_dir."/skin/ideal_comfort/images");
}

Don’t forget that “cdn.your-domain.net” must be replaced with the proper CDN temp URL or, if you have a custom URL, the proper custom URL. You may find our if your X-Cart is using the CDN by reloading pages in browser and viewing their source codes.

X-Cart 4.4.x (and later versions) + CDN implementation – dynamic skin path

If you need the skin path to be assigned dynamically, follow these steps:

Open the core X-Cart file smarty.php that can be found in root directory of X-Cart. Find the following two lines:

$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
Replace them with the following lines:
// WCM - UCDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign('ImagesDir', "http://cdn.your-domain.net" . $smarty_skin_dir .
'/images');
$smarty->assign('SkinDir', "http://cdn.your-domain.net" . $smarty_skin_dir);
}
else
{
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
}

* Use CDN for CSS and JS files (/var/cache/).
Open /include/templater/plugins/function.loaddefercode.php and detect the following line:
$cacheWebFile = $var_dirs_web[‘cache’] . ‘/’ . $label . ‘.’ . $md5Suffix . ‘.’ . $type;
Replace that line with the following:

// WCM - UCDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$cacheWebFile = "http://cdn.your-domain.net/var/cache" . '/' . $label . '.' . $md5Suffix .
'.' . $type;
}
else
{
$cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type;
}

* Use CDN for “W”, “D”, “P” and “T” types of images.

Open /include/func/func.files.php and find the following line:
global $config, $sql_tbl, $xcart_dir, $current_location;
ADD these new lines below (DON’T just replace them with but ADD below the line)

if ($HTTPS)
$current_location = $current_location;
else
$current_location = 'http://cdn.your-domain.net';

* Use CDN for “C” type of image file.

Open /include/templater/plugins/function.getcategoryimage_url.php and find the following
line:

return func_convert_amp(func_get_image_url($category['categoryid'], 'C',
$category['image_path']));
Replace this line with the following:
return return str_replace("your-domain.net ","cdn.your-
domain.net",func_convert_amp(func_get_image_url($category['categoryid'], 'C',
$category['image_path'])));

* Use CDN for “A” type of image.

Open /skin/commonfiles/modules/BannerSystem/banner_rotator.tpl and find the following line:

src="{$content.image_path|amp}"
Replace it with the following:
src="{$content.image_path|amp|replace:'your-domain.net':'cdn.your-domain.net'}"

Please note that “cdn.your-domain.net” should be replaced with proper CDN temp URL or, if you have a custom URL, the proper custom URL. Also, “your-domain.net” has to be substituted with your actual origin server URL. You can check if your X-Cart uses CDN by loading it in your browser and checking the source code.

Another CDN implementation is using the default skin called “skin1,” so if you have another skin you need to modify the code shown below to match the name of your skin.

X-Cart 4.3.x CDN implementation

Open the core X-Cart file smarty.php that can be found in root directory of X-Cart. Find the following two lines:

$smarty->assign("SkinDir",$xcart_web_dir."/skin1");
$smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
Replace these two lines with following:
// WCM - UCDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign("SkinDir","http://cdn.your-domain.net/skin1");
$smarty->assign("ImagesDir","http://cdn.your-domain.net/skin1/images");
}
else
{
$smarty->assign("SkinDir",$xcart_web_dir."/skin1");
$smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
}

Repeat the steps 2 – 5 as shown in “X-Cart 4.4.x (and later) + CDN implementation – dynamic skin path”.

Pay attention that “cdn.your-domain.net” should be replaced with proper CDN temp URL or, if you have custom URL, the proper custom URL. You can check whether your X-Cart is using CDN by reloading it in browser and looking at the source code of pages.