OpenCart Medianova CDN Integration

Medianova Turkey’s largest e-commerce companies to provide CDN services

In this article, we explained how to integrate Medianova CDN with OpenCart’s 3.x version to our customers who build e-commerce sites on OpenCart platform.

This allows you to get better site performance by serving your static content from the nearest Medianova servers.

  1. First, create a Medianova CDN Zone for your content by logging into panel.medianova.com. With this integration, you will be able to serve your small files from Medianova CDN.
  2. Download the VQmod plugin from the OpenCart market and follow the installation steps for the OpenCart 3.x version
  3. Insert the following XML file into the system/folder
    <modification>
        <id><![CDATA[Medianova OpenCart CDN Integration]]></id>
        <version><![CDATA[2.4+]]></version>
        <vqmver><![CDATA[1.0.0]]></vqmver>
        <author><![CDATA[http://www.medianova.com]]></author>
        <file name="system/library/response.php">
            <operation>
                <search position="replace"><![CDATA[echo $output;]]></search>
                <add><![CDATA[echo $this->cdn_output($output);]]></add>
            </operation>
            <operation>
                <search position="before"><![CDATA[public function output() {]]></search>
                <add>
                    <![CDATA[
                        function cdn_output($result) {
                            $cdn_domain = 'your-domain.mncdn.com';
                            $http_scheme = (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) ? 'https' : 'http';
                            $cdn_domain = $http_scheme .'://'. $cdn_domain;
    
                            $result = str_replace($http_scheme . "://" . $_SERVER['HTTP_HOST'] . '/image/', $cdn_domain . '/image/', $result);
                            $result = str_replace('src="catalog/view/javascript/', 'src="' . $cdn_domain . '/catalog/view/javascript/', $result);
                            $result = str_replace('href="catalog/view/javascript/', 'href="' . $cdn_domain . '/catalog/view/javascript/', $result);
                            $result = str_replace('src="' . $http_scheme . "://" . $_SERVER['HTTP_HOST'] . '/catalog/view/javascript/', 'src="' . $cdn_domain . '/catalog/view/javascript/', $result);
                            $result = str_replace('src="catalog/view/theme/journal2/image/', 'src="' . $cdn_domain . '/catalog/view/theme/journal2/image/', $result);
                            $result = str_replace('src="catalog/view/theme/default/image/', 'src="' . $cdn_domain . '/catalog/view/theme/default/image/', $result);
                            $result = str_replace('href="catalog/view/theme/journal2/stylesheet/', 'href="' . $cdn_domain . '/catalog/view/theme/journal2/stylesheet/', $result);
                            $result = str_replace('href="catalog/view/theme/default/stylesheet/', 'href="' . $cdn_domain . '/catalog/view/theme/default/stylesheet/', $result);
    
                            return $result;
                        }
                    ]]>
                </add>
            </operation>
        </file>
    </modification>
  4. Be sure to replace your-domain.mncdn.com  with your CDN URL
Note: You can view the CDN URL by this link:https://docs.medianova.com/medianova-cdn-user-integration/ 

If you want to use HTTPS only for the “Zone” you created, you can set $ cdn_domain as follows

$cdn_domain = 'https://'. $cdn_domain;

5. Login the OpenCart admin panel

6.  And then go to Extensions> Modifications and click the “Refresh” button in the right upper

7. If you’re complete the installation, you can test whether static files are delivered with Medianova CDN by viewing the page source

Note: The file extensions that run in the small account are as follows:

gif | jpg | jpeg | png | bmp | swf | psd | tif | tiff | txt | html | jsp | js | css | ico | aspx | php  | woff | ttf | eot | otf | htm | xml | pdf | psb | ashx | swz | cur | svg | jpr

 

 

Was this post helpful?