Example #1
0
	function DeleteByProduct($ProductID, $arExceptionIDs = array())
	{
		global $DB;

		$ProductID = intval($ProductID);
		if ($ProductID <= 0)
			return false;
		foreach (GetModuleEvents("catalog", "OnBeforeProductPriceDelete", true) as $arEvent)
		{
			if (ExecuteModuleEventEx($arEvent, array($ProductID, &$arExceptionIDs))===false)
				return false;
		}

		if (!empty($arExceptionIDs))
			CatalogClearArray($arExceptionIDs, false);

		if (!empty($arExceptionIDs))
		{
			$strSql = "DELETE FROM b_catalog_price WHERE PRODUCT_ID = ".$ProductID." AND ID NOT IN (".implode(',',$arExceptionIDs).")";
		}
		else
		{
			$strSql = "DELETE FROM b_catalog_price WHERE PRODUCT_ID = ".$ProductID;
		}

		$mxRes = $DB->Query($strSql, true);

		foreach (GetModuleEvents("catalog", "OnProductPriceDelete", true) as $arEvent)
		{
			ExecuteModuleEventEx($arEvent, array($ProductID,$arExceptionIDs));
		}

		return $mxRes;
	}
Example #2
0
		}

		if ($USER->IsAdmin() && CBXFeatures::IsFeatureEnabled('SaleRecurring'))
		{
			$arOldAvailContentGroups = array();
			$oldAvailContentGroups = (string)Option::get('catalog', 'avail_content_groups');
			if ($oldAvailContentGroups != '')
				$arOldAvailContentGroups = explode(",", $oldAvailContentGroups);
			if (!empty($arOldAvailContentGroups))
				$arOldAvailContentGroups = array_fill_keys($arOldAvailContentGroups, true);

			$fieldsClear = array();
			if (isset($_POST['AVAIL_CONTENT_GROUPS']) && is_array($_POST['AVAIL_CONTENT_GROUPS']))
			{
				$fieldsClear = $_POST['AVAIL_CONTENT_GROUPS'];
				CatalogClearArray($fieldsClear);
				foreach ($fieldsClear as &$oneValue)
				{
					if (isset($arOldAvailContentGroups[$oneValue]))
						unset($arOldAvailContentGroups[$oneValue]);
				}
				if (isset($oneValue))
					unset($oneValue);

			}
			Option::set('catalog', 'avail_content_groups', implode(',', $fieldsClear), '');
			if (!empty($arOldAvailContentGroups))
			{
				$arOldAvailContentGroups = array_keys($arOldAvailContentGroups);
				foreach ($arOldAvailContentGroups as &$oneValue)
				{
Example #3
0
 public static function CouponOneOrderDisable($intOrderID = 0)
 {
     global $DB;
     if (!empty(self::$arOneOrderCoupons)) {
         $arCouponID = array_keys(self::$arOneOrderCoupons);
         foreach (self::$arOneOrderCoupons as &$arCoupon) {
             $arCoupon['USER_ID'] = intval($arCoupon['USER_ID']);
             if (0 < $arCoupon['USER_ID']) {
                 CCatalogDiscountCoupon::EraseCouponByManage($arCoupon['USER_ID'], $arCoupon['COUPON']);
             } else {
                 CCatalogDiscountCoupon::EraseCoupon($arCoupon['COUPON']);
             }
         }
         if (isset($arCoupon)) {
             unset($arCoupon);
         }
         CatalogClearArray($arCouponID, false);
         if (!empty($arCouponID)) {
             $strSql = "UPDATE b_catalog_discount_coupon SET ACTIVE='N' WHERE ID IN (" . implode(', ', $arCouponID) . ") AND ONE_TIME='" . self::TYPE_ONE_ORDER . "'";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         self::$arOneOrderCoupons = array();
     }
 }
Example #4
0
 protected function getDiscountHandlers($discountList)
 {
     global $DB;
     $defaultRes = array('MODULES' => array(), 'EXT_FILES' => array());
     $result = array();
     CatalogClearArray($discountList, true);
     if (!empty($discountList)) {
         $result = array_fill_keys($discountList, $defaultRes);
         $discountIn = implode(', ', $discountList);
         $sqlQuery = 'select * from b_catalog_discount_module where DISCOUNT_ID IN (' . $discountIn . ')';
         $resQuery = $DB->Query($sqlQuery, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__);
         while ($row = $resQuery->Fetch()) {
             $row['DISCOUNT_ID'] = (int) $row['DISCOUNT_ID'];
             $result[$row['DISCOUNT_ID']]['MODULES'][] = $row['MODULE_ID'];
         }
     }
     return $result;
 }
Example #5
0
function CatalogGetPriceTableEx($ID, $filterQauntity = 0, $arFilterType = array(), $VAT_INCLUDE = 'Y', $arCurrencyParams = array())
{
    global $USER;
    static $arPriceTypes = array();
    $ID = (int) $ID;
    if ($ID <= 0) {
        return false;
    }
    $filterQauntity = (int) $filterQauntity;
    if (!is_array($arFilterType)) {
        $arFilterType = array($arFilterType);
    }
    $boolConvert = false;
    $strCurrencyID = '';
    $arCurrencyList = array();
    if (!empty($arCurrencyParams) && is_array($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID'])) {
        $boolConvert = true;
        $strCurrencyID = $arCurrencyParams['CURRENCY_ID'];
    }
    $arResult = array();
    $arResult["ROWS"] = array();
    $arResult["COLS"] = array();
    $arResult["MATRIX"] = array();
    $arResult["CAN_BUY"] = array();
    $arResult["AVAILABLE"] = "N";
    $cacheTime = CATALOG_CACHE_DEFAULT_TIME;
    if (defined("CATALOG_CACHE_TIME")) {
        $cacheTime = intval(CATALOG_CACHE_TIME);
    }
    $arUserGroups = $USER->GetUserGroupArray();
    CatalogClearArray($arUserGroups, true);
    $strCacheID = 'UG_' . implode('_', $arUserGroups);
    if (isset($arPriceTypes[$strCacheID])) {
        $arPriceGroups = $arPriceTypes[$strCacheID];
    } else {
        $arPriceGroups = CCatalogGroup::GetGroupsPerms($arUserGroups, array());
        $arPriceTypes[$strCacheID] = $arPriceGroups;
    }
    if (empty($arPriceGroups["view"])) {
        return $arResult;
    }
    $currentQuantity = -1;
    $rowsCnt = -1;
    $arFilter = array("PRODUCT_ID" => $ID);
    if ($filterQauntity > 0) {
        $arFilter["+<=QUANTITY_FROM"] = $filterQauntity;
        $arFilter["+>=QUANTITY_TO"] = $filterQauntity;
    }
    if (!empty($arFilterType)) {
        $arTmp = array();
        foreach ($arPriceGroups["view"] as &$intOneGroup) {
            if (in_array($intOneGroup, $arFilterType)) {
                $arTmp[] = $intOneGroup;
            }
        }
        if (isset($intOneGroup)) {
            unset($intOneGroup);
        }
        if (empty($arTmp)) {
            return $arResult;
        }
        $arFilter["CATALOG_GROUP_ID"] = $arTmp;
    } else {
        $arFilter["CATALOG_GROUP_ID"] = $arPriceGroups["view"];
    }
    $productQuantity = 0;
    $productQuantityTrace = "N";
    $dbRes = CCatalogProduct::GetVATInfo($ID);
    if ($arVatInfo = $dbRes->Fetch()) {
        $fVatRate = floatval($arVatInfo['RATE'] * 0.01);
        $bVatIncluded = $arVatInfo['VAT_INCLUDED'] == 'Y';
    } else {
        $fVatRate = 0.0;
        $bVatIncluded = false;
    }
    $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('ID', 'CAN_BUY_ZERO', 'QUANTITY_TRACE', 'QUANTITY'));
    if ($arProduct = $rsProducts->Fetch()) {
        $intIBlockID = CIBlockElement::GetIBlockByID($arProduct['ID']);
        if (!$intIBlockID) {
            return false;
        }
        $arProduct['IBLOCK_ID'] = $intIBlockID;
    } else {
        return false;
    }
    $dbPrice = CPrice::GetListEx(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC"), $arFilter, false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO"));
    while ($arPrice = $dbPrice->Fetch()) {
        if ($VAT_INCLUDE == 'N') {
            if ($bVatIncluded) {
                $arPrice['PRICE'] /= 1 + $fVatRate;
            }
        } else {
            if (!$bVatIncluded) {
                $arPrice['PRICE'] *= 1 + $fVatRate;
            }
        }
        $arPrice['VAT_RATE'] = $fVatRate;
        CCatalogDiscountSave::Disable();
        $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arProduct["IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $arUserGroups, "N", SITE_ID, array());
        CCatalogDiscountSave::Enable();
        $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts);
        $arPrice["DISCOUNT_PRICE"] = $discountPrice;
        $arPrice["QUANTITY_FROM"] = doubleval($arPrice["QUANTITY_FROM"]);
        if ($currentQuantity != $arPrice["QUANTITY_FROM"]) {
            $rowsCnt++;
            $arResult["ROWS"][$rowsCnt]["QUANTITY_FROM"] = $arPrice["QUANTITY_FROM"];
            $arResult["ROWS"][$rowsCnt]["QUANTITY_TO"] = doubleval($arPrice["QUANTITY_TO"]);
            $currentQuantity = $arPrice["QUANTITY_FROM"];
        }
        if ($boolConvert && $strCurrencyID != $arPrice["CURRENCY"]) {
            $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "ORIG_PRICE" => $arPrice["PRICE"], "ORIG_DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "ORIG_CURRENCY" => $arPrice["CURRENCY"], "ORIG_VAT_RATE" => $arPrice["VAT_RATE"], 'PRICE' => CCurrencyRates::ConvertCurrency($arPrice["PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'DISCOUNT_PRICE' => CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT_PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'CURRENCY' => $strCurrencyID, 'VAT_RATE' => CCurrencyRates::ConvertCurrency($arPrice["VAT_RATE"], $arPrice["CURRENCY"], $strCurrencyID));
            $arCurrencyList[] = $arPrice["CURRENCY"];
        } else {
            $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "PRICE" => $arPrice["PRICE"], "DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "CURRENCY" => $arPrice["CURRENCY"], "VAT_RATE" => $arPrice["VAT_RATE"]);
        }
    }
    $arCatalogGroups = CCatalogGroup::GetListArray();
    foreach ($arCatalogGroups as $key => $value) {
        if (isset($arResult["MATRIX"][$key])) {
            $arResult["COLS"][$value["ID"]] = $value;
        }
    }
    $arResult["CAN_BUY"] = $arPriceGroups["buy"];
    $arResult["AVAILABLE"] = 0 >= $arProduct['QUANTITY'] && 'Y' == $arProduct['QUANTITY_TRACE'] && 'N' == $arProduct['CAN_BUY_ZERO'] ? 'N' : 'Y';
    if ($boolConvert) {
        if (!empty($arCurrencyList)) {
            $arCurrencyList[] = $strCurrencyID;
        }
        $arResult['CURRENCY_LIST'] = $arCurrencyList;
    }
    return $arResult;
}
Example #6
0
 protected function deleteFromSet($intID, $arEx)
 {
     global $DB;
     $intID = (int) $intID;
     if (0 >= $intID) {
         return false;
     }
     CatalogClearArray($arEx, false);
     if (empty($arEx)) {
         return false;
     }
     $strSql = "delete from b_catalog_product_sets where SET_ID=" . $intID . " and ID NOT IN(" . implode(', ', $arEx) . ")";
     $DB->Query($strSql, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__);
     return true;
 }
Example #7
0
	public static function GetItemPrices($IBLOCK_ID, $arCatalogPrices, $arItem, $bVATInclude = true, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID)
	{
		$arPrices = array();

		if (empty($arCatalogPrices) || !is_array($arCatalogPrices))
		{
			return $arPrices;
		}

		global $USER;
		static $arCurUserGroups = array();
		static $strBaseCurrency = '';

		if (self::$catalogIncluded === null)
			self::$catalogIncluded = \Freetrix\Main\Loader::includeModule('catalog');
		if (self::$catalogIncluded)
		{
			$USER_ID = intval($USER_ID);
			$intUserID = $USER_ID;
			if (0 >= $intUserID)
				$intUserID = $USER->GetID();
			if (!isset($arCurUserGroups[$intUserID]))
			{
				$arUserGroups = (0 < $USER_ID ? CUser::GetUserGroup($USER_ID) : $USER->GetUserGroupArray());
				CatalogClearArray($arUserGroups);
				$arCurUserGroups[$intUserID] = $arUserGroups;
			}
			else
			{
				$arUserGroups = $arCurUserGroups[$intUserID];
			}

			$boolConvert = false;
			$strCurrencyID = '';
			if (isset($arCurrencyParams['CURRENCY_ID']) && !empty($arCurrencyParams['CURRENCY_ID']))
			{
				$boolConvert = true;
				$strCurrencyID = $arCurrencyParams['CURRENCY_ID'];
			}
			if (!$boolConvert && '' == $strBaseCurrency)
				$strBaseCurrency = CCurrency::GetBaseCurrency();

			$strMinCode = '';
			$boolStartMin = true;
			$dblMinPrice = 0;
			$strMinCurrency = ($boolConvert ? $strCurrencyID : $strBaseCurrency);
			CCatalogDiscountSave::Disable();
			foreach($arCatalogPrices as $key => $value)
			{
				if($value["CAN_VIEW"] && strlen($arItem["CATALOG_PRICE_".$value["ID"]]) > 0)
				{
					// get final price with VAT included.
					if ($arItem['CATALOG_VAT_INCLUDED'] != 'Y')
					{
						$arItem['CATALOG_PRICE_'.$value['ID']] *= (1 + $arItem['CATALOG_VAT'] * 0.01);
					}
					// so discounts will include VAT
					$arDiscounts = CCatalogDiscount::GetDiscount(
						$arItem["ID"],
						$arItem["IBLOCK_ID"],
						array($value["ID"]),
						$arUserGroups,
						"N",
						$LID,
						array()
					);
					$discountPrice = CCatalogProduct::CountPriceWithDiscount(
						$arItem["CATALOG_PRICE_".$value["ID"]],
						$arItem["CATALOG_CURRENCY_".$value["ID"]],
						$arDiscounts
					);
					// get clear prices WO VAT
					$arItem['CATALOG_PRICE_'.$value['ID']] /= (1 + $arItem['CATALOG_VAT'] * 0.01);
					$discountPrice /= (1 + $arItem['CATALOG_VAT'] * 0.01);

					$vat_value_discount = $discountPrice * $arItem['CATALOG_VAT'] * 0.01;
					$vat_discountPrice = $discountPrice + $vat_value_discount;

					$vat_value = $arItem['CATALOG_PRICE_'.$value['ID']] * $arItem['CATALOG_VAT'] * 0.01;
					$vat_price = $arItem["CATALOG_PRICE_".$value["ID"]] + $vat_value;

					if ($boolConvert && $strCurrencyID != $arItem["CATALOG_CURRENCY_".$value["ID"]])
					{
						$strOrigCurrencyID = $arItem["CATALOG_CURRENCY_".$value["ID"]];
						$dblOrigNoVat = $arItem["CATALOG_PRICE_".$value["ID"]];
						$dblNoVat = CCurrencyRates::ConvertCurrency($dblOrigNoVat, $strOrigCurrencyID, $strCurrencyID);
						$dblVatPrice = CCurrencyRates::ConvertCurrency($vat_price, $strOrigCurrencyID, $strCurrencyID);
						$dblVatValue = CCurrencyRates::ConvertCurrency($vat_value, $strOrigCurrencyID, $strCurrencyID);
						$dblDiscountValueNoVat = CCurrencyRates::ConvertCurrency($discountPrice, $strOrigCurrencyID, $strCurrencyID);
						$dblVatDiscountPrice = CCurrencyRates::ConvertCurrency($vat_discountPrice, $strOrigCurrencyID, $strCurrencyID);
						$dblDiscountValueVat = CCurrencyRates::ConvertCurrency($vat_value_discount, $strOrigCurrencyID, $strCurrencyID);

						$arPrices[$key] = array(
							'ORIG_VALUE_NOVAT' => $dblOrigNoVat,
							"VALUE_NOVAT" => $dblNoVat,
							"PRINT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($dblNoVat, $strCurrencyID, true),

							'ORIG_VALUE_VAT' => $vat_price,
							"VALUE_VAT" => $dblVatPrice,
							"PRINT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($dblVatPrice, $strCurrencyID, true),

							'ORIG_VATRATE_VALUE' => $vat_value,
							"VATRATE_VALUE" => $dblVatValue,
							"PRINT_VATRATE_VALUE" => CCurrencyLang::CurrencyFormat($dblVatValue, $strCurrencyID, true),

							'ORIG_DISCOUNT_VALUE_NOVAT' => $discountPrice,
							"DISCOUNT_VALUE_NOVAT" => $dblDiscountValueNoVat,
							"PRINT_DISCOUNT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($dblDiscountValueNoVat, $strCurrencyID, true),

							"ORIG_DISCOUNT_VALUE_VAT" => $vat_discountPrice,
							"DISCOUNT_VALUE_VAT" => $dblVatDiscountPrice,
							"PRINT_DISCOUNT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($dblVatDiscountPrice, $strCurrencyID, true),

							'ORIG_DISCOUNT_VATRATE_VALUE' => $vat_value_discount,
							'DISCOUNT_VATRATE_VALUE' => $dblDiscountValueVat,
							'PRINT_DISCOUNT_VATRATE_VALUE' => CCurrencyLang::CurrencyFormat($dblDiscountValueVat, $strCurrencyID, true),

							'ORIG_CURRENCY' => $strOrigCurrencyID,
							"CURRENCY" => $strCurrencyID,
						);
					}
					else
					{
						$strPriceCurrency = $arItem["CATALOG_CURRENCY_".$value["ID"]];
						$arPrices[$key] = array(
							"VALUE_NOVAT" => $arItem["CATALOG_PRICE_".$value["ID"]],
							"PRINT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($arItem["CATALOG_PRICE_".$value["ID"]], $strPriceCurrency, true),

							"VALUE_VAT" => $vat_price,
							"PRINT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($vat_price, $strPriceCurrency, true),

							"VATRATE_VALUE" => $vat_value,
							"PRINT_VATRATE_VALUE" => CCurrencyLang::CurrencyFormat($vat_value, $strPriceCurrency, true),

							"DISCOUNT_VALUE_NOVAT" => $discountPrice,
							"PRINT_DISCOUNT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($discountPrice, $strPriceCurrency, true),

							"DISCOUNT_VALUE_VAT" => $vat_discountPrice,
							"PRINT_DISCOUNT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($vat_discountPrice, $strPriceCurrency, true),

							'DISCOUNT_VATRATE_VALUE' => $vat_value_discount,
							'PRINT_DISCOUNT_VATRATE_VALUE' => CCurrencyLang::CurrencyFormat($vat_value_discount, $strPriceCurrency, true),

							"CURRENCY" => $arItem["CATALOG_CURRENCY_".$value["ID"]],
						);
					}
					$arPrices[$key]["ID"] = $arItem["CATALOG_PRICE_ID_".$value["ID"]];
					$arPrices[$key]["CAN_ACCESS"] = $arItem["CATALOG_CAN_ACCESS_".$value["ID"]];
					$arPrices[$key]["CAN_BUY"] = $arItem["CATALOG_CAN_BUY_".$value["ID"]];
					$arPrices[$key]['MIN_PRICE'] = 'N';

					if ($bVATInclude)
					{
						$arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_VAT'];
						$arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_VAT'];
						$arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_VAT'];
						$arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_VAT'];
					}
					else
					{
						$arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_NOVAT'];
						$arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_NOVAT'];
						$arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_NOVAT'];
						$arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_NOVAT'];
					}

					if (roundEx($arPrices[$key]['VALUE'], 2) == roundEx($arPrices[$key]['DISCOUNT_VALUE'], 2))
					{
						$arPrices[$key]['DISCOUNT_DIFF'] = 0;
						$arPrices[$key]['DISCOUNT_DIFF_PERCENT'] = 0;
						$arPrices[$key]['PRINT_DISCOUNT_DIFF'] = CCurrencyLang::CurrencyFormat(0, $arPrices[$key]['CURRENCY'], true);
					}
					else
					{
						$arPrices[$key]['DISCOUNT_DIFF'] = $arPrices[$key]['VALUE'] - $arPrices[$key]['DISCOUNT_VALUE'];
						$arPrices[$key]['DISCOUNT_DIFF_PERCENT'] = roundEx(100*$arPrices[$key]['DISCOUNT_DIFF']/$arPrices[$key]['VALUE'], 0);
						$arPrices[$key]['PRINT_DISCOUNT_DIFF'] = CCurrencyLang::CurrencyFormat($arPrices[$key]['DISCOUNT_DIFF'], $arPrices[$key]['CURRENCY'], true);
					}

					if ($value["CAN_VIEW"])
					{
						if ($boolStartMin)
						{
							$dblMinPrice = ($boolConvert || ($arPrices[$key]['CURRENCY'] == $strMinCurrency)
								? $arPrices[$key]['DISCOUNT_VALUE']
								: CCurrencyRates::ConvertCurrency($arPrices[$key]['DISCOUNT_VALUE'], $arPrices[$key]['CURRENCY'], $strMinCurrency)
							);
							$strMinCode = $key;
							$boolStartMin = false;
						}
						else
						{
							$dblComparePrice = ($boolConvert || ($arPrices[$key]['CURRENCY'] == $strMinCurrency)
								? $arPrices[$key]['DISCOUNT_VALUE']
								: CCurrencyRates::ConvertCurrency($arPrices[$key]['DISCOUNT_VALUE'], $arPrices[$key]['CURRENCY'], $strMinCurrency)
							);
							if ($dblMinPrice > $dblComparePrice)
							{
								$dblMinPrice = $dblComparePrice;
								$strMinCode = $key;
							}
						}
					}
				}
			}
			if ('' != $strMinCode)
				$arPrices[$strMinCode]['MIN_PRICE'] = 'Y';
			CCatalogDiscountSave::Enable();
		}
		else
		{
			$strMinCode = '';
			$boolStartMin = true;
			$dblMinPrice = 0;
			foreach($arCatalogPrices as $key => $value)
			{
				if($value["CAN_VIEW"])
				{
					$dblValue = round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]), 2);
					if ($boolStartMin)
					{
						$dblMinPrice = $dblValue;
						$strMinCode = $key;
						$boolStartMin = false;
					}
					else
					{
						if ($dblMinPrice > $dblValue)
						{
							$dblMinPrice = $dblValue;
							$strMinCode = $key;
						}
					}
					$arPrices[$key] = array(
						"ID" => $arItem["PROPERTY_".$value["ID"]."_VALUE_ID"],
						"VALUE" => $dblValue,
						"PRINT_VALUE" => $dblValue." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"DISCOUNT_VALUE" => $dblValue,
						"PRINT_DISCOUNT_VALUE" => $dblValue." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"CURRENCY" => $arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"CAN_ACCESS" => true,
						"CAN_BUY" => false,
						'DISCOUNT_DIFF_PERCENT' => 0,
						'DISCOUNT_DIFF' => 0,
						'PRINT_DISCOUNT_DIFF' => '0 '.$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"MIN_PRICE" => "N"
					);
				}
			}
			if ('' != $strMinCode)
				$arPrices[$strMinCode]['MIN_PRICE'] = 'Y';
		}
		return $arPrices;
	}
