Wednesday, November 9, 2016

vqmod -- Examples of use

"Replace" Example

  1. Create a new text file and call it "replace-demo.xml"
  2. Add the minimum required xml structure
Input
    $var = 'ABC';
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>Replace ABC with 123</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/myfile.php">
            <operation info="replace ABC with 123">
                <search position="replace"><![CDATA[
                $var = 'ABC';
                ]]></search>
                <add><![CDATA[
                $var = '123';
                ]]></add>
            </operation>
        </file>
    </modification>
Output
    $var = '123';

"Before" Example

  1. Create a new text file and call it "before-demo.xml"
  2. Add the minimum required xml structure
Input
    $var = 'ABC';
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>Before ABC, add 123</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/myfile.php">
            <operation info="Before ABC, add 123">
                <search position="before"><![CDATA[
                $var = 'ABC';
                ]]></search>
                <add><![CDATA[
                $var = '123';
                ]]></add>
            </operation>
        </file>
    </modification>
Output
    $var = '123';
    $var = 'ABC';
"After" Example
  1. Create a new text file and call it "after-demo.xml"
  2. Add the minimum required xml structure
Input
    $var = 'ABC';
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>After ABC, add 123</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/myfile.php">
            <operation info="After ABC, add 123">
                <search position="after"><![CDATA[
                $var = 'ABC';
                ]]></search>
                <add><![CDATA[
                $var = '123';
                ]]></add>
            </operation>
        </file>
    </modification>
Output
    $var = 'ABC';
    $var = '123';
<ignoreif> tag Example (2.3.0+)
  1. Create a new text file and call it "ignoreif-after-demo.xml"
  2. Add the minimum required xml structure
Input
    $var = 'ABC';
    $var2 = 'XYZ';
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>After ABC, add 123 only if XYZ not in file</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/myfile.php">
            <operation info="After ABC, add 123 if XYZ not in file">
                <ignoreif><![CDATA[
                XYZ
                ]]></ignoreif>
                <search position="after"><![CDATA[
                $var = 'ABC';
                ]]></search>
                <add><![CDATA[
                $var = '123';
                ]]></add>
            </operation>
        </file>
    </modification>
Output
    $var = 'ABC';
    $var2 = 'XYZ';

Multiple files and a base path example (2.3.0+)

Sometimes you require adding the same modification to a number of files at once. Rather than having to do this for individual files and duplicating code for each, you can specify multiple files at once delimited by commas. You can also specify a base path to be used if the files are in a common directory. For example, suppose you want to replace ABC with 123 in the following files
  • /path/to/a.php
  • /path/to/b.php
  • /path/to/c.php
  1. Create a new text file and call it "multi-file-demo.xml"
  2. Add the minimum required xml structure
Input (all files)
    $var = 'ABC';
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>Replace ABC with 123</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file path="path/to/" name="a.php,b.php,c.php">
            <operation info="Replace ABC with 123">
                <search position="replace"><![CDATA[
                ABC
                ]]></search>
                <add><![CDATA[
                123
                ]]></add>
            </operation>
        </file>
    </modification>
Output (all files)
    $var = '123';

'Multi-line Replace' Example

vQmod is limited to a single-line search, but you can use the "offset" attribute to blindly blanket additional lines of code in the replace.
  • Create a new text file and call it "multi-replace-demo.xml"
  • Add the minimum required xml structure
  • To replace multiple lines we use the "offset" attribute with replace. Count the number of total lines to replace and subtract one as the main line is already covered by the replace command. In this example, there are 8 lines of code, so offset would be 7. When possible it's advised to avoid doing this
Input
    public function index() {
        $a = rand();
        $b = rand();
        if ($a == $b) {
            echo 'oh noes';
            return false;
        }
    }
