Ejemplo n.º 1
0
 public function Add($arFields, $boolCalc = false)
 {
     global $DB;
     if (!CCatalogDiscountSave::CheckFields("ADD", $arFields)) {
         return false;
     }
     $arInsert = $DB->PrepareInsert("b_catalog_discount", $arFields);
     $strSql = "INSERT INTO b_catalog_discount(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = intval($DB->LastID());
     if ($ID > 0) {
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $ID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "INSERT INTO b_catalog_disc_save_range(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "INSERT INTO b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) VALUES(" . $ID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         $boolCalc = $boolCalc === true ? true : false;
         if ($boolCalc) {
             CCatalogDiscountSave::UserDiscountCalc($ID, $arFields, false);
         }
     }
     return $ID;
 }
Ejemplo n.º 2
0
 public function Add($arFields, $boolCalc = false)
 {
     global $DB;
     global $stackCacheManager;
     global $USER;
     $arFields1 = array();
     if (!(!isset($USER) || !($USER instanceof CUser && 'CUser' == get_class($USER)))) {
         if (!isset($arFields["CREATED_BY"]) || intval($arFields["CREATED_BY"]) <= 0) {
             $arFields["CREATED_BY"] = intval(@$USER->GetID());
         }
         if (!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0) {
             $arFields["MODIFIED_BY"] = intval(@$USER->GetID());
         }
     }
     if (array_key_exists('TIMESTAMP_X', $arFields)) {
         unset($arFields['TIMESTAMP_X']);
     }
     if (array_key_exists('DATE_CREATE', $arFields)) {
         unset($arFields['DATE_CREATE']);
     }
     $arFields1['TIMESTAMP_X'] = $DB->GetNowFunction();
     $arFields1['DATE_CREATE'] = $DB->GetNowFunction();
     if (!CCatalogDiscountSave::CheckFields("ADD", $arFields)) {
         return false;
     }
     //$stackCacheManager->Clear("catalog_discount_save");
     $arInsert = $DB->PrepareInsert("b_catalog_discount", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($arInsert[0]) > 0) {
             $arInsert[0] .= ", ";
             $arInsert[1] .= ", ";
         }
         $arInsert[0] .= $key;
         $arInsert[1] .= $value;
     }
     $strSql = "INSERT INTO b_catalog_discount(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = intval($DB->LastID());
     if ($ID > 0) {
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $ID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "INSERT INTO b_catalog_disc_save_range(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "INSERT INTO b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) VALUES(" . $ID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         //CCatalogDiscountSave::__AddGroupsCache($ID,$arFields['GROUP_IDS']);
         $boolCalc = $boolCalc === true ? true : false;
         if ($boolCalc) {
             CCatalogDiscountSave::UserDiscountCalc($ID, $arFields, false);
         }
     }
     return $ID;
 }
Ejemplo n.º 3
0
function __AddRangeCellDiscount($intRangeID, $strPrefix, $arRange)
{
    static $discsaveTypes = null;
    if ($discsaveTypes === null) {
        $discsaveTypes = CCatalogDiscountSave::GetDiscountSaveTypes(true);
    }
    $result = '<td><input type="text" name="' . $strPrefix . $intRangeID . '_VALUE" size="13" value="' . htmlspecialcharsbx($arRange['VALUE']) . '"> <select name="' . $strPrefix . $intRangeID . '_TYPE" style="width:150px;">';
    foreach ($discsaveTypes as $key => $value) {
        $result .= '<option value="' . $key . '" ' . ($key == $arRange['TYPE'] ? 'selected' : '') . '>' . $value . '</option>';
    }
    $result .= '</select></td>';
    return $result;
}
Ejemplo n.º 4
0
 public function Update($intID, $arFields, $boolCalc = false)
 {
     global $DB;
     $intID = (int) $intID;
     if ($intID <= 0) {
         return false;
     }
     if (!CCatalogDiscountSave::CheckFields('UPDATE', $arFields, $intID)) {
         return false;
     }
     $strUpdate = $DB->PrepareUpdate("b_catalog_discount", $arFields);
     if (!empty($strUpdate)) {
         $strSql = "update b_catalog_discount SET " . $strUpdate . " where ID = " . $intID . " and TYPE = " . self::ENTITY_ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     if (!empty($arFields['RANGES'])) {
         $DB->Query("delete from b_catalog_disc_save_range where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $intID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "insert into b_catalog_disc_save_range(" . $arInsert[0] . ") values(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         unset($arRange);
     }
     if (!empty($arFields['GROUP_IDS'])) {
         $DB->Query("delete from b_catalog_disc_save_group where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "insert into b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) values(" . $intID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         unset($intGroupID);
     }
     $boolCalc = $boolCalc === true;
     if ($boolCalc) {
         CCatalogDiscountSave::UserDiscountCalc($intID, $arFields, false);
     }
     return $intID;
 }
Ejemplo n.º 5
0
 public function GetDiscount($intProductID, $intIBlockID, $arCatalogGroups = array(), $arUserGroups = array(), $strRenewal = "N", $siteID = false, $arDiscountCoupons = false, $boolSKU = true, $boolGetIDS = false)
 {
     global $DB;
     global $APPLICATION;
     global $stackCacheManager;
     foreach (GetModuleEvents("catalog", "OnGetDiscount", true) as $arEvent) {
         $mxResult = ExecuteModuleEventEx($arEvent, array($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS));
         if (true !== $mxResult) {
             return $mxResult;
         }
     }
     $boolSKU = true === $boolSKU ? true : false;
     $boolGetIDS = true === $boolGetIDS ? true : false;
     $intProductID = intval($intProductID);
     if (0 >= $intProductID) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID");
         return false;
     }
     $intIBlockID = intval($intIBlockID);
     if (0 >= $intIBlockID) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"), "NO_IBLOCK_ID");
         return false;
     }
     if (isset($arCatalogGroups)) {
         if (is_array($arCatalogGroups)) {
             array_walk($arCatalogGroups, create_function("&\$item", "\$item=intval(\$item);"));
             $arCatalogGroups = array_unique($arCatalogGroups);
         } else {
             if (intval($arCatalogGroups) . "|" == $arCatalogGroups . "|") {
                 $arCatalogGroups = array(intval($arCatalogGroups));
             } else {
                 $arCatalogGroups = array();
             }
         }
     } else {
         $arCatalogGroups = array();
     }
     if (!is_array($arUserGroups) && intval($arUserGroups) . "|" == $arUserGroups . "|") {
         $arUserGroups = array(intval($arUserGroups));
     }
     if (!is_array($arUserGroups)) {
         $arUserGroups = array();
     }
     if (!in_array(2, $arUserGroups)) {
         $arUserGroups[] = 2;
     }
     $strRenewal = $strRenewal == "Y" ? "Y" : "N";
     if ($siteID === false) {
         $siteID = SITE_ID;
     }
     if ($arDiscountCoupons === false) {
         $arDiscountCoupons = CCatalogDiscountCoupon::GetCoupons();
     }
     $arSKU = false;
     if ($boolSKU) {
         $arSKU = CCatalogSKU::GetProductInfo($intProductID, $intIBlockID);
         if (!is_array($arSKU)) {
             $boolSKU = false;
         }
     }
     $arResult = array();
     $arResultID = array();
     $arFilter = array('PRICE_TYPE_ID' => $arCatalogGroups, 'USER_GROUP_ID' => $arUserGroups);
     $arDiscountIDs = CCatalogDiscount::__GetDiscountID($arFilter);
     if (!empty($arDiscountIDs)) {
         $boolGenerate = false;
         $arSelect = array("ID", "TYPE", "SITE_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "RENEWAL", "NAME", "SORT", "MAX_DISCOUNT", "VALUE_TYPE", "VALUE", "CURRENCY", "PRIORITY", "LAST_DISCOUNT", "COUPON", "COUPON_ONE_TIME", "COUPON_ACTIVE", 'UNPACK');
         $strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
         $arFilter = array("ID" => $arDiscountIDs, "SITE_ID" => $siteID, "TYPE" => DISCOUNT_TYPE_STANDART, "ACTIVE" => "Y", "RENEWAL" => $strRenewal, "+<=ACTIVE_FROM" => $strDate, "+>=ACTIVE_TO" => $strDate);
         if (is_array($arDiscountCoupons)) {
             $arFilter["+COUPON"] = $arDiscountCoupons;
         }
         $rsPriceDiscounts = CCatalogDiscount::GetList(array(), $arFilter, false, false, $arSelect);
         while ($arPriceDiscount = $rsPriceDiscounts->Fetch()) {
             if ($arPriceDiscount['COUPON_ACTIVE'] != 'N') {
                 if (!$boolGenerate) {
                     $arProduct = array('ID' => $intProductID, 'IBLOCK_ID' => $intIBlockID);
                     if (!self::__GenerateFields($arProduct)) {
                         return false;
                     }
                     $boolGenerate = true;
                 }
                 if (CCatalogDiscount::__Unpack($arProduct, $arPriceDiscount['UNPACK'])) {
                     unset($arPriceDiscount['UNPACK']);
                     $arResult[] = $arPriceDiscount;
                     $arResultID[] = $arPriceDiscount['ID'];
                 }
             }
         }
     }
     if ($boolSKU) {
         $arDiscountParent = CCatalogDiscount::GetDiscount($arSKU['ID'], $arSKU['IBLOCK_ID'], $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, false, false);
         if (!empty($arDiscountParent)) {
             if (empty($arResult)) {
                 $arResult = $arDiscountParent;
             } else {
                 foreach ($arDiscountParent as &$arOneParentDiscount) {
                     if (in_array($arOneParentDiscount['ID'], $arResultID)) {
                         continue;
                     }
                     $arResult[] = $arOneParentDiscount;
                     $arResultID[] = $arOneParentDiscount['ID'];
                 }
                 if (isset($arOneParentDiscount)) {
                     unset($arOneParentDiscount);
                 }
             }
         }
     }
     if (!$boolGetIDS) {
         $arDiscSave = CCatalogDiscountSave::GetDiscount(array('USER_ID' => 0, 'USER_GROUPS' => $arUserGroups, 'SITE_ID' => $siteID));
         if (!empty($arDiscSave)) {
             $arResult = !empty($arResult) ? array_merge($arResult, $arDiscSave) : $arDiscSave;
         }
     } else {
         $arResult = $arResultID;
     }
     foreach (GetModuleEvents("catalog", "OnGetDiscountResult", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arResult));
     }
     return $arResult;
 }
Ejemplo n.º 6
0
 public static function OrderProduct($arParams)
 {
     if (!is_set($arParams, "RENEWAL") || $arParams["RENEWAL"] != "Y") {
         $arParams["RENEWAL"] = "N";
     }
     if (!is_set($arParams, "USER_ID") || IntVal($arParams["USER_ID"]) <= 0) {
         $arParams["USER_ID"] = 0;
     }
     if (!is_set($arParams["SITE_ID"])) {
         $arParams["SITE_ID"] = false;
     }
     global $USER;
     global $DB;
     $productID = intval($arParams["PRODUCT_ID"]);
     $quantity = doubleval($arParams["QUANTITY"]);
     $renewal = $arParams["RENEWAL"] == "Y" ? "Y" : "N";
     $strSiteID = $arParams["SITE_ID"];
     $intUserID = intval($arParams["USER_ID"]);
     if (0 > $intUserID) {
         $intUserID = 0;
     }
     $arResult = array();
     static $arUserCache = array();
     if (0 < $intUserID) {
         if (!array_key_exists($intUserID, $arUserCache)) {
             $rsUsers = CUser::GetList($by = 'ID', $order = 'DESC', array("ID_EQUAL_EXACT" => $intUserID), array('FIELDS' => array('ID')));
             if ($arUser = $rsUsers->Fetch()) {
                 $arUserCache[$arUser['ID']] = CUser::GetUserGroup($arUser['ID']);
             } else {
                 $intUserID = 0;
                 return $arResult;
             }
         }
         $dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $productID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSION" => "N"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
         if (!($arProduct = $dbIBlockElement->GetNext())) {
             return $arResult;
         }
         if ('E' == CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], "RIGHTS_MODE")) {
             $arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID);
             if (empty($arUserRights)) {
                 return $arResult;
             } elseif (!is_array($arUserRights) || !array_key_exists('element_read', $arUserRights)) {
                 return $arResult;
             }
         } else {
             if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID)) {
                 return $arResult;
             }
         }
     } else {
         $dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $productID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "Y", "MIN_PERMISSION" => "R"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
         if (!($arProduct = $dbIBlockElement->GetNext())) {
             return $arResult;
         }
     }
     if ($arCatalogProduct = CCatalogProduct::GetByID($productID)) {
         if ($arCatalogProduct["CAN_BUY_ZERO"] != "Y" && ($arCatalogProduct["QUANTITY_TRACE"] == "Y" && doubleval($arCatalogProduct["QUANTITY"]) < doubleVal($quantity))) {
             return $arResult;
         }
     } else {
         return $arResult;
     }
     if (0 < $intUserID) {
         $arCoupons = CCatalogDiscountCoupon::GetCouponsByManage($intUserID);
         CCatalogDiscountSave::SetDiscountUserID($intUserID);
     } else {
         $arCoupons = CCatalogDiscountCoupon::GetCoupons();
     }
     $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray(), $renewal, array(), 0 < $intUserID ? $strSiteID : false, $arCoupons);
     if (empty($arPrice)) {
         if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray())) {
             $quantity = $nearestQuantity;
             $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray(), $renewal, array(), 0 < $intUserID ? $strSiteID : false, $arCoupons);
         }
     }
     if (empty($arPrice)) {
         if (0 < $intUserID) {
             CCatalogDiscountSave::ClearDiscountUserID();
         }
         return $arResult;
     }
     $boolDiscountVat = 'N' != COption::GetOptionString('catalog', 'discount_vat', 'Y');
     $currentPrice = $arPrice["PRICE"]["PRICE"];
     $currentDiscount = 0.0;
     if ($boolDiscountVat) {
         if ('N' == $arPrice['PRICE']['VAT_INCLUDED']) {
             $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE'];
             $arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
         }
     } else {
         if ('Y' == $arPrice['PRICE']['VAT_INCLUDED']) {
             $currentPrice /= 1 + $arPrice['PRICE']['VAT_RATE'];
             $arPrice['PRICE']['VAT_INCLUDED'] = 'N';
         }
     }
     $arDiscountList = array();
     $arCouponList = array();
     if (!empty($arPrice["DISCOUNT_LIST"])) {
         $dblStartPrice = $currentPrice;
         foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount) {
             switch ($arOneDiscount['VALUE_TYPE']) {
                 case 'F':
                     if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                         $currentDiscount = $arOneDiscount['VALUE'];
                     } else {
                         $currentDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount["VALUE"], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                     }
                     $currentPrice = $currentPrice - $currentDiscount;
                     break;
                 case 'P':
                     $currentDiscount = $currentPrice * $arOneDiscount["VALUE"] / 100.0;
                     if (0 < $arOneDiscount['MAX_DISCOUNT']) {
                         if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                             $dblMaxDiscount = $arOneDiscount['MAX_DISCOUNT'];
                         } else {
                             $dblMaxDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount['MAX_DISCOUNT'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                         }
                         if ($currentDiscount > $dblMaxDiscount) {
                             $currentDiscount = $dblMaxDiscount;
                         }
                     }
                     $currentPrice = $currentPrice - $currentDiscount;
                     break;
                 case 'S':
                     if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                         $currentPrice = $arOneDiscount['VALUE'];
                     } else {
                         $currentPrice = CCurrencyRates::ConvertCurrency($arOneDiscount['VALUE'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                     }
                     break;
             }
             $arOneList = array('ID' => $arOneDiscount['ID'], 'NAME' => $arOneDiscount['NAME'], 'COUPON' => '');
             if ($arOneDiscount['COUPON']) {
                 $arOneList['COUPON'] = $arOneDiscount['COUPON'];
                 $arCouponList[] = $arOneDiscount['COUPON'];
             }
             $arDiscountList[] = $arOneList;
         }
         if (isset($arOneDiscount)) {
             unset($arOneDiscount);
         }
         $currentDiscount = $dblStartPrice - $currentPrice;
     }
     if (empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"])) {
         if (!empty($arPrice["PRICE"]["CATALOG_GROUP_ID"])) {
             $rsCatGroups = CCatalogGroup::GetList(array(), array('ID' => $arPrice["PRICE"]["CATALOG_GROUP_ID"]), false, array('nTopCount' => 1), array('ID', 'NAME', 'NAME_LANG'));
             if ($arCatGroup = $rsCatGroups->Fetch()) {
                 $arPrice["PRICE"]["CATALOG_GROUP_NAME"] = !empty($arCatGroup['NAME_LANG']) ? $arCatGroup['NAME_LANG'] : $arCatGroup['NAME'];
             }
         }
     }
     if (!$boolDiscountVat) {
         $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE'];
         $currentDiscount *= 1 + $arPrice['PRICE']['VAT_RATE'];
         $arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
     }
     $arResult = array("PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"], "PRICE" => $currentPrice, "VAT_RATE" => $arPrice['PRICE']['VAT_RATE'], "CURRENCY" => $arPrice["PRICE"]["CURRENCY"], "QUANTITY" => $quantity, "WEIGHT" => 0, "NAME" => $arProduct["~NAME"], "CAN_BUY" => "Y", "DETAIL_PAGE_URL" => $arProduct['DETAIL_PAGE_URL'], "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DISCOUNT_PRICE" => $currentDiscount);
     if (!empty($arPrice["DISCOUNT_LIST"])) {
         $arResult["DISCOUNT_VALUE"] = 100 * $currentDiscount / ($currentDiscount + $currentPrice) . "%";
         $arResult["DISCOUNT_NAME"] = "[" . $arPrice["DISCOUNT"]["ID"] . "] " . $arPrice["DISCOUNT"]["NAME"];
         $arResult['DISCOUNT_LIST'] = $arDiscountList;
         if (strlen($arPrice["DISCOUNT"]["COUPON"]) > 0) {
             $arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"];
         }
         if (!empty($arCouponList)) {
             foreach ($arCouponList as &$strOneCoupon) {
                 $mxApply = CCatalogDiscountCoupon::CouponApply($intUserID, $strOneCoupon);
             }
             if (isset($strOneCoupon)) {
                 unset($strOneCoupon);
             }
         }
     }
     if ($arCatalogProduct) {
         $arResult["WEIGHT"] = intval($arCatalogProduct["WEIGHT"]);
     }
     if (0 < $intUserID) {
         CCatalogDiscountSave::ClearDiscountUserID();
     }
     return $arResult;
 }