Example #8
0
 public static function SetProductSectionsCache($arItemIDs)
 {
     if (empty($arItemIDs) || !is_array($arItemIDs)) {
         return;
     }
     CatalogClearArray($arItemIDs);
     if (empty($arItemIDs)) {
         return;
     }
     if (empty(self::$arCacheProductSections)) {
         self::$arCacheProductSections = array_fill_keys($arItemIDs, array());
     } else {
         foreach ($arItemIDs as &$intOneID) {
             self::$arCacheProductSections[$intOneID] = array();
         }
         unset($intOneID);
     }
     $rsSections = CIBlockElement::GetElementGroups($arItemIDs, true, array("ID", "IBLOCK_SECTION_ID", "IBLOCK_ELEMENT_ID"));
     while ($arSection = $rsSections->Fetch()) {
         $arSection['ID'] = (int) $arSection['ID'];
         $arSection['IBLOCK_SECTION_ID'] = (int) $arSection['IBLOCK_SECTION_ID'];
         $arSection['IBLOCK_ELEMENT_ID'] = (int) $arSection['IBLOCK_ELEMENT_ID'];
         self::$arCacheProductSections[$arSection['IBLOCK_ELEMENT_ID']][] = $arSection;
     }
     unset($arSection, $rsSections);
 }
