Trying to run a query to do as the title suggests. I need to know how many of a product has sold in the last 30 days. Not quite sure how to do it though as the data is in both tables 'order' and 'order_product'. Looking at some other code looks like I might need to use 'LEFT JOIN' perhaps? Any help appreciated.
If I forgot to mention: it's OpenCart Vv1.5.6
I've come up with the following which kind of works, but always seems to be a few out compared to other reports:
Any suggestions? I've tried things like 30 DAY, 1 MONTH, 1 DAY, 1 YEAR, always close but not right?
Code: Select all
SELECT sum(op.quantity) AS total FROM order_product op LEFT JOIN `order` o ON (op.order_id = o.order_id) WHERE product_id=257 AND DATE(date_added) >= CURDATE()-INTERVAL 1 MONTH;
If I forgot to mention: it's OpenCart Vv1.5.6
I am trying to display on the admin > catalogue > products page how many of each item has sold in the past 30 days.
I have tried the following but I'm a bit unsure what I'm doing so wondering if anyone could help where I'm going wrong.
In admin/model/catalog/product.php I have added
In admin/controller/catalog/product.php I have added
But when I try to echo $sold30 in product_list.tpl it has no value. I don't know if I'm close and or way off with what I've done so far though to be honest 
I have tried the following but I'm a bit unsure what I'm doing so wondering if anyone could help where I'm going wrong.
In admin/model/catalog/product.php I have added
Code: Select all
public function totalsold30days(){
$query = "I CANT SEEM TO POST WITHOUT REMOVING the ACTUAL SQL QUERY HERE BUT IT'S ABOVE ANYWAY";
return $this->db->query($query);
}
Code: Select all
public function totalsold30days() {
$this -> data ['sold30'] = $this -> model_catalog_product -> totalsold30days();
}

If I forgot to mention: it's OpenCart Vv1.5.6
give this a try
Code: Select all
public function totalsold30days(){
$query = $this->db->query("SELECT sum(op.quantity) AS total FROM order_product op LEFT JOIN `order` o ON (op.order_id = o.order_id) WHERE product_id=257 AND DATE(date_added) >= CURDATE()-INTERVAL 1 MONTH");
return $query->row['total'];
}
You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.
OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.
OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE
Thanks for your reply. I feel like I'm close, but I'm still getting "Undefined variable: sold30 in /home/blades/public_html/vqmod/vqcache/vq2-dashboard_view_template_catalog_product_list.tpl".
If I forgot to mention: it's OpenCart Vv1.5.6
on your controller
in your model file
Code: Select all
foreach ($results as $result) { //index 1
..etc
//public function totalsold30days() { //remove
$this -> data ['sold30'] = $this -> model_catalog_product -> totalsold30days($result['product_id']);
//} //remove
... etc
Code: Select all
public function totalsold30days($product_id){
$query = $this->db->query("SELECT sum(op.quantity) AS total FROM order_product op LEFT JOIN `order` o ON (op.order_id = o.order_id) WHERE product_id='" . (int)$product_id . "' AND DATE(date_added) >= CURDATE()-INTERVAL 1 MONTH");
return $query->row['total'];
}
You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.
OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.
OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE
Who is online
Users browsing this forum: Amazon [Bot] and 57 guests