You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to make OpenCart save the customer's HTTP_REFERER source in the order

Practice




How to make OpenCart save the customer's source HTTP_REFERER in the order

the site they came from

In the file catalog/controll/common/header.php, in index insert:


if( isset($_SERVER['HTTP_REFERER']) && (
!isset($this->session->data['url_refferer'])
|| $this->session->data['url_refferer'] ==''
)) { //in the second condition we check that data['url_refferer'] doesn't exist, i.e. the user visited the site for the first time
$this->session->data['url_refferer'] = $_SERVER['HTTP_REFERER'];
}


in the file /catalog/controller/checkout/confirm.php index
insert

if (isset($this->session->data['url_refferer'] ) &&$this->session->data['url_refferer'] !='') {
$data['url_refferer'] = $this->session->data['url_refferer'];
$this->session->data['url_refferer']='';
}
else $data['url_refferer'] ='no_info_reffer';


in the file /catalog/model/checkout/order.php function addOrder

insert

"', shipping_zone = '" . $this->db->escape($data['shipping_zone']) .
"', url_refferer = '" . $this->db->escape($data['url_refferer']) .


"', shipping_zone_id = '" . (int)$data['shipping_zone_id'] .

for the admin panel
in the file /admin/view/template/common/home.tpl insert with changes

<td class="right"><?php echo $column_order; ?></td>
<td class="left"><?php echo $column_customer; ?></td>
<td class="left"><?php echo $column_status; ?></td>
<td class="left"><?php echo $column_date_added; ?></td>
<td class="right"><?php echo $column_total; ?></td>
<td class="right">Источник</td>
<td class="right"><?php echo $column_action; ?></td>
</tr>
</thead>
<tbody>
<?php if ($orders) { ?>
<?php foreach ($orders as $order) { ?>
<tr>
<td class="right"><?php echo $order['order_id']; ?></td>
<td class="left"><?php echo $order['customer']; ?></td>
<td class="left"><?php echo $order['status']; ?></td>
<td class="left"><?php echo $order['date_added']; ?></td>
<td class="right"><?php echo $order['total']; ?></td>
<td class="right"><a target="_blank" href="<?php echo $order['url_refferer']; ?>"><?php echo $order['url_refferer']; ?></a></td>
<td class="right"><?php foreach ($order['action'] as $action) { ?>
[ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
<?php } ?></td>
in the file /admin/controller/common/home.php insert
$this->data['orders'][] = array(
'order_id' => $result['order_id'],
'customer' => $result['customer'],
'status' => $result['status'],
'url_refferer' => $result['url_refferer'],
'date_added' => date('j.m.Y G:i',strtotime($result['date_added']) ),
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'action' => $action
);




in the file /admin/model/sale/order.php

insert with changes
public function getOrders($data = array()) {
$sql = "SELECT o.order_id,
o.url_refferer,
CONCAT(o.firstname,....

By analogy, you could save the product's points the same way — for this you need to add a points column to the order_products table in the DB, but when editing the order via the admin panel the points get reset to 0, how do I fix that?

in which files did you make changes, and did you do a test var_dump() right before the actual save moment?
so you can see what's actually being written to the database?

I didn't do a var_dump(), the problem occurs earlier — to put the points into the database they need to come from somewhere, I don't understand the logic of adding a product to an order via the admin panel. You add a product, it takes its Model, Options and Price, but how do I make it take the product's Bonus points too? I've been digging through order_form.tpl, controller->order.php

P.S. I'm just starting to get into PHP, I got the front-end part working fine, i.e. we take the product's points and stick them into the database in order_product in a new points column. By the way, Simple is bolted onto the engine



here I wrote in detail how I once added
a new field to a product in the admin panel in OpenCart

The product field isn't new, it already exists and is called points (bonus points), let me explain in more detail:
- I added an extra field, points, to the order_product table, i.e. when someone places an order the bonus points get written there, everything's fine.
When editing an order via the admin panel (for example, someone forgot to order something, called and asked to add it to the order), when adding a product to an existing order I want the bonus points of the added product to be saved too. I got stuck at the point of adding the product, i.e. I didn't understand how to pull out of the product, besides the model and price, also the bonus points (points) (not to be confused with reward points)

What I changed:

1. Added a points column to oc_order_product in the database

2. catalog/controller/checkout/simplecheckout.php
Added:

'points' => $product['points']


3. catalog/model/checkout/order.php

Added:
"', points = '" . $this->db->escape($product['points'])

let's simplify the task: I need the product's bonus points to be displayed when editing and adding an order via the admin panel, when adding a product to that order (admin/view/template/sale/order_form.tpl)
created: 2013-12-21
updated: 2026-03-10
1171



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)