Ejemplo n.º 7
0
 function PreGenerateImport($profile_id)
 {
     global $DB;
     $profile_id = IntVal($profile_id);
     if ($profile_id <= 0) {
         return false;
     }
     $ar_profile = CCatalogImport::GetByID($profile_id);
     if (!$ar_profile || 'Y' == $ar_profile['NEED_EDIT']) {
         return false;
     }
     if ($ar_profile["DEFAULT_PROFILE"] != "Y") {
         parse_str($ar_profile["SETUP_VARS"]);
     }
     $bFirstLoadStep = True;
     if (!defined("CATALOG_LOAD_NO_STEP")) {
         define("CATALOG_LOAD_NO_STEP", true);
     }
     CCatalogDiscountSave::Disable();
     $strFile = CATALOG_PATH2IMPORTS . $ar_profile["FILE_NAME"] . "_run.php";
     if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
         $strFile = CATALOG_PATH2IMPORTS_DEF . $ar_profile["FILE_NAME"] . "_run.php";
         if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
             CCatalogDiscountSave::Enable();
             return false;
         }
     }
     $strImportErrorMessage = "";
     $strImportOKMessage = "";
     $bAllDataLoaded = True;
     @(include $_SERVER["DOCUMENT_ROOT"] . $strFile);
     CCatalogDiscountSave::Enable();
     CCatalogImport::Update($profile_id, array("=LAST_USE" => $DB->GetNowFunction()));
     return "CCatalogImport::PreGenerateImport(" . $profile_id . ");";
 }
