Page 2 of 2

Re: How to show the number of items sold

Posted: Tue Mar 15, 2011 11:14 pm
by openmycart.com

Code: Select all

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

Re: How to show the number of items sold

Posted: Wed Mar 16, 2011 1:50 am
by dim565
If the goods are not bought one yet - will show 0. Without this, nothing is displayed

Re: How to show the number of items sold

Posted: Wed Mar 16, 2011 5:39 am
by openmycart.com
but from your code it look like if goods sold then show sold else show 0, I don't think so why show goods to 0 if another not sold, CMIIW

Re: How to show the number of items sold

Posted: Fri Jan 06, 2012 1:13 am
by kxs1
As a newbie, I tried to follow this thread with no luck. Is there a summary of the tasks required on how to Display Units Sold on Product and Category pages? Also is there a quick way to use the vQmod? thank you in advance.

Re: How to show the number of items sold

Posted: Sat Apr 28, 2012 12:03 am
by scd1982
fido-x wrote: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) { ?>
I slightly modified the product.tpl code and the $text_units_sold language so I could get this to work sort of as a count down using the existing $stock.

Might be useful for someone who manufactures/ships orders in bulk to display how many more of an item needs to be purchased until they are produced/shipped.

The only way this works though is if you use the product's quantity field as the number of sales needed to produce the product, and set the subtract stock to "no". If the product being sold is going to go through multiple batches, you'll have to add the number to the existing quantity to get it to work correctly. (i.e. first batch of 100 is sold, produced, shipped, and now a second batch of 100 is up for sale - set quantity to 200).

It's not neat, not the best way to do it, and probably could stand to use some improvement. But it works..

Code: Select all

<?php if ($units_sold) { ?>
			<table>
			<tr>
				<td><b><?php echo $text_units_sold; ?></b></td>
				<td><?php if ($stock - $units_sold < 1)
				echo $text_item_live;
				else 
				echo $stock - $units_sold; 
				?></td>
			</tr>
			</table><br />
		<?php } ?>
Also added text_item_live to the language and controller files:
Insert the following into "catalog/language/english/product/product.php":

Code: Select all

$_['text_item_live']    = 'Required minimum reached. Item will ship in 3 business days.';
Insert the following into "catalog/controller/product/product.php":

Code: Select all

$this->data['text_item_live'] = $this->language->get('text_item_live');
For both, insert the code just below where fido-x suggested earlier.

Re: How to show the number of items sold

Posted: Sat Mar 30, 2013 8:13 pm
by ankurgambhir3
i am trying this but not working please help me with this

Re: How to show the number of items sold

Posted: Tue Oct 31, 2017 12:29 am
by beerlim
For OC V3.0.2.0
I corrected the SQL for the 0 return (NULL return).
I also wrapped it in vqMod based on a instruction I found somewhere online and it worked first try. Pretty good
So here the XML you need to drop into /vqmod/xml/

Re: How to show the number of items sold

Posted: Tue Oct 31, 2017 1:59 am
by IP_CAM
Good Work ! And some for older OC Versions exist also, just to round up this topic ;)
Ernie
EC Sold Items - Number Bought free, OC v.1.5.4 - 2.0.3.1:
https://www.opencart.com/index.php?rout ... n_id=15185
Image
---
Custom Stock Display free, OC v.1.5.4 - 1.5.6.4:
https://www.opencart.com/index.php?rout ... n_id=15786

Re: How to show the number of items sold

Posted: Sun Apr 08, 2018 12:10 am
by yancp
I am interested in something similar: to show number of products sold per order in admin's order list, is there such an extension, i did not find any in marketplace?