Example #9
0
 public static function CheckProducts($arItemIDs)
 {
     if (!is_array($arItemIDs)) {
         $arItemIDs = array($arItemIDs);
     }
     CatalogClearArray($arItemIDs);
     if (empty($arItemIDs)) {
         return false;
     }
     $arProductList = array();
     $rsProducts = CCatalogProduct::GetList(array(), array('@ID' => $arItemIDs), false, false, array('ID'));
     while ($arProduct = $rsProducts->Fetch()) {
         $arProduct['ID'] = (int) $arProduct['ID'];
         $arProductList[$arProduct['ID']] = true;
     }
     if (empty($arProductList)) {
         return false;
     }
     $boolFlag = true;
     foreach ($arItemIDs as &$intItemID) {
         if (!isset($arProductList[$intItemID])) {
             $boolFlag = false;
             break;
         }
     }
     unset($intItemID);
     return $boolFlag;
 }
Example #10
0
	public static function GetDiscountResultCacheKey($arDiscountIDs, $strSiteID, $strRenewal, $boolNeedClear = true)
	{
		$boolNeedClear = !!$boolNeedClear;
		if ($boolNeedClear)
		{
			if (!is_array($arDiscountIDs))
				return false;
			CatalogClearArray($arDiscountIDs);
			if (empty($arDiscountIDs))
				return false;

			if ('' == $strSiteID)
				return false;
			$strRenewal = ('Y' == $strRenewal ? 'Y' : 'N');
		}
		return md5('D'.implode('_', $arDiscountIDs).'-'.'S'.$strSiteID.'-R'.$strRenewal);
	}
