How to show the number of items sold in product page in OpenCart v3? Unfortunately, I don't have any knowledge in php or twig. I tried to find an extension as well, but no luck.
If it does not exist, so, you'll have to get it made, if you're in a hurry,
or then wait, until possibly someone will create an Extension, one day ...
Good Luck
Ernie
or then wait, until possibly someone will create an Extension, one day ...
Good Luck
Ernie
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.
The query you could use on the product page is
Then you'd do
<?php echo $sold_count; ?>
on the tpl or whatever the twig format is.
Code: Select all
$data['sold_count'] = $this->db->query("SELECT SUM(op.quantity) AS quantity 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_info['product_id'] . "' GROUP BY op.product_id")->row['quantity'];
<?php echo $sold_count; ?>
on the tpl or whatever the twig format is.
You can use this extension https://www.opencart.com/index.php?rout ... n_id=35203
You may like these extension : - https://www.opencart.com/index.php?rout ... r=cmsrooms
HiHow to show the number of items sold in product page in OpenCart v3? Unfortunately, I don't have any knowledge in php or twig. I tried to find an extension as well, but no luck.
@markjohnson You can just say thank's Qphoria... and me . Download attached extension and count products which are sold...
After installing this ocmod extension do not forget refresh modifications...
Cheers
I slightly edited Qphoria code, because when the product is not yet sold, we get an error.
Attachments
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
I know this is an old thread but I used this snippet and it works as expected, however, I keep getting the errorQphoria wrote: ↑Tue Aug 15, 2017 2:00 pmThe query you could use on the product page isThen you'd doCode: Select all
$data['sold_count'] = $this->db->query("SELECT SUM(op.quantity) AS quantity 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_info['product_id'] . "' GROUP BY op.product_id")->row['quantity'];
<?php echo $sold_count; ?>
on the tpl or whatever the twig format is.
Undefined index: quantity
for the variable "->row['quantity'] most likely. Maybe when there are no results.
And this is cluttering my error log. I've tried lots of things but I can't make it go away. (try / catch, etc)
Please, is there some simple way? I just want to avoid the error. but I can't figure out where this code ->row['quantity'] , where does "row" come from?
Thank you - worked perfectly first time :-)Qphoria wrote: ↑Tue Aug 15, 2017 2:00 pmThe query you could use on the product page isThen you'd doCode: Select all
$data['sold_count'] = $this->db->query("SELECT SUM(op.quantity) AS quantity 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_info['product_id'] . "' GROUP BY op.product_id")->row['quantity'];
<?php echo $sold_count; ?>
on the tpl or whatever the twig format is.
If you can't find an extension, you could pay a developer such as ourselves or post a job in the Commercial Support Forum.markjohnson wrote: ↑Tue Aug 15, 2017 5:06 amHow to show the number of items sold in product page in OpenCart v3? Unfortunately, I don't have any knowledge in php or twig. I tried to find an extension as well, but no luck.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Guru Member
Actually.... it does not work perfectly :-)
If you've not sold any of a product, then you'll get an entry in your error log as fredJ says.
So I've changed my code to:
If you've not sold any of a product, then you'll get an entry in your error log as fredJ says.
So I've changed my code to:
Code: Select all
$sold_count_query = $this->db->query("SELECT SUM(op.quantity) AS quantity 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_info['product_id'] . "' GROUP BY op.product_id");
if ($sold_count_query->num_rows == 1)
{
$data['sold_count'] = $sold_count_query->row['quantity'];
}
else
{
$data['sold_count'] = 0;
}
Corrected OCMod file
Who is online
Users browsing this forum: No registered users and 368 guests