Ejemplo n.º 8
0
 /**
  * @param int $intProductID
  * @param int $intIBlockID
  * @param array $arCatalogGroups
  * @param array $arUserGroups
  * @param string $strRenewal
  * @param bool|string $siteID
  * @param bool|array $arDiscountCoupons
  * @param bool $boolSKU
  * @param bool $boolGetIDS
  * @return array|false
  */
 public function GetDiscount($intProductID, $intIBlockID, $arCatalogGroups = array(), $arUserGroups = array(), $strRenewal = "N", $siteID = false, $arDiscountCoupons = false, $boolSKU = true, $boolGetIDS = false)
 {
     static $eventOnGetExists = null;
     static $eventOnResultExists = null;
     global $DB, $APPLICATION;
     self::initDiscountSettings();
     if ($eventOnGetExists === true || $eventOnGetExists === null) {
         foreach (GetModuleEvents("catalog", "OnGetDiscount", true) as $arEvent) {
             $eventOnGetExists = true;
             $mxResult = ExecuteModuleEventEx($arEvent, array($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS));
             if ($mxResult !== true) {
                 return $mxResult;
             }
         }
         if ($eventOnGetExists === null) {
             $eventOnGetExists = false;
         }
     }
     $boolSKU = $boolSKU === true;
     $boolGetIDS = $boolGetIDS === true;
     $intProductID = (int) $intProductID;
     if ($intProductID <= 0) {
         $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID");
         return false;
     }
     $intIBlockID = (int) $intIBlockID;
     if ($intIBlockID <= 0) {
         $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"), "NO_IBLOCK_ID");
         return false;
     }
     if (!is_array($arUserGroups)) {
         $arUserGroups = array($arUserGroups);
     }
     $arUserGroups[] = 2;
     if (!empty($arUserGroups)) {
         Main\Type\Collection::normalizeArrayValuesByInt($arUserGroups, true);
     }
     if (!is_array($arCatalogGroups)) {
         $arCatalogGroups = array($arCatalogGroups);
     }
     if (empty($arCatalogGroups)) {
         $catalogGroupIterator = CCatalogGroup::GetGroupsList(array('GROUP_ID' => $arUserGroups, 'BUY' => array('Y', 'N')));
         while ($catalogGroup = $catalogGroupIterator->Fetch()) {
             $arCatalogGroups[$catalogGroup['CATALOG_GROUP_ID']] = $catalogGroup['CATALOG_GROUP_ID'];
         }
         unset($catalogGroup, $catalogGroupIterator);
     }
     if (!empty($arCatalogGroups)) {
         Main\Type\Collection::normalizeArrayValuesByInt($arCatalogGroups, true);
     }
     if (empty($arCatalogGroups)) {
         return false;
     }
     $strRenewal = (string) $strRenewal == 'Y' ? 'Y' : 'N';
     if ($siteID === false) {
         $siteID = SITE_ID;
     }
     $arSKUExt = false;
     if ($boolSKU) {
         $arSKUExt = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
         $boolSKU = !empty($arSKUExt);
     }
     $arResult = array();
     $arResultID = array();
     if (self::$useSaleDiscount) {
     } else {
         $strCacheKey = md5('C' . implode('_', $arCatalogGroups) . '-' . 'U' . implode('_', $arUserGroups));
         if (!isset(self::$arCacheDiscountFilter[$strCacheKey])) {
             $arFilter = array('PRICE_TYPE_ID' => $arCatalogGroups, 'USER_GROUP_ID' => $arUserGroups);
             $arDiscountIDs = CCatalogDiscount::__GetDiscountID($arFilter);
             if (!empty($arDiscountIDs)) {
                 sort($arDiscountIDs);
             }
             self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
         } else {
             $arDiscountIDs = self::$arCacheDiscountFilter[$strCacheKey];
         }
         $arProduct = array();
         if (!empty($arDiscountIDs)) {
             if ($arDiscountCoupons === false) {
                 if (self::$existCouponsManager && Loader::includeModule('sale')) {
                     $arDiscountCoupons = DiscountCouponsManager::getForApply(array('MODULE' => 'catalog', 'DISCOUNT_ID' => $arDiscountIDs), array('MODULE' => 'catalog', 'PRODUCT_ID' => $intProductID, 'BASKET_ID' => '0'), true);
                     if (!empty($arDiscountCoupons)) {
                         $arDiscountCoupons = array_keys($arDiscountCoupons);
                     }
                 } else {
                     if (!isset($_SESSION['CATALOG_USER_COUPONS']) || !is_array($_SESSION['CATALOG_USER_COUPONS'])) {
                         $_SESSION['CATALOG_USER_COUPONS'] = array();
                     }
                     $arDiscountCoupons = $_SESSION["CATALOG_USER_COUPONS"];
                 }
             }
             if ($arDiscountCoupons === false) {
                 $arDiscountCoupons = array();
             }
             $boolGenerate = false;
             if (empty(self::$cacheDiscountHandlers)) {
                 self::$cacheDiscountHandlers = CCatalogDiscount::getDiscountHandlers($arDiscountIDs);
             } else {
                 $needDiscountHandlers = array();
                 foreach ($arDiscountIDs as &$discountID) {
                     if (!isset(self::$cacheDiscountHandlers[$discountID])) {
                         $needDiscountHandlers[] = $discountID;
                     }
                 }
                 unset($discountID);
                 if (!empty($needDiscountHandlers)) {
                     $discountHandlersList = CCatalogDiscount::getDiscountHandlers($needDiscountHandlers);
                     if (!empty($discountHandlersList)) {
                         foreach ($discountHandlersList as $discountID => $discountHandlers) {
                             self::$cacheDiscountHandlers[$discountID] = $discountHandlers;
                         }
                         unset($discountHandlers, $discountID);
                     }
                     unset($discountHandlersList);
                 }
                 unset($needDiscountHandlers);
             }
             $strCacheKey = 'D' . implode('_', $arDiscountIDs) . '-' . 'S' . $siteID . '-R' . $strRenewal;
             if (!empty($arDiscountCoupons)) {
                 $strCacheKey .= '-C' . implode('|', $arDiscountCoupons);
             }
             $strCacheKey = md5($strCacheKey);
             if (!isset(self::$arCacheDiscountResult[$strCacheKey])) {
                 $arDiscountList = array();
                 $arSelect = array('ID', 'TYPE', 'SITE_ID', 'ACTIVE', 'ACTIVE_FROM', 'ACTIVE_TO', 'RENEWAL', 'NAME', 'SORT', 'MAX_DISCOUNT', 'VALUE_TYPE', 'VALUE', 'CURRENCY', 'PRIORITY', 'LAST_DISCOUNT', 'COUPON', 'COUPON_ONE_TIME', 'COUPON_ACTIVE', 'UNPACK', 'CONDITIONS');
                 $strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
                 $discountRows = array_chunk($arDiscountIDs, 500);
                 foreach ($discountRows as &$row) {
                     $arFilter = array('@ID' => $row, 'SITE_ID' => $siteID, 'TYPE' => self::ENTITY_ID, 'RENEWAL' => $strRenewal, '+<=ACTIVE_FROM' => $strDate, '+>=ACTIVE_TO' => $strDate);
                     if (is_array($arDiscountCoupons)) {
                         $arFilter['+COUPON'] = $arDiscountCoupons;
                     }
                     CTimeZone::Disable();
                     $rsPriceDiscounts = CCatalogDiscount::GetList(array(), $arFilter, false, false, $arSelect);
                     CTimeZone::Enable();
                     while ($arPriceDiscount = $rsPriceDiscounts->Fetch()) {
                         $arPriceDiscount['HANDLERS'] = array();
                         $arPriceDiscount['MODULE_ID'] = 'catalog';
                         $arDiscountList[] = $arPriceDiscount;
                     }
                 }
                 unset($row, $discountRows);
                 self::$arCacheDiscountResult[$strCacheKey] = $arDiscountList;
             } else {
                 $arDiscountList = self::$arCacheDiscountResult[$strCacheKey];
             }
             if (!empty($arDiscountList)) {
                 $discountApply = array();
                 foreach ($arDiscountList as &$arPriceDiscount) {
                     if (!isset($discountApply[$arPriceDiscount['ID']]) && $arPriceDiscount['COUPON_ACTIVE'] != 'N') {
                         if (!$boolGenerate) {
                             if (!isset(self::$arCacheProduct[$intProductID])) {
                                 $arProduct = array('ID' => $intProductID, 'IBLOCK_ID' => $intIBlockID);
                                 if (!self::__GenerateFields($arProduct)) {
                                     return false;
                                 }
                                 if ($boolSKU) {
                                     if (!self::__GenerateParent($arProduct, $arSKUExt)) {
                                         $boolSKU = false;
                                     }
                                 }
                                 $boolGenerate = true;
                                 self::$arCacheProduct[$intProductID] = $arProduct;
                             } else {
                                 $boolGenerate = true;
                                 $arProduct = self::$arCacheProduct[$intProductID];
                             }
                         }
                         $discountApply[$arPriceDiscount['ID']] = true;
                         $applyFlag = true;
                         if (isset(self::$cacheDiscountHandlers[$arPriceDiscount['ID']])) {
                             $arPriceDiscount['HANDLERS'] = self::$cacheDiscountHandlers[$arPriceDiscount['ID']];
                             $moduleList = self::$cacheDiscountHandlers[$arPriceDiscount['ID']]['MODULES'];
                             if (!empty($moduleList)) {
                                 foreach ($moduleList as &$moduleID) {
                                     if (!isset(self::$usedModules[$moduleID])) {
                                         self::$usedModules[$moduleID] = Loader::includeModule($moduleID);
                                     }
                                     if (!self::$usedModules[$moduleID]) {
                                         $applyFlag = false;
                                         break;
                                     }
                                 }
                                 unset($moduleID);
                             }
                             unset($moduleList);
                         }
                         if ($applyFlag && CCatalogDiscount::__Unpack($arProduct, $arPriceDiscount['UNPACK'])) {
                             $arResult[] = $arPriceDiscount;
                             $arResultID[] = $arPriceDiscount['ID'];
                         }
                     }
                 }
                 if (isset($arPriceDiscount)) {
                     unset($arPriceDiscount);
                 }
                 unset($discountApply);
             }
         }
         if (!$boolGetIDS) {
             $arDiscSave = CCatalogDiscountSave::GetDiscount(array('USER_ID' => 0, 'USER_GROUPS' => $arUserGroups, 'SITE_ID' => $siteID));
             if (!empty($arDiscSave)) {
                 $arResult = !empty($arResult) ? array_merge($arResult, $arDiscSave) : $arDiscSave;
             }
         } else {
             $arResult = $arResultID;
         }
     }
     if ($eventOnResultExists === true || $eventOnResultExists === null) {
         foreach (GetModuleEvents("catalog", "OnGetDiscountResult", true) as $arEvent) {
             $eventOnResultExists = true;
             ExecuteModuleEventEx($arEvent, array(&$arResult));
         }
         if ($eventOnResultExists === null) {
             $eventOnResultExists = false;
         }
     }
     return $arResult;
 }
                    }
                    if ($res != "") {
                        $v .= ($v != '' ? ' / ' : '') . $res;
                    }
                }
                if ($v != "") {
                    $row->AddViewField("PROPERTY_" . $aProp['ID'], $v);
                }
                unset($arSelectedProps[$aProp['ID']]["CACHE"]);
            }
            foreach ($arPrices as $price) {
                $row->AddViewField("PRICE" . $price['ID'], $arPricesResult[$price['ID']][$arItems["ID"]]);
            }
        }
    }
    CCatalogDiscountSave::Enable();
    $lAdmin->BeginEpilogContent();
    ?>
	<script type="text/javascript">
	<?php 
    if (!empty($arSku)) {
        foreach ($arSku as $k => $v) {
            ?>
			if(BX('sku-<?php 
            echo $v;
            ?>
'))
				BX.hide(BX('sku-<?php 
            echo $v;
            ?>
').parentNode.parentNode);
Ejemplo n.º 10
0
define('CATALOG_NEW_OFFERS_IBLOCK_NEED','-1');

$bReadOnly = !$USER->CanDoOperation('catalog_settings');
if ($USER->CanDoOperation('catalog_read') || !$bReadOnly)
{
	Loader::includeModule('catalog');
	Loc::loadMessages(__FILE__);

	$useSaleDiscountOnly = false;
	$saleIsInstalled = ModuleManager::isModuleInstalled('sale');
	if ($saleIsInstalled)
	{
		$useSaleDiscountOnly = (string)Option::get('sale', 'use_sale_discount_only') == 'Y';
	}

	$applyDiscSaveModeList = CCatalogDiscountSave::GetApplyModeList(true);

	if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_REQUEST['RestoreDefaults']) && !$bReadOnly && check_bitrix_sessid())
	{
		if (!$USER->IsAdmin())
			$strValTmp = Option::get('catalog', 'avail_content_groups');

		Option::delete('catalog', array());
		$z = CGroup::GetList(($v1="id"),($v2="asc"), array("ACTIVE" => "Y", "ADMIN" => "N"));
		while($zr = $z->Fetch())
			$APPLICATION->DelGroupRight($module_id, array($zr["ID"]));

		if (!$USER->IsAdmin())
			Option::set('catalog', 'avail_content_groups', $strValTmp, '');
	}
Ejemplo n.º 11
0
		$arCurrencyList[$arCurrency['CURRENCY']] = $arCurrency['CURRENCY'];
	}
}

$arPeriodTypeList = CCatalogDiscountSave::GetPeriodTypeList(true);

$arUserList = array();
$arUserID = array();
$strNameFormat = CSite::GetNameFormat(true);

$arNavParams = (isset($_REQUEST["mode"]) && "excel" == $_REQUEST["mode"]
	? false
	: array("nPageSize" => CAdminResult::GetNavSize($sTableID))
);

$obDiscSave = new CCatalogDiscountSave();
$rsDiscSaves = $obDiscSave->GetList(
	array($by=>$order),
	$arFilter,
	false,
	$arNavParams,
	$arSelectFields
);

$rsDiscSaves = new CAdminResult($rsDiscSaves, $sTableID);

$rsDiscSaves->NavStart();

$lAdmin->NavText($rsDiscSaves->GetNavPrint(GetMessage("BT_CAT_DISC_SAVE_ADM_DISCOUNTS")));

$arRows = array();
Ejemplo n.º 12
0
	/**
	 * <p>Метод выполняет профиль <i>profile_id</i> на агенте.</p>
	 *
	 *
	 *
	 *
	 * @param int $profile_id  Код выполняемого профиля.
	 *
	 *
	 *
	 * @return mixed <p>В случае успешного выполнения профиля импорта метод возвращает
	 * строку для следующего вызова агента. В противном случае метод
	 * вернет <i>false</i>.</p><br><br>
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogimport/pregenerateimport.php
	 * @author Bitrix
	 */
	public static function PreGenerateImport($profile_id)
	{
		global $DB;

		$profile_id = intval($profile_id);
		if ($profile_id <= 0)
			return false;

		$ar_profile = CCatalogImport::GetByID($profile_id);
		if ((!$ar_profile) || ('Y' == $ar_profile['NEED_EDIT']))
			return false;

		$strFile = CATALOG_PATH2IMPORTS.$ar_profile["FILE_NAME"]."_run.php";
		if (!file_exists($_SERVER["DOCUMENT_ROOT"].$strFile))
		{
			$strFile = CATALOG_PATH2IMPORTS_DEF.$ar_profile["FILE_NAME"]."_run.php";
			if (!file_exists($_SERVER["DOCUMENT_ROOT"].$strFile))
			{
				CCatalogDiscountSave::Enable();
				return false;
			}
		}

		$bFirstLoadStep = true;

		if (!defined("CATALOG_LOAD_NO_STEP"))
			// define("CATALOG_LOAD_NO_STEP", true);

		$strImportErrorMessage = "";
		$strImportOKMessage = "";

		$bAllDataLoaded = true;

		$arSetupVars = array();
		$intSetupVarsCount = 0;
		if ('Y' != $ar_profile["DEFAULT_PROFILE"])
		{
			parse_str($ar_profile["SETUP_VARS"], $arSetupVars);
			if (!empty($arSetupVars) && is_array($arSetupVars))
			{
				$intSetupVarsCount = extract($arSetupVars, EXTR_SKIP);
			}
		}

		CCatalogDiscountSave::Disable();
		include($_SERVER["DOCUMENT_ROOT"].$strFile);
		CCatalogDiscountSave::Enable();

		CCatalogImport::Update($profile_id, array(
			"=LAST_USE" => $DB->GetNowFunction()
			)
		);

		return "CCatalogImport::PreGenerateImport(".$profile_id.");";
	}
Ejemplo n.º 13
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;
	}
Ejemplo n.º 14
0
$arCellTemplates = array();
$arCellTemplates[] = CUtil::JSEscape(__AddRangeCellSum('tmp_xxx', 'PREFIX', $arRange));
$arCellTemplates[] = CUtil::JSEscape(__AddRangeCellDiscount('tmp_xxx', 'PREFIX', $arRange));
$message = false;
$aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_NAME_MAIN"), "ICON" => "catalog", "TITLE" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_TITLE_MAIN")), array("DIV" => "edit2", "TAB" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_NAME_RANGES"), "ICON" => "catalog", "TITLE" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_TITLE_RANGES")), array("DIV" => "edit3", "TAB" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_NAME_GROUPS"), "ICON" => "catalog", "TITLE" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_TITLE_GROUPS")), array("DIV" => "edit4", "TAB" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_NAME_MISC"), "ICON" => "catalog", "TITLE" => GetMessage("BT_CAT_DISC_SAVE_EDIT_TAB_TITLE_MISC")));
$tabControl = new CAdminForm("cat_disc_save", $aTabs);
$ID = intval($ID);
$bVarsFromForm = false;
$arErrors = array();
$boolCopy = false;
if (0 < $ID) {
    $boolCopy = isset($_REQUEST['action']) && 'copy' == $_REQUEST['action'];
}
if ($_SERVER['REQUEST_METHOD'] == "POST" && (!empty($save) || !empty($apply)) && !$bReadOnly && check_bitrix_sessid()) {
    $APPLICATION->ResetException();
    $obDiscSave = new CCatalogDiscountSave();
    if (isset($_POST['ACTION_PERIOD'])) {
        $ACTION_PERIOD = substr(trim($_POST['ACTION_PERIOD']), 0, 1);
        if ('D' == $ACTION_PERIOD) {
            if (empty($_POST['ACTIVE_FROM']) && empty($_POST['ACTIVE_TO'])) {
                $arErrors[] = array('id' => 'ACTIVE_FROM', "text" => GetMessage('BT_CAT_DISC_SAVE_EDIT_ERR_ACTION_DATE_EMPTY'));
                $bVarsFromForm = true;
            } else {
                $_POST['ACTION_SIZE'] = 0;
                $_POST['ACTION_TYPE'] = 'Y';
                $ACTION_SIZE = 0;
                $ACTION_TYPE = 'Y';
            }
        } elseif ('P' == $ACTION_PERIOD) {
            if (0 >= intval($_POST['ACTION_SIZE']) || empty($_POST['ACTION_TYPE'])) {
                $arErrors[] = array('id' => 'ACTION_SIZE', "text" => GetMessage('BT_CAT_DISC_SAVE_EDIT_ERR_ACTION_SIZE_EMPTY'));
Ejemplo n.º 15
0
	public static function OrderProduct($arParams)
	{
		if (!is_set($arParams, "RENEWAL") || $arParams["RENEWAL"] != "Y")
			$arParams["RENEWAL"] = "N";

		if (!is_set($arParams, "USER_ID") || IntVal($arParams["USER_ID"]) <= 0)
			$arParams["USER_ID"] = 0;

		if (!is_set($arParams["SITE_ID"]))
			$arParams["SITE_ID"] = false;

		if (!is_set($arParams["CHECK_QUANTITY"]) || $arParams["CHECK_QUANTITY"] != "N")
			$arParams["CHECK_QUANTITY"] = "Y";

		global $USER;

		$productID = intval($arParams["PRODUCT_ID"]);
		$quantity = doubleval($arParams["QUANTITY"]);
		$renewal = (($arParams["RENEWAL"] == "Y") ? "Y" : "N");
		$strSiteID = $arParams["SITE_ID"];

		$intUserID = intval($arParams["USER_ID"]);
		if (0 > $intUserID)
			$intUserID = 0;

		$arResult = array();

		static $arUserCache = array();
		if (0 < $intUserID)
		{
			if (!isset($arUserCache[$intUserID]))
			{
				$by = 'ID';
				$order = 'DESC';
				$rsUsers = CUser::GetList($by, $order, array("ID_EQUAL_EXACT"=>$intUserID),array('FIELDS' => array('ID')));
				if ($arUser = $rsUsers->Fetch())
				{
					$arUser['ID'] = intval($arUser['ID']);
					$arUserCache[$arUser['ID']] = CUser::GetUserGroup($arUser['ID']);
				}
				else
				{
					$intUserID = 0;
					return $arResult;
				}
			}

			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
						"ID" => $productID,
						"ACTIVE" => "Y",
						"ACTIVE_DATE" => "Y",
						"CHECK_PERMISSION" => "N",
					),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
				);
			if(!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;

			if ('E' == CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], "RIGHTS_MODE"))
			{
				$arUserRights = CIBlockElementRights::GetUserOperations($productID,$intUserID);
				if (empty($arUserRights))
				{
					return $arResult;
				}
				elseif (!is_array($arUserRights) || !array_key_exists('element_read',$arUserRights))
				{
					return $arResult;
				}
			}
			else
			{
				if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID))
				{
					return $arResult;
				}
			}
		}
		else
		{
			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
					"ID" => $productID,
					"ACTIVE" => "Y",
					"ACTIVE_DATE" => "Y",
					"CHECK_PERMISSIONS" => "Y",
					"MIN_PERMISSION" => "R",
				),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
			);
			if(!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;
		}

		$rsProducts = CCatalogProduct::GetList(
		array(),
		array('ID' => $productID),
		false,
		false,
		array(
			'ID',
			'CAN_BUY_ZERO',
			'QUANTITY_TRACE',
			'QUANTITY',
			'WEIGHT',
			'WIDTH',
			'HEIGHT',
			'LENGTH',
			'BARCODE_MULTI',
			'TYPE'
			)
		);

		if ($arCatalogProduct = $rsProducts->Fetch())
		{
			$arCatalogProduct["QUANTITY"] = (double)$arCatalogProduct["QUANTITY"];
			if ($arParams["CHECK_QUANTITY"] == "Y")
			{
				if (
					'Y' != $arCatalogProduct["CAN_BUY_ZERO"]
					&& 'Y' == $arCatalogProduct["QUANTITY_TRACE"]
					&& ($arCatalogProduct["QUANTITY"] <= 0 || $quantity > $arCatalogProduct["QUANTITY"])
				)
				{
					return $arResult;
				}
			}
		}
		else
		{
			return $arResult;
		}

		if (0 < $intUserID)
		{
			$arCoupons = CCatalogDiscountCoupon::GetCouponsByManage($intUserID);
			CCatalogDiscountSave::SetDiscountUserID($intUserID);
		}
		else
		{
			$arCoupons = CCatalogDiscountCoupon::GetCoupons();
		}

		$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, (0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray()), $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);

		if (empty($arPrice))
		{
			if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, (0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray())))
			{
				$quantity = $nearestQuantity;
				$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, (0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray()), $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);
			}
		}

		if (empty($arPrice))
		{
			if (0 < $intUserID)
			{
				CCatalogDiscountSave::ClearDiscountUserID();
			}
			return $arResult;
		}

		$boolDiscountVat = ('N' != COption::GetOptionString('catalog', 'discount_vat', 'Y'));

		$currentPrice = $arPrice["PRICE"]["PRICE"];
		$currentDiscount = 0.0;

		if ($boolDiscountVat)
		{
			if ('N' == $arPrice['PRICE']['VAT_INCLUDED'])
			{
				$currentPrice *= (1 + $arPrice['PRICE']['VAT_RATE']);
				$arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
			}
		}
		else
		{
			if ('Y' == $arPrice['PRICE']['VAT_INCLUDED'])
			{
				$currentPrice /= (1 + $arPrice['PRICE']['VAT_RATE']);
				$arPrice['PRICE']['VAT_INCLUDED'] = 'N';
			}
		}

		$arDiscountList = array();
		$arCouponList = array();

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			$dblStartPrice = $currentPrice;

			foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount)
			{
				switch ($arOneDiscount['VALUE_TYPE'])
				{
				case CCatalogDiscount::TYPE_FIX:
					if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"])
						$currentDiscount = $arOneDiscount['VALUE'];
					else
						$currentDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount["VALUE"], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
					$currentPrice = $currentPrice - $currentDiscount;
					break;
				case CCatalogDiscount::TYPE_PERCENT:
					$currentDiscount = $currentPrice*$arOneDiscount["VALUE"]/100.0;
					if (0 < $arOneDiscount['MAX_DISCOUNT'])
					{
						if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"])
							$dblMaxDiscount = $arOneDiscount['MAX_DISCOUNT'];
						else
							$dblMaxDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount['MAX_DISCOUNT'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);;
						if ($currentDiscount > $dblMaxDiscount)
							$currentDiscount = $dblMaxDiscount;
					}
					$currentPrice = $currentPrice - $currentDiscount;
					break;
				case CCatalogDiscount::TYPE_SALE:
					if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"])
						$currentPrice = $arOneDiscount['VALUE'];
					else
						$currentPrice = CCurrencyRates::ConvertCurrency($arOneDiscount['VALUE'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
					break;
				}

				$arOneList = array(
					'ID' => $arOneDiscount['ID'],
					'NAME' => $arOneDiscount['NAME'],
					'COUPON' => '',
					'COUPON_TYPE' => '',
					'MODULE_ID' => 'catalog',
					'TYPE' => $arOneDiscount['TYPE'],
					'VALUE' => $arOneDiscount['VALUE'],
					'VALUE_TYPE' => $arOneDiscount['VALUE_TYPE'],
					'CURRENCY' => $arOneDiscount['CURRENCY'],
					'HANDLERS' => (isset($arOneDiscount['HANDLERS']) ? $arOneDiscount['HANDLERS'] : array())
				);

				if ($arOneDiscount['COUPON'])
				{
					$arOneList['COUPON'] = $arOneDiscount['COUPON'];
					$arOneList['COUPON_TYPE'] = $arOneDiscount['COUPON_ONE_TIME'];
					$arCouponList[] = $arOneDiscount['COUPON'];
				}

				$arDiscountList[] = $arOneList;
			}
			if (isset($arOneDiscount))
				unset($arOneDiscount);

			$currentDiscount = $dblStartPrice - $currentPrice;
		}

		if (empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"]))
		{
			if (!empty($arPrice["PRICE"]["CATALOG_GROUP_ID"]))
			{
				$rsCatGroups = CCatalogGroup::GetListEx(array(),array('ID' => $arPrice["PRICE"]["CATALOG_GROUP_ID"]),false,false,array('ID','NAME','NAME_LANG'));
				if ($arCatGroup = $rsCatGroups->Fetch())
				{
					$arPrice["PRICE"]["CATALOG_GROUP_NAME"] = (!empty($arCatGroup['NAME_LANG']) ? $arCatGroup['NAME_LANG'] : $arCatGroup['NAME']);
				}
			}
		}

		if (!$boolDiscountVat)
		{
			$currentPrice *= (1 + $arPrice['PRICE']['VAT_RATE']);
			$currentDiscount *= (1 + $arPrice['PRICE']['VAT_RATE']);
			$arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
		}


		$arResult = array(
			"PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"],
			"PRICE" => $currentPrice,
			"VAT_RATE" => $arPrice['PRICE']['VAT_RATE'],
			"CURRENCY" => $arPrice["PRICE"]["CURRENCY"],
			"WEIGHT" => floatval($arCatalogProduct["WEIGHT"]),
			"DIMENSIONS" => serialize(array(
				"WIDTH" => $arCatalogProduct["WIDTH"],
				"HEIGHT" => $arCatalogProduct["HEIGHT"],
				"LENGTH" => $arCatalogProduct["LENGTH"]
			)),
			"NAME" => $arProduct["~NAME"],
			"CAN_BUY" => "Y",
			"DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'],
			"NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"],
			"DISCOUNT_PRICE" => $currentDiscount,
			"TYPE" => ($arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET) ? CCatalogProductSet::TYPE_SET : NULL,
			"DISCOUNT_VALUE" => 0,
			"DISCOUNT_NAME" => "",
			"DISCOUNT_COUPON" => "",
			"DISCOUNT_LIST" => array()
		);

		if ($arParams["CHECK_QUANTITY"] == "Y")
			$arResult["QUANTITY"] = $quantity;
		else
			$arResult["QUANTITY"] = $arParams["QUANTITY"];

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			$arResult['DISCOUNT_LIST'] = $arDiscountList;
			$arResult["DISCOUNT_VALUE"] = (100*$currentDiscount/($currentDiscount+$currentPrice))."%";
			$arResult["DISCOUNT_NAME"] = "[".$arPrice["DISCOUNT"]["ID"]."] ".$arPrice["DISCOUNT"]["NAME"];

			if (!empty($arPrice["DISCOUNT"]["COUPON"]))
			{
				$arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"];
			}

			if (!empty($arCouponList))
			{
				$mxApply = CCatalogDiscountCoupon::CouponApply($intUserID, $arCouponList);
			}
		}

		if (0 < $intUserID)
		{
			CCatalogDiscountSave::ClearDiscountUserID();
		}
		return $arResult;
	}
