Back to PhocacartGroup class

Method updateGroupProductPriceById

public static
updateGroupProductPriceById
(mixed $productId, mixed $price, mixed $groupId = 1)

Method updateGroupProductPriceById - Source code

/* We store price for default group - because we need to compare group prices in one sql query
 * When customer is assigned to more groups select the lowest price - lowest group for this customer
 * Example: group A = 500, group B = 400 - customer is assigned to both groups so he gets the lowest price for group B
 * When we store the product, we need to update the default price in phocacart_product_price_groups table
 * because it cannot be manually set, it is set automatically by price of product
 * it is universal function but as default: group = 1 which is default group
 */
public static function updateGroupProductPriceById($productId, $price, $groupId = 1)
{
    $db = Factory::getDBO();
    $query = 'UPDATE #__phocacart_product_price_groups SET' . ' price = ' . $db->quote($price) . ' WHERE product_id = ' . (int) $productId . ' AND group_id = ' . (int) $groupId;
    $db->setQuery($query);
    $db->execute();
}