X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 4 (https://forum.x-cart.com/forumdisplay.php?f=45)
-   -   MAX cdn (https://forum.x-cart.com/showthread.php?t=64443)

zone1creative 07-31-2012 10:25 AM

MAX cdn
 
Hi,

I have just configured a site with MAXcdn.com. They provide a guide but it is not designed for xcart 4.4.x.

The guide can be found at http://www.maxcdn.com/features/integrations/x-cart/

Would be worth xcart contacting MAXcdn to give them a more accurate guide.

I will provide my integration for xcart 4.4.x when I get a chance.

Also when I get results of how good this tool is for site performance

ambal 07-31-2012 10:40 PM

Re: MAX cdn
 
> I will provide my integration for xcart 4.4.x when I get a chance.

Thank you for sharing this information in advance.
You are welcome to post it here or submit directly at
http://help.x-cart.com/index.php?title=X-Cart:Performance_tips#Use_Content_Delivery_Network s_like_MaxCDN

philrisk 09-19-2012 07:10 AM

Re: MAX cdn
 
Code:

Open smarty.php:

**************************************************************************************
$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
**************************************************************************************
Replace with this:

**************************************************************************************
/ WCM - MaxCDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign('ImagesDir',        "http://CdnUrl.example.com" . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir',          "http://CdnUrl.example.com" . $smarty_skin_dir);
}
else
{
$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
}
**************************************************************************************


This only calls the common_files images though. Looking for better integration.

zone1creative 09-19-2012 07:53 AM

Re: MAX cdn
 
There were a few files I had to change including smarty plugin functions. The above only covers a few images. The main images such as thumbnails expanded, and category and manufacturer images are not covered here

totaltec 09-19-2012 07:54 AM

Re: MAX cdn
 
I don't have Max CDN but to include the $AltSkinDir and $AltImagesDir it seems that you would need to find:
PHP Code:

if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
        
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
        
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
    } 

and replace with:
PHP Code:

// WCM - MaxCDN Implementation
if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
  if (
$_SERVER['HTTPS'] != 'on')
  {
    
$smarty->assign('AltImagesDir'"http://CdnUrl.example.com" $alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   "http://CdnUrl.example.com" $alt_skin_info['web_path']);
    
  }
  else
  {
    
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
  }


Again, just shooting in the dark. Look correct?

philrisk 09-19-2012 11:26 PM

Re: MAX cdn
 
Quote:

Originally Posted by totaltec
I don't have Max CDN but to include the $AltSkinDir and $AltImagesDir it seems that you would need to find:
PHP Code:

if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
        
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
        
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
    } 

and replace with:
PHP Code:

// WCM - MaxCDN Implementation
if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
  if (
$_SERVER['HTTPS'] != 'on')
  {
    
$smarty->assign('AltImagesDir'"http://CdnUrl.example.com" $alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   "http://CdnUrl.example.com" $alt_skin_info['web_path']);
    
  }
  else
  {
    
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
  }


Again, just shooting in the dark. Look correct?


I tried similar to this and the urls looked correct but the images were missing as not populated on maxcdn.

philrisk 09-19-2012 11:27 PM

Re: MAX cdn
 
Quote:

Originally Posted by zone1creative
There were a few files I had to change including smarty plugin functions. The above only covers a few images. The main images such as thumbnails expanded, and category and manufacturer images are not covered here


Can you give us a clue on the files you changed?

philrisk 09-21-2012 01:16 AM

Re: MAX cdn
 
I worked out out how to use the default images folder plus the alt images folder on maxcdn.

In smarty.php

PHP Code:

if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign('ImagesDir',    "http://collectables.collectablesreta.netdna-cdn.com" $smarty_skin_dir '/images');
$smarty->assign('SkinDir',        "http://collectables.collectablesreta.netdna-cdn.com" $smarty_skin_dir);
$smarty->assign("AltImagesDir",    "http://collectables.collectablesreta.netdna-cdn.com/skin/ideal_comfort/images");
$smarty->assign("AltSkinDir",    "http://collectables.collectablesreta.netdna-cdn.com/skin/ideal_comfort");
}
else
{
$smarty->assign('ImagesDir',        $xcart_web_dir $smarty_skin_dir '/images');
$smarty->assign('SkinDir',          $xcart_web_dir $smarty_skin_dir);



philrisk 09-21-2012 01:17 AM

Re: MAX cdn
 
Just have to work out how to do product images as this didn't work.

PHP Code:

// WCM - CDN Images
        
if (($type == 'T' OR $type == 'P') AND $_SERVER['HTTPS'] != 'on')
        {
        
$image_path str_replace('/path/to/images//','http://collectables.collectablesreta.netdna-cdn.com/',$image_path);
        return 
str_replace('$http_location','',$image_path);
        }
        
// / WCM - CDN Images 


PhilJ 09-21-2012 01:24 AM

Re: MAX cdn
 
Skip to...

http://forum.x-cart.com/showpost.php?p=352228&postcount=57

philrisk 09-21-2012 01:30 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ
Might help...

PHP Code:

/**
 * Store all compiled templates to the single directory
 */
$smarty->use_sub_dirs false;

if (! empty ( 
$alt_skin_dir )) {
    
    
$smarty->template_dir = array ($alt_skin_dir$xcart_dir $smarty_skin_dir );
    
    
$compileDir $var_dirs ['templates_c'] . XC_DS md5 $alt_skin_dir );
    
    if (! 
is_dir $compileDir )) {
        
        
func_mkdir $compileDir );
    
    }
    
    