Ejemplo n.º 16
0
    $arParams['USER_ID'] = intval($USER->GetID());
}
if (0 >= $arParams['USER_ID']) {
    return;
}
$arParams['SHOW_NEXT_LEVEL'] = isset($arParams['SHOW_NEXT_LEVEL']) && 'Y' == $arParams['SHOW_NEXT_LEVEL'] ? 'Y' : 'N';
if (!CModule::IncludeModule('catalog')) {
    return;
}
if (!CBXFeatures::IsFeatureEnabled('CatDiscountSave')) {
    CCatalogDiscountSave::Disable();
    ShowError(GetMessage("CAT_FEATURE_NOT_ALLOW"));
    return;
}
$arFields = array('USER_ID' => $arParams['USER_ID'], 'SITE_ID' => $arParams['SITE_ID']);
$arResult = CCatalogDiscountSave::GetDiscount($arFields);
if (!empty($arResult)) {
    foreach ($arResult as $key => $arDiscountSave) {
        if ('Y' == $arParams['SHOW_NEXT_LEVEL']) {
            $rsRanges = CCatalogDiscountSave::GetRangeByDiscount(array('RANGE_FROM' => 'ASC'), array('DISCOUNT_ID' => $arDiscountSave['ID'], '>RANGE_FROM' => $arDiscountSave['RANGE_FROM'], false, array('nTopCount' => 1)));
            if ($arRange = $rsRanges->Fetch()) {
                $arTempo = array('RANGE_FROM' => $arRange['RANGE_FROM'], 'VALUE' => $arRange['VALUE'], 'VALUE_TYPE' => $arRange['TYPE']);
                $arDiscountSave['NEXT_LEVEL'] = $arTempo;
            }
        }
        $arDiscountSave['~NAME'] = $arDiscountSave['NAME'];
        $arDiscountSave['NAME'] = htmlspecialcharsex($arDiscountSave['NAME']);
        $arResult[$key] = $arDiscountSave;
    }
}
$this->IncludeComponentTemplate();
Ejemplo n.º 17
0
	static public function GetDiscount($intProductID, $intIBlockID, $arCatalogGroups = array(), $arUserGroups = array(), $strRenewal = "N", $siteID = false, $arDiscountCoupons = false, $boolSKU = true, $boolGetIDS = false)
	{
		global $DB;
		global $APPLICATION;
		global $stackCacheManager;

		foreach (GetModuleEvents("catalog", "OnGetDiscount", true) as $arEvent)
		{
			$mxResult = ExecuteModuleEventEx($arEvent, array($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS));
			if (true !== $mxResult)
				return $mxResult;
		}

		$boolSKU = (true === $boolSKU ? true : false);
		$boolGetIDS = (true === $boolGetIDS ? true : false);

		$intProductID = intval($intProductID);
		if (0 >= $intProductID)
		{
			$APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID");
			return false;
		}

		$intIBlockID = intval($intIBlockID);
		if (0 >= $intIBlockID)
		{
			$APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"), "NO_IBLOCK_ID");
			return false;
		}

		if (!empty($arCatalogGroups))
		{
			if (!is_array($arCatalogGroups))
			{
				$arCatalogGroups = (intval($arCatalogGroups)."|" == $arCatalogGroups."|" ? array($arCatalogGroups) : array());
			}
		}
		else
		{
			$arCatalogGroups = array();
		}
		if (!empty($arCatalogGroups))
		{
			CatalogClearArray($arCatalogGroups);
		}

		if (!is_array($arUserGroups))
		{
			$arUserGroups = (intval($arUserGroups)."|" == $arUserGroups."|" ? array($arUserGroups) : array());
		}
		$arUserGroups[] = 2;
		if (!empty($arUserGroups))
		{
			CatalogClearArray($arUserGroups);
		}

		$strRenewal = (($strRenewal == "Y") ? "Y" : "N");

		if ($siteID === false)
			$siteID = SITE_ID;

		if ($arDiscountCoupons === false)
			$arDiscountCoupons = CCatalogDiscountCoupon::GetCoupons();

		$arSKU = false;

		$arResult = array();
		$arResultID = array();

		$strCacheKey = md5('C'.implode('_', $arCatalogGroups).'-'.'U'.implode('_', $arUserGroups));
		if (!array_key_exists($strCacheKey, self::$arCacheDiscountFilter))
		{
			$arFilter = array(
				'PRICE_TYPE_ID' => $arCatalogGroups,
				'USER_GROUP_ID' => $arUserGroups,
			);
			$arDiscountIDs = CCatalogDiscount::__GetDiscountID($arFilter);
			if (!empty($arDiscountIDs))
			{
				sort($arDiscountIDs);
			}
			self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
		}
		else
		{
			$arDiscountIDs = self::$arCacheDiscountFilter[$strCacheKey];
		}

		$arProduct = array();

		if (!empty($arDiscountIDs))
		{
			$boolGenerate = false;

			$strCacheKey = 'D'.implode('_', $arDiscountIDs).'-'.'S'.$siteID.'-R'.$strRenewal;
			if (!empty($arDiscountCoupons))
			{
				$strCacheKey .= '-C'.implode('|', $arDiscountCoupons);
			}
			$strCacheKey = md5($strCacheKey);

			if (!array_key_exists($strCacheKey, self::$arCacheDiscountResult))
			{
				$arSelect = array(
					"ID", "TYPE", "SITE_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO",
					"RENEWAL", "NAME", "SORT", "MAX_DISCOUNT", "VALUE_TYPE", "VALUE", "CURRENCY",
					"PRIORITY", "LAST_DISCOUNT",
					"COUPON", "COUPON_ONE_TIME", "COUPON_ACTIVE", 'UNPACK'
				);
				$strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
				$arFilter = array(
					"ID" => $arDiscountIDs,
					"SITE_ID" => $siteID,
					"TYPE" => DISCOUNT_TYPE_STANDART,
					"ACTIVE" => "Y",
					"RENEWAL" => $strRenewal,
					"+<=ACTIVE_FROM" => $strDate,
					"+>=ACTIVE_TO" => $strDate,
				);

				if (is_array($arDiscountCoupons))
				{
					$arFilter["+COUPON"] = $arDiscountCoupons;
				}

				$arDiscountList = array();

				$rsPriceDiscounts = CCatalogDiscount::GetList(
					array(),
					$arFilter,
					false,
					false,
					$arSelect
				);

				while ($arPriceDiscount = $rsPriceDiscounts->Fetch())
				{
					$arDiscountList[] = $arPriceDiscount;
				}
				self::$arCacheDiscountResult[$strCacheKey] = $arDiscountList;
			}
			else
			{
				$arDiscountList = self::$arCacheDiscountResult[$strCacheKey];
			}

			if (!empty($arDiscountList))
			{
				foreach ($arDiscountList as &$arPriceDiscount)
				{
					if ($arPriceDiscount['COUPON_ACTIVE'] != 'N')
					{
						if (!$boolGenerate)
						{
							if (!array_key_exists($intProductID, self::$arCacheProduct))
							{
								$arProduct = array('ID' => $intProductID, 'IBLOCK_ID' => $intIBlockID);
								if (!self::__GenerateFields($arProduct))
									return false;
								$boolGenerate = true;
								self::$arCacheProduct[$intProductID] = $arProduct;
							}
							else
							{
								$arProduct = self::$arCacheProduct[$intProductID];
							}
						}
						if (CCatalogDiscount::__Unpack($arProduct, $arPriceDiscount['UNPACK']))
						{
							unset($arPriceDiscount['UNPACK']);
							$arResult[] = $arPriceDiscount;
							$arResultID[] = $arPriceDiscount['ID'];
						}
					}
				}
				if (isset($arPriceDiscount))
					unset($arPriceDiscount);
			}
		}

		if ($boolSKU)
		{
			$boolSKU = false;
			$arSKU = false;
			$arSKUExt = false;
			$arSKUExt = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
			if (!empty($arSKUExt) && is_array($arSKUExt) && 0 < intval($arSKUExt['SKU_PROPERTY_ID']) && 0 < intval($arSKUExt['PRODUCT_IBLOCK_ID']))
			{
				if (array_key_exists('PROPERTY_'.$arSKUExt['SKU_PROPERTY_ID'].'_VALUE', $arProduct))
				{
					$arVal = $arProduct['PROPERTY_'.$arSKUExt['SKU_PROPERTY_ID'].'_VALUE'];
					$arSKU = array(
						'ID' => $arVal[0],
						'IBLOCK_ID' => $arSKUExt['PRODUCT_IBLOCK_ID'],
					);
					$boolSKU = true;
				}
			}
		}
		if ($boolSKU)
		{
			$arDiscountParent = CCatalogDiscount::GetDiscount($arSKU['ID'], $arSKU['IBLOCK_ID'], $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, false, false);
			if (!empty($arDiscountParent))
			{
				if (empty($arResult))
				{
					$arResult = $arDiscountParent;
				}
				else
				{
					foreach ($arDiscountParent as &$arOneParentDiscount)
					{
						if (in_array($arOneParentDiscount['ID'], $arResultID))
							continue;
						$arResult[] = $arOneParentDiscount;
						$arResultID[] = $arOneParentDiscount['ID'];
					}
					if (isset($arOneParentDiscount))
						unset($arOneParentDiscount);
				}
			}
		}

		if (!$boolGetIDS)
		{
			$arDiscSave = CCatalogDiscountSave::GetDiscount(array(
				'USER_ID' => 0,
				'USER_GROUPS' => $arUserGroups,
				'SITE_ID' => $siteID
			));
			if (!empty($arDiscSave))
			{
				$arResult = (!empty($arResult) ? array_merge($arResult, $arDiscSave) : $arDiscSave);
			}
		}
		else
		{
			$arResult = $arResultID;
		}

		foreach (GetModuleEvents("catalog", "OnGetDiscountResult", true) as $arEvent)
		{
			ExecuteModuleEventEx($arEvent, array(&$arResult));
		}

		return $arResult;
	}
