Back to PhocacartPrice class

Method getPriceItems

public
getPriceItems
(mixed $price, mixed $taxId, mixed $tax, mixed $taxCalculationType, mixed $taxTitle = '', mixed $baseAmount = 0, mixed $baseUnit = '', mixed $zeroPrice = 0, mixed $round = 1, mixed $groupPrice = null)

Method getPriceItems - Source code

/*
 * param format - format the price or not (add currency symbol, price decimals thousands separator, ...)
 */
public function getPriceItems($price, $taxId, $tax, $taxCalculationType, $taxTitle = '', $baseAmount = 0, $baseUnit = '', $zeroPrice = 0, $round = 1, $groupPrice = null)
{
    // We need to round because if not
    // BRUTTO          0.15  ... 0.15
    // TAX             0.025 ... 0.03
    // NETTO           0.125 ... 0.13
    // BRUTTO IS WRONG 0.15  ... 0.16
    // If user is assigned to some group, the lowest price was selected from groups for all groups he is assigned
    if ($groupPrice !== null) {
        $price = $groupPrice;
    }
    if ($round == 1) {
        $price = $this->roundPrice($price);
    }
    // Change TAX based on country or region
    $taxChangedA = PhocacartTax::changeTaxBasedOnRule($taxId, $tax, $taxCalculationType, $taxTitle);
    $tax = $this->roundPrice($taxChangedA['taxrate']);
    $taxTitle = $taxChangedA['taxtitle'];
    $taxTitle = Text::_($taxTitle);
    $priceO = array();
    $app = Factory::getApplication();
    //$paramsC 					= PhocacartUtils::getComponentParameters();
    $paramsC = PhocacartUtils::getComponentParameters();
    $tax_calculation = $paramsC->get('tax_calculation', 0);
    $display_unit_price = $paramsC->get('display_unit_price', 1);
    //$zero_price_text			= $paramsC->get( 'zero_price_text', '' );
    //$zero_price_label			= $paramsC->get( 'zero_price_label', '' );
    $priceO['taxtxt'] = $taxTitle;
    $priceO['taxcalc'] = $tax_calculation;
    // Set in Options: Brutto, Netto, None
    $priceO['taxcalctype'] = $taxCalculationType;
    // Set in Tax edit: Percentate, Fixed Amount
    $priceO['zero'] = 0;
    $priceO['taxcountryid'] = $taxChangedA['taxcountryid'];
    $priceO['taxregionid'] = $taxChangedA['taxregionid'];
    $priceO['taxkey'] = PhocacartTax::getTaxKey($taxId, $taxChangedA['taxcountryid'], $taxChangedA['taxregionid']);
    // NO TAX
    if ($tax_calculation == 0) {
        $priceO['netto'] = $price;
        $priceO['tax'] = 0;
        $priceO['brutto'] = $price;
        $priceO['bruttotxt'] = Text::_('COM_PHOCACART_PRICE');
        $priceO['nettotxt'] = Text::_('COM_PHOCACART_PRICE');
        // EXCLUSIVE TAX
    } else {
        if ($tax_calculation == 1) {
            $priceO['netto'] = $price;
            if ($taxCalculationType == 2) {
                // FIX
                $priceO['tax'] = $tax;
                $priceO['brutto'] = $priceO['netto'] + $tax;
                $priceO['taxtxt'] = $taxTitle . ' (' . $this->getPriceFormat($tax) . ')';
            } else {
                // Percentage
                $priceO['tax'] = $priceO['netto'] * ($tax / 100);
                if ($round == 1) {
                    $priceO['tax'] = $this->roundPrice($priceO['tax']);
                }
                $priceO['brutto'] = $priceO['netto'] + $priceO['tax'];
                $priceO['taxtxt'] = $taxTitle . ' (' . $this->getTaxFormat($tax, $taxCalculationType, 0) . ')';
            }
            $priceO['bruttotxt'] = Text::_('COM_PHOCACART_PRICE_INCL_TAX');
            $priceO['nettotxt'] = Text::_('COM_PHOCACART_PRICE_EXCL_TAX');
            // INCLUSIVE TAX
        } else {
            if ($tax_calculation == 2) {
                $priceO['brutto'] = $price;
                if ($taxCalculationType == 2) {
                    // FIX
                    $priceO['tax'] = $tax;
                    $priceO['netto'] = $priceO['brutto'] - $tax;
                    $priceO['taxtxt'] = $taxTitle . ' (' . $this->getPriceFormat($tax) . ')';
                } else {
                    // Percentage
                    $priceO['tax'] = $priceO['brutto'] - $priceO['brutto'] / ($tax / 100 + 1);
                    if ($round == 1) {
                        $priceO['tax'] = $this->roundPrice($priceO['tax']);
                    }
                    $priceO['netto'] = $priceO['brutto'] - $priceO['tax'];
                    //$priceO['netto']	= $priceO['brutto'] * 100 / ($tax + 100);
                    //$priceO['tax']	= $priceO['brutto'] - $priceO['netto'];
                    //$coefficient		= $tax / ($tax + 100);
                    //$priceO['tax']	= $priceO['brutto'] * $coefficient; // POSIBLE TO DO - round e.g. to 4
                    //$priceO['netto']	= $priceO['brutto'] - $priceO['tax'];
                    $priceO['taxtxt'] = $taxTitle . ' (' . $this->getTaxFormat($tax, $taxCalculationType, 0) . ')';
                }
                $priceO['bruttotxt'] = Text::_('COM_PHOCACART_PRICE_INCL_TAX');
                $priceO['nettotxt'] = Text::_('COM_PHOCACART_PRICE_EXCL_TAX');
            }
        }
    }
    if ($priceO['netto'] == $priceO['brutto']) {
        //$priceO['netto'] 		= false;
        $priceO['bruttotxt'] = Text::_('COM_PHOCACART_PRICE');
        $priceO['nettotxt'] = Text::_('COM_PHOCACART_PRICE');
    }
    //if ($tax_calculation > 0) {
    if ($priceO['netto']) {
        $priceO['nettoformat'] = $this->getPriceFormat($priceO['netto']);
    }
    if ($priceO['tax']) {
        $priceO['taxformat'] = $this->getPriceFormat($priceO['tax']);
    }
    //}
    $priceO['bruttoformat'] = $this->getPriceFormat($priceO['brutto']);
    // Unit price
    $priceO['base'] = '';
    $priceO['baseformat'] = '';
    if ($baseAmount > 0 && (int) $display_unit_price > 0) {
        $priceO['base'] = $priceO['brutto'] / $baseAmount;
        if ($round == 1) {
            $priceO['base'] = $this->roundPrice($priceO['base']);
        }
        $priceO['baseformat'] = $this->getPriceFormat($priceO['base']) . '/' . $baseUnit;
    }
    // MOVED TO TEMPLATE BECAUSE CAN BE INFLUENCED BY ATTRIBUTES
    // Must be different in comparison to payment and shipping method because product price can be changed by attributes
    /*
            if ($price == 0 && $zeroPrice == 1) {
    
                if ($zero_price_text != '') {
                    $priceO['zeronettoformat'] = $priceO['bruttoformat'] = $priceO['taxformat'] = Text::_($zero_price_text);
                }
    
                if ($zero_price_label == '0') {
                    $priceO['nettotxt'] = $priceO['bruttotxt'] = $priceO['taxtxt'] = '';
                } else if ($zero_price_label != '') {
                    $priceO['nettotxt'] = $priceO['bruttotxt'] = $priceO['taxtxt'] = Text::_($zero_price_label);
                }
    
            }*/
    if ($priceO['brutto'] == 0 && $priceO['netto'] == 0) {
        $priceO['zero'] = 1;
        // Zero for basic price but this can be changed by attribute price
    }
    if ($round == 1) {
        $priceO['netto'] = $this->roundPrice($priceO['netto']);
        $priceO['brutto'] = $this->roundPrice($priceO['brutto']);
        $priceO['tax'] = $this->roundPrice($priceO['tax']);
    }
    return $priceO;
}