$smarty->compile_dir $compileDir;
    
    if (@
file_exists $alt_skin_dir XC_DS 'css' XC_DS 'altskin.css' )) {

/* CDN support for smarty BEGIN */
        
define "CDN_SUPPORT"true );
        
        if (! 
CDN_SUPPORT) {
            
$cdn_web_dir $xcart_web_dir;
        } else {
            if (
$HTTPS) {
                
$__CDN_BASE_URL 'https://www.yourstore.com';
            } else {
                
$__CDN_BASE_URL 'http://yourstore.yourstore.netdna-cdn.com';
            }
            
            
$smarty->assign 'AltImagesDir'$__CDN_BASE_URL $alt_skin_info ['alt_skin_dir'] . '/images' );
            
$smarty->assign 'AltSkinDir'$__CDN_BASE_URL $alt_skin_info ['alt_skin_dir'] );
            
            
$cdn_web_dir $__CDN_BASE_URL;
        }
        
    
//  $smarty->assign('AltImagesDir', $alt_skin_info['web_path'] . '/images');
    //  $smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);;        

/* CDN support for smarty END */
    
}

} else {
    
    
$smarty->template_dir $xcart_dir $smarty_skin_dir;
    
$smarty->compile_dir $var_dirs ['templates_c'];





Is that for the AltImages?

PhilJ 09-21-2012 01:31 AM

Re: MAX cdn
 
Give it a bash, works for a client of mine...

philrisk 09-21-2012 01:39 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ
Give it a bash, works for a client of mine...

I already have AltImages working via my mod above. I am looking to do product T and P images. Any ideas?

PhilJ 09-21-2012 01:42 AM

Re: MAX cdn
 
That should work for T and P images, yes.

JacksmithxD 09-21-2012 01:46 AM

Re: MAX cdn
 
I can verify that the code Phil has provided works, MaxCDN installed correctly is awesome. :D

PhilJ 09-21-2012 01:56 AM

Re: MAX cdn
 
Quote:

I can verify that the code Phil has provided works, MaxCDN installed correctly is awesome. :grin:

^ what he said :)

philrisk 09-21-2012 02:05 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ
That should work for T and P images, yes.


Hi PhilJ

That doesn't seem to work for T and P images. Works fine for AltImages though.

philrisk 09-21-2012 02:23 AM

Re: MAX cdn
 
PHP Code:

// WCM - CDN Images 
        
if (($type == 'T' OR $type == 'P') AND $_SERVER['HTTPS'] != 'on'
        { 
        
$image_path str_replace('/path/to/images/','http://collectables.collectablesreta.netdna-cdn.com/',$image_path); 
        return 
str_replace('$http_location','',$image_path); 
        } 
        
// / WCM - CDN Images 


This changes the url correctly but the images are missing and not being pulled by maxcdn.

PhilJ 09-21-2012 02:31 AM

Re: MAX cdn
 
Skip to...

http://forum.x-cart.com/showpost.php?p=352228&postcount=57

philrisk 09-21-2012 03:00 AM

Re: MAX cdn
 
Sorry this did work just needed my image path tweaked. Well worked for thumbnails anyway not P images.

philrisk 09-21-2012 04:20 AM

Re: MAX cdn
 
Has anyone successfully managed to get maxcdn pulling the cached css and js from the speedup tool?

dave01978 09-21-2012 05:39 PM

Re: MAX cdn
 
anyone got any ideas for 4.5.2?

Tried the above codes, but doesnt pull up from it

JacksmithxD 09-22-2012 06:07 AM

Re: MAX cdn
 
Quote:

Originally Posted by dave01978
anyone got any ideas for 4.5.2?

Tried the above codes, but doesnt pull up from it


Mercuryminds does the full install and setup for $30 I think, works a charm on my site. They do a full documentation for $50 in total, might be worth asking them. :D

dave01978 09-22-2012 11:41 AM

Re: MAX cdn
 
yeah i may go that route, but i am cheap and will probably spend more time to end up paying the $30
Thanks for the info

philrisk 09-24-2012 01:42 AM

Re: MAX cdn
 
Do Mercuryminds also manage to pull the cached css and js?

Learner 10-15-2012 11:51 PM

Re: MAX cdn
 
Quote:

Originally Posted by totaltec
I don't have Max CDN but to include the $AltSkinDir and $AltImagesDir it seems that you would need to find:
PHP Code:

if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
        
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
        
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
    } 

