Back to PhocacartOrder class

Method updateNumberOfSalesOfProduct

public
updateNumberOfSalesOfProduct
(mixed $orderProductId, mixed $productId, mixed $orderId)

Method updateNumberOfSalesOfProduct - Source code

public function updateNumberOfSalesOfProduct($orderProductId, $productId, $orderId)
{
    // We store the number of sales of one product directly to product table
    // because of saving SQL queries in frontend, to not run sql query for each product
    $db = Factory::getDBO();
    $query = ' SELECT SUM(quantity) FROM #__phocacart_order_products' . ' WHERE product_id = ' . (int) $productId . ' LIMIT 0,1';
    $db->setQuery($query);
    $sum = $db->loadColumn();
    if (isset($sum[0])) {
        $query = ' UPDATE #__phocacart_products' . ' SET sales = ' . (int) $sum[0] . ' WHERE id = ' . (int) $productId;
        $db->setQuery($query);
        $db->execute();
    }
    return true;
}