Use this guide in case you store up-to-date orders data in OpenCart.

Back up all files that you're going to modify.

Configuring integration in OpenCart

Server-side modification

1. Download the archive and then copy the files to the corresponding folders on the server where OpenCart is installed.


2. Open the catalog/model/checkout/order.php file and find the following code snippet at the beginning of the file:

public function addOrder($data) {

Insert the following code snippet immediately after the code line mentioned above:

// Here you'll get the promo code from the cookie:
$roistat_visit = ( ! empty($_COOKIE['roistat_visit'])) ? $_COOKIE['roistat_visit'] : null;

 

3. Scroll down and find the following line:

$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" . $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "',  date_added = NOW(), date_modified = NOW()");

Replace it with the following code snippet:

$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" . $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "', roistat_visit = '" . $this->db->escape($roistat_visit) . "', date_added = NOW(), date_modified = NOW()");


4. Open the admin/view/template/sale/order_form.tpl file and find the code snippet as follows:

<tr>
  <td><?php echo $entry_fax; ?></td>
  <td><input type="text" name="fax" value="<?php echo $fax; ?>" /></td>
</tr>

Add the following code block immediately after this <tr></tr> tag:

<!-- ROIstat -->
<tr>
  <td>ROIstat ID</td>
  <td><input type="text" name="roistat_visit" value="<?php echo $roistat_visit; ?>" /></td>
</tr>
<!-- END ROIstat -->


5. Open the admin/view/template/sale/order_info.tpl file and find:

<tr>
  <td><?php echo $text_date_modified; ?></td>
  <td><?php echo $date_modified; ?></td>
</tr>

Insert the following code snippet after this <tr></tr> tag and before < /table>:

<tr>
  <td>ROIstat:</td>
  <td><?php echo $roistat_visit; ?></td>
</tr>


6. Open the admin/model/sale/order.php file and find:

'date_modified'           => $order_query->row['date_modified']

Replace this line with the following one:

'date_modified'           => $order_query->row['date_modified'],
'roistat_visit'           => $order_query->row['roistat_visit'],


7. Open the admin/controller/sale/order.php file and find:

if (isset($this->request->post['email'])) {
    $this->data['email'] = $this->request->post['email'];
} elseif (!empty($order_info)) { 
    $this->data['email'] = $order_info['email'];
} else {
    $this->data['email'] = '';
}

Immediately after these lines, add the following code block:

// roistat_visit
if (isset($this->request->post['roistat_visit'])) {
    $this->data['roistat_visit'] = $this->request->post['roistat_visit'];
} elseif ( ! empty($order_info)) { 
    $this->data['roistat_visit'] = $order_info['roistat_visit'];
} else {
    $this->data['roistat_visit'] = '';
}


8. Find the following lines in the same admin/controller/sale/order.php file:

$this->data['store_name'] = $order_info['store_name'];
$this->data['store_url'] = $order_info['store_url'];
$this->data['firstname'] = $order_info['firstname'];
$this->data['lastname'] = $order_info['lastname'];

Immediately after these lines, add the following code block:

// ROIstat
$this->data['roistat_visit'] = $order_info['roistat_visit'];

Complete the setup via the admin panel

9. Open the OpenCart admin panel. Navigate to Extensions  Modules. Find the Roistat data export module in the modules list and click Install.

 

10. Once the module is installed, choose the Edit option.

 The export settings page will open then. Enter the following connection details:

  • Project ID: the Roistat project number. It can be copied from the browser's address bar (e.g. http://cloud.roistat.com/project/1288, where 1288 is your project number)
  • The Username and Password are not created automatically but by yourself.

The username and password should be unique and shouldn't coincide with your administrator login details or any other. It is crucial for protecting your orders data from being lost or corrupted.

 

11. Once you have saved the project ID, the Roistat tracking code will be automatically copied into the Google Analytics Code field.

 If it hasn't happened, in the OpenCart admin panel navigate to System  Settings and click Edit near the store you want to customize.

Then, open the Server tab and find the Google Analytics Code field at the bottom of the tab. Install the Roistat tracking code from Roistat Settings Tracking Code:

Configuring integration in Roistat

Configure Roistat access to Opencart

12. Open Settings  Integrations and choose OpenCart from the Available integrations drop-down menu.


13. The integration settings page will then open.

Enter the URL of your website into the corresponding field, e.g. http://mysite.com . 

Enter the same username and password that you created in paragraph 10.

Click Save to apply the changes.

Once you have specified all the information needed and saved it by clicking Save, OpenCart deal statuses will be imported to Roistat.

Arrange statuses

Once OpenCart has integrated with Roistat, you'll need to arrange the statuses uploaded:

  • Not registered: waste leads or duplicate deals. Do not delete such deals to provide reliable statistics. You can gather them all in one status, e.g. Waste.

  • Processing: deals being in process, not completed, e.g. negotiations or product packaging.

  • Paid: deals that are paid or very likely to be paid.

  • Rejected: when a client rejects the purchase or requests a refund.

Just drag and drop a status to the box you wish.

Roistat will track your achievements (the Paid group) and forecast possible achievements (the Processing and Paid statuses) basing on the grouping principle.