Ejemplo n.º 18
0
function CatalogGetPriceTable($ID)
{
    global $USER;
    $ID = (int) $ID;
    if ($ID <= 0) {
        return false;
    }
    $arResult = array();
    $arPriceGroups = array();
    $cacheKey = LANGUAGE_ID . "_" . $USER->GetGroups();
    if (isset($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"]) && is_array($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"]) && isset($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey]) && is_array($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey])) {
        $arPriceGroups = $GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey];
    } else {
        $dbPriceGroupsList = CCatalogGroup::GetList(array("SORT" => "ASC"), array("CAN_ACCESS" => "Y", "LID" => LANGUAGE_ID), array("ID", "NAME_LANG", "SORT"), false, array("ID", "NAME_LANG", "CAN_BUY", "SORT"));
        while ($arPriceGroupsList = $dbPriceGroupsList->Fetch()) {
            $arPriceGroups[] = $arPriceGroupsList;
            $GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey][] = $arPriceGroupsList;
        }
    }
    if (empty($arPriceGroups)) {
        return false;
    }
    $arBorderMap = array();
    $arPresentGroups = array();
    $bMultiQuantity = False;
    $dbPrice = CPrice::GetList(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), array("PRODUCT_ID" => $ID), false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO", "ELEMENT_IBLOCK_ID", "SORT"));
    while ($arPrice = $dbPrice->Fetch()) {
        CCatalogDiscountSave::Disable();
        $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arPrice["ELEMENT_IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $USER->GetUserGroupArray(), "N", SITE_ID, array());
        CCatalogDiscountSave::Enable();
        $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts);
        $arPrice["DISCOUNT_PRICE"] = $discountPrice;
        if (array_key_exists($arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"], $arBorderMap)) {
            $jnd = $arBorderMap[$arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"]];
        } else {
            $jnd = count($arBorderMap);
            $arBorderMap[$arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"]] = $jnd;
        }
        $arResult[$jnd]["QUANTITY_FROM"] = DoubleVal($arPrice["QUANTITY_FROM"]);
        $arResult[$jnd]["QUANTITY_TO"] = DoubleVal($arPrice["QUANTITY_TO"]);
        if (DoubleVal($arPrice["QUANTITY_FROM"]) > 0 || DoubleVal($arPrice["QUANTITY_TO"]) > 0) {
            $bMultiQuantity = True;
        }
        $arResult[$jnd]["PRICE"][$arPrice["CATALOG_GROUP_ID"]] = $arPrice;
    }
    $numGroups = count($arPriceGroups);
    for ($i = 0; $i < $numGroups; $i++) {
        $bNeedKill = True;
        for ($j = 0, $intCount = count($arResult); $j < $intCount; $j++) {
            if (!array_key_exists($arPriceGroups[$i]["ID"], $arResult[$j]["PRICE"])) {
                $arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]] = False;
            }
            if ($arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]] != false) {
                $bNeedKill = False;
            }
        }
        if ($bNeedKill) {
            for ($j = 0, $intCount = count($arResult); $j < $intCount; $j++) {
                unset($arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]]);
            }
            unset($arPriceGroups[$i]);
        }
    }
    return array("COLS" => $arPriceGroups, "MATRIX" => $arResult, "MULTI_QUANTITY" => $bMultiQuantity ? "Y" : "N");
}
Ejemplo n.º 19
0
	/**
	 * @param array $arParams
	 * @return array|false
	 */
	public static function OrderProduct($arParams)
	{
		$arParams['RENEWAL'] = (isset($arParams['RENEWAL']) && $arParams['RENEWAL'] == 'Y' ? 'Y' : 'N');
		$arParams['CHECK_QUANTITY'] = (isset($arParams['CHECK_QUANTITY']) && $arParams['CHECK_QUANTITY'] == 'N' ? 'N' : 'Y');
		$arParams['CHECK_DISCOUNT'] = (isset($arParams['CHECK_DISCOUNT']) && $arParams['CHECK_DISCOUNT'] == 'N' ? 'N' : 'Y');
		$arParams['USER_ID'] = (isset($arParams['USER_ID']) ? (int)$arParams['USER_ID'] : 0);
		if ($arParams['USER_ID'] < 0)
			$arParams['USER_ID'] = 0;
		$arParams['SITE_ID'] = (isset($arParams['SITE_ID']) ? $arParams['SITE_ID'] : false);
		$strSiteID = $arParams['SITE_ID'];
		$arParams['BASKET_ID'] = (string)(isset($arParams['BASKET_ID']) ? $arParams['BASKET_ID'] : '0');

		if (isset($arParams['CURRENCY']))
			$arParams['CURRENCY'] = CCurrency::checkCurrencyID($arParams['CURRENCY']);
		if ($arParams['CURRENCY'] === false)
			$arParams['CURRENCY'] = CSaleLang::GetLangCurrency($strSiteID ? $strSiteID : SITE_ID);

		global $USER;

		$productID = (int)$arParams['PRODUCT_ID'];
		$quantity = (float)$arParams['QUANTITY'];
		$renewal = $arParams['RENEWAL'];

		$intUserID = (int)$arParams['USER_ID'];

		$arResult = array();

		static $arUserCache = array();
		if (0 < $intUserID)
		{
			if (!isset($arUserCache[$intUserID]))
			{
				$by = 'ID';
				$order = 'DESC';
				$rsUsers = CUser::GetList($by, $order, array("ID_EQUAL_EXACT"=>$intUserID),array('FIELDS' => array('ID')));
				if ($arUser = $rsUsers->Fetch())
				{
					$arUser['ID'] = intval($arUser['ID']);
					$arUserCache[$arUser['ID']] = CUser::GetUserGroup($arUser['ID']);
				}
				else
				{
					$intUserID = 0;
					return $arResult;
				}
			}

			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
						"ID" => $productID,
						"ACTIVE" => "Y",
						"ACTIVE_DATE" => "Y",
						"CHECK_PERMISSION" => "N",
					),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
				);
			if(!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;

			if ('E' == CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], "RIGHTS_MODE"))
			{
				$arUserRights = CIBlockElementRights::GetUserOperations($productID,$intUserID);
				if (empty($arUserRights))
				{
					return $arResult;
				}
				elseif (!is_array($arUserRights) || !array_key_exists('element_read',$arUserRights))
				{
					return $arResult;
				}
			}
			else
			{
				if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID))
				{
					return $arResult;
				}
			}
		}
		else
		{
			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
					"ID" => $productID,
					"ACTIVE" => "Y",
					"ACTIVE_DATE" => "Y",
					"CHECK_PERMISSIONS" => "Y",
					"MIN_PERMISSION" => "R",
				),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
			);
			if(!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;
		}

		$rsProducts = CCatalogProduct::GetList(
		array(),
		array('ID' => $productID),
		false,
		false,
		array(
			'ID',
			'CAN_BUY_ZERO',
			'QUANTITY_TRACE',
			'QUANTITY',
			'WEIGHT',
			'WIDTH',
			'HEIGHT',
			'LENGTH',
			'BARCODE_MULTI',
			'TYPE'
			)
		);

		if ($arCatalogProduct = $rsProducts->Fetch())
		{
			$arCatalogProduct["QUANTITY"] = (double)$arCatalogProduct["QUANTITY"];
			if ($arParams["CHECK_QUANTITY"] == "Y")
			{
				if (
					'Y' != $arCatalogProduct["CAN_BUY_ZERO"]
					&& 'Y' == $arCatalogProduct["QUANTITY_TRACE"]
					&& ($arCatalogProduct["QUANTITY"] <= 0 || $quantity > $arCatalogProduct["QUANTITY"])
				)
				{
					return $arResult;
				}
			}
		}
		else
		{
			return $arResult;
		}

		if (0 < $intUserID)
		{
			$arCoupons = CCatalogDiscountCoupon::GetCouponsByManage($intUserID);
			CCatalogDiscountSave::SetDiscountUserID($intUserID);
		}
		else
		{
			$arCoupons = CCatalogDiscountCoupon::GetCoupons();
		}

		$userGroups = ($intUserID > 0 ? $arUserCache[$intUserID] : $USER->GetUserGroupArray());
		$currentVatMode = CCatalogProduct::getPriceVatIncludeMode();
		$currentUseDiscount = CCatalogProduct::getUseDiscount();
		CCatalogProduct::setUseDiscount($arParams['CHECK_DISCOUNT'] == 'Y');
		CCatalogProduct::setPriceVatIncludeMode(true);
		CCatalogProduct::setUsedCurrency($arParams['CURRENCY']);
		$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);

		if (empty($arPrice))
		{
			if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $userGroups))
			{
				$quantity = $nearestQuantity;
				$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);
			}
		}
		CCatalogProduct::clearUsedCurrency();
		CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
		CCatalogProduct::setUseDiscount($currentUseDiscount);
		unset($userGroups, $currentUseDiscount, $currentVatMode);
		if (0 < $intUserID)
		{
			CCatalogDiscountSave::ClearDiscountUserID();
		}

		if (empty($arPrice))
		{
			return $arResult;
		}

		$arDiscountList = array();
		$arCouponList = array();

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount)
			{
				$arOneList = array(
					'ID' => $arOneDiscount['ID'],
					'NAME' => $arOneDiscount['NAME'],
					'COUPON' => '',
					'COUPON_TYPE' => '',
					'MODULE_ID' => (isset($oneDiscount['MODULE_ID']) ? $oneDiscount['MODULE_ID'] : 'catalog'),
					'TYPE' => $arOneDiscount['TYPE'],
					'VALUE' => $arOneDiscount['VALUE'],
					'VALUE_TYPE' => $arOneDiscount['VALUE_TYPE'],
					'CURRENCY' => $arOneDiscount['CURRENCY'],
					'HANDLERS' => (isset($arOneDiscount['HANDLERS']) ? $arOneDiscount['HANDLERS'] : array())
				);

				if ($arOneDiscount['COUPON'])
				{
					$arOneList['COUPON'] = $arOneDiscount['COUPON'];
					$arOneList['COUPON_TYPE'] = $arOneDiscount['COUPON_ONE_TIME'];
					$arCouponList[] = $arOneDiscount['COUPON'];
				}

				$arDiscountList[] = $arOneList;
			}
			unset($arOneList, $arOneDiscount);
		}

		if (empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"]))
		{
			if (!empty($arPrice["PRICE"]["CATALOG_GROUP_ID"]))
			{
				$rsCatGroups = CCatalogGroup::GetListEx(array(),array('ID' => $arPrice["PRICE"]["CATALOG_GROUP_ID"]),false,false,array('ID','NAME','NAME_LANG'));
				if ($arCatGroup = $rsCatGroups->Fetch())
				{
					$arPrice["PRICE"]["CATALOG_GROUP_NAME"] = (!empty($arCatGroup['NAME_LANG']) ? $arCatGroup['NAME_LANG'] : $arCatGroup['NAME']);
				}
			}
		}

		$arResult = array(
			"PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"],
			'BASE_PRICE' => $arPrice['RESULT_PRICE']['BASE_PRICE'],
			"PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'],
			"VAT_RATE" => $arPrice['PRICE']['VAT_RATE'],
			"CURRENCY" => $arPrice['RESULT_PRICE']['CURRENCY'],
			"WEIGHT" => (float)$arCatalogProduct["WEIGHT"],
			"DIMENSIONS" => serialize(array(
				"WIDTH" => $arCatalogProduct["WIDTH"],
				"HEIGHT" => $arCatalogProduct["HEIGHT"],
				"LENGTH" => $arCatalogProduct["LENGTH"]
			)),
			"NAME" => $arProduct["~NAME"],
			"CAN_BUY" => "Y",
			"DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'],
			"NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"],
			"DISCOUNT_PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT'],
			"TYPE" => ($arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET) ? CCatalogProductSet::TYPE_SET : NULL,
			"DISCOUNT_VALUE" => ($arPrice['RESULT_PRICE']['PERCENT'] > 0 ? $arPrice['RESULT_PRICE']['PERCENT'].'%' : 0),
			"DISCOUNT_NAME" => "",
			"DISCOUNT_COUPON" => "",
			"DISCOUNT_LIST" => array()
		);

		if ($arParams["CHECK_QUANTITY"] == "Y")
			$arResult["QUANTITY"] = $quantity;
		else
			$arResult["QUANTITY"] = $arParams["QUANTITY"];

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			$arResult['DISCOUNT_LIST'] = $arDiscountList;
			$arResult["DISCOUNT_NAME"] = "[".$arPrice["DISCOUNT"]["ID"]."] ".$arPrice["DISCOUNT"]["NAME"];

			if (!empty($arPrice["DISCOUNT"]["COUPON"]))
			{
				$arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"];
			}

			if (!empty($arCouponList))
			{
				$mxApply = CCatalogDiscountCoupon::CouponApply($intUserID, $arCouponList);
			}
		}

		return $arResult;
	}
