Back to PhocacartDiscountProduct class

Method getProductDiscountPrice

public static
getProductDiscountPrice
(mixed $productId, mixed &$priceItems, mixed $params = array())

Method getProductDiscountPrice - Source code

/*
 * Display the discount price in category, items or product view
 */
public static function getProductDiscountPrice($productId, &$priceItems, $params = array())
{
    $paramsC = PhocacartUtils::getComponentParameters();
    $display_discount_product_views = $paramsC->get('display_discount_product_views', 0);
    // 0 ... disabled, 1 ... enabled, 2 ... enabled - quantity rule is ignored
    if (isset($params['ignore_view_rule']) && $params['ignore_view_rule'] == 1) {
        // Different modules like countdown module
    } else {
        if ($display_discount_product_views == 0) {
            return false;
        }
    }
    if ($display_discount_product_views == 2) {
        $params['ignore_quantity_rule'] = 1;
    }
    $discount = self::getProductDiscount($productId, 1, 1, $params);
    if (isset($discount['discount']) && isset($discount['calculation_type'])) {
        $price = new PhocacartPrice();
        $priceItems['bruttotxt'] = $discount['title'];
        $priceItems['nettotxt'] = $discount['title'];
        $quantity = 1;
        //Quantity for displaying the price in items,category and product view is always 1
        $total = array();
        // not used in product view
        if ($discount['calculation_type'] == 0) {
            // FIXED AMOUNT
            if (isset($priceItems['netto']) && $priceItems['netto'] > 0) {
                $r = $discount['discount'] * 100 / $priceItems['netto'];
            } else {
                $r = 0;
            }
            // The function works with ratio, so we need to recalculate fixed amount to ratio even in this case
            // the amount will be not divided into more items like it is in checkout
            // so only because of compatibility to the function used in checkout we use ratio instead of fixed amount
            PhocacartCalculation::calculateDiscountFixedAmount($r, $quantity, $priceItems, $total);
        } else {
            // PERCENTAGE
            PhocacartCalculation::calculateDiscountPercentage($discount['discount'], $quantity, $priceItems, $total);
        }
        PhocacartCalculation::correctItemsIfNull($priceItems);
        PhocacartCalculation::formatItems($priceItems);
        return true;
    }
    return false;
}