public static function getPriceTypesList($useId = false) { $useId = $useId === true; $result = array(); $priceTypeIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'NAME', 'NAME_LANG' => 'CURRENT_LANG.NAME'), 'order' => array('SORT' => 'ASC', 'ID' => 'ASC'))); while ($priceType = $priceTypeIterator->fetch()) { $priceType['NAME_LANG'] = (string) $priceType['NAME_LANG']; $priceCode = $useId ? $priceType['ID'] : $priceType['NAME']; $priceTitle = '[' . $priceType['ID'] . '] [' . $priceType['NAME'] . ']' . ($priceType['NAME_LANG'] != '' ? ' ' . $priceType['NAME_LANG'] : ''); $result[$priceCode] = $priceTitle; } unset($priceTitle, $priceCode, $priceType, $priceTypeIterator); return $result; }
protected static function getPriceTitle($priceType) { $priceType = (int) $priceType; if ($priceType <= 0) { return ''; } if (!isset(self::$priceTitleCache[$priceType])) { self::$priceTitleCache[$priceType] = ''; $groupIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'NAME', 'NAME_LANG' => 'CURRENT_LANG.NAME'), 'filter' => array('=ID' => $priceType))); $group = $groupIterator->fetch(); if (!empty($group)) { $group['NAME_LANG'] = (string) $group['NAME_LANG']; self::$priceTitleCache[$priceType] = $group['NAME_LANG'] != '' ? $group['NAME_LANG'] : $group['NAME']; } unset($group, $groupIterator); } return self::$priceTitleCache[$priceType]; }
protected function getPrices() { if ($this->arPrices === null) { $this->arPrices = array(); $priceTypeIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'BASE', 'NAME', 'NAME_LANG' => 'CURRENT_LANG.NAME'), 'order' => array('SORT' => 'ASC', 'ID' => 'ASC'))); while ($priceType = $priceTypeIterator->fetch()) { $priceType['ID'] = (int) $priceType['ID']; $priceType['NAME_LANG'] = (string) $priceType['NAME_LANG']; $this->arPrices[] = $priceType; } unset($priceType, $priceTypeIterator); } return $this->arPrices; }
/** * @param bool|string $strControlID * @return bool|array */ public static function GetControls($strControlID = false) { $priceTypeList = array(-1 => Loc::getMessage('BX_COND_CATALOG_PRICE_TYPE_ALL')); $priceTypeIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'NAME', 'LANG_NAME' => 'CURRENT_LANG.NAME'), 'order' => array('SORT' => 'ASC', 'ID' => 'ASC'))); while ($priceType = $priceTypeIterator->fetch()) { $priceType['ID'] = (int) $priceType['ID']; $priceType['LANG_NAME'] = (string) $priceType['LANG_NAME']; $priceTypeList[$priceType['ID']] = $priceType['NAME'] . ($priceType['LANG_NAME'] != '' ? ' (' . $priceType['LANG_NAME'] . ')' : ''); } unset($priceType, $priceTypeIterator); $priceTypeLogic = array(BT_COND_LOGIC_EQ => Loc::getMessage('BX_COND_CATALOG_PRICE_TYPE_LOGIC_EQ_LABEL'), BT_COND_LOGIC_NOT_EQ => Loc::getMessage('BX_COND_CATALOG_PRICE_TYPE_LOGIC_NOT_EQ_LABEL')); $controlList = array('CondCatalogPriceType' => array('ID' => 'CondCatalogPriceType', 'PARENT' => false, 'EXECUTE_MODULE' => 'catalog', 'EXIST_HANDLER' => 'Y', 'MODULE_ID' => 'catalog', 'MODULE_ENTITY' => 'catalog', 'ENTITY' => 'PRICE', 'FIELD' => 'CATALOG_GROUP_ID', 'FIELD_TABLE' => 'CATALOG_GROUP_ID', 'FIELD_TYPE' => 'int', 'MULTIPLE' => 'N', 'GROUP' => 'N', 'LABEL' => Loc::getMessage('BX_COND_CATALOG_PRICE_TYPE_LABEL'), 'PREFIX' => Loc::getMessage('BX_COND_CATALOG_PRICE_TYPE_PREFIX'), 'LOGIC' => static::GetLogicEx(array_keys($priceTypeLogic), $priceTypeLogic), 'JS_VALUE' => array('type' => 'select', 'values' => $priceTypeList, 'multiple' => 'Y', 'show_value' => 'Y'), 'PHP_VALUE' => array('VALIDATE' => 'list')), 'CondCatalogRenewal' => array('ID' => 'CondCatalogRenewal', 'PARENT' => false, 'EXECUTE_MODULE' => 'catalog', 'EXIST_HANDLER' => 'Y', 'MODULE_ID' => 'catalog', 'MODULE_ENTITY' => 'catalog', 'ENTITY' => 'DISCOUNT', 'FIELD' => 'RENEWAL', 'FIELD_TABLE' => 'RENEWAL', 'FIELD_TYPE' => 'char', 'MULTIPLE' => 'N', 'GROUP' => 'N', 'LABEL' => Loc::getMessage('BX_COND_CATALOG_RENEWAL_LABEL'), 'PREFIX' => Loc::getMessage('BX_COND_CATALOG_RENEWAL_PREFIX'), 'JS_VALUE' => array('type' => 'hidden', 'value' => 'Y'))); if ($strControlID === false) { return $controlList; } elseif (isset($controlList[$strControlID])) { return $controlList[$strControlID]; } else { return false; } }
/** * @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; } $userGroups = self::getUserGroups($intUserID); if (empty($userGroups)) { 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 (CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'RIGHTS_MODE') == 'E') { $arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID); if (empty($arUserRights) || !isset($arUserRights['element_read'])) { return $arResult; } unset($arUserRights); } else { if (CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID) < 'R') { return $arResult; } } } else { $userGroups = $USER->GetUserGroupArray(); $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 ($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'])) { $groupIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'NAME', 'NAME_LANG' => 'CURRENT_LANG.NAME'), 'filter' => array('ID' => $arPrice['PRICE']['CATALOG_GROUP_ID']))); if ($group = $groupIterator->fetch()) { $arPrice["PRICE"]["CATALOG_GROUP_NAME"] = !empty($group['NAME_LANG']) ? $group['NAME_LANG'] : $group['NAME']; } unset($group, $groupIterator); } } 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']); } } return $arResult; }
/** * Returns list of price IDs for storing in the index. * * @return integer[] */ protected function getFilterPrices() { if (!isset($this->priceFilter)) { $this->priceFilter = array(); if (self::$catalog) { $priceList = Catalog\GroupTable::getList(array('select' => array('ID'), 'order' => array('ID' => 'ASC'))); while ($price = $priceList->fetch()) { $this->priceFilter[] = (int) $price['ID']; } unset($price, $priceList); } } return $this->priceFilter; }
} if ($strHidden == '') { $strHidden = '<input type="hidden" name="GROUP_IDS[]" value="">'; } $tabControl->EndCustomField('GROUP_IDS', $strHidden); $tabControl->BeginCustomField("CAT_IDS", GetMessage('DSC_PRICE_TYPES') . ":", false); $strHidden = ''; ?> <tr id="tr_CAT_IDS"> <td valign="top" width="40%"><?php echo $tabControl->GetCustomLabelHTML(); ?> </td> <td valign="top" width="60%"> <select name="CAT_IDS[]" multiple size="8"><?php $priceTypeIterator = Catalog\GroupTable::getList(array('select' => array('ID', 'NAME', 'LANG_NAME' => 'CURRENT_LANG.NAME'), 'order' => array('NAME' => 'ASC', 'ID' => 'ASC'))); while ($priceType = $priceTypeIterator->fetch()) { $priceType['ID'] = (int) $priceType['ID']; $priceType['LANG_NAME'] = (string) $priceType['LANG_NAME']; $priceName = $priceType['NAME'] . ($priceType['LANG_NAME'] != '' ? ' (' . $priceType['LANG_NAME'] . ')' : ''); $selected = in_array($priceType['ID'], $arDiscountCatList) ? ' selected' : ''; ?> <option value="<?php echo $priceType['ID']; ?> "<?php echo $selected; ?> >[<?php echo $priceType['ID']; ?>
$strHidden = implode('', $arHidden); } if ($strHidden == '') $strHidden = '<input type="hidden" name="GROUP_IDS[]" value="">'; $tabControl->EndCustomField('GROUP_IDS', $strHidden); $tabControl->BeginCustomField("CAT_IDS", GetMessage('DSC_PRICE_TYPES').":", false); $strHidden = ''; ?><tr id="tr_CAT_IDS"> <td valign="top" width="40%"><? echo $tabControl->GetCustomLabelHTML(); ?></td> <td valign="top" width="60%"> <select name="CAT_IDS[]" multiple size="8"><? $priceTypeIterator = Catalog\GroupTable::getList(array( 'select' => array('ID', 'NAME', 'LANG_NAME' => 'LANG.NAME'), 'filter' => array('LANG.LANG' => LANGUAGE_ID), 'order' => array('NAME' => 'ASC', 'ID' => 'ASC') )); while ($priceType = $priceTypeIterator->fetch()) { $priceType['ID'] = (int)$priceType['ID']; $priceType['LANG_NAME'] = (string)$priceType['LANG_NAME']; $priceName = $priceType['NAME'].($priceType['LANG_NAME'] != '' ? ' ('.$priceType['LANG_NAME'].')' : ''); $selected = (in_array($priceType['ID'], $arDiscountCatList) ? ' selected' : ''); ?><option value="<? echo $priceType['ID']; ?>"<? echo $selected; ?>>[<? echo $priceType['ID']; ?>] <? echo htmlspecialcharsEx($priceName); ?></option><? } unset($selected, $priceName, $priceType, $priceTypeIterator); ?></select> </td> </tr><? if ($ID > 0 && !empty($arDiscountCatList))