/** * Convert discount data to other currency (sale currency). * * @param array &$discount Discout data. * @param string $currency New currency. * @return void */ public static function convertCurrency(&$discount, $currency) { $currency = Currency\CurrencyManager::checkCurrencyID($currency); if ($currency === false || empty($discount) || !is_array($discount)) { return; } if (!isset($discount['VALUE_TYPE']) || !isset($discount['CURRENCY']) || $discount['CURRENCY'] == $currency) { return; } switch ($discount['VALUE_TYPE']) { case self::VALUE_TYPE_FIX: case self::VALUE_TYPE_SALE: $discount['VALUE'] = roundEx(\CCurrencyRates::convertCurrency($discount['VALUE'], $discount['CURRENCY'], $currency), CATALOG_VALUE_PRECISION); $discount['CURRENCY'] = $currency; break; case self::VALUE_TYPE_PERCENT: if ($discount['MAX_DISCOUNT'] > 0) { $discount['MAX_DISCOUNT'] = roundEx(\CCurrencyRates::convertCurrency($discount['MAX_DISCOUNT'], $discount['CURRENCY'], $currency), CATALOG_VALUE_PRECISION); } $discount['CURRENCY'] = $currency; break; } }
/** * @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; }
public static function isExistCurrencyLanguage($currency, $language) { global $DB; $currency = Currency\CurrencyManager::checkCurrencyID($currency); $language = Currency\CurrencyManager::checkLanguage($language); if ($currency === false || $language === false) return false; $query = "select LID from b_catalog_currency_lang where CURRENCY = '".$DB->ForSql($currency)."' and LID = '".$DB->ForSql($language)."'"; $searchIterator = $DB->Query($query, false, 'File: '.__FILE__.'<br>Line: '.__LINE__); if ($result = $searchIterator->Fetch()) { return true; } return false; }
public static function checkCurrencyID($currency) { return Currency\CurrencyManager::checkCurrencyID($currency); }
protected static function updateBaseCurrency($currency) { global $DB, $USER; $currency = Currency\CurrencyManager::checkCurrencyID($currency); if ($currency === false) { return false; } $userID = self::isUserExists() ? (int) $USER->GetID() : false; $currentDate = $DB->GetNowFunction(); $fields = array('BASE' => 'N', '~DATE_UPDATE' => $currentDate, 'MODIFIED_BY' => $userID); $update = $DB->PrepareUpdate('b_catalog_currency', $fields); $query = "update b_catalog_currency set " . $update . " where CURRENCY <> '" . $currency . "' and BASE = 'Y'"; $DB->Query($query, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); $fields = array('BASE' => 'Y', '~DATE_UPDATE' => $currentDate, 'MODIFIED_BY' => $userID, 'AMOUNT' => 1, 'AMOUNT_CNT' => 1); $update = $DB->PrepareUpdate('b_catalog_currency', $fields); $query = "update b_catalog_currency set " . $update . " where CURRENCY = '" . $currency . "'"; $DB->Query($query, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); self::updateBaseRates($currency); return true; }
$filterFields = array(); if (!isset($by)) $by = 'SORT'; if (!isset($order)) $order = 'ASC'; $by = strtoupper($by); $order = strtoupper($order); if ($adminList->EditAction() && $CURRENCY_RIGHT == "W") { if (isset($FIELDS) && is_array($FIELDS)) { foreach ($FIELDS as $ID => $arFields) { $ID = Currency\CurrencyManager::checkCurrencyID($ID); if ($ID === false) continue; if (!$adminList->IsUpdated($ID)) continue; if (!CCurrency::Update($ID, $arFields)) { if ($ex = $APPLICATION->GetException()) { $adminList->AddUpdateError(GetMessage("CURRENCY_SAVE_ERR", array("#ID#" => $ID, "#ERROR_TEXT#" => $ex->GetString())), $ID); } else { $adminList->AddUpdateError(GetMessage("CURRENCY_SAVE_ERR2", array("#ID#"=>$ID)), $ID);
echo $prefix; echo \CCurrencyLang::CurrencyFormat($profit, CurrencyManager::getBaseCurrency(), true); ?> </div> <div class="seo-adv-block-text"><?php echo Loc::getMessage('SEO_YANDEX_STATS_HINT_GROSS'); ?> </div> </div> <?php $color = $expences > 0 ? 'red' : 'gray'; $prefix = $expences > 0 ? '– ' : ''; $text = CCurrencyLang::CurrencyFormat($expences, CurrencyManager::getBaseCurrency(), false); if ($currency == '') { $text .= ' ' . Loc::getMessage('SEO_YANDEX_CURRENCY'); } elseif (CurrencyManager::checkCurrencyID($currency)) { $text = CCurrencyLang::CurrencyFormat($expences, $currency, true); } else { $text .= ' ' . $currency; } ?> <div class="seo-adv-block seo-adv-block-<?php echo $color; ?> "> <div class="seo-adv-block-icon"></div> <div class="seo-adv-block-title"><?php echo $prefix; echo $text; ?> </div>
/** * Update base currency. * * @param string $currency Currency id. * @return bool */ public static function updateBaseCurrency($currency) { /** @global \CUser $USER */ global $USER; $currency = CurrencyManager::checkCurrencyID($currency); if ($currency === false) { return false; } $event = new Main\Event('currency', self::EVENT_ON_UPDATE_BASE_CURRENCY, array('NEW_BASE_CURRENCY' => $currency)); $event->send(); unset($event); $conn = Main\Application::getConnection(); $helper = $conn->getSqlHelper(); $userID = isset($USER) && $USER instanceof \CUser ? (int) $USER->getID() : 0; $tableName = $helper->quote(CurrencyTable::getTableName()); $baseField = $helper->quote('BASE'); $dateUpdateField = $helper->quote('DATE_UPDATE'); $modifiedByField = $helper->quote('MODIFIED_BY'); $amountField = $helper->quote('AMOUNT'); $amountCntField = $helper->quote('AMOUNT_CNT'); $currencyField = $helper->quote('CURRENCY'); $query = 'update ' . $tableName . ' set ' . $baseField . ' = \'N\', ' . $dateUpdateField . ' = ' . $helper->getCurrentDateTimeFunction() . ', ' . $modifiedByField . ' = ' . ($userID == 0 ? 'NULL' : $userID) . ' where ' . $currencyField . ' <> \'' . $helper->forSql($currency) . '\' and ' . $baseField . ' = \'Y\''; $conn->queryExecute($query); $query = 'update ' . $tableName . ' set ' . $baseField . ' = \'Y\', ' . $dateUpdateField . ' = ' . $helper->getCurrentDateTimeFunction() . ', ' . $modifiedByField . ' = ' . ($userID == 0 ? 'NULL' : $userID) . ', ' . $amountField . ' = 1, ' . $amountCntField . ' = 1 where ' . $currencyField . ' = \'' . $helper->forSql($currency) . '\''; $conn->queryExecute($query); static::updateBaseRates(); $event = new Main\Event('currency', self::EVENT_ON_AFTER_UPDATE_BASE_CURRENCY, array('NEW_BASE_CURRENCY' => $currency)); $event->send(); unset($event); self::$baseCurrency = ''; return true; }