Ejemplo n.º 20
0
 /**
  * @param array $arParams
  * @return array|false
  */
 public static function OrderProduct($arParams)
 {
     $adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true;
     $arParams['RENEWAL'] = isset($arParams['RENEWAL']) && $arParams['RENEWAL'] == 'Y' ? 'Y' : 'N';
     $arParams['CHECK_QUANTITY'] = isset($arParams['CHECK_QUANTITY']) && $arParams['CHECK_QUANTITY'] == 'N' ? 'N' : 'Y';
     $arParams['CHECK_DISCOUNT'] = isset($arParams['CHECK_DISCOUNT']) && $arParams['CHECK_DISCOUNT'] == 'N' ? 'N' : 'Y';
     $arParams['USER_ID'] = isset($arParams['USER_ID']) ? (int) $arParams['USER_ID'] : 0;
     if ($arParams['USER_ID'] < 0) {
         $arParams['USER_ID'] = 0;
     }
     $arParams['SITE_ID'] = isset($arParams['SITE_ID']) ? $arParams['SITE_ID'] : false;
     $strSiteID = $arParams['SITE_ID'];
     $arParams['BASKET_ID'] = (string) (isset($arParams['BASKET_ID']) ? $arParams['BASKET_ID'] : '0');
     $arParams['CURRENCY'] = isset($arParams['CURRENCY']) ? Currency\CurrencyManager::checkCurrencyID($arParams['CURRENCY']) : false;
     if ($arParams['CURRENCY'] === false) {
         $arParams['CURRENCY'] = CSaleLang::GetLangCurrency($strSiteID ? $strSiteID : SITE_ID);
     }
     global $USER;
     $productID = (int) $arParams['PRODUCT_ID'];
     $quantity = (double) $arParams['QUANTITY'];
     $intUserID = (int) $arParams['USER_ID'];
     $arResult = array();
     if ($adminSection) {
         if ($intUserID == 0) {
             return $arResult;
         }
         if (!($userGroups = static::getHitCache('USER_GROUPS', $intUserID))) {
             $userGroups = self::getUserGroups($intUserID);
             static::setHitCache('USER_GROUPS', $intUserID, $userGroups);
         }
         if (empty($userGroups)) {
             return $arResult;
         }
         if (!($arProduct = static::getHitCache('IBLOCK_ELEMENT_PERM_N', $productID))) {
             $dbIBlockElement = CIBlockElement::GetList(array(), array('ID' => $productID, 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'CHECK_PERMISSION' => 'N'), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
             if ($arProduct = $dbIBlockElement->GetNext()) {
                 static::setHitCache('IBLOCK_ELEMENT_PERM_N', $productID, $arProduct);
             }
             unset($dbIBlockElement);
         }
         if (empty($arProduct) || !is_array($arProduct)) {
             return $arResult;
         }
         $iblockRightByID = null;
         if (!($iblockRightByID = static::getHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID']))) {
             if ($iblockRightByID = CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'RIGHTS_MODE')) {
                 static::setHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID'], $iblockRightByID);
             }
         }
         if ($iblockRightByID == 'E') {
             $proxyUserPermissionKey = $productID . "|" . $intUserID;
             if (!($arUserRights = static::getHitCache('USER_RIGHT', $proxyUserPermissionKey))) {
                 if ($arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID)) {
                     static::setHitCache('USER_RIGHT', $proxyUserPermissionKey, $arUserRights);
                 }
             }
             if (empty($arUserRights) || !isset($arUserRights['element_read'])) {
                 return $arResult;
             }
             unset($arUserRights);
         } else {
             $proxyIblockPermissionKey = $arProduct['IBLOCK_ID'] . "|" . $intUserID;
             if (!($iblockPermissions = static::getHitCache('IBLOCK_PERM', $proxyIblockPermissionKey))) {
                 if ($iblockPermissions = CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID)) {
                     static::setHitCache('IBLOCK_PERM', $proxyIblockPermissionKey, $iblockPermissions);
                 }
             }
             if ($iblockPermissions < 'R') {
                 return $arResult;
             }
         }
     } else {
         $userGroups = $USER->GetUserGroupArray();
         if (!($arProduct = static::getHitCache('IBLOCK_ELEMENT_PERM_Y', $productID))) {
             $dbIBlockElement = CIBlockElement::GetList(array(), array('ID' => $productID, 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'R'), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
             if ($arProduct = $dbIBlockElement->GetNext()) {
                 static::setHitCache('IBLOCK_ELEMENT_PERM_Y', $productID, $arProduct);
             }
             unset($dbIBlockElement);
         }
         if (empty($arProduct) || !is_array($arProduct)) {
             return $arResult;
         }
     }
     if (!($arCatalogProduct = static::getHitCache('CATALOG_PRODUCT', $productID))) {
         $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $productID), false, false, array('ID', 'CAN_BUY_ZERO', 'QUANTITY_TRACE', 'QUANTITY', 'WEIGHT', 'WIDTH', 'HEIGHT', 'LENGTH', 'BARCODE_MULTI', 'TYPE'));
         if ($arCatalogProduct = $rsProducts->Fetch()) {
             static::setHitCache('CATALOG_PRODUCT', $productID, $arCatalogProduct);
         }
         unset($rsProducts);
     }
     if (!empty($arCatalogProduct) && is_array($arCatalogProduct)) {
         $arCatalogProduct["QUANTITY"] = (double) $arCatalogProduct["QUANTITY"];
         if ($arParams["CHECK_QUANTITY"] == "Y") {
             if ('Y' != $arCatalogProduct["CAN_BUY_ZERO"] && 'Y' == $arCatalogProduct["QUANTITY_TRACE"] && ($arCatalogProduct["QUANTITY"] <= 0 || $quantity > $arCatalogProduct["QUANTITY"])) {
                 return $arResult;
             }
         }
     } else {
         return $arResult;
     }
     if ($adminSection) {
         CCatalogDiscountSave::SetDiscountUserID($intUserID);
     }
     $productHash = array('MODULE' => 'catalog', 'PRODUCT_ID' => $productID, 'BASKET_ID' => $arParams['BASKET_ID']);
     $arCoupons = DiscountCouponsManager::getForApply(array(), $productHash, true);
     if (!empty($arCoupons)) {
         $arCoupons = array_keys($arCoupons);
     }
     $currentVatMode = CCatalogProduct::getPriceVatIncludeMode();
     $currentUseDiscount = CCatalogProduct::getUseDiscount();
     CCatalogProduct::setUseDiscount($arParams['CHECK_DISCOUNT'] == 'Y');
     CCatalogProduct::setPriceVatIncludeMode(true);
     CCatalogProduct::setUsedCurrency($arParams['CURRENCY']);
     $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $arParams['RENEWAL'], array(), $adminSection ? $strSiteID : false, $arCoupons);
     if (empty($arPrice)) {
         if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $userGroups)) {
             $quantity = $nearestQuantity;
             $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $arParams['RENEWAL'], array(), $adminSection ? $strSiteID : false, $arCoupons);
         }
     }
     CCatalogProduct::clearUsedCurrency();
     CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
     CCatalogProduct::setUseDiscount($currentUseDiscount);
     unset($userGroups, $currentUseDiscount, $currentVatMode);
     if ($adminSection) {
         CCatalogDiscountSave::ClearDiscountUserID();
     }
     if (empty($arPrice)) {
         return $arResult;
     }
     $arDiscountList = array();
     if (empty($arPrice['DISCOUNT_LIST']) && !empty($arPrice['DISCOUNT']) && is_array($arPrice['DISCOUNT'])) {
         $arPrice['DISCOUNT_LIST'] = array($arPrice['DISCOUNT']);
     }
     if (!empty($arPrice['DISCOUNT_LIST'])) {
         $appliedCoupons = array();
         foreach ($arPrice['DISCOUNT_LIST'] as &$arOneDiscount) {
             $arOneList = array('ID' => $arOneDiscount['ID'], 'NAME' => $arOneDiscount['NAME'], 'COUPON' => '', 'COUPON_TYPE' => '', 'USE_COUPONS' => isset($arOneDiscount['USE_COUPONS']) ? $arOneDiscount['USE_COUPONS'] : 'N', 'MODULE_ID' => isset($oneDiscount['MODULE_ID']) ? $oneDiscount['MODULE_ID'] : 'catalog', 'TYPE' => $arOneDiscount['TYPE'], 'VALUE' => $arOneDiscount['VALUE'], 'VALUE_TYPE' => $arOneDiscount['VALUE_TYPE'], 'MAX_VALUE' => $arOneDiscount['VALUE_TYPE'] == Catalog\DiscountTable::VALUE_TYPE_PERCENT ? $arOneDiscount['MAX_DISCOUNT'] : 0, 'CURRENCY' => $arOneDiscount['CURRENCY'], 'HANDLERS' => isset($arOneDiscount['HANDLERS']) ? $arOneDiscount['HANDLERS'] : array());
             if (!empty($arOneDiscount['COUPON'])) {
                 $arOneList['USE_COUPONS'] = 'Y';
                 $arOneList['COUPON'] = $arOneDiscount['COUPON'];
                 $arOneList['COUPON_TYPE'] = $arOneDiscount['COUPON_ONE_TIME'];
                 $appliedCoupons[] = $arOneDiscount['COUPON'];
             }
             $arDiscountList[] = $arOneList;
         }
         unset($arOneList, $arOneDiscount);
         if (!empty($appliedCoupons)) {
             $resultApply = DiscountCouponsManager::setApplyByProduct($productHash, $appliedCoupons);
         }
         unset($resultApply, $appliedCoupons);
     }
     if (empty($arPrice['PRICE']['CATALOG_GROUP_NAME'])) {
         if (!empty($arPrice['PRICE']['CATALOG_GROUP_ID'])) {
             $priceName = self::getPriceTitle($arPrice['PRICE']['CATALOG_GROUP_ID']);
             if ($priceName != '') {
                 $arPrice['PRICE']['CATALOG_GROUP_NAME'] = $priceName;
             }
             unset($priceName);
         }
     }
     if (empty($arPrice['RESULT_PRICE']) || !is_array($arPrice['RESULT_PRICE'])) {
         $arPrice['RESULT_PRICE'] = CCatalogDiscount::calculateDiscountList($arPrice['PRICE'], $arParams['CURRENCY'], $arDiscountList, true);
     }
     $arResult = array('PRODUCT_PRICE_ID' => $arPrice['PRICE']['ID'], 'BASE_PRICE' => $arPrice['RESULT_PRICE']['BASE_PRICE'], 'PRICE' => $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'], 'VAT_RATE' => $arPrice['PRICE']['VAT_RATE'], "CURRENCY" => $arPrice['RESULT_PRICE']['CURRENCY'], "WEIGHT" => (double) $arCatalogProduct["WEIGHT"], "DIMENSIONS" => serialize(array("WIDTH" => $arCatalogProduct["WIDTH"], "HEIGHT" => $arCatalogProduct["HEIGHT"], "LENGTH" => $arCatalogProduct["LENGTH"])), "NAME" => $arProduct["~NAME"], "CAN_BUY" => "Y", "DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'], "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DISCOUNT_PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT'], "TYPE" => $arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET ? CCatalogProductSet::TYPE_SET : null, "DISCOUNT_VALUE" => $arPrice['RESULT_PRICE']['PERCENT'] > 0 ? $arPrice['RESULT_PRICE']['PERCENT'] . '%' : 0, "DISCOUNT_NAME" => '', "DISCOUNT_COUPON" => '', "DISCOUNT_LIST" => array());
     if ($arParams["CHECK_QUANTITY"] == "Y") {
         $arResult["QUANTITY"] = $quantity;
     } else {
         $arResult["QUANTITY"] = $arParams["QUANTITY"];
     }
     if (!empty($arDiscountList)) {
         $arResult['DISCOUNT_LIST'] = $arDiscountList;
     }
     if (!empty($arPrice['DISCOUNT'])) {
         $arResult['DISCOUNT_NAME'] = '[' . $arPrice['DISCOUNT']['ID'] . '] ' . $arPrice['DISCOUNT']['NAME'];
         if (!empty($arPrice['DISCOUNT']['COUPON'])) {
             $arResult['DISCOUNT_COUPON'] = $arPrice['DISCOUNT']['COUPON'];
         }
         if (empty($arResult['DISCOUNT_LIST'])) {
             $arResult['DISCOUNT_LIST'] = array($arPrice['DISCOUNT']);
         }
     }
     $arResult["VAT_INCLUDED"] = "Y";
     return $arResult;
 }