Example #11
0
 public static function GetDiscount($arParams = array(), $getAll = false)
 {
     global $DB, $USER;
     $arResult = array();
     if (!CCatalog::IsUserExists() || !$USER->IsAuthorized() || !self::IsEnabled()) {
         return $arResult;
     }
     foreach (GetModuleEvents("catalog", "OnGetDiscountSave", true) as $arEvent) {
         $mxResult = ExecuteModuleEventEx($arEvent, $arParams);
         if ($mxResult !== true) {
             return $mxResult;
         }
     }
     if (empty($arParams) || !is_array($arParams)) {
         return $arResult;
     }
     $intUserID = 0;
     $arUserGroups = array();
     $strSiteID = false;
     if (isset($arParams['USER_ID'])) {
         $intUserID = $arParams['USER_ID'];
     }
     if (isset($arParams['USER_GROUPS'])) {
         $arUserGroups = $arParams['USER_GROUPS'];
     }
     if (isset($arParams['SITE_ID'])) {
         $strSiteID = $arParams['SITE_ID'];
     }
     if (self::GetDiscountUserID() > 0) {
         $intUserID = self::GetDiscountUserID();
         $arUserGroups = $USER->GetUserGroup($intUserID);
     } else {
         $intUserID = (int) $intUserID;
         if ($intUserID <= 0) {
             $intUserID = $USER->GetID();
             $arUserGroups = $USER->GetUserGroupArray();
         } else {
             if (empty($arUserGroups)) {
                 $arUserGroups = $USER->GetUserGroup($intUserID);
             }
         }
     }
     if (empty($arUserGroups) || !is_array($arUserGroups) || $intUserID <= 0) {
         return $arResult;
     }
     $key = array_search(2, $arUserGroups);
     if ($key !== false) {
         unset($arUserGroups[$key]);
     }
     if (empty($arUserGroups)) {
         return $arResult;
     }
     if ($strSiteID === false) {
         $strSiteID = SITE_ID;
     }
     $arCurrentDiscountID = CCatalogDiscountSave::__GetDiscountIDByGroup($arUserGroups);
     if (isset($arParams['ID'])) {
         CatalogClearArray($arParams['ID'], false);
         if (!empty($arParams['ID'])) {
             $arCurrentDiscountID = array_intersect($arCurrentDiscountID, $arParams['ID']);
         }
     }
     if (!empty($arCurrentDiscountID)) {
         $getAll = $getAll === true;
         $intCurrentTime = getmicrotime();
         $strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $intCurrentTime);
         $arFilter = array('ID' => $arCurrentDiscountID, 'SITE_ID' => $strSiteID, 'TYPE' => self::ENTITY_ID, 'ACTIVE' => 'Y', '+<=ACTIVE_FROM' => $strDate, '+>=ACTIVE_TO' => $strDate);
         CTimeZone::Disable();
         $rsDiscSaves = CCatalogDiscountSave::GetList(array(), $arFilter);
         CTimeZone::Enable();
         while ($arDiscSave = $rsDiscSaves->Fetch()) {
             $arDiscSave['ACTION_SIZE'] = (int) $arDiscSave['ACTION_SIZE'];
             $arDiscSave['COUNT_SIZE'] = (int) $arDiscSave['COUNT_SIZE'];
             $arDiscSave['ACTIVE_FROM_UT'] = false;
             $arDiscSave['ACTIVE_TO_UT'] = false;
             $arDiscSave['COUNT_FROM_UT'] = false;
             $arDiscSave['COUNT_TO_UT'] = false;
             $strCountPeriod = self::COUNT_TIME_ALL;
             $strActionPeriod = self::ACTION_TIME_ALL;
             $arCountPeriodBack = array();
             $arActionPeriodBack = array();
             $arActionPeriod = array();
             $arStartDate = false;
             $arOldOrderSumm = false;
             $arOrderSumm = false;
             $boolPeriodInsert = true;
             $intCountTime = $intCurrentTime;
             $arOrderFilter = array('USER_ID' => $intUserID, 'LID' => $arDiscSave['SITE_ID'], 'PAYED' => 'Y', 'CANCELED' => 'N');
             $arOldOrderFilter = $arOrderFilter;
             if (!empty($arDiscSave['ACTIVE_FROM']) || !empty($arDiscSave['ACTIVE_TO'])) {
                 $strActionPeriod = self::ACTION_TIME_INTERVAL;
                 if (!empty($arDiscSave['ACTIVE_FROM'])) {
                     $arDiscSave['ACTIVE_FROM_UT'] = MakeTimeStamp($arDiscSave['ACTIVE_FROM']);
                 }
                 if (!empty($arDiscSave['ACTIVE_TO'])) {
                     $arDiscSave['ACTIVE_TO_UT'] = MakeTimeStamp($arDiscSave['ACTIVE_TO']);
                 }
             } elseif ($arDiscSave['ACTION_SIZE'] > 0 && in_array($arDiscSave['ACTION_TYPE'], array('D', 'M', 'Y'))) {
                 $strActionPeriod = self::ACTION_TIME_PERIOD;
                 $arActionPeriodBack = CCatalogDiscountSave::__GetTimeStampArray($arDiscSave['ACTION_SIZE'], $arDiscSave['ACTION_TYPE']);
                 $arActionPeriod = CCatalogDiscountSave::__GetTimeStampArray($arDiscSave['ACTION_SIZE'], $arDiscSave['ACTION_TYPE'], true);
             }
             if (!empty($arDiscSave['COUNT_FROM']) || !empty($arDiscSave['COUNT_TO'])) {
                 $strCountPeriod = self::COUNT_TIME_INTERVAL;
                 if (!empty($arDiscSave['COUNT_FROM'])) {
                     $arDiscSave['COUNT_FROM_UT'] = MakeTimeStamp($arDiscSave['COUNT_FROM']);
                 }
                 if (!empty($arDiscSave['COUNT_TO'])) {
                     $arDiscSave['COUNT_TO_UT'] = MakeTimeStamp($arDiscSave['COUNT_TO']);
                     if ($arDiscSave['COUNT_TO_UT'] > $intCountTime) {
                         $arDiscSave['COUNT_TO_UT'] = $intCountTime;
                         $arDiscSave['COUNT_TO'] = ConvertTimeStamp($intCountTime, 'FULL');
                     }
                 }
             } elseif ($arDiscSave['COUNT_SIZE'] > 0 && in_array($arDiscSave['COUNT_TYPE'], array('D', 'M', 'Y'))) {
                 $strCountPeriod = self::COUNT_TIME_PERIOD;
                 $arCountPeriodBack = CCatalogDiscountSave::__GetTimeStampArray($arDiscSave['COUNT_SIZE'], $arDiscSave['COUNT_TYPE']);
             }
             if ($strCountPeriod == self::COUNT_TIME_INTERVAL) {
                 if (false !== $arDiscSave['COUNT_FROM_UT']) {
                     if ($arDiscSave['COUNT_FROM_UT'] > $intCountTime) {
                         continue;
                     }
                     if (false !== $arDiscSave['COUNT_TO_UT'] && $arDiscSave['COUNT_TO_UT'] <= $arDiscSave['COUNT_FROM_UT']) {
                         continue;
                     }
                     if (false !== $arDiscSave['ACTIVE_TO_UT'] && $arDiscSave['COUNT_FROM_UT'] >= $arDiscSave['ACTIVE_TO_UT']) {
                         continue;
                     }
                 }
                 if (false !== $arDiscSave['COUNT_TO_UT']) {
                     if ($strActionPeriod == self::ACTION_TIME_PERIOD && $arDiscSave['COUNT_TO_UT'] < AddToTimeStamp($arActionPeriodBack, $intCountTime)) {
                         continue;
                     }
                 }
             }
             if ($strActionPeriod == self::ACTION_TIME_PERIOD) {
                 if ($strCountPeriod == self::COUNT_TIME_PERIOD) {
                     $arStartDate = CCatalogDiscountSave::__GetUserInfoByDiscount(array('DISCOUNT_ID' => $arDiscSave['ID'], 'USER_ID' => $intUserID, 'ACTIVE_FROM' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), AddToTimeStamp($arActionPeriodBack, $intCountTime))));
                     if (is_array($arStartDate) && !empty($arStartDate)) {
                         $arOldOrderFilter['<DATE_INSERT'] = $arStartDate['ACTIVE_FROM_FORMAT'];
                         $arOldOrderFilter['>=DATE_INSERT'] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), AddToTimeStamp($arCountPeriodBack, MakeTimeStamp($arStartDate['ACTIVE_FROM_FORMAT'])));
                         $arOldOrderSumm = CCatalogDiscountSave::__SaleOrderSumm($arOldOrderFilter, $arDiscSave['CURRENCY']);
                     }
                 } else {
                     $arStartDate = CCatalogDiscountSave::__GetUserInfoByDiscount(array('DISCOUNT_ID' => $arDiscSave['ID'], 'USER_ID' => $intUserID), array('ACTIVE_FROM' => false, 'DELETE' => false));
                     if (is_array($arStartDate) && !empty($arStartDate)) {
                         $intTimeStart = MakeTimeStamp($arStartDate['ACTIVE_FROM_FORMAT']);
                         $intTimeFinish = MakeTimeStamp($arStartDate['ACTIVE_TO_FORMAT']);
                         if (!($intTimeStart <= $intCountTime && $intTimeFinish >= $intCountTime)) {
                             continue;
                         } else {
                             $boolPeriodInsert = false;
                         }
                     }
                 }
             }
             $intTimeStart = false;
             $intTimeFinish = false;
             if ($strCountPeriod == self::COUNT_TIME_INTERVAL) {
                 $intTimeStart = !empty($arDiscSave['COUNT_FROM']) ? $arDiscSave['COUNT_FROM'] : false;
                 $intTimeFinish = !empty($arDiscSave['COUNT_TO']) ? $arDiscSave['COUNT_TO'] : false;
             } elseif ($strCountPeriod == self::COUNT_TIME_PERIOD) {
                 $intTimeStart = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), AddToTimeStamp($arCountPeriodBack, $intCountTime));
             }
             if ($intTimeStart) {
                 $arOrderFilter['>=DATE_INSERT'] = $intTimeStart;
             }
             if ($intTimeFinish) {
                 $arOrderFilter['<DATE_INSERT'] = $intTimeFinish;
             }
             $arOrderSumm = CCatalogDiscountSave::__SaleOrderSumm($arOrderFilter, $arDiscSave['CURRENCY']);
             if (is_array($arOldOrderSumm) && 0 < $arOldOrderSumm['RANGE_SUMM']) {
                 if ($arOrderSumm['RANGE_SUMM'] <= $arOldOrderSumm['RANGE_SUMM']) {
                     $arOrderSumm = $arOldOrderSumm;
                 } else {
                     $arOldOrderSumm = false;
                 }
             }
             $rsRanges = CCatalogDiscountSave::GetRangeByDiscount(array('RANGE_FROM' => 'desc'), array('DISCOUNT_ID' => $arDiscSave['ID'], '<=RANGE_FROM' => $arOrderSumm['RANGE_SUMM']), false, array('nTopCount' => 1));
             $arRange = $rsRanges->Fetch();
             if (!empty($arRange) || $getAll) {
                 if (!empty($arRange)) {
                     if ($strActionPeriod == self::ACTION_TIME_PERIOD) {
                         if ($strCountPeriod == self::COUNT_TIME_PERIOD) {
                             if (!is_array($arOldOrderSumm)) {
                                 CCatalogDiscountSave::__UpdateUserInfoByDiscount(array('DISCOUNT_ID' => $arDiscSave['ID'], 'USER_ID' => $intUserID, 'ACTIVE_FROM' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $intCountTime), 'ACTIVE_TO' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), AddToTimeStamp($arActionPeriod, $intCountTime)), 'RANGE_FROM' => -1));
                             }
                         } else {
                             if ($boolPeriodInsert) {
                                 CCatalogDiscountSave::__UpdateUserInfoByDiscount(array('DISCOUNT_ID' => $arDiscSave['ID'], 'USER_ID' => $intUserID, 'ACTIVE_FROM' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $intCountTime), 'ACTIVE_TO' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), AddToTimeStamp($arActionPeriod, $intCountTime)), 'RANGE_FROM' => -1), array('SEARCH' => true, 'DELETE' => false));
                             }
                         }
                     }
                 }
                 unset($arDiscSave['ACTIVE_FROM_UT'], $arDiscSave['ACTIVE_TO_UT'], $arDiscSave['COUNT_FROM_UT'], $arDiscSave['COUNT_TO_UT']);
                 $arOneResult = $arDiscSave;
                 if (!empty($arRange)) {
                     $arOneResult['VALUE'] = $arRange['VALUE'];
                     $arOneResult['VALUE_TYPE'] = $arRange['TYPE'];
                     $arOneResult['RANGE_FROM'] = $arRange['RANGE_FROM'];
                 } else {
                     $arOneResult['VALUE'] = 0;
                     $arOneResult['VALUE_TYPE'] = self::TYPE_PERCENT;
                     $rsRanges = CCatalogDiscountSave::GetRangeByDiscount(array('RANGE_FROM' => 'asc'), array('DISCOUNT_ID' => $arDiscSave['ID']), false, array('nTopCount' => 1));
                     $arRange = $rsRanges->Fetch();
                     $arOneResult['NEXT_RANGE_FROM'] = $arRange['RANGE_FROM'];
                     $arOneResult['NEXT_VALUE'] = $arRange['VALUE'];
                     $arOneResult['NEXT_VALUE_TYPE'] = $arRange['TYPE'];
                 }
                 $arOneResult['SUMM'] = $arOrderSumm['SUMM'];
                 $arOneResult['SUMM_CURRENCY'] = $arOrderSumm['CURRENCY'];
                 $arOneResult['RANGE_SUMM'] = $arOrderSumm['RANGE_SUMM'];
                 $arOneResult['LAST_ORDER_DATE'] = $arOrderSumm['LAST_ORDER_DATE'];
                 $arResult[] = $arOneResult;
             }
         }
     }
     return $arResult;
 }