and replace with:
PHP Code:

// WCM - MaxCDN Implementation
if (@file_exists($alt_skin_dir XC_DS 'css' XC_DS 'altskin.css')) {
  if (
$_SERVER['HTTPS'] != 'on')
  {
    
$smarty->assign('AltImagesDir'"http://CdnUrl.example.com" $alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   "http://CdnUrl.example.com" $alt_skin_info['web_path']);
    
  }
  else
  {
    
$smarty->assign('AltImagesDir'$alt_skin_info['web_path'] . '/images');
    
$smarty->assign('AltSkinDir',   $alt_skin_info['web_path']);
  }


Again, just shooting in the dark. Look correct?


Hi Mike,
I have Artistictune business as my template and my version is x-cart Pro 4.4.2.Please help me how to add my skin,images and template through max cdn.After adding this codes the whole site breaks.

Please provide me the modified smarty.php for my 4.4.2 Pro.

Thanks.

zone1creative 12-06-2012 08:56 AM

Re: MAX cdn
 
Hi

Sorry I have not been following the thread but here are the files I edit to implement maxcdn.

Along with smarty.php do the following

To get xcart to use css and js files from maxcdn edit
include/templater/plugins/function.load_defer_code.php

find
Code:

$result = ('js' == $type)
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';


replace with
Code:

$result = ('js' == $type)
            ? '<script type="text/javascript" src="' . str_replace("www.yoursiteurl.co.uk","yourcdnurl.com",$cacheWebFile) . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . str_replace("www.yoursiteurl.co.uk","yourcdnurl.com",$cacheWebFile) . '" />';


This will cover a lot of your background images and all javascript calls.

Then to make all your category images use cdn

edit include/templater/plugins/function.get_category_image_url.php
find

Code:

return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));

replace with

Code:

return str_replace("www.yoursiteurl.co.uk","yourcdnurl.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));

zone1creative 12-06-2012 09:02 AM

Re: MAX cdn
 
Then in the template files for the product thumbnail and expanded view

you can use the smaty replace function in the following way
Code:

{$tmbn_url|amp|replace:'www.yoursiteurl.co.uk':'yourcdnurl.com'}

dave01978 12-07-2012 05:43 PM

Re: MAX cdn
 
Quote:

Originally Posted by zone1creative
Then in the template files for the product thumbnail and expanded view

you can use the smaty replace function in the following way
Code:

{$tmbn_url|amp|replace:'www.yoursiteurl.co.uk':'yourcdnurl.com'}


What template files do you put that, and where i am lost on this i am sorry for beeing such a noob

PhilJ 12-11-2012 12:48 PM

Re: MAX cdn
 
http://support.netdna.com/pullzone/xcart-cdn/

MAPerformance 12-17-2012 09:27 AM

Re: MAX cdn
 
Quote:

Originally Posted by dave01978
What template files do you put that, and where i am lost on this i am sorry for beeing such a noob


The file is /skin/common_files/product_thumbnail.tpl. That's where I found the line to edit and it works perfectly!

Find this near line 9:
Code:

{$tmbn_url|amp}

And replace with this:
Code:

{$tmbn_url|amp|replace:'www.your-main-url.com':'your-cdn-url.com'}

dave01978 12-18-2012 05:10 AM

Re: MAX cdn
 
Quote:

Originally Posted by MAPerformance
The file is /skin/common_files/product_thumbnail.tpl. That's where I found the line to edit and it works perfectly!

Find this near line 9:
Code:

{$tmbn_url|amp}

And replace with this:
Code:

{$tmbn_url|amp|replace:'www.your-main-url.com':'your-cdn-url.com'}


Like that it works great but when you go https:// the images are gone which i understand but i tried this
and the images come up with a path like this any ideas?
https://www.waterlesscarwashproducts.com/if%20($_SERVER%5B%27HTTPS%27%5D%20!=%20%27on%27)%7 Delse%7D

here is how i tried to work around the ssl
like i did in the rest of the code changes i made
Code:

if ($_SERVER['HTTPS'] != 'on')
{
{$tmbn_url|amp|replace:'www.waterlesscarwashproducts.com':'driwash.waterlesscarwashproducts.com'}
}
else
{
{$tmbn_url|amp}
}


MAPerformance 12-20-2012 09:26 AM

Re: MAX cdn
 
I hadn't even noticed that! The only place you'd see it on my site is in the cart during checkout, and now I see thumbnails do not load due to HTTPS. Maybe someone else can chime in on this?

PhilJ 12-21-2012 04:17 PM

Re: MAX cdn
 
I found these coupons for 50% off the MaxCDN starter package :)

