Post by dim565 » Thu Mar 03, 2011 11:28 pm

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

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by scanreg » Fri Mar 04, 2011 1:12 am

This would be interesting, bookmarked

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by SXGuy » Fri Mar 04, 2011 1:43 am

you would need to write an sql query on the product model file which counts how many rows there are which had the current product id listed, in the orders table i think, or maybe sales, im not sure.

then you could pull the retreived number on the product view file.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by dim565 » Fri Mar 04, 2011 2:49 am

SXGuy wrote:you would need to write an sql query...
Difficult for me. Is there an easier solution?

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by openmycart.com » Fri Mar 04, 2011 3:31 am

there is already product quantity, You just need to minus product quantity with last quantity

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


User avatar
Active Member

Posts

Joined
Tue Oct 12, 2010 4:47 am


Post by dim565 » Fri Mar 04, 2011 12:36 pm

and whether there is a variable, where the initial value of quantity??

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by dim565 » Sat Mar 05, 2011 12:53 pm

Somebody can give a working complete solution?

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by fido-x » Sat Mar 05, 2011 6:29 pm

Let's see, the order_product table stores the products that have sold, the order table records the order status. So, you need to count the products in the order_products table based on the product_id where the order status in the order table is set to "complete". Easy!

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;
    }
} 
Insert the following into "catalog/language/english/product/product.php":

Code: Select all

$_['text_units_sold'] = 'Units Sold:'; 
Insert the following into "catalog/controller/product/product.php":

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); 
before (line 157):

Code: Select all

$this->load->model('catalog/review'); 
Then insert the following into "catalog/view/theme/default/template/product/product.tpl":

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 } ?>
before (around line 35 in the default):

Code: Select all

<?php if ($manufacturer) { ?>

Image
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!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by dim565 » Sat Mar 05, 2011 7:21 pm

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 ?

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by fido-x » Sat Mar 05, 2011 8:11 pm

Ummh, you said in your first post:
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
Now, you're saying:
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:';  
Insert the following into "catalog/controller/product/category.php":

Code: Select all

$this->data['text_units_sold'] = $this->language->get('text_units_sold'); 
after (line 58):

Code: Select all

$this->data['text_sort'] = $this->language->get('text_sort'); 
Then, same file, insert the following:

Code: Select all

'units_sold' => $this->model_catalog_category->getUnitsSold($result['product_id']), 
into the "products" array (around line 170).

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 } ?>
somewhere around line 60/61.

Image
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!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by dim565 » Sat Mar 05, 2011 8:52 pm

fido-x, sorry - I was wrong in the first message

Thank you for your help, everything works fine!
:) :) :)

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by i2Paq » Sat Mar 05, 2011 10:48 pm

Would it not be great if this was a vQmod? 8)

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.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by dim565 » Sun Mar 06, 2011 12:38 am

i2Paq wrote:was a vQmod? 8)
Sorry, but i don't know - what is vQmod

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by dim565 » Mon Mar 07, 2011 10:34 pm

i2Paq, Hello. Noticed this: if I order a single item in multiple quantities, they are not included in your code

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;
    }
} 
but nothing happened :(

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by fido-x » Wed Mar 09, 2011 3:46 pm

My bad. There's a mistake in the db query. Change the query to:

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 . "'"); 
The only difference is the change from "COUNT(*)" to "SUM(op.quantity)".
i2Paq wrote:Would it not be great if this was a vQmod? 8)
viewtopic.php?f=131&t=28362

Image
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!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by dim565 » Wed Mar 09, 2011 7:06 pm

fido-x, Thank you very much! :) :)

P.S In you code i change

Code: Select all

> '0'
to

Code: Select all

= '5'

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by dim565 » Sat Mar 12, 2011 10:37 pm

Hello.
If the goods never purchased, the meter does not show 0, can we fix it?

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by dim565 » Tue Mar 15, 2011 12:11 pm

Well, at least tell me the place where to insert the test condition on 0

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm

Post by fido-x » Tue Mar 15, 2011 3:56 pm

dim565 wrote:If the goods never purchased, the meter does not show 0, can we fix it?
Sorry, I don't understand what you mean.

Image
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!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by dim565 » Tue Mar 15, 2011 7:54 pm

Sorry, the solution was simple. Instead

Code: Select all

<?php echo $products[$j]['units_sold']; ?>
it was necessary to write:

Code: Select all

<?php if ($products[$j]['units_sold']) { ?>
<?php echo $products[$j]['units_sold']; ?>
<?php } else echo "0" ?>

New member

Posts

Joined
Fri Feb 18, 2011 12:48 pm
Who is online

Users browsing this forum: No registered users and 79 guests