Script
    <?xml version="1.0" encoding="UTF-8"?>
    <modification
                xmlns="https://github.com/vqmod/vqmod"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd">
                >
        <id>Replace many lines with one</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/myfile.php">
            <operation info="Replace index function">
                <search position="replace" offset="7"><![CDATA[
                public function index() {
                ]]></search>
                <add><![CDATA[
                public function index($arr = array()) {
                    foreach ($arr as $a) {
                        echo $a;
                        }
                }
                ]]></add>
            </operation>
        </file>
    </modification>
Output
    public function index($arr = array()) {
        foreach ($arr as $a) {
            echo $a;
            }
    }
Note there are still 7 blank lines. The offset clears the extra 7 lines of code from the input, but the replaced code is added in place of the initial line. So there will be 7 extra spaces after the new code, but it will not affect the code functionality, only the look of the vqcache file which is of no importance.

Tuesday, November 8, 2016

About vQmod

What is vQmod?

vQmod™ (aka virtual Quick mod) gives the ability to create modification "scripts" that override the code during execution time. It intercepts the "include()" and "require()" functionality of php and substitutes the modified code in place of the original.

How does it work?

Instead of modifying actual files to add custom modifications, source files are parsed "on-the-fly" right before any of the follow functions are called:
  • include()
  • include_once()
  • require()
  • require_once()
The source is then cloned to a temp file and modifications read from an external script file are made to that temp file. The temp file is then substituted for the real file in the include path. Now the modification is in place while the original file has not actually been altered. This means no code is ever altered from the original. To uninstall a script, simply remove the xml script file and you are back to the original. Simple!

Other Details

  • The vQmod class is currently written in PHP and the script files are xml based, but the concept could be theoretically be ported to any language and parsers could be created for any format.
  • Currently, OpenCart is the only fully tested and working platform that vQmod works with, but this is a concept that can work for other projects and platforms that are controller-based.

Limitations

vQmod relies on a controller based system that has a series of files that are linked and extended. There are some files that cannot be used with vQmod.
  • index.php - since this is the main file of the site, it has to load vQmod first for it to work on other pages. So you can't put the cart in front of the horse.
  • Standalone files - Files that are just standalone and don't extend or have no hierarchy will not work with vQmod. vQmod works by intercepting the "include" functions. So if file isn't being included or required, then it cannot be vQmodded
  • css & js files - These files are rendered at the browser level, not at the server level, so vQmod has no effect on these. You can, however, create new files and use vQmod to alter the tpl files to point to these new css/js files. Or you can put

Monday, November 7, 2016

vQmod

vQmod

While strictly modules, product feeds and OpenCart extensions should be standalone and modular, some require modifications to the OpenCart core. Modifying OpenCart 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 OpenCart 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 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/opencart in the Remote site side. Uploading the vQmod folder here will make the vqmod folder visible in public_html/opencart.

vQmod advises you to set the permissions to writable for the vqmod/vqcache folders, index.php, and admin/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!".

Thursday, October 27, 2016

System Requirements OpenCart 2.3.0.2

System / Server requirements

OpenCart requires certain technical requirements to be met for the store to operate properly. First, a web server must be created to make the OpenCart store publicly available on the web. Domain names and hosting services can easily be purchased for an affordable price.
When selecting a hosting service, you should check to see that these server requirements are provided and installed on their web servers:
These extensions must be enabled for OpenCart to install properly on the web server.
  • Web Server (Apache suggested)
  • PHP 5.3+(1.5.x at least 5.2+)
  • Database (MySQLi suggested)
Required PHP libraries / modules
  • Curl
  • ZIP
  • Zlib
  • GD Library
  • Mcrypt
  • Mbstrings
  • Xml
The above PHP extensions should be available by almost all hosting providers, during the install processa it will check you have them all enabled. You should contact your hosting provider if one is missing.

Wednesday, October 26, 2016

How to cancel credit in opencart

Suppose it may happen, customer purchase something from your website but after successful transaction, you come to know that particular product is not in stock.

Now you have to give refund to that customer as a credit amount so customer can use that amount in future.

For that do following:

1.Go to customers section
2.go to that particular customer
3.There, you will see “Transactions” tab. Press it and enter amount and description. Click Add Transaction.
4.That’s it. Now your customer get credit and mail also send to that customer (Tested in OP 2)

Saturday, October 22, 2016

Validation of viewstate MAC failed.

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.



Hello Friend, I have face this issue many time on online live website project.

Solution : 

Set the machinekey in the web config file.

If you want to generate the machinkey as per .net framework or see the below generated key.


Framework version

Asp.net 1.1

<machineKey validationKey="4B6124F1A96C1D90C2EB5298094895EBB9B1AB2227971EAC82E46D6E9B3E9
76CE56A7629E8C4E6C1AEF7A3B4F47681B60119D792EA47613971729564072DEB2A"
decryptionKey="4DD6849D7B818F86F6566B4AEDF1A9BD134DA1994236F8B8"
validation="SHA1" /> 

Asp.net 2.0

<machineKey validationKey="713BBE182A80928A389952B90A305817D43D87DF110B8F1BF4CF3D5628013F
8F93460838C28092EE99106FA2056191A9E3D9D4412607ADB55FE61193CFE30112"
decryptionKey="146AEAA8D1D915B020764CAF11EBD91A4C63B7D8898D13BDA7915F2E14E
92B41" validation="SHA1" decryption="AES" />


Asp.net 4.0

<machineKey validationKey="9BDD1AED72B3669A61961D2E1140865B6737FD394BCA2F4923C90F23CDCF
EE4E522A6E63EF6DA2BCD2DF736C917BBD47EEDCC570B46A623906334757A53ACF21"
decryptionKey="628176C339754EFADF3449C40A400ED185EC0DEBE8290331E3BD70AF463B
BDFA" validation="SHA1" decryption="AES" />


Asp.net 4.5

<machineKey validationKey="4047C7FA412278CF4A5D19BC670739DC9526FFB72F96C29D37A58807E1E4D8
374B6A19C97F7F27C73DB8AC81F5FA389138A9EB3F4752A578035966D5763BB72D"
decryptionKey="93BD9A1F3D1281400E1F5A3CCFF831F1249DC86930226D6B987E00007B989
DD5" validation="SHA1" decryption="AES" />