then you could pull the retreived number on the product view file.
Find and get many various of opencart modules, themes, mods, etc for your opencart store at http://www.openmycart.com/oc/, OPENCART SITE customization and Maintenance supports at here
Insert the following function into "catalog/model/catalog/product.php":
Code: Select all
public function getUnitsSold($product_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) WHERE o.order_status_id = '5' AND op.product_id = '" . (int)$product_id . "'");
if ($query->row) {
return $query->row['total'];
} else {
return FALSE;
}
}
Code: Select all
$_['text_units_sold'] = 'Units Sold:';
Code: Select all
$this->data['text_units_sold'] = $this->language->get('text_units_sold');
$this->data['units_sold'] = $this->model_catalog_product->getUnitsSold($product_id);
Code: Select all
$this->load->model('catalog/review');
Code: Select all
<?php if ($units_sold) { ?>
<tr>
<td><b><?php echo $text_units_sold; ?></b></td>
<td><?php echo $units_sold; ?></td>
</tr>
<?php } ?>
Code: Select all
<?php if ($manufacturer) { ?>
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Please, if you have free time, please tell us - how to convert code to embed the page /catalog/view/theme/default/template/product/category.tpl ?
Now, you're saying:dim565 wrote:Hello.
I have to do on the page product/product... was displayed - how many times bought this product (ie, the status of "complete transaction"). Help me please do so
dim565 wrote:Many thanks for your reply. But I wanted to print the number of purchases on the page, product/category ... (after the price of goods)
Please, if you have free time, please tell us - how to convert code to embed the page /catalog/view/theme/default/template/product/category.tpl ?
OK. As well as the aforementioned changes, do the following:
First of all, put the model function into "catalog/model/catalog/category.php", then --
Insert the following into "catalog/language/english/product/category":
Code: Select all
$_['text_units_sold'] = 'Units Sold:';
Code: Select all
$this->data['text_units_sold'] = $this->language->get('text_units_sold');
Code: Select all
$this->data['text_sort'] = $this->language->get('text_sort');
Code: Select all
'units_sold' => $this->model_catalog_category->getUnitsSold($result['product_id']),
And then, insert the following into "catalog/view/theme/default/template/product/category.tpl":
Code: Select all
<?php if ($products[$j]['units_sold']) { ?>
<br />
<?php echo $text_units_sold; ?>: <?php echo $products[$j]['units_sold']; ?>
<?php } ?>
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
[How to] BTW + Verzend + betaal setup.
ie I have ordered the goods in the "quantity " wrote the 5 units. And in your code (<?php echo $products[$j]['units_sold'] number increases by only 1.
Can fix it?
I truid to change code:
Code: Select all
public function getUnitsSold($product_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) WHERE o.order_status_id = '5' AND op.product_id = '" . (int)$product_id . "'");
if ($query->row) {
return $query->row['total'];
} else {
return FALSE;
}
}
Code: Select all
$query = $this->db->query("SELECT SUM(op.quantity) AS total FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) WHERE o.order_status_id > '0' AND op.product_id = '" . (int)$product_id . "'");
viewtopic.php?f=131&t=28362i2Paq wrote:Would it not be great if this was a vQmod?
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
P.S In you code i change
Code: Select all
> '0'
Code: Select all
= '5'
Sorry, I don't understand what you mean.dim565 wrote:If the goods never purchased, the meter does not show 0, can we fix it?
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Code: Select all
<?php echo $products[$j]['units_sold']; ?>
Code: Select all
<?php if ($products[$j]['units_sold']) { ?>
<?php echo $products[$j]['units_sold']; ?>
<?php } else echo "0" ?>
Users browsing this forum: No registered users and 79 guests