Ejemplo n.º 21
0
 public function GetDiscount($arParams = array())
 {
     global $DB;
     global $USER;
     $arResult = array();
     if (!(isset($USER) && $USER instanceof CUser && 'CUser' == get_class($USER))) {
         return $arResult;
     }
     if (!$USER->IsAuthorized()) {
         return $arResult;
     }
     if (!self::IsEnabled()) {
         return $arResult;
     }
     foreach (GetModuleEvents("catalog", "OnGetDiscountSave", true) as $arEvent) {
         $mxResult = ExecuteModuleEventEx($arEvent, $arParams);
         if (true !== $mxResult) {
             return $mxResult;
         }
     }
     if (!is_array($arParams) || empty($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 (0 < self::GetDiscountUserID()) {
         $intUserID = self::GetDiscountUserID();
         $arUserGroups = $USER->GetUserGroup($intUserID);
     } else {
         $intUserID = intval($intUserID);
         if (0 >= $intUserID) {
             $intUserID = $USER->GetID();
             $arUserGroups = $USER->GetUserGroupArray();
         } else {
             if (empty($arUserGroups)) {
                 $arUserGroups = $USER->GetUserGroup($intUserID);
             }
         }
     }
     if (!is_array($arUserGroups) || empty($arUserGroups) || 0 >= $intUserID) {
         return $arResult;
     }
     $key = array_search(2, $arUserGroups);
     if (false !== $key) {
         unset($arUserGroups[$key]);
     }
     if (empty($arUserGroups)) {
         return $arResult;
     }
     if ($strSiteID === false) {
         $strSiteID = SITE_ID;
     }
     $arCurrentDiscountID = CCatalogDiscountSave::__GetDiscountIDByGroup($arUserGroups);
     if (!empty($arCurrentDiscountID)) {
         $intCurrentTime = getmicrotime();
         $arFilter = array("ID" => $arCurrentDiscountID, 'SITE_ID' => $strSiteID, "TYPE" => DISCOUNT_TYPE_SAVE, 'ACTIVE' => 'Y', "+<=ACTIVE_FROM" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $intCurrentTime), "+>=ACTIVE_TO" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $intCurrentTime));
         $rsDiscSaves = CCatalogDiscountSave::GetList(array(), $arFilter);
         while ($arDiscSave = $rsDiscSaves->Fetch()) {
             $arDiscSave['ACTION_SIZE'] = intval($arDiscSave['ACTION_SIZE']);
             $arDiscSave['COUNT_SIZE'] = intval($arDiscSave['COUNT_SIZE']);
             $arDiscSave['ACTIVE_FROM_UT'] = false;
             $arDiscSave['ACTIVE_TO_UT'] = false;
             $arDiscSave['COUNT_FROM_UT'] = false;
             $arDiscSave['COUNT_TO_UT'] = false;
             $strCountPeriod = 'U';
             $strActionPeriod = 'U';
             $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 = 'D';
                 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 (0 < $arDiscSave['ACTION_SIZE'] && in_array($arDiscSave['ACTION_TYPE'], array('D', 'M', 'Y'))) {
                 $strActionPeriod = 'P';
                 $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 = 'D';
                 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 (0 < $arDiscSave['COUNT_SIZE'] && in_array($arDiscSave['COUNT_TYPE'], array('D', 'M', 'Y'))) {
                 $strCountPeriod = 'P';
                 $arCountPeriodBack = CCatalogDiscountSave::__GetTimeStampArray($arDiscSave['COUNT_SIZE'], $arDiscSave['COUNT_TYPE']);
             }
             if ('D' == $strCountPeriod) {
                 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 ('P' == $strActionPeriod && $arDiscSave['COUNT_TO_UT'] < AddToTimeStamp($arActionPeriodBack, $intCountTime)) {
                         continue;
                     }
                 }
             }
             if ('P' == $strActionPeriod) {
                 if ('P' == $strCountPeriod) {
                     $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 ('D' == $strCountPeriod) {
                 $intTimeStart = !empty($arDiscSave['COUNT_FROM']) ? $arDiscSave['COUNT_FROM'] : false;
                 $intTimeFinish = !empty($arDiscSave['COUNT_TO']) ? $arDiscSave['COUNT_TO'] : false;
             } elseif ('P' == $strCountPeriod) {
                 $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));
             if ($arRange = $rsRanges->Fetch()) {
                 if ('P' == $strActionPeriod) {
                     if ('P' == $strCountPeriod) {
                         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']);
                 unset($arDiscSave['ACTIVE_TO_UT']);
                 unset($arDiscSave['COUNT_FROM_UT']);
                 unset($arDiscSave['COUNT_TO_UT']);
                 $arOneResult = array();
                 $arOneResult = $arDiscSave;
                 $arOneResult['VALUE'] = $arRange['VALUE'];
                 $arOneResult['VALUE_TYPE'] = $arRange['TYPE'];
                 $arOneResult['RANGE_FROM'] = $arRange['RANGE_FROM'];
                 $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;
 }
Ejemplo n.º 22
0
 public static function PreGenerateImport($profile_id)
 {
     global $DB;
     $profile_id = (int) $profile_id;
     if ($profile_id <= 0) {
         return false;
     }
     $ar_profile = CCatalogImport::GetByID($profile_id);
     if (!$ar_profile || 'Y' == $ar_profile['NEED_EDIT']) {
         return false;
     }
     $strFile = CATALOG_PATH2IMPORTS . $ar_profile["FILE_NAME"] . "_run.php";
     if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
         $strFile = CATALOG_PATH2IMPORTS_DEF . $ar_profile["FILE_NAME"] . "_run.php";
         if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
             CCatalogDiscountSave::Enable();
             return false;
         }
     }
     $bFirstLoadStep = true;
     if (!defined("CATALOG_LOAD_NO_STEP")) {
         define("CATALOG_LOAD_NO_STEP", true);
     }
     $strImportErrorMessage = "";
     $strImportOKMessage = "";
     $bAllDataLoaded = true;
     $arSetupVars = array();
     $intSetupVarsCount = 0;
     if ('Y' != $ar_profile["DEFAULT_PROFILE"]) {
         parse_str($ar_profile["SETUP_VARS"], $arSetupVars);
         if (!empty($arSetupVars) && is_array($arSetupVars)) {
             $intSetupVarsCount = extract($arSetupVars, EXTR_SKIP);
         }
     }
     global $arCatalogAvailProdFields;
     $arCatalogAvailProdFields = CCatalogCSVSettings::getSettingsFields(CCatalogCSVSettings::FIELDS_ELEMENT);
     global $arCatalogAvailPriceFields;
     $arCatalogAvailPriceFields = CCatalogCSVSettings::getSettingsFields(CCatalogCSVSettings::FIELDS_CATALOG);
     global $arCatalogAvailValueFields;
     $arCatalogAvailValueFields = CCatalogCSVSettings::getSettingsFields(CCatalogCSVSettings::FIELDS_PRICE);
     global $arCatalogAvailQuantityFields;
     $arCatalogAvailQuantityFields = CCatalogCSVSettings::getSettingsFields(CCatalogCSVSettings::FIELDS_PRICE_EXT);
     global $arCatalogAvailGroupFields;
     $arCatalogAvailGroupFields = CCatalogCSVSettings::getSettingsFields(CCatalogCSVSettings::FIELDS_SECTION);
     global $defCatalogAvailProdFields;
     $defCatalogAvailProdFields = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_ELEMENT);
     global $defCatalogAvailPriceFields;
     $defCatalogAvailPriceFields = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_CATALOG);
     global $defCatalogAvailValueFields;
     $defCatalogAvailValueFields = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_PRICE);
     global $defCatalogAvailQuantityFields;
     $defCatalogAvailQuantityFields = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_PRICE_EXT);
     global $defCatalogAvailGroupFields;
     $defCatalogAvailGroupFields = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_SECTION);
     global $defCatalogAvailCurrencies;
     $defCatalogAvailCurrencies = CCatalogCSVSettings::getDefaultSettings(CCatalogCSVSettings::FIELDS_CURRENCY);
     CCatalogDiscountSave::Disable();
     include $_SERVER["DOCUMENT_ROOT"] . $strFile;
     CCatalogDiscountSave::Enable();
     CCatalogImport::Update($profile_id, array("=LAST_USE" => $DB->GetNowFunction()));
     return "CCatalogImport::PreGenerateImport(" . $profile_id . ");";
 }
