Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Count Total Sold Products Rate Topic   - - - - -

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 03 August 2021 - 09:56 AM #1

I use this to count the total number of sold product, the problem is that it doesn't count sold product with the complete status only processed, how can this be fixed? thanks
 
function fn_product_sold($product_id, $order_status = 'P') {
$count = (int)db_get_field('SELECT SUM(a.amount) FROM ?:order_details a
LEFT JOIN ?:orders b ON a.order_id = b.order_id
WHERE a.product_id = ?i AND b.status = ?s', $product_id, $order_status);
  return $count;
}

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22192 posts

Posted 03 August 2021 - 01:17 PM #2

Try

 

function fn_product_sold($product_id, $order_status = 'P') {
    $count = (int)db_get_field('SELECT SUM(a.amount) FROM ?:order_details a
    LEFT JOIN ?:orders b ON a.order_id = b.order_id
    WHERE a.product_id = ?i AND b.status IN ?a', $product_id, [$order_status, 'C']);
    return $count;
}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 04 August 2021 - 06:59 AM #3

I tried this but it's not working

 

 

Try

 

function fn_product_sold($product_id, $order_status = 'P') {
    $count = (int)db_get_field('SELECT SUM(a.amount) FROM ?:order_details a
    LEFT JOIN ?:orders b ON a.order_id = b.order_id
    WHERE a.product_id = ?i AND b.status IN ?a', $product_id, [$order_status, 'C']);
    return $count;
}

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22192 posts

Posted 04 August 2021 - 01:10 PM #4

I tried this but it's not working

 

Do you receive any error? Or empty result?


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 05 August 2021 - 01:51 AM #5

Do you receive any error? Or empty result?

 

Empty value, I ended up doing it this way..

function fn_product_sold($product_id, $order_status = 'C') {
    $count = (int)db_get_field('SELECT SUM(a.amount) FROM ?:order_details a
    LEFT JOIN ?:orders b ON a.order_id = b.order_id
    WHERE a.product_id = ?i AND b.status IN ?a', $product_id, [$order_status, 'C']);
    return $count;
}

function fn_product_sold($product_id, $order_status = 'P') {
    $count = (int)db_get_field('SELECT SUM(a.amount) FROM ?:order_details a
    LEFT JOIN ?:orders b ON a.order_id = b.order_id
    WHERE a.product_id = ?i AND b.status IN ?a', $product_id, [$order_status, 'C']);
    return $count;
}

on tpl
{$complete_orders = $product.product_id|complete_orders_count}
{$paid_orders = $product.product_id|paid_orders_count}
{$sold_amt = $complete_orders+$paid_orders}


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22192 posts

Posted 05 August 2021 - 05:56 AM #6

Please make sure that the required status uses the "C" letter


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 05 August 2021 - 01:08 PM #7

Please make sure that the required status uses the "C" letter

yes it does



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22192 posts

Posted 05 August 2021 - 01:30 PM #8

As far as I can see, your code does not call my function.


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)