Code: Select all
<?php if ($products[$j]['units_sold']) { ?>
<?php echo $products[$j]['units_sold']; ?>
<?php } else { echo "0";} ?>
Code: Select all
<?php if ($products[$j]['units_sold']) { ?>
<?php echo $products[$j]['units_sold']; ?>
<?php } else { echo "0";} ?>
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
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
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.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":Insert the following into "catalog/language/english/product/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/controller/product/product.php":Code: Select all
$_['text_units_sold'] = 'Units Sold:';
before (line 157):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);
Then insert the following into "catalog/view/theme/default/template/product/product.tpl":Code: Select all
$this->load->model('catalog/review');
before (around line 35 in the default):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) { ?>
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 } ?>
Code: Select all
$_['text_item_live'] = 'Required minimum reached. Item will ship in 3 business days.';
Code: Select all
$this->data['text_item_live'] = $this->language->get('text_item_live');
I usually forget to mention I'm using OC v1.4.9.4
/Marcel
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Users browsing this forum: Google [Bot] and 330 guests