public static function OnSetCouponList($intUserID, $arCoupons, $arModules) { global $USER; $boolResult = false; if (empty($arModules) || is_array($arModules) && in_array('catalog', $arModules)) { if (!empty($arCoupons)) { if (!is_array($arCoupons)) { $arCoupons = array($arCoupons); } $intUserID = intval($intUserID); if (0 < $intUserID) { $boolCurrentUser = $USER->IsAuthorized() && $intUserID == $USER->GetID(); if (!isset($_SESSION["CATALOG_MANAGE_COUPONS"]) || !is_array($_SESSION["CATALOG_MANAGE_COUPONS"])) { $_SESSION["CATALOG_MANAGE_COUPONS"] = array(); } if (!isset($_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID]) || !is_array($_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID])) { $_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID] = array(); } if ($boolCurrentUser) { if (!isset($_SESSION["CATALOG_USER_COUPONS"]) || !is_array($_SESSION["CATALOG_USER_COUPONS"])) { $_SESSION["CATALOG_USER_COUPONS"] = array(); } } foreach ($arCoupons as &$strOneCoupon) { $strOneCoupon = trim($strOneCoupon); if (empty($strOneCoupon)) { continue; } if (in_array($strOneCoupon, $_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID]) && !($boolCurrentUser && !in_array($strOneCoupon, $_SESSION["CATALOG_USER_COUPONS"]))) { continue; } $rsCoupons = CCatalogDiscountCoupon::GetList(array(), array("COUPON" => $strOneCoupon, "ACTIVE" => "Y"), false, false, array('ID')); if ($arCoupon = $rsCoupons->Fetch()) { if (!in_array($strOneCoupon, $_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID])) { $_SESSION["CATALOG_MANAGE_COUPONS"][$intUserID][] = $strOneCoupon; } $boolResult = true; if ($boolCurrentUser) { if (!in_array($strOneCoupon, $_SESSION["CATALOG_USER_COUPONS"])) { $_SESSION["CATALOG_USER_COUPONS"][] = $strOneCoupon; } } } } if (isset($strOneCoupon)) { unset($strOneCoupon); } } elseif (0 == $intUserID && !$USER->IsAuthorized()) { if (!isset($_SESSION["CATALOG_USER_COUPONS"]) || !is_array($_SESSION["CATALOG_USER_COUPONS"])) { $_SESSION["CATALOG_USER_COUPONS"] = array(); } foreach ($arCoupons as &$strOneCoupon) { $strOneCoupon = trim($strOneCoupon); if (empty($strOneCoupon) || in_array($strOneCoupon, $_SESSION["CATALOG_USER_COUPONS"])) { continue; } $rsCoupons = CCatalogDiscountCoupon::GetList(array(), array("COUPON" => $strOneCoupon, "ACTIVE" => "Y"), false, false, array('ID')); if ($arCoupon = $rsCoupons->Fetch()) { if (!in_array($strOneCoupon, $_SESSION["CATALOG_USER_COUPONS"])) { $_SESSION["CATALOG_USER_COUPONS"][] = $strOneCoupon; } $boolResult = true; } } if (isset($strOneCoupon)) { unset($strOneCoupon); } } } } return $boolResult; }
{ $arResult['STATUS'] = 'ERROR'; $arResult['MESSAGE'] = GetMessage('BT_CAT_TOOLS_GEN_CPN_ERR_RIGHTS'); $boolFlag = false; } } if (true == $boolFlag) { require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/catalog/include.php"); require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/catalog/prolog.php"); do { $boolCheck = true; $strCoupon = CatalogGenerateCoupon(); $arFilter = array("COUPON" => substr($strCoupon, 0, 32)); $rsCoupons = CCatalogDiscountCoupon::GetList(array(),$arFilter, false, array('nTopCount' => 1),array('ID', 'COUPON')); if ($arCoupon = $rsCoupons->Fetch()) { $boolCheck = false; } } while (!$boolCheck); $arResult['RESULT'] = $strCoupon; } echo CUtil::PhpToJSObject($arResult); ?>
public static function CouponApply($intUserID, $strCoupon) { global $DB; $mxResult = false; $intUserID = intval($intUserID); if (0 > $intUserID) { $intUserID = 0; } $arCouponList = array(); $arCheck = is_array($strCoupon) ? $strCoupon : array($strCoupon); foreach ($arCheck as &$strOneCheck) { $strOneCheck = strval($strOneCheck); if ('' != $strOneCheck) { $arCouponList[] = $strOneCheck; } } if (isset($strOneCheck)) { unset($strOneCheck); } if (empty($arCouponList)) { return $mxResult; } $boolFlag = false; $rsCoupons = CCatalogDiscountCoupon::GetList(array(), array('COUPON' => $arCouponList, 'ACTIVE' => 'Y'), false, false, array('ID', 'ONE_TIME', 'COUPON')); $strDateFunction = $DB->GetNowFunction(); while ($arCoupon = $rsCoupons->Fetch()) { $arCoupon['ID'] = intval($arCoupon['ID']); $arFields = array("~DATE_APPLY" => $strDateFunction); if (self::TYPE_ONE_TIME == $arCoupon["ONE_TIME"]) { $arFields["ACTIVE"] = "N"; if (0 < $intUserID) { CCatalogDiscountCoupon::EraseCouponByManage($intUserID, $arCoupon['COUPON']); } else { CCatalogDiscountCoupon::EraseCoupon($arCoupon['COUPON']); } } elseif (self::TYPE_ONE_ORDER == $arCoupon["ONE_TIME"]) { $boolFlag = true; if (!array_key_exists($arCoupon['ID'], self::$arOneOrderCoupons)) { self::$arOneOrderCoupons[$arCoupon['ID']] = array('COUPON' => $arCoupon['COUPON'], 'USER_ID' => $intUserID); } } $strUpdate = $DB->PrepareUpdate("b_catalog_discount_coupon", $arFields); if (!empty($strUpdate)) { $strSql = "UPDATE b_catalog_discount_coupon SET " . $strUpdate . " WHERE ID = " . $arCoupon['ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $mxResult = true; } } if ($boolFlag) { AddEventHandler('sale', 'OnBasketOrder', array('CCatalogDiscountCoupon', 'CouponOneOrderDisable')); AddEventHandler('sale', 'OnDoBasketOrder', array('CCatalogDiscountCoupon', 'CouponOneOrderDisable')); } return $mxResult; }
if ($ex = $APPLICATION->GetException()) { $lAdmin->AddGroupError($ex->GetString(), $ID); } else { $lAdmin->AddGroupError(str_replace("#ID#", $ID, GetMessage("ERROR_UPDATE_DISCOUNT_CPN")), $ID); } } break; } } } $lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "DISCOUNT_NAME", "content" => GetMessage("DSC_CPN_NAME"), "sort" => "DISCOUNT_NAME", "default" => true), array("id" => "ACTIVE", "content" => GetMessage("DSC_CPN_ACTIVE"), "sort" => "ACTIVE", "default" => true), array("id" => "COUPON", "content" => GetMessage("DSC_CPN_CPN"), "sort" => "COUPON", "default" => true), array("id" => "DATE_APPLY", "content" => GetMessage("DSC_CPN_DATE"), "sort" => "DATE_APPLY", "default" => true), array("id" => "ONE_TIME", "content" => GetMessage("DSC_CPN_TIME2"), "sort" => "ONE_TIME", "default" => true), array("id" => "DESCRIPTION", "content" => GetMessage("DSC_CPN_DESCRIPTION"), "sort" => "", "default" => false), array("id" => "MODIFIED_BY", "content" => GetMessage('DSC_MODIFIED_BY'), "sort" => "MODIFIED_BY", "default" => true), array("id" => "TIMESTAMP_X", "content" => GetMessage('DSC_TIMESTAMP_X'), "sort" => "TIMESTAMP_X", "default" => true), array("id" => "CREATED_BY", "content" => GetMessage('DSC_CREATED_BY'), "sort" => "CREATED_BY", "default" => false), array("id" => "DATE_CREATE", "content" => GetMessage('DSC_DATE_CREATE'), "sort" => "DATE_CREATE", "default" => false))); $arVisibleColumns = $lAdmin->GetVisibleHeaderColumns(); $arUserList = array(); $strNameFormat = CSite::GetNameFormat(true); $arCouponType = array('Y' => GetMessage('DSC_COUPON_TYPE_ONE_TIME'), 'O' => GetMessage('DSC_COUPON_TYPE_ONE_ORDER'), 'N' => GetMessage('DSC_COUPON_TYPE_NO_LIMIT')); $dbResultList = CCatalogDiscountCoupon::GetList(array($by => $order), $arFilter, false, false, $arVisibleColumns); $dbResultList = new CAdminResult($dbResultList, $sTableID); $dbResultList->NavStart(); $lAdmin->NavText($dbResultList->GetNavPrint(GetMessage("DSC_NAV"))); while ($arDiscount = $dbResultList->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_ID, $arDiscount); $row->AddField("ID", $f_ID); $row->AddViewField("DISCOUNT_NAME", $f_DISCOUNT_NAME); $strCreatedBy = ''; $strModifiedBy = ''; $arDiscount['CREATED_BY'] = intval($arDiscount['CREATED_BY']); if (0 < $arDiscount['CREATED_BY']) { if (!array_key_exists($arDiscount['CREATED_BY'], $arUserList)) { $rsUsers = CUser::GetList($by2 = 'ID', $order2 = 'ASC', array('ID_EQUAL_EXACT' => $arDiscount['CREATED_BY']), array('FIELDS' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME'))); if ($arOneUser = $rsUsers->Fetch()) { $arOneUser['ID'] = intval($arOneUser['ID']);
public function CouponApply($intUserID, $strCoupon) { global $DB; global $CATALOG_ONETIME_COUPONS_ORDER; $mxResult = false; $intUserID = intval($intUserID); if (0 > $intUserID) { $intUserID = 0; } $strCoupon = strval($strCoupon); $rsCoupons = CCatalogDiscountCoupon::GetList(array(), array("COUPON" => $strCoupon, 'ACTIVE' => 'Y'), false, false, array("ID", "ONE_TIME")); if ($arCoupon = $rsCoupons->Fetch()) { $arCoupon['ID'] = intval($arCoupon['ID']); $arFields = array("DATE_APPLY" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)))); if (self::TYPE_ONE_TIME == $arCoupon["ONE_TIME"]) { $arFields["ACTIVE"] = "N"; if (0 < $intUserID) { CCatalogDiscountCoupon::EraseCouponByManage($intUserID, $strCoupon); } else { CCatalogDiscountCoupon::EraseCoupon($strCoupon); } } elseif (self::TYPE_ONE_ORDER == $arCoupon["ONE_TIME"]) { if (!is_array($CATALOG_ONETIME_COUPONS_ORDER)) { $CATALOG_ONETIME_COUPONS_ORDER = array(); AddEventHandler("sale", "OnBasketOrder", 'CatalogDeactivateOneTimeCoupons'); AddEventHandler("sale", "OnDoBasketOrder", 'CatalogDeactivateOneTimeCoupons'); } if (!array_key_exists($arCoupon['ID'], $CATALOG_ONETIME_COUPONS_ORDER)) { $CATALOG_ONETIME_COUPONS_ORDER[$arCoupon['ID']] = array('COUPON' => $strCoupon, 'USER_ID' => $intUserID); } } $strUpdate = $DB->PrepareUpdate("b_catalog_discount_coupon", $arFields); if (!empty($strUpdate)) { $strSql = "UPDATE b_catalog_discount_coupon SET " . $strUpdate . " WHERE ID = " . $arCoupon['ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $mxResult = $arCoupon['ID']; } } return $mxResult; }
$arDefaultValues = array( 'DISCOUNT_ID' => '', 'ACTIVE' => 'Y', 'ONE_TIME' => CCatalogDiscountCoupon::TYPE_ONE_TIME, 'COUPON' => '', 'DATE_APPLY' => '', 'DESCRIPTION' => '', ); $arSelect = array_merge(array('ID'), array_keys($arDefaultValues)); $arCoupon = $arDefaultValues; if ($ID > 0) { $rsCoupons = CCatalogDiscountCoupon::GetList(array(), array("ID" => $ID), false, false, $arSelect); if (!($arCoupon = $rsCoupons->Fetch())) { $ID = 0; $arCoupon = $arDefaultValues; } } if ($bVarsFromForm) { if ($ID > 0) { $intDiscountID = $arCoupon['DISCOUNT_ID']; $arCoupon = $arFields; $arCoupon['DISCOUNT_ID'] = $intDiscountID; }
if (!in_array('ID', $arSelectFields)) { $arSelectFields[] = 'ID'; } $arSelectFields = array_values($arSelectFields); $arSelectFieldsMap = array_fill_keys($arSelectFields, true); $arCouponType = CCatalogDiscountCoupon::GetCoupontTypes(true); $arUserList = array(); $arUserID = array(); $strNameFormat = CSite::GetNameFormat(true); if (!(false == B_ADMIN_SUBCOUPONS_LIST && $bCopy)) { if (array_key_exists("mode", $_REQUEST) && $_REQUEST["mode"] == "excel") { $arNavParams = false; } else { $arNavParams = array("nPageSize" => CAdminSubResult::GetNavSize($sTableID, 20, $lAdmin->GetListUrl(true))); } $dbResultList = CCatalogDiscountCoupon::GetList(array($by => $order), $arFilter, false, $arNavParams, $arSelectFields); $dbResultList = new CAdminSubResult($dbResultList, $sTableID, $lAdmin->GetListUrl(true)); $dbResultList->NavStart(); $lAdmin->NavText($dbResultList->GetNavPrint(htmlspecialcharsbx(GetMessage("DSC_NAV")))); $arRows = array(); while ($arCouponDiscount = $dbResultList->Fetch()) { $edit_url = '/bitrix/admin/cat_subcoupon_edit.php?ID=' . $arCouponDiscount['ID'] . '&DISCOUNT_ID=' . $intDiscountID . '&lang=' . LANGUAGE_ID . '&TMP_ID=' . $strSubTMP_ID; $arCouponDiscount['ID'] = intval($arCouponDiscount['ID']); if (array_key_exists('CREATED_BY', $arSelectFieldsMap)) { $arCouponDiscount['CREATED_BY'] = intval($arCouponDiscount['CREATED_BY']); if (0 < $arCouponDiscount['CREATED_BY']) { $arUserID[$arCouponDiscount['CREATED_BY']] = true; } } if (array_key_exists('MODIFIED_BY', $arSelectFieldsMap)) { $arCouponDiscount['MODIFIED_BY'] = intval($arCouponDiscount['MODIFIED_BY']);
public function HaveCoupons($ID, $excludeID = 0) { $ID = intval($ID); if ($ID <= 0) { return false; } $arFilter = array("DISCOUNT_ID" => $ID); $excludeID = intval($excludeID); if ($excludeID > 0) { $arFilter["!ID"] = $excludeID; } $dbRes = CCatalogDiscountCoupon::GetList(array(), $arFilter, false, array("nTopCount" => 1), array("ID")); if ($dbRes->Fetch()) { return true; } else { return false; } }
function CatalogRecurringCallback($productID, $userID) { global $APPLICATION; global $USER; global $DB; $productID = intval($productID); if ($productID <= 0) { return false; } $userID = intval($userID); if ($userID <= 0) { return false; } $arProduct = CCatalogProduct::GetByID($productID); if (!$arProduct) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_NO_PRODUCT")), "NO_PRODUCT"); return false; } if ($arProduct["PRICE_TYPE"] == "T") { $arProduct = CCatalogProduct::GetByID($arProduct["TRIAL_PRICE_ID"]); if (!$arProduct) { $APPLICATION->ThrowException(str_replace("#TRIAL_ID#", $productID, str_replace("#ID#", $arProduct["TRIAL_PRICE_ID"], GetMessage("I_NO_TRIAL_PRODUCT"))), "NO_PRODUCT_TRIAL"); return false; } } $productID = intval($arProduct["ID"]); if ($arProduct["PRICE_TYPE"] != "R") { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_PRODUCT_NOT_SUBSCR")), "NO_IBLOCK_SUBSCR"); return false; } $dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $productID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "N"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')); if (!($arIBlockElement = $dbIBlockElement->GetNext())) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT"); return false; } if ('E' == CIBlock::GetArrayByID($arIBlockElement['IBLOCK_ID'], "RIGHTS_MODE")) { $arUserRights = CIBlockElementRights::GetUserOperations($productID, $userID); if (empty($arUserRights)) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT"); return false; } elseif (!is_array($arUserRights) || !array_key_exists('element_read', $arUserRights)) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT"); return false; } } else { if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $userID)) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT"); return false; } } $arCatalog = CCatalog::GetByID($arIBlockElement["IBLOCK_ID"]); if ($arCatalog["SUBSCRIPTION"] != "Y") { $APPLICATION->ThrowException(str_replace("#ID#", $arIBlockElement["IBLOCK_ID"], GetMessage("I_CATALOG_NOT_SUBSCR")), "NOT_SUBSCRIPTION"); return false; } if ($arProduct["CAN_BUY_ZERO"] != "Y" && ($arProduct["QUANTITY_TRACE"] == "Y" && doubleval($arProduct["QUANTITY"]) <= 0)) { $APPLICATION->ThrowException(str_replace("#ID#", $productID, GetMessage("I_PRODUCT_SOLD")), "PRODUCT_END"); return false; } $arUserGroups = CUser::GetUserGroup($userID); $arUserGroups = array_values(array_unique($arUserGroups)); CCatalogDiscountSave::Disable(); $arPrice = CCatalogProduct::GetOptimalPrice($productID, 1, $arUserGroups, "Y"); if (empty($arPrice)) { if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, 1, $arUserGroups)) { $quantity = $nearestQuantity; $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $arUserGroups, "Y"); } } CCatalogDiscountSave::Enable(); if (empty($arPrice)) { return false; } $currentPrice = $arPrice["PRICE"]["PRICE"]; $currentDiscount = 0.0; //SIGURD: logic change. see mantiss 5036. // discount applied to a final price with VAT already included. if (doubleval($arPrice['PRICE']['VAT_RATE']) > 0) { $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE']; } $arDiscountList = 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' => '', 'MODULE_ID' => 'catalog'); if ($arOneDiscount['COUPON']) { $arOneList['COUPON'] = $arOneDiscount['COUPON']; $dbRes = CCatalogDiscountCoupon::GetList(array(), array('COUPON' => $arOneDiscount['COUPON'], 'ONE_TIME' => 'Y'), false, array('nTopCount' => 1), array('ID')); if ($arRes = $dbRes->Fetch()) { $CATALOG_ONETIME_COUPONS_BASKET[$arOneDiscount['COUPON']] = $productID; } } $arDiscountList[] = $arOneList; } if (isset($arOneDiscount)) { unset($arOneDiscount); } $currentDiscount = $dblStartPrice - $currentPrice; } $recurType = $arProduct["RECUR_SCHEME_TYPE"]; $recurLength = intval($arProduct["RECUR_SCHEME_LENGTH"]); $recurSchemeVal = 0; if ($recurType == "H") { $recurSchemeVal = mktime(date("H") + $recurLength, date("i"), date("s"), date("m"), date("d"), date("Y")); } elseif ($recurType == "D") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $recurLength, date("Y")); } elseif ($recurType == "W") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 7 * $recurLength, date("Y")); } elseif ($recurType == "M") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + $recurLength, date("d"), date("Y")); } elseif ($recurType == "Q") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 3 * $recurLength, date("d"), date("Y")); } elseif ($recurType == "S") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 6 * $recurLength, date("d"), date("Y")); } elseif ($recurType == "Y") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + $recurLength); } elseif ($recurType == "T") { $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + 2 * $recurLength); } $arResult = array("WEIGHT" => $arProduct["WEIGHT"], "VAT_RATE" => $arPrice["PRICE"]["VAT_RATE"], "QUANTITY" => 1, "PRICE" => $currentPrice, "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "PRODUCT_ID" => $productID, "PRODUCT_NAME" => $arIBlockElement["~NAME"], "PRODUCT_URL" => $arIBlockElement["DETAIL_PAGE_URL"], "PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"], "CURRENCY" => $arPrice["PRICE"]["CURRENCY"], "NAME" => $arIBlockElement["NAME"], "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "CATALOG_GROUP_NAME" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arIBlockElement["DETAIL_PAGE_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "PRODUCT_XML_ID" => $arIBlockElement["XML_ID"], "NEXT_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), $recurSchemeVal)); if (!empty($arPrice["DISCOUNT_LIST"])) { $arResult['DISCOUNT_LIST'] = $arDiscountList; } return $arResult; }
/** * * @param $productID * @param $quantity * @param $renewal */ function CatalogBasketOrderCustomCallback($productID, $quantity, $renewal = "N") { $productID = IntVal($productID); $quantity = DoubleVal($quantity); $renewal = (($renewal == "Y") ? "Y" : "N"); $arResult = array(); if ($arCatalogProduct = CCatalogProduct::GetByID($productID)) { if ($arCatalogProduct["QUANTITY_TRACE"]=="Y" && DoubleVal($arCatalogProduct["QUANTITY"])<doubleVal($quantity)) return $arResult; } $rs = CPrice::GetList(array(), array("CATALOG_GROUP_NAME" => GetCityPrice(), "PRODUCT_ID" => $productID), false, false); $ar = $rs -> Fetch(); $arPrice = array(); $arPrice[] = array( "ID" => $ar["ID"], "PRICE" => $ar["PRICE"], "CURRENCY" => $ar["CURRENCY"], "CATALOG_GROUP_ID" => $ar["CATALOG_GROUP_ID"] ); $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray(), $renewal, $arPrice); if (!$arPrice || count($arPrice) <= 0) { if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray())) { $quantity = $nearestQuantity; $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray(), $renewal); } } if (!$arPrice || count($arPrice) <= 0) { return $arResult; } $dbIBlockElement = CIBlockElement::GetList( array(), array( "ID" => $productID, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y" ) ); $arProduct = $dbIBlockElement->GetNext(); $currentPrice = $arPrice["PRICE"]["PRICE"]; $currentDiscount = 0.0; //SIGURD: logic change. see mantiss 5036. // discount applied to a final price with VAT already included. if ($arPrice['PRICE']['VAT_INCLUDED'] == 'N') { if(DoubleVal($arPrice['PRICE']['VAT_RATE']) > 0) { $currentPrice *= (1 + $arPrice['PRICE']['VAT_RATE']); $arPrice['PRICE']['VAT_INCLUDED'] = 'Y'; } } if (isset($arPrice["DISCOUNT"]) && count($arPrice["DISCOUNT"]) > 0) { if ($arPrice["DISCOUNT"]["VALUE_TYPE"]=="F") { if ($arPrice["DISCOUNT"]["CURRENCY"] == $arPrice["PRICE"]["CURRENCY"]) $currentDiscount = $arPrice["DISCOUNT"]["VALUE"]; else $currentDiscount = CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT"]["VALUE"], $arPrice["DISCOUNT"]["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]); } else $currentDiscount = $currentPrice * $arPrice["DISCOUNT"]["VALUE"] / 100.0; $currentDiscount = roundEx($currentDiscount, SALE_VALUE_PRECISION); if (DoubleVal($arPrice["DISCOUNT"]["MAX_DISCOUNT"]) > 0) { if ($arPrice["DISCOUNT"]["CURRENCY"] == $baseCurrency) $maxDiscount = $arPrice["DISCOUNT"]["MAX_DISCOUNT"]; else $maxDiscount = CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT"]["MAX_DISCOUNT"], $arPrice["DISCOUNT"]["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]); $maxDiscount = roundEx($maxDiscount, CATALOG_VALUE_PRECISION); if ($currentDiscount > $maxDiscount) $currentDiscount = $maxDiscount; } $currentPrice = $currentPrice - $currentDiscount; } $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", "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DISCOUNT_PRICE" => $currentDiscount, ); if(!empty($arPrice["DISCOUNT"])) { if(strlen($arPrice["DISCOUNT"]["COUPON"])>0) $arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"]; if($arPrice["DISCOUNT"]["VALUE_TYPE"]=="P") $arResult["DISCOUNT_VALUE"] = $arPrice["DISCOUNT"]["VALUE"]."%"; else $arResult["DISCOUNT_VALUE"] = SaleFormatCurrency($arPrice["DISCOUNT"]["VALUE"], $arPrice["DISCOUNT"]["CURRENCY"]); $arResult["DISCOUNT_NAME"] = "[".$arPrice["DISCOUNT"]["ID"]."] ".$arPrice["DISCOUNT"]["NAME"]; $dbCoupon = CCatalogDiscountCoupon::GetList( array(), array("COUPON" => $arPrice["DISCOUNT"]["COUPON"]), false, false, array("ID", "ONE_TIME") ); if ($arCoupon = $dbCoupon->Fetch()) { $arFieldsCoupon = Array("DATE_APPLY" => Date($GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)))); if ($arCoupon["ONE_TIME"] == "Y") { $arFieldsCoupon["ACTIVE"] = "N"; foreach($_SESSION["CATALOG_USER_COUPONS"] as $k => $v) { if(trim($v) == trim($arPrice["DISCOUNT"]["COUPON"])) { unset($_SESSION["CATALOG_USER_COUPONS"][$k]); $_SESSION["CATALOG_USER_COUPONS"][$k] == ""; } } } CCatalogDiscountCoupon::Update($arCoupon["ID"], $arFieldsCoupon); } } if ($arCatalogProduct) { $arResult["WEIGHT"] = IntVal($arCatalogProduct["WEIGHT"]); } CCatalogProduct::QuantityTracer($productID, $quantity); return $arResult; }
public function HaveCoupons($ID, $excludeID = 0) { $ID = (int)$ID; if ($ID <= 0) return false; $arFilter = array("DISCOUNT_ID" => $ID); $excludeID = (int)$excludeID; if ($excludeID > 0) $arFilter['!ID'] = $excludeID; $dbRes = CCatalogDiscountCoupon::GetList(array(), $arFilter, false, array('nTopCount' => 1), array("ID")); if ($dbRes->Fetch()) return true; else return false; }