Orders count of product in Opencart

While developing e-commerce website I came across adding a feature to display total orders count of product in OpenCart on product’s page. This way visitors will be able to know about how much orders of a specific product have been given (my client’s perspective). Since OpenCart follows MVC architecture, therefore the developer experienced with MVC architecture and especially with Codeigniter can easily understand and follow the modifications described below.

  1. We are required to add a function in the product’s Model for fetching orders count of a product.
  2. Gather the required info from Model into Controller
  3. Display the info on view page of product

Code for displaying Orders count of product in Opencart

In Model folder, find product.php file and add the following function/code. This code contains required query for getting orders count of product.

I found required file in > (catalog/model/catalog/product.php)

In Controller folder, find product.php file and add following statement in its index() function.

I found required file  in(catalog/controller/product/product.php)

We are now done with backend code and left with front-end for display of counter. Open your theme folder and find product template file(product.tpl).

product.tpl (catalog/view/theme/your_theme/template/product/product.tpl)

Its now all about HTML for displaying required info according to your template.

So this is it, all done. These were three simple steps for a web developer to add a functionality for displaying orders count of product in OpenCart.

Read More

setTimeout function jQuery

If you are thinking to perform some operation(s) after some specified interval of time, then jquery setTimeout function is ready to do the job for you.

setTimeout function

setTimeout() accepts two arguments.

  1. The function that you want to execute after specified delay.
  2. The duration of delay in milliseconds

In the above example code, myFunction is the one which I wanted to execute after 2 seconds.

In another way, one can also use anonymous function(if not want to define the function separately) and define login in setTimeout as follows:

setTimeout() is a basic JavaScript function, actually. Do not confuse setTimeout() with setInterval() function. The difference between the two is that setTimeout() executes once after specified time, while setInterval() repeats the execution of function.

Read More

Send email using PHP script

A basic and simple article for the beginners who want know about how to to send email using php.

In this article, we will use HTML form to get data from the user and send an email using PHP script. PHP mail() function is used to send an email. We can send both simple/text emails and also HTML emails. First, we will learn about how to send email using PHP.

HTML form

Following is the HTML form which will be used to fill the required data.

Send email using php

Following is the script which will be used to send an email using PHP. Create new file named as “process_email_form.php” for script.

The above script initially get the form data and then applies check on them if any field was left empty. Finally, mail() function is used in order to send email using php script.

This was all about sending simple text email and using mail() function. You can play with the code to add validation and error checks.

Next article will be about sending HTML email in PHP.

Other related articles:

use php mail functions to send email

 

 

Read More

Get URL parameter using jQuery

With the help of jquery we can easily extract or get URL parameter. This post contains the jquery code which can be used to get URL parameter.

jQuery Script to get URL parameter

This script will help you in extracting the required parameter from URL. The function getUrlParameter() is responsible for extracting parameters from URL and returning the value of required paramater, if found.

Example

For example, you have the following URL
somedomain.com?message=sent

Now you want to find message and its value. Call the function getUrlParamter() and pass the string “message”. The function will extract parameters from current URL will match “message” will each. A value will be returned if “message” parameter is found.

 

Read More

select one element from same class using jquery

At times, you may come across a situation when you need to select one element from same class. jQuery makes is very simple to select an element from same class.

Lets setup an example of five paragraph which share same class.

Now, we want to change the color of third paragraph, only. Following script will work for us.

:eq() is one of the index-selectors. Other index-selector are :lt() :gt() :odd() :even. Try to play with them ,too.

 

References:

eq-selector @ api.jquery.com

 

Read More

Download file using jQuery / JavaScript

In this article, we will share a simple script about how to download file using jQuery or JavaScript. Example will focus on jQuery click event.

Suppose we have a button or a link which has id=”download_file”.

 

We want to download the file when a user clicks on this button.

 

This is a very simple script about how to download file using jQuery / JavaScript.

 

 

Read More

jQuery click not working on dynamic content [solution]

jQuery click not working? Follow this article to find a solution.

Sometimes you may come across an issue where jquery event does not work on an element, which is generated dynamically via jQuery. For example, if you have any HTML element on which you click to create/append some other HTML element, jQuery click will not work on the appended or dynamically created element on the page.

If the code is not working on dynamically created content, the code might be as follows.

.class_name is actually the name of class of the element that was generated by jQuery, dynamically.

In such case, you will have to modify your code a bit in the following way.

This change in code has always worked for me whenever I wanted to trigger a function on the event or simply click event upon dynamically created content. I hope this will work you, too.

For further study:

Jquery event handler not working on dynamic content

Read More

Multiple filters with ngRepeat in AngularJS

In this article with will learn how to use multiple filters with ngRepeat in AngularJS. Our example will focus on filtering the data produced from ng-repeat by using multiple filters.

Let’s suppose we have the following data in JSON.

Now printing the data with ng-repeat in HTML part of code.

Adding multiple filters with ng-repeat. Modify the above HTML code as follows.

At this point, we have added two (multipe) filters with ng-repeat. For example, if user types “to” in the name field and “is” in district field, then this will act like AND condition as selecting those records in which name inlucdes “to” and district includes “is”.

This is how easily we have added multiple filters with ngRepeat.

Read More

Remove WordPress version information

You may come across some different ways of removing WordPress version from the head tag. The preferred way of how to remove WordPress version from the head tag is mentioned in this article. The reason to be preferred is that it will remove WordPress version information from both site and RSS feeds.

Within your themes folder, open functions.php file and paste the following code.

Preferred way of how to remove WordPress version info

This is how you can remove WordPress version information not only from the site but from all the locations.

 

Read More

AngularJS Custom Directives – Basics

One of the many good features of AngularJS is that you can create your own directives, the custom directives.

Types of Custom Directives in AngularJS

You can create four types of custom directives in AngularJS.

  1. Element directive
  2. Attribute directive
  3. Class directive
  4. Comment directive

Examples:

Element directive, <player></player>

Attribute directive, <span player></span>

Class directive, <span class=”player”></span>

Comment directive, <!– directive:player –>

Creating a Basic Custom Directive

This is how we can register our directive

  1. What we have done is simply registered an Element type directive with its name as the player. Whenever any HTML element ‘player’ is found in our AngularJS application, this custom directive ‘player’ will come into play.
  2. If you want to register the directive as Attribute type, simply replace ‘E’ by ‘A’ in the above code.
  3. And if you want to use both types for this directive, use ‘EA’ instead.
  4. The value of directive.template is what will be shown on the webpage.

Lets’ use this directive. As we have registered this custom directive as element type so we only need to use HTML player tag.

Wherever this tag is placed, it will display “This is my custom directive” and if it was an attribute type directive, then we had to do following

Right now template.directive is simple by having only a sentence. What if we have to display relatively longer part of a template containing HTML? The answer is simple, we will use directive.templatURL instead and will give it the path of that file.

Now AngularJS will load the directive-template.html file.

Still there is a lot more about custom directives which will be discussed in coming articles. This is enough for now to understand the basics of AngularJS custom directives.

Read More