예제 #1
0
    }
    if ($arResult['ALLOW_LD_TAX']) {
        $row['PRICE'] = CCrmProductRow::CalculateExclusivePrice($row['PRICE'], $row['TAX_RATE']);
        $row['TAX_RATE'] = 0.0;
        $row['TAX_INCLUDED'] = 'N';
    }
    $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($row['PRICE'], $row['TAX_RATE']);
    $discountTypeID = intval($row['DISCOUNT_TYPE_ID']);
    if ($discountTypeID === \Bitrix\Crm\Discount::MONETARY) {
        $row['PRICE_NETTO'] = $exclusivePrice + $row['DISCOUNT_SUM'];
    } else {
        $discoutRate = doubleval($row['DISCOUNT_RATE']);
        $discoutSum = $discoutRate < 100 ? \Bitrix\Crm\Discount::calculateDiscountSum($exclusivePrice, $discoutRate) : doubleval($row['DISCOUNT_SUM']);
        $row['PRICE_NETTO'] = $exclusivePrice + $discoutSum;
    }
    $row['PRICE_BRUTTO'] = CCrmProductRow::CalculateInclusivePrice($row['PRICE_NETTO'], $row['TAX_RATE']);
    $totalDiscount += round($row['QUANTITY'] * $row['DISCOUNT_SUM'], 2);
    //$totalSum += round($row['QUANTITY'] * $row['PRICE'], 2);
    //$totalTax += round($row['PRICE'] - $exclusivePrice, 2);
}
unset($row);
if (count($arResult['PRODUCT_ROWS']) > 0 && (!isset($arParams['TOTAL_SUM']) || !isset($arParams['TOTAL_TAX']))) {
    $enableSaleDiscount = false;
    $calcOptions = array();
    if ($arResult['ALLOW_LD_TAX']) {
        $calcOptions['LOCATION_ID'] = isset($arParams['LOCATION_ID']) ? $arParams['LOCATION_ID'] : '';
    }
    $result = CCrmSaleHelper::Calculate($arResult['PRODUCT_ROWS'], $currencyID, $personTypeId, $enableSaleDiscount, SITE_ID, $calcOptions);
    $totalSum = isset($result['PRICE']) ? round(doubleval($result['PRICE']), 2) : 0.0;
    $totalTax = isset($result['TAX_VALUE']) ? round(doubleval($result['TAX_VALUE']), 2) : 0.0;
}
예제 #2
0
 private static function PrepareShoppingCartItems(&$productRows, $currencyID, $siteId)
 {
     $items = array();
     foreach ($productRows as $k => &$v) {
         $item = array();
         $item['PRODUCT_ID'] = isset($v['PRODUCT_ID']) ? intval($v['PRODUCT_ID']) : 0;
         $isCustomized = isset($v['CUSTOMIZED']) && $v['CUSTOMIZED'] === 'Y';
         if ($item['PRODUCT_ID'] > 0 && !$isCustomized) {
             $item['MODULE'] = 'catalog';
             $item['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider';
         } else {
             $item['MODULE'] = $item['PRODUCT_PROVIDER_CLASS'] = '';
         }
         if ($isCustomized) {
             $item['CUSTOM_PRICE'] = 'Y';
         }
         $item['TABLE_ROW_ID'] = $k;
         $item['QUANTITY'] = isset($v['QUANTITY']) ? doubleval($v['QUANTITY']) : 0;
         $item['QUANTITY_DEFAULT'] = $item['QUANTITY'];
         $item['PRICE'] = isset($v['PRICE']) ? doubleval($v['PRICE']) : 0.0;
         $item['PRICE_DEFAULT'] = $item['PRICE'];
         $item['CURRENCY'] = $currencyID;
         // discount info
         $item['CRM_PR_FIELDS'] = array();
         $item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] = isset($v['DISCOUNT_TYPE_ID']) ? intval($v['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::PERCENTAGE;
         $item['CRM_PR_FIELDS']['DISCOUNT_RATE'] = isset($v['DISCOUNT_RATE']) ? round(doubleval($v['DISCOUNT_RATE']), 2) : 0.0;
         $item['CRM_PR_FIELDS']['DISCOUNT_SUM'] = isset($v['DISCOUNT_SUM']) ? round(doubleval($v['DISCOUNT_SUM']), 2) : 0.0;
         // tax info
         $taxRate = isset($v['TAX_RATE']) ? round(doubleval($v['TAX_RATE']), 2) : 0.0;
         $allowLDTax = CCrmTax::isTaxMode();
         if ($allowLDTax) {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = 0.0;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = 'N';
         } else {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = $taxRate;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = isset($v['TAX_INCLUDED']) && $v['TAX_INCLUDED'] === 'Y' ? 'Y' : 'N';
         }
         // price netto, price brutto
         $exclusivePrice = $taxRate !== 0.0 ? CCrmProductRow::CalculateExclusivePrice($item['PRICE'], $taxRate) : $item['PRICE'];
         if ($item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] === \Bitrix\Crm\Discount::MONETARY) {
             $priceNetto = $exclusivePrice + $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         } else {
             $discoutRate = $item['CRM_PR_FIELDS']['DISCOUNT_RATE'];
             $discoutSum = $discoutRate < 100 ? \Bitrix\Crm\Discount::calculateDiscountByDiscountPrice($exclusivePrice, $discoutRate) : $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $priceNetto = $exclusivePrice + $discoutSum;
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         }
         if ($item['CRM_PR_FIELDS']['DISCOUNT_SUM'] === 0.0) {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = $item['PRICE'];
         } else {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = round(CCrmProductRow::CalculateInclusivePrice($priceNetto, $item['CRM_PR_FIELDS']['TAX_RATE']), 2);
         }
         if (isset($v['VAT_RATE'])) {
             $item['VAT_RATE'] = $v['VAT_RATE'];
         } elseif (isset($v['TAX_RATE'])) {
             $item['VAT_RATE'] = $v['TAX_RATE'] / 100;
         }
         if (isset($v['MEASURE_CODE'])) {
             $item['MEASURE_CODE'] = $v['MEASURE_CODE'];
         }
         if (isset($v['MEASURE_NAME'])) {
             $item['MEASURE_NAME'] = $v['MEASURE_NAME'];
         }
         $item['NAME'] = isset($v['NAME']) ? $v['NAME'] : (isset($v['PRODUCT_NAME']) ? $v['PRODUCT_NAME'] : '');
         $item['LID'] = $siteId;
         $item['CAN_BUY'] = 'Y';
         $items[] =& $item;
         unset($item);
     }
     unset($v);
     return $items;
 }