vQmod¶
# Enable/Disable The vQmod from CLI
php cli app:vqmod
[Do you want to enable/disable vQmod? press y=enable or n=disable]
Type y for enable.
Type n for disable.
What is vQmod?¶
While strictly modules, product feeds and Phspark extensions should be standalone and modular, some require modifications to the Phspark core. Modifying Phspark core files greatly reduces your ability to upgrade your store to later versions, and can affect other modules and extensions. vQmod provides a mechanism by which modules requiring Phspark core modifications can be installed without damaging the integrity of your core system for upgrades. vQmod keeps a list of filenames and changes required, in the form of one XML file per extension. These changes are then created as the core files are used, and the resulting files are stored as cached copies which are executed instead of the original, core PHP or TPL or Twig file.
Installing vQmod¶
If you wish to upgrade your store, or have a 3rd party extension that you have not used before, it is advisable that you use the vQmod system. The vQmod download and instructions for installation can be found here:https://github.com/vqmod/vqmod.
Once you have downloaded the appropriate vQmod zip file provided in the link, you need to uncompress the zip file and FTP the vQmod folder to your site’s root directory. From the Filezilla screenshot below, we can see the root directory of this store is located at public_html/phspark in the Remote site side. Uploading the vQmod folder here will make the vqmod folder visible in public_html/phspark.
vQmod advises you to set the permissions to writable for the vqmod/vqcache folders, index.php, and backend/index.php. In Filezilla you can right click on a file or folder, select “File Permissions…”, and enter 755 or 777 in the “Numeric value” to set it to writable.
The next step in installing vQmod is to visit the install page in your store. Enter your store’s location in your browser, then “vqmod/install” afterwards. If your store is located at “www.mystore.com”, the vQmod install page would be located at “www.mystore.com/vqmod/install”. The following text will appear on the page if it was installed correctly: “VQMOD HAS BEEN INSTALLED ON YOUR SYSTEM!”.
*** Unlike the install folder after installing Phspark, do not delete vQmod’s install folder after the vQmod installation!
vQmod advises that you load your homepage to see if it appears and works correctly after the install. You would also need to check your vqmod/vqcache folder to see if there are new vq files.
Important Notes¶
- When install vQmod, it changes two files
index.php
<?php // Startup require_once(DIR_SYSTEM . 'startup.php'); Change to // VirtualQMOD require_once('./vqmod/vqmod.php'); VQMod::bootup(); // VQMODDED Startup require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));
backend/index.php
<?php // Startup require_once(DIR_SYSTEM . 'startup.php'); Change to //VirtualQMOD require_once('../vqmod/vqmod.php'); VQMod::bootup(); // VQMODDED Startup require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));
Example: Altering the Core of OpenCart Using vQmod¶
Here, going to change meta tag of header.php file.
Step-01: vqmod/xml/vqmod_homepage.xml
<?xml version=”1.0” encoding=”UTF-8”?> <modification>
<id>Replace Text in Page</id> <version>1.0</version> <vqmver>2.X</vqmver> <author>NajmulHSN</author>
- <file name=”frontend/extension/widget/common/view/theme/default/template/header.php”>
- <operation info=”Replace the css property in heading title in Home page”>
<search position=”replace”><![CDATA[ <meta name=”copyright” content=”Najmul ZCE”> ]]></search> <add><![CDATA[ <meta name=”copyright” content=”NajmulHSN”> ]]></add>
</operation>
</file>
</modification>
Step-02: Now, when the header file going to load then a cache file will be generated automatically, contains modified contents- vqmod/vqcache/vq2-frontend_extension_widget_common_view_theme_default_template_header.php
Important Note:¶
*** Catche file only create when browse the exact page. Suppose, we want to edit twig template loader file with vQmod: system/library/template/twig.php
… <file path=”system/library/template/twig.php” error=”skip” info=”fix Core Phspark twig files modification”> <operation error=”skip”>
<search><![CDATA[$file = $template . ‘.twig’;]]></search> <add position=”replace”><![CDATA[$file = modification($template . ‘.twig’); if( class_exists(‘VQMod’) ) {
$file = VQMod::modCheck($file, $template . ‘.twig’);
} ]]></add>
</operation>
</file> …
Now, when the twig template will be really called then the catche file will be generated at vqmod/vqcache/vq2-frontend_extension_widget_common_view_theme_default_template_header.php.
vQmod vs PSMOD¶
In fact, PSMOD is basically a stripped down version of vQmod system. It works in a similar way – modifications are stored in xml files and uploaded to the store via admin panel, then parsed and applied to OpenCart core code. Unlike vQmod, OpenCart has a built-in PSMOD modification uploader and manager.