Ejemplo n.º 23
0
 public static function GetDiscount($intProductID, $intIBlockID, $arCatalogGroups = array(), $arUserGroups = array(), $strRenewal = "N", $siteID = false, $arDiscountCoupons = false, $boolSKU = true, $boolGetIDS = false)
 {
     global $DB;
     global $APPLICATION;
     foreach (GetModuleEvents("catalog", "OnGetDiscount", true) as $arEvent) {
         $mxResult = ExecuteModuleEventEx($arEvent, array($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS));
         if ($mxResult !== true) {
             return $mxResult;
         }
     }
     $boolSKU = $boolSKU === true;
     $boolGetIDS = $boolGetIDS === true;
     $intProductID = (int) $intProductID;
     if ($intProductID <= 0) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID");
         return false;
     }
     $intIBlockID = (int) $intIBlockID;
     if ($intIBlockID <= 0) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"), "NO_IBLOCK_ID");
         return false;
     }
     if (!is_array($arCatalogGroups)) {
         $arCatalogGroups = array($arCatalogGroups);
     }
     if (!empty($arCatalogGroups)) {
         CatalogClearArray($arCatalogGroups);
     }
     if (!is_array($arUserGroups)) {
         $arUserGroups = array($arUserGroups);
     }
     $arUserGroups[] = 2;
     if (!empty($arUserGroups)) {
         CatalogClearArray($arUserGroups);
     }
     $strRenewal = $strRenewal == "Y" ? "Y" : "N";
     if ($siteID === false) {
         $siteID = SITE_ID;
     }
     if ($arDiscountCoupons === false) {
         $arDiscountCoupons = CCatalogDiscountCoupon::GetCoupons();
     }
     $arSKU = false;
     $arSKUExt = false;
     if ($boolSKU) {
         $arSKUExt = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
         $boolSKU = !empty($arSKUExt);
     }
     $arResult = array();
     $arResultID = array();
     $strCacheKey = md5('C' . implode('_', $arCatalogGroups) . '-' . 'U' . implode('_', $arUserGroups));
     if (!isset(self::$arCacheDiscountFilter[$strCacheKey])) {
         $arFilter = array('PRICE_TYPE_ID' => $arCatalogGroups, 'USER_GROUP_ID' => $arUserGroups);
         $arDiscountIDs = CCatalogDiscount::__GetDiscountID($arFilter);
         if (!empty($arDiscountIDs)) {
             sort($arDiscountIDs);
         }
         self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
     } else {
         $arDiscountIDs = self::$arCacheDiscountFilter[$strCacheKey];
     }
     $arProduct = array();
     if (!empty($arDiscountIDs)) {
         $boolGenerate = false;
         if (empty(self::$cacheDiscountHandlers)) {
             self::$cacheDiscountHandlers = CCatalogDiscount::getDiscountHandlers($arDiscountIDs);
         } else {
             $needDiscountHandlers = array();
             foreach ($arDiscountIDs as &$discountID) {
                 if (!isset(self::$cacheDiscountHandlers[$discountID])) {
                     $needDiscountHandlers[] = $discountID;
                 }
             }
             unset($discountID);
             if (!empty($needDiscountHandlers)) {
                 $discountHandlersList = CCatalogDiscount::getDiscountHandlers($needDiscountHandlers);
                 if (!empty($discountHandlersList)) {
                     foreach ($discountHandlersList as $discountID => $discountHandlers) {
                         self::$cacheDiscountHandlers[$discountID] = $discountHandlers;
                     }
                     unset($discountHandlers, $discountID);
                 }
                 unset($discountHandlersList);
             }
             unset($needDiscountHandlers);
         }
         $strCacheKey = 'D' . implode('_', $arDiscountIDs) . '-' . 'S' . $siteID . '-R' . $strRenewal;
         if (!empty($arDiscountCoupons)) {
             $strCacheKey .= '-C' . implode('|', $arDiscountCoupons);
         }
         $strCacheKey = md5($strCacheKey);
         if (!isset(self::$arCacheDiscountResult[$strCacheKey])) {
             $arSelect = array('ID', 'TYPE', 'SITE_ID', 'ACTIVE', 'ACTIVE_FROM', 'ACTIVE_TO', 'RENEWAL', 'NAME', 'SORT', 'MAX_DISCOUNT', 'VALUE_TYPE', 'VALUE', 'CURRENCY', 'PRIORITY', 'LAST_DISCOUNT', 'COUPON', 'COUPON_ONE_TIME', 'COUPON_ACTIVE', 'UNPACK');
             $strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
             $arFilter = array('ID' => $arDiscountIDs, 'SITE_ID' => $siteID, 'TYPE' => self::ENTITY_ID, 'RENEWAL' => $strRenewal, '+<=ACTIVE_FROM' => $strDate, '+>=ACTIVE_TO' => $strDate);
             if (is_array($arDiscountCoupons)) {
                 $arFilter["+COUPON"] = $arDiscountCoupons;
             }
             $arDiscountList = array();
             CTimeZone::Disable();
             $rsPriceDiscounts = CCatalogDiscount::GetList(array(), $arFilter, false, false, $arSelect);
             CTimeZone::Enable();
             while ($arPriceDiscount = $rsPriceDiscounts->Fetch()) {
                 $arPriceDiscount['HANDLERS'] = array();
                 $arDiscountList[] = $arPriceDiscount;
             }
             self::$arCacheDiscountResult[$strCacheKey] = $arDiscountList;
         } else {
             $arDiscountList = self::$arCacheDiscountResult[$strCacheKey];
         }
         if (!empty($arDiscountList)) {
             $discountApply = array();
             foreach ($arDiscountList as &$arPriceDiscount) {
                 if (!isset($discountApply[$arPriceDiscount['ID']]) && $arPriceDiscount['COUPON_ACTIVE'] != 'N') {
                     if (!$boolGenerate) {
                         if (!isset(self::$arCacheProduct[$intProductID])) {
                             $arProduct = array('ID' => $intProductID, 'IBLOCK_ID' => $intIBlockID);
                             if (!self::__GenerateFields($arProduct)) {
                                 return false;
                             }
                             if ($boolSKU) {
                                 if (!self::__GenerateParent($arProduct, $arSKUExt)) {
                                     $boolSKU = false;
                                 }
                             }
                             $boolGenerate = true;
                             self::$arCacheProduct[$intProductID] = $arProduct;
                         } else {
                             $boolGenerate = true;
                             $arProduct = self::$arCacheProduct[$intProductID];
                         }
                     }
                     $discountApply[$arPriceDiscount['ID']] = true;
                     $applyFlag = true;
                     if (isset(self::$cacheDiscountHandlers[$arPriceDiscount['ID']])) {
                         $arPriceDiscount['HANDLERS'] = self::$cacheDiscountHandlers[$arPriceDiscount['ID']];
                         $moduleList = self::$cacheDiscountHandlers[$arPriceDiscount['ID']]['MODULES'];
                         if (!empty($moduleList)) {
                             foreach ($moduleList as &$moduleID) {
                                 if (!isset(self::$usedModules[$moduleID])) {
                                     self::$usedModules[$moduleID] = Loader::includeModule($moduleID);
                                 }
                                 if (!self::$usedModules[$moduleID]) {
                                     $applyFlag = false;
                                     break;
                                 }
                             }
                             unset($moduleID);
                         }
                         unset($moduleList);
                     }
                     if ($applyFlag && CCatalogDiscount::__Unpack($arProduct, $arPriceDiscount['UNPACK'])) {
                         unset($arPriceDiscount['UNPACK']);
                         $arResult[] = $arPriceDiscount;
                         $arResultID[] = $arPriceDiscount['ID'];
                     }
                 }
             }
             if (isset($arPriceDiscount)) {
                 unset($arPriceDiscount);
             }
             unset($discountApply);
         }
     }
     if (!$boolGetIDS) {
         $arDiscSave = CCatalogDiscountSave::GetDiscount(array('USER_ID' => 0, 'USER_GROUPS' => $arUserGroups, 'SITE_ID' => $siteID));
         if (!empty($arDiscSave)) {
             $arResult = !empty($arResult) ? array_merge($arResult, $arDiscSave) : $arDiscSave;
         }
     } else {
         $arResult = $arResultID;
     }
     foreach (GetModuleEvents("catalog", "OnGetDiscountResult", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arResult));
     }
     return $arResult;
 }
Ejemplo n.º 24
0
 function PreGenerateExport($profile_id)
 {
     global $DB;
     $profile_id = intval($profile_id);
     if ($profile_id <= 0) {
         return false;
     }
     $ar_profile = CCatalogExport::GetByID($profile_id);
     if (!$ar_profile || 'Y' == $ar_profile['NEED_EDIT']) {
         return false;
     }
     if ($ar_profile["DEFAULT_PROFILE"] != "Y") {
         parse_str($ar_profile["SETUP_VARS"]);
     }
     CCatalogDiscountSave::Disable();
     $strFile = CATALOG_PATH2EXPORTS . $ar_profile["FILE_NAME"] . "_run.php";
     if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
         $strFile = CATALOG_PATH2EXPORTS_DEF . $ar_profile["FILE_NAME"] . "_run.php";
         if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $strFile)) {
             return false;
         }
     }
     @(include $_SERVER["DOCUMENT_ROOT"] . $strFile);
     CCatalogDiscountSave::Enable();
     CCatalogExport::Update($profile_id, array("=LAST_USE" => $DB->GetNowFunction()));
     return "CCatalogExport::PreGenerateExport(" . $profile_id . ");";
 }
Ejemplo n.º 25
0
	public static function GetItemPrices($IBLOCK_ID, $arCatalogPrices, $arItem, $bVATInclude = true, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID)
	{
		static $arCurUserGroups = array();

		global $USER;
		$arPrices = array();
		if(CModule::IncludeModule("catalog"))
		{
			$USER_ID = intval($USER_ID);
			$intUserID = $USER_ID;
			if (0 >= $intUserID)
				$intUserID = $USER->GetID();
			if (!array_key_exists($intUserID, $arCurUserGroups))
			{
				$arCurUserGroups[$intUserID] = (0 < $USER_ID ? CUser::GetUserGroup($USER_ID) : $USER->GetUserGroupArray());
			}
			$arUserGroups = $arCurUserGroups[$intUserID];

			$boolConvert = false;
			$strCurrencyID = '';
			if (is_array($arCurrencyParams) && !empty($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID']))
			{
				$boolConvert = true;
				$strCurrencyID = $arCurrencyParams['CURRENCY_ID'];
			}
			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);
					}
					CCatalogDiscountSave::Disable();
					// so discounts will include VAT
					$arDiscounts = CCatalogDiscount::GetDiscount(
						$arItem["ID"],
						$arItem["IBLOCK_ID"],
						array($value["ID"]),
						$arUserGroups,
						"N",
						$LID,
						array()
					);
					CCatalogDiscountSave::Enable();
					$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" => FormatCurrency($dblNoVat, $strCurrencyID),

							'ORIG_VALUE_VAT' => $vat_price,
							"VALUE_VAT" => $dblVatPrice,
							"PRINT_VALUE_VAT" => FormatCurrency($dblVatPrice, $strCurrencyID),

							'ORIG_VATRATE_VALUE' => $vat_value,
							"VATRATE_VALUE" => $dblVatValue,
							"PRINT_VATRATE_VALUE" => FormatCurrency($dblVatValue, $strCurrencyID),

							'ORIG_DISCOUNT_VALUE_NOVAT' => $discountPrice,
							"DISCOUNT_VALUE_NOVAT" => $dblDiscountValueNoVat,
							"PRINT_DISCOUNT_VALUE_NOVAT" => FormatCurrency($dblDiscountValueNoVat, $strCurrencyID),

							"ORIG_DISCOUNT_VALUE_VAT" => $vat_discountPrice,
							"DISCOUNT_VALUE_VAT" => $dblVatDiscountPrice,
							"PRINT_DISCOUNT_VALUE_VAT" => FormatCurrency($dblVatDiscountPrice, $strCurrencyID),

							'ORIG_DISCOUNT_VATRATE_VALUE' => $vat_value_discount,
							'DISCOUNT_VATRATE_VALUE' => $dblDiscountValueVat,
							'PRINT_DISCOUNT_VATRATE_VALUE' => FormatCurrency($dblDiscountValueVat, $strCurrencyID),

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

							"VALUE_VAT" => $vat_price,
							"PRINT_VALUE_VAT" => FormatCurrency($vat_price, $arItem["CATALOG_CURRENCY_".$value["ID"]]),

							"VATRATE_VALUE" => $vat_value,
							"PRINT_VATRATE_VALUE" => FormatCurrency($vat_value, $arItem["CATALOG_CURRENCY_".$value["ID"]]),

							"DISCOUNT_VALUE_NOVAT" => $discountPrice,
							"PRINT_DISCOUNT_VALUE_NOVAT" => FormatCurrency($discountPrice, $arItem["CATALOG_CURRENCY_".$value["ID"]]),

							"DISCOUNT_VALUE_VAT" => $vat_discountPrice,
							"PRINT_DISCOUNT_VALUE_VAT" => FormatCurrency($vat_discountPrice, $arItem["CATALOG_CURRENCY_".$value["ID"]]),

							'DISCOUNT_VATRATE_VALUE' => $vat_value_discount,
							'PRINT_DISCOUNT_VATRATE_VALUE' => FormatCurrency($vat_value_discount, $arItem["CATALOG_CURRENCY_".$value["ID"]]),

							"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"]];

					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'];
					}
				}
			}
		}
		else
		{
			foreach($arCatalogPrices as $key => $value)
			{
				if($value["CAN_VIEW"])
				{
					$arPrices[$key] = array(
						"ID" => $arItem["PROPERTY_".$value["ID"]."_VALUE_ID"],
						"VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2),
						"PRINT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2)." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"DISCOUNT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2),
						"PRINT_DISCOUNT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2)." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"CURRENCY" => $arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"],
						"CAN_ACCESS" => true,
						"CAN_BUY" => false,
					);
				}
			}
		}
		return $arPrices;
	}
Ejemplo n.º 26
0
 public function GetDiscount($arParams = array(), $getAll = false)
 {
     global $DB, $USER;
     $adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true;
     $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 = (int) $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 = (int) self::GetDiscountUserID();
         $arUserGroups = array();
     }
     if ($intUserID <= 0 && !$adminSection) {
         $intUserID = (int) $USER->GetID();
         $arUserGroups = array();
     }
     if (empty($arUserGroups)) {
         if (!isset(self::$userGroups[$intUserID])) {
             self::$userGroups[$intUserID] = $USER->GetUserGroup($intUserID);
         }
         $arUserGroups = self::$userGroups[$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;
     }
     Main\Type\Collection::normalizeArrayValuesByInt($arUserGroups, true);
     if (empty($arUserGroups)) {
         return $arResult;
     }
     if ($strSiteID === false) {
         $strSiteID = SITE_ID;
     }
     $cacheKey = md5('U' . implode('_', $arUserGroups));
     if (!isset(self::$discountFilterCache[$cacheKey])) {
         self::$discountFilterCache[$cacheKey] = CCatalogDiscountSave::__GetDiscountIDByGroup($arUserGroups);
     }
     if (empty(self::$discountFilterCache[$cacheKey])) {
         return $arResult;
     }
     $arCurrentDiscountID = self::$discountFilterCache[$cacheKey];
     if (isset($arParams['ID'])) {
         Main\Type\Collection::normalizeArrayValuesByInt($arUserGroups, true);
         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;
             $arDiscSave['TYPE'] = (int) $arDiscSave['TYPE'];
             $arDiscSave['MODULE_ID'] = 'catalog';
             $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'];
                     $arOneResult['MAX_DISCOUNT'] = 0;
                 } else {
                     $arOneResult['VALUE'] = 0;
                     $arOneResult['VALUE_TYPE'] = self::TYPE_PERCENT;
                     $arOneResult['MAX_DISCOUNT'] = 0;
                     $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;
 }
Ejemplo n.º 27
0
	/**
	 * <p>Метод выполняет профиль <i>profile_id</i> на агенте.</p>
	 *
	 *
	 *
	 *
	 * @param int $profile_id  Код выполняемого профиля.
	 *
	 *
	 *
	 * @return mixed <p>В случае успешного выполнения профиля экспорта метод
	 * возвращает строку для следующего вызова агента. В противном
	 * случае метод вернет <i>false</i>.</p><br><br>
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogexport/pregenerateexport.php
	 * @author Bitrix
	 */
	public static function PreGenerateExport($profile_id)
	{
		global $DB;

		$profile_id = intval($profile_id);
		if ($profile_id<=0) return false;

		$ar_profile = CCatalogExport::GetByID($profile_id);
		if ((!$ar_profile) || ('Y' == $ar_profile['NEED_EDIT']))
			return false;

		$strFile = CATALOG_PATH2EXPORTS.$ar_profile["FILE_NAME"]."_run.php";
		if (!file_exists($_SERVER["DOCUMENT_ROOT"].$strFile))
		{
			$strFile = CATALOG_PATH2EXPORTS_DEF.$ar_profile["FILE_NAME"]."_run.php";
			if (!file_exists($_SERVER["DOCUMENT_ROOT"].$strFile))
			{
				return false;
			}
		}

		$arSetupVars = array();
		$intSetupVarsCount = 0;
		if ('Y' != $ar_profile["DEFAULT_PROFILE"])
		{
			parse_str($ar_profile["SETUP_VARS"], $arSetupVars);
			if (!empty($arSetupVars) && is_array($arSetupVars))
			{
				$intSetupVarsCount = extract($arSetupVars, EXTR_SKIP);
			}
		}

		CCatalogDiscountSave::Disable();
		include($_SERVER["DOCUMENT_ROOT"].$strFile);
		CCatalogDiscountSave::Enable();

		CCatalogExport::Update($profile_id, array(
			"=LAST_USE" => $DB->GetNowFunction()
			)
		);

		return "CCatalogExport::PreGenerateExport(".$profile_id.");";
	}