Back to PhocacartPriceBulkprice class

Method setNewPrice

public static
setNewPrice
(mixed $productId, mixed $price, mixed $params)

Method setNewPrice - Source code

public static function setNewPrice($productId, $price, $params)
{
    $newPrice = $price;
    $amount = $params->get('amount', '');
    $operator = $params->get('operator', '-');
    $calculation_type = $params->get('calculation_type', 1);
    $calculation_rounding = $params->get('calculation_rounding', 2);
    // Bulk Price options - no, 0, 1, 2 digits
    $pC = PhocacartUtils::getComponentParameters();
    $rounding_calculation = $pC->get('rounding_calculation', 1);
    // Global Phoca Cart options - round half up, round half down
    if ($calculation_type == 0) {
        // FIXED AMOUNT
        if ($calculation_type == '+') {
            $newPrice = $price + $amount;
        } else {
            $newPrice = $price - $amount;
        }
    } else {
        // PERCENTAGE
        if ($calculation_type == '+') {
            $newPrice = $price + $price * $amount / 100;
        } else {
            $newPrice = $price - $price * $amount / 100;
        }
    }
    if ($calculation_rounding > -1) {
        $bruttoCurrency = round($newPrice, (int) $calculation_rounding, $rounding_calculation);
    }
    if ($newPrice != $price) {
        // Set new price
        $db = Factory::getDBO();
        $query = 'UPDATE #__phocacart_products SET price = ' . $db->quote($newPrice) . ' WHERE id = ' . (int) $productId;
        $db->setQuery($query);
        $db->execute();
        // Set price history
    }
    return $newPrice;
}