Bootstrapper50

OR

codrops

Signup

carpeperdiem 01-12-2013 08:55 PM

Re: MAX cdn
 
Is everyone happy with MaxCDN and the integration as discussed in this thread?

Is using the smarty replace technique the best/fastest/most efficient way to get the data to the CDN?

My site is well under 1TB/year in bandwidth -- so I was thinking the basic plan is sufficient.

Is one "zone" sufficient for a North American site? The maxcdn FAQ doesn't really discuss "zones". My server is in California (Hands-on VPS) and my business is 97% US and 3% Canada -- we haven't advertised or localized for other countries yet. We are not pushing video (we use embedded youtube for all video)

Anyone using more than one zone? Why?

Gonna try this now -- any other guidance from those using MaxCDN? Thanks.
Jeremy

carpeperdiem 01-12-2013 10:29 PM

Re: MAX cdn
 
Quote:

Originally Posted by MAPerformance
I hadn't even noticed that! The only place you'd see it on my site is in the cart during checkout, and now I see thumbnails do not load due to HTTPS. Maybe someone else can chime in on this?


file:
/common_files/product_thumbnail.tpl

Code:

{* MaxCDN edit - comment out next line *}
{* {$tmbn_url|amp} *}
{if $smarty.server.HTTPS ne "on"}
{$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'}
{else}
{$tmbn_url|amp}
{/if}
{* END MaxCDN edit *}


carpeperdiem 01-12-2013 10:52 PM

Re: MAX cdn
 
Quote:

Originally Posted by zone1creative
To get xcart to use css and js files from maxcdn edit
include/templater/plugins/function.load_defer_code.php

find
Code:

$result = ('js' == $type)
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';


replace with
Code:

$result = ('js' == $type)
            ? '<script type="text/javascript" src="' . str_replace("www.yoursiteurl.co.uk","yourcdnurl.com",$cacheWebFile) . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . str_replace("www.yoursiteurl.co.uk","yourcdnurl.com",$cacheWebFile) . '" />';


This will cover a lot of your background images and all javascript calls.


Slight problem here that hopefully someone can help solve...

This code works -- until you go https at checkout, and then it's a mess (css disappears).

I tried the following, but this cased a server error:

PHP Code:

/* MaxCDN edit - comment out next two lines
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';
*/
// Then insert the following:
if ($_SERVER['HTTPS'] != 'on') {
            ? 
'<script type="text/javascript" src="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '" />';
}
else
{
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />';



Hmm... must be my php syntax, right? Isn't this how to do an if? What am I missing? Thanks!
Jeremy

carpeperdiem 01-13-2013 05:58 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ
I found these coupons for 50% off the MaxCDN starter package :)

Bootstrapper50

OR

codrops

Signup


I used Bootstrapper50. Thanks!
This is a no-brainer.

carpeperdiem 01-13-2013 06:12 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ

Bear in mind, this is for v4.5.2


Unfortunately, 4.5.4 is different enough that you can't copy/paste this.

I am working on assembling all edits for 4.5.4 and I'll re-post in one place. many good suggestions in this thread. Most work, some don't.

Thanks to all for contributions.

carpeperdiem 01-13-2013 07:20 AM

Re: MAX cdn
 
Am I doing this backwards?

Is there a net difference in speed by setting the path to the cdn images in php files vs. templates?

For example, I used this code for the Banner System Images:

Code:

FILE:
/skin/common_files/modules/Banner_System/banner_rotator.tpl

FIND:
src="{$content.image_path|amp}"

REPLACE WITH:
src="{$content.image_path|amp|replace:'www.domain.com':'cdn.domain.com'}"


I used this code for the Thumbs (trapping for https):

Code:

FILE:
/skin/common_files/product_thumbnail.tpl

FIND:
{$tmbn_url|amp}

REPLACE WITH:

{* MaxCDN edit - comment out next line *}
{* {$tmbn_url|amp} *}
{if $smarty.server.HTTPS ne "on"}
{$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'}
{else}
{$tmbn_url|amp}
{/if}
{* END MaxCDN edit *}


I will now do similar "replace" code for variant and detailed images, right?

What else am I missing (besides the js and css) ?

Does it hurt site speed and performance to set the CDN path in templates vs. php files?

This could be a very useful feature that X-Cart SHOULD have as default -- supporting a CDN with a simple 1 field form entry (cdn.domain.com) and a switch to turn it on. As opposed to editing 6 or more files.

But as long as we know the list of files to edit, no worries...
Gonna keep editing...


All times are GMT -8. The time now is 06:20 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.