Showing posts with label opencart. Show all posts
Showing posts with label opencart. Show all posts

Saturday, December 8, 2018

Opencart objects defined, Opencart development tutorials




Predefined objects’ methods are functionalities which are already defined and you can use it directly.


It prevents from DRY, which means Don't Repeat Yourself. Don’t write code unless you have to. Write code only what you need, if you missed these predefined objects’ methods then you may repeat codes.


You can find predefined objects’ methods at system/library


Opencart has many predefined objects’ methods that can be called in Controller and Model.  Like in admin section we can see predefined objects like: config, log, event, load, request, response, db, session, cache, url, langauge, openbay, document, customer, currency, tax, weight, length, cart, encryption, model_setting_event, user.



Database Object of Opencart is
$this->db

Methods are:
  • $this->db->escape($value) - mysql_real_escape_string() on the value passed
  • $this->db->countAffected() - rows affected by an UPDATE query
  • $this->db->getLastId() - last auto increment id same as mysql_insert_id()
  • $this->db->connected() – Pings a server connection, or tries to reconnect if the connection has gone down
$this->db->query($sql)
All SQL queries are run from $this->db->query method which looks like: $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE $this->db->query("REPLACE INTO `" . DB_PREFIX . "category_path` SET ...); $this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET ...); $this->db->query("DELETE FROM " . DB_PREFIX . "category WHERE ...); $this->db->query("UPDATE " . DB_PREFIX . "category SET image = ...);

$this->db->query method returns three properties:  
$result->num_rows = $query->num_rows; - gets the number of rows in a results  
$result->row = isset($data[0]) ? $data[0] : array(); - get the first row data  
$result->rows = $data; - get an array of row results

Tuesday, December 4, 2018

Installing OpenCart Vesrion 3.0.2.0 - Opencart Development tutorials Video 2







  •  Download OpenCart files from http://opencart.com 
  • Create a database
  • Upload files and folders
  • Create config files one at root folder and another inside admin/ folder. 
  • Steps to create custom URL to work locally https://webocreation.com/blog/steps-create-custom-url-work-locally-xampp-localhost-virtual-host
  • Go to the URL
  • If you see any other errors then you have to solve them. One could curl disabled which you have to enable from php.ini
  • Delete the install folder, if you rename the folder then you are a by-passing error message but there will be security holes remained in that folder so the hacker can find it easily and exploit your database so strongly recommended to delete the install folder after installation is complete.


Friday, July 29, 2016

OCMOD Modification System opencart 2.3 example for Show all products module ecommerce

Things to take care while making OCMOD file:
  1. File extension must be either .ocmod.zip or .ocmod.xml.
  2. Upload from admin section, Admin>>Extensions >> Extension Installer, Upload the .xomod.zip or .ocmod.xml file from here.
Now go to following link and download "Display all Products" module

You will find following ocmod example which shows how to show "All Products" links at the top menu bar.



For example:

<modification>
<version>OpenCart Version 2.2</version>
<vqmver>2.0.0</vqmver>
<author>Rupak Nepali</author>
   <code>List_all_Products</code>
<file name="catalog/view/theme/*/template/common/header.tpl" error="skip">
<operation>
<search position="after"><![CDATA[
<ul class="nav navbar-nav">
]]></search>
<add><![CDATA[
<li><a href="index.php?route=product/allproduct">All Products</a></li>
]]></add>
</operation>
</file>
</modification>


OCMOD is a system that allows store owners to be able to modify their store by uploading a compressed file that contains XML, SQL and PHP files.
If a OCMOD is developed correctly it can modify how a users OpenCart store works without changing any of the core files. This means that if a modification is removed none of the original OpenCart files need to be restored or fixed.

OCMOD Files

OCMOD files can be upload via the opencart admin under:
Extensions / Extension Installer
For a OCMOD file to be uploaded the file extension must be either .ocmod.zip or .ocmod.xml. This is to avoid none OCMOD files from being uploaded to a store users admin.

File Structure

Example file structure for OCMOD compressed files.
  • upload
  • install.sql
  • install.php
  • install.xml

upload

All files under this directory will be uploaded to the to directory of your OpenCart installation.

install.sql

Add any create, drop, insert and update SQL quires here. Make sure each query ends with ;

install.php

If the modification requires any custom PHP code.

install.xml

The XML modification file.
You can view the documentation for this system below.

XML

This is the file that creates a virtual copy of any files that require changes. Use this system instead of overwriting any default installation files. Multiple modifications can be applied to the same file.
Example OCMOD file:
<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search><![CDATA[
            $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="replace"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>

Tags

File

You can set multiple file locations by spiting up the file locations using commas. The modification system uses PHP function glob.
Example:
Direct file path.
<file path="catalog/controller/common/home.php">
Using braces allows for selecting multiple files and not having to repeat the code operation multiple times.
<file path="system/engine/action.php|system/engine/loader.php|system/library/config.php|system/library/language.php">
also allows braces
<file path="system/{engine,library}/{action,loader,config,language}*.php">
please note that all file paths must start with either admin, catalog or system. you can also use wildcard *

Search

Search code
Allowed Attributes
  • trim="(true|false)"
  • regex="(true|false)"
  • index="(number)"
Example:
<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search trim="true|false" index="1"><![CDATA[
            $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="replace" offset="1"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>

Add

The code to replace the search with.
Allowed Attributes
  • trim="(true|false)"
  • position="(Replace|Before|After)"
  • offset="(number)"
(note position can not be used if regex is set to true in the search attribute).
Example
<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search trim="true|false"><![CDATA[
            $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="Replace|Before|After" trim="true|false" offset="2"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>
Regex
Allowed Attributes
  • limit="(number)"
Example:
<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Regex Example</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <file path="system/{engine,library}/{action,loader,config,language}*.php">
        <operation>
            <search regex="true" limit="1"><![CDATA[
            ~(require|include)(_once)?\(([^)]+)~
            ]]></search>
            <add><![CDATA[
            $1$2(modification($3)
            ]]></add>
        </operation>
    </file>
</modification>
If you use regex you can not use attributes position, trim or offset as these are handled by the regular expression code you write. The limit attribute is still available.
If, for example, you want to change the 3rd 'foo' to 'bar' on the following line:
lorem ifoopsum foo lor foor ipsum foo dolor foo
^1      ^2      ^3         ^4        ^5
Run:
s/\(.\{-}\zsfoo\)\{3}/bar/
Result:
lorem ifoopsum foo lor barr ipsum foo dolor foo
^1      ^2      ^3=bar     ^4        ^5
You can find more information about the regular expression PHP function OCMOD uses can be found here:
More information about regular expression can be found here: