protected function addCatalogProducts($arParams){ if (!CModule::IncludeModule("iblock") && !CModule::IncludeModule("catalog") && !CModule::IncludeModule("sale")): return false; endif; $arFields = array( "ID" => $arParams["PRODUCT_ID"], "QUANTITY" => $arParams["BALANCE"], "CAN_BUY_ZERO" => "Y", "NEGATIVE_AMOUNT_TRACE" => "Y", "QUANTITY_TRACE" => "Y" ); $db_res = CCatalogProduct::GetList( array(), array("ID" => $arParams["PRODUCT_ID"]), false, array() ); if ($ar_res = $db_res->Fetch()): if (!CCatalogProduct::Update($ar_res["ID"], $arFields)): return false; endif; else: if(!CCatalogProduct::Add($arFields)): return false; endif; endif; return true; }
function OnProductCatalogHandler($ID, $arFields) { Bitrix\Main\Loader::includeModule('iblock'); Bitrix\Main\Loader::includeModule('catalog'); define('IBLOCK_ID_PRODUCTS', 2); define('IBLOCK_ID_OFFERS', 3); $query = new \Bitrix\Main\Entity\Query(Bitrix\Iblock\ElementTable::getEntity()); $query->setSelect(array("ID", "IBLOCK_ID"))->setFilter(array("ID" => $ID))->setOrder(array("ID" => "ASC")); $resElement = $query->exec()->fetch(); if ($resElement['IBLOCK_ID'] == IBLOCK_ID_PRODUCTS) { CIBlockElement::SetPropertyValuesEx($ID, $resElement['IBLOCK_ID'], array("AVAILABLE_QUANTITY_CATALOG" => $arFields['QUANTITY'])); } elseif ($resElement['IBLOCK_ID'] == IBLOCK_ID_OFFERS) { //1 $rsElementOffer = CIBlockElement::GetList(array(), array("ID" => $ID), false, false, array("ID", "IBLOCK_ID", 'NAME', "PROPERTY_CML2_LINK"))->fetch(); $resElemOfferProduct = (int) $rsElementOffer['PROPERTY_CML2_LINK_VALUE']; //2 $resOffersCML2 = CIBlockElement::GetList(array(), array("PROPERTY_CML2_LINK" => $resElemOfferProduct, 'IBLOCK_ID' => IBLOCK_ID_OFFERS), false, false, array("ID", "IBLOCK_ID", 'NAME')); //3 $arrOffersIDs = array(); while ($res = $resOffersCML2->fetch()) { $arrOffersIDs[] = $res['ID']; } //4 $availQuant = array(); foreach ($arrOffersIDs as $k => $v) { $ar_res_cat = CCatalogProduct::GetList(array("ID" => "DESC"), array("ID" => (int) $v), false, false, array("ID", "QUANTITY", 'ELEMENT_IBLOCK_ID', 'ELEMENT_NAME'))->fetch(); $availQuant[] = $ar_res_cat['QUANTITY']; } //5 $minAvailQuant = (int) min($availQuant); //6 $resUpdateSCU = CIBlockElement::SetPropertyValuesEx($resElemOfferProduct, IBLOCK_ID_PRODUCTS, array("AVAILABLE_QUANTITY_CATALOG" => $minAvailQuant)); } }
/** * @param Basket $basketCollection * @param array $productList * @return array */ public static function getProductList(Basket $basketCollection, array $productList = array()) { $productBasketIndex = array(); $result = array(); foreach ($basketCollection as $basketKey => $basketItem) { $productId = intval($basketItem->getProductId()); if (intval($productId < 0) || sizeof($productList) > 0 && in_array($productId, $productList)) { continue; } $productBasketIndex[$basketKey] = $productId; } $rsProducts = \CCatalogProduct::GetList(array(), array('ID' => $productBasketIndex), false, false, array('ID', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE', 'QUANTITY_TRACE', 'QUANTITY', 'QUANTITY_RESERVED')); while ($arProduct = $rsProducts->Fetch()) { $result[$arProduct['ID']] = $arProduct; } return $result; }
public static function updateAll($page = 0, &$total, $perPage = CAutoPriceUpdater::LIMIT) { $list = CCatalogProduct::GetList(array(), array('IBLOCK_ID' => self::enabledCatalogs()), false, array('iNumPage' => $page + 1, 'nPageSize' => $perPage), array('ID')); $total = $list->NavPageCount; if ($page + 1 > $list->NavPageCount) { return false; } $priceType = COption::GetOptionInt('autoprice', 'priceTypes', 0); while ($res = $list->Fetch()) { $price = CPrice::GetBasePrice($res['ID'], false, false); $priseRub = floatval($price * self::$usdRate); if ($priseRub < 1000 && self::$extras[0]) { self::setExtra($res['ID'], $priceType, self::$extras[0]); } elseif ($priseRub < 10000 && self::$extras[1]) { self::setExtra($res['ID'], $priceType, self::$extras[1]); } elseif ($priseRub < 100000 && self::$extras[2]) { self::setExtra($res['ID'], $priceType, self::$extras[2]); } } return $page + 1 < $total; }
public static function getProductMeasures($productID) { if (!Main\Loader::includeModule('catalog')) { throw new Main\SystemException("Could not load 'catalog' module."); } $productIDs = is_array($productID) ? $productID : array($productID); $measure2product = array(); if (!empty($productIDs)) { $productEntity = new \CCatalogProduct(); $dbProductResult = $productEntity->GetList(array(), array('@ID' => $productIDs), false, false, array('ID', 'MEASURE')); if (is_object($dbProductResult)) { while ($productFields = $dbProductResult->Fetch()) { $measureID = isset($productFields['MEASURE']) ? intval($productFields['MEASURE']) : 0; if ($measureID <= 0) { continue; } if (isset($measure2product[$measureID])) { $measure2product[$measureID] = array(); } $measure2product[$measureID][] = intval($productFields['ID']); } } } $result = array(); if (!empty($measure2product)) { $dbMeasureResult = \CCatalogMeasure::getList(array(), array('@ID' => array_keys($measure2product)), false, false, array('ID', 'CODE', 'SYMBOL_RUS', 'SYMBOL_INTL', 'IS_DEFAULT')); if (is_object($dbMeasureResult)) { while ($measureFields = $dbMeasureResult->Fetch()) { $measureID = intval($measureFields['ID']); $measureInfo = array('ID' => $measureID, 'CODE' => intval($measureFields['CODE']), 'IS_DEFAULT' => isset($measureFields['IS_DEFAULT']) && $measureFields['IS_DEFAULT'] === 'Y', 'SYMBOL' => isset($measureFields['SYMBOL_RUS']) ? $measureFields['SYMBOL_RUS'] : $measureFields['SYMBOL_INTL']); foreach ($measure2product[$measureID] as $productID) { $result[$productID] = array($measureInfo); } } } } return $result; }
function getAvailableQuantity($arBasketItems) { if (empty($arBasketItems) || !is_array($arBasketItems)) { return array(); } if ($catalogIncluded === null) { $catalogIncluded = Loader::includeModule('catalog'); } if (!$catalogIncluded) { return false; } $arElementId = array(); $productMap = array(); foreach ($arBasketItems as $key => $arItem) { $arElementId[$arItem['PRODUCT_ID']] = $arItem['PRODUCT_ID']; if (!isset($productMap[$arItem['PRODUCT_ID']])) { $productMap[$arItem['PRODUCT_ID']] = array(); } $productMap[$arItem['PRODUCT_ID']][] = $key; } unset($key, $arItem); if (!empty($arElementId)) { $productIterator = CCatalogProduct::GetList(array(), array('ID' => $arElementId), false, false, array('ID', 'QUANTITY')); while ($product = $productIterator->Fetch()) { if (!isset($productMap[$product['ID']])) { continue; } foreach ($productMap[$product['ID']] as $key) { $arBasketItems[$key]['AVAILABLE_QUANTITY'] = $product['QUANTITY']; } unset($key); } unset($product, $productIterator); } unset($productMap, $arElementId); return $arBasketItems; }
protected function fillSetItemsParams(&$items) { $productIterator = CCatalogProduct::GetList(array(), array('=ID' => array_keys($items)), false, false, array('ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO', 'WEIGHT')); while ($product = $productIterator->Fetch()) { $product['ID'] = (int) $product['ID']; if (isset($items[$product['ID']])) { $items[$product['ID']] = array_merge($items[$product['ID']], $product); } } }
/** * @param $userId * @param $lid * @param $productId * @param string $productName * @param string $currency * @param array $arProduct * @return array|bool */ function GetProductSku($userId, $lid, $productId, $productName = '', $currency = '', $arProduct = array()) { $userId = intval($userId); $productId = intval($productId); if ($productId <= 0) { return false; } $lid = trim($lid); if (strlen($lid) <= 0) { return false; } $productName = trim($productName); $arResult = array(); static $arCacheGroups = array(); if (!isset($arCacheGroups[$userId])) { $arCacheGroups[$userId] = CUser::GetUserGroup($userId); } $arGroups = $arCacheGroups[$userId]; if (!isset($arProduct["IBLOCK_ID"]) || 0 >= intval($arProduct["IBLOCK_ID"])) { $arProduct["IBLOCK_ID"] = CIBlockElement::GetIBlockByID($arProduct["IBLOCK_ID"]); } static $arOffersIblock = array(); if (!isset($arOffersIblock[$arProduct["IBLOCK_ID"]])) { $mxResult = CCatalogSKU::GetInfoByProductIBlock($arProduct["IBLOCK_ID"]); if (is_array($mxResult)) { $arOffersIblock[$arProduct["IBLOCK_ID"]] = $mxResult["IBLOCK_ID"]; } } if ($arOffersIblock[$arProduct["IBLOCK_ID"]] > 0) { static $arCacheOfferProperties = array(); if (!is_set($arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]])) { $dbOfferProperties = CIBlockProperty::GetList(array('SORT' => 'ASC', 'ID' => 'ASC'), array('IBLOCK_ID' => $arOffersIblock[$arProduct["IBLOCK_ID"]], 'ACTIVE' => 'Y', "!XML_ID" => "CML2_LINK")); while ($arOfferProperties = $dbOfferProperties->Fetch()) { if ('F' == $arOfferProperties['PROPERTY_TYPE']) { continue; } $arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]][] = $arOfferProperties; } } $arOfferProperties = $arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]]; $arIblockOfferProps = array(); $arIblockOfferPropsFilter = array(); if (is_array($arOfferProperties)) { foreach ($arOfferProperties as $val) { $arIblockOfferProps[] = array("CODE" => $val["CODE"], "NAME" => $val["NAME"]); $arIblockOfferPropsFilter[] = $val["CODE"]; } } $arOffers = CIBlockPriceTools::GetOffersArray($arProduct["IBLOCK_ID"], $productId, array("ID" => "DESC"), array("NAME", "EXTERNAL_ID"), $arIblockOfferPropsFilter, 0, array(), 1, array(), $userId, $lid); $arSku = array(); $arSkuId = array(); $arImgSku = array(); foreach ($arOffers as $arOffer) { $arSkuId[] = $arOffer['ID']; } if (!empty($arSkuId)) { $res = CIBlockElement::GetList(array(), array("ID" => $arSkuId), false, false, array("ID", "IBLOCK_ID", "NAME", "PREVIEW_PICTURE", "DETAIL_PICTURE", "DETAIL_PAGE_URL", "ACTIVE")); while ($arOfferImg = $res->GetNext()) { $arImgSku[$arOfferImg["ID"]] = $arOfferImg; } } $arOffersId = array(); foreach ($arOffers as $arOffer) { $arOffersId[] = $arOffer['ID']; } $dbCatalogProduct = CCatalogProduct::GetList(array(), array("ID" => $arOffersId)); while ($arCatalogProduct = $dbCatalogProduct->fetch()) { $arCatalogProductResult[$arCatalogProduct["ID"]] = $arCatalogProduct; } foreach ($arOffers as $arOffer) { $arSkuTmp = array(); $active = ''; $arOffer["CAN_BUY"] = "N"; $arCatalogProduct = $arCatalogProductResult[$arOffer["ID"]]; if (!empty($arCatalogProduct)) { if ($arCatalogProduct["CAN_BUY_ZERO"] != "Y" && ($arCatalogProduct["QUANTITY_TRACE"] == "Y" && doubleval($arCatalogProduct["QUANTITY"]) <= 0)) { $arOffer["CAN_BUY"] = "N"; } else { $arOffer["CAN_BUY"] = "Y"; } } $arSkuTmp["ImageUrl"] = ''; if ($arOffer["CAN_BUY"] == "Y") { if (isset($arImgSku[$arOffer['ID']]) && !empty($arImgSku[$arOffer['ID']])) { if ('' == $productName) { $productName = $arImgSku[$arOffer['ID']]["~NAME"]; } $active = $arImgSku[$arOffer['ID']]["ACTIVE"]; if ($arImgSku[$arOffer['ID']]["PREVIEW_PICTURE"] != "") { $arSkuTmp["PREVIEW_PICTURE"] = $arImgSku[$arOffer['ID']]["PREVIEW_PICTURE"]; } if ($arImgSku[$arOffer['ID']]["DETAIL_PICTURE"] != "") { $arSkuTmp["DETAIL_PICTURE"] = $arImgSku[$arOffer['ID']]["DETAIL_PICTURE"]; } } } foreach ($arIblockOfferProps as $arCode) { if (is_array($arCode) && isset($arOffer["PROPERTIES"][$arCode["CODE"]])) { if (isset($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]])) { $mxValues = ''; if ('E' == $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['PROPERTY_TYPE']) { if (!empty($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_ELEMENT_VALUE'])) { $mxValues = array(); foreach ($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_ELEMENT_VALUE'] as $arTempo) { $mxValues[] = $arTempo['NAME'] . ' [' . $arTempo['ID'] . ']'; } } } elseif ('G' == $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['PROPERTY_TYPE']) { if (!empty($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_SECTION_VALUE'])) { $mxValues = array(); foreach ($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_SECTION_VALUE'] as $arTempo) { $mxValues[] = $arTempo['NAME'] . ' [' . $arTempo['ID'] . ']'; } } } if (empty($mxValues)) { $mxValues = $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]["DISPLAY_VALUE"]; } $arSkuTmp[] = strip_tags(is_array($mxValues) ? implode("/ ", $mxValues) : $mxValues); } else { $arSkuTmp[] = ''; } } } if (!empty($arCatalogProduct)) { $arSkuTmp["BALANCE"] = $arCatalogProduct["QUANTITY"]; $arSkuTmp["WEIGHT"] = $arCatalogProduct["WEIGHT"]; $arSkuTmp["BARCODE_MULTI"] = $arCatalogProduct["BARCODE_MULTI"]; } else { $arSkuTmp["BALANCE"] = 0; $arSkuTmp["WEIGHT"] = 0; $arSkuTmp["BARCODE_MULTI"] = 'N'; } $arSkuTmp["USER_ID"] = $userId; $arSkuTmp["ID"] = $arOffer["ID"]; $arSkuTmp["TYPE"] = $arOffer["CATALOG_TYPE"]; $arSkuTmp["NAME"] = CUtil::JSEscape($arOffer["NAME"]); $arSkuTmp["PRODUCT_NAME"] = CUtil::JSEscape(htmlspecialcharsbx($productName)); $arSkuTmp["PRODUCT_ID"] = $productId; $arSkuTmp["LID"] = CUtil::JSEscape($lid); $arSkuTmp["CAN_BUY"] = $arOffer["CAN_BUY"]; $arSkuTmp["ACTIVE"] = $active; $arSkuTmp["EXTERNAL_ID"] = $arOffer['EXTERNAL_ID']; $arSku[] = $arSkuTmp; } if ((!is_array($arIblockOfferProps) || empty($arIblockOfferProps)) && is_array($arSku) && !empty($arSku)) { $arIblockOfferProps[0] = array("CODE" => "TITLE", "NAME" => GetMessage("SKU_TITLE")); foreach ($arSku as $key => $val) { $arSku[$key][0] = $val["NAME"]; } } $arResult["SKU_ELEMENTS"] = $arSku; $arResult["SKU_PROPERTIES"] = $arIblockOfferProps; $arResult["OFFERS_IBLOCK_ID"] = $arOffersIblock[$arProduct["IBLOCK_ID"]]; } return $arResult; }
public function ExtendBasketItems(&$arBasket, $arExtend) { $arFields = array('ID', 'IBLOCK_ID', 'CODE', 'XML_ID', 'NAME', 'DATE_ACTIVE_FROM', 'DATE_ACTIVE_TO', 'SORT', 'PREVIEW_TEXT', 'DETAIL_TEXT', 'DATE_CREATE', 'CREATED_BY', 'TIMESTAMP_X', 'MODIFIED_BY', 'TAGS', 'TIMESTAMP_X_UNIX', 'DATE_CREATE_UNIX'); $arCatFields = array('ID', 'QUANTITY', 'WEIGHT', 'VAT_ID', 'VAT_INCLUDED'); $boolFields = false; if (isset($arExtend['catalog']['fields'])) { $boolFields = (bool) $arExtend['catalog']['fields']; } $boolProps = false; if (isset($arExtend['catalog']['props'])) { $boolProps = (bool) $arExtend['catalog']['props']; } if ($boolFields || $boolProps) { $arMap = array(); $arIDS = array(); foreach ($arBasket as $strKey => $arOneRow) { if (isset($arOneRow['MODULE']) && 'catalog' == $arOneRow['MODULE']) { $intProductID = (int) $arOneRow['PRODUCT_ID']; if ($intProductID > 0) { $arIDS[$intProductID] = true; if (!isset($arMap[$intProductID])) { $arMap[$intProductID] = array(); } $arMap[$intProductID][] = $strKey; } } } if (!empty($arIDS)) { $arBasketResult = array(); $iblockGroup = array(); $arIDS = array_keys($arIDS); self::SetProductSectionsCache($arIDS); CTimeZone::Disable(); $rsItems = CIBlockElement::GetList(array(), array('ID' => $arIDS), false, false, $arFields); while ($arItem = $rsItems->Fetch()) { $arBasketData = array(); $arItem['ID'] = (int) $arItem['ID']; $arItem['IBLOCK_ID'] = (int) $arItem['IBLOCK_ID']; if (!isset($iblockGroup[$arItem['IBLOCK_ID']])) { $iblockGroup[$arItem['IBLOCK_ID']] = array(); } $iblockGroup[$arItem['IBLOCK_ID']][] = $arItem['ID']; if ($boolFields) { $arBasketData['ID'] = $arItem['ID']; $arBasketData['IBLOCK_ID'] = $arItem['IBLOCK_ID']; $arBasketData['NAME'] = $arItem['NAME']; $arBasketData['XML_ID'] = (string) $arItem['XML_ID']; $arBasketData['CODE'] = (string) $arItem['CODE']; $arBasketData['TAGS'] = (string) $arItem['TAGS']; $arBasketData['SORT'] = (int) $arBasketData['SORT']; $arBasketData['PREVIEW_TEXT'] = (string) $arBasketData['PREVIEW_TEXT']; $arBasketData['DETAIL_TEXT'] = (string) $arBasketData['DETAIL_TEXT']; $arBasketData['CREATED_BY'] = (int) $arBasketData['CREATED_BY']; $arBasketData['MODIFIED_BY'] = (int) $arBasketData['MODIFIED_BY']; $arBasketData['DATE_ACTIVE_FROM'] = (string) $arItem['DATE_ACTIVE_FROM']; if (!empty($arBasketData['DATE_ACTIVE_FROM'])) { $arBasketData['DATE_ACTIVE_FROM'] = (int) MakeTimeStamp($arBasketData['DATE_ACTIVE_FROM']); } $arBasketData['DATE_ACTIVE_TO'] = (string) $arItem['DATE_ACTIVE_TO']; if (!empty($arBasketData['DATE_ACTIVE_TO'])) { $arBasketData['DATE_ACTIVE_TO'] = (int) MakeTimeStamp($arBasketData['DATE_ACTIVE_TO']); } if (isset($arItem['DATE_CREATE_UNIX'])) { $arBasketData['DATE_CREATE'] = (string) $arItem['DATE_CREATE_UNIX']; if ($arBasketData['DATE_CREATE'] != '') { $arBasketData['DATE_CREATE'] = (int) $arBasketData['DATE_CREATE']; } } else { $arBasketData['DATE_CREATE'] = (string) $arItem['DATE_CREATE']; if ($arBasketData['DATE_CREATE'] != '') { $arBasketData['DATE_CREATE'] = (int) MakeTimeStamp($arBasketData['DATE_CREATE']); } } if (isset($arItem['TIMESTAMP_X_UNIX'])) { $arBasketData['TIMESTAMP_X'] = (string) $arItem['TIMESTAMP_X_UNIX']; if ($arBasketData['TIMESTAMP_X'] != '') { $arBasketData['TIMESTAMP_X'] = (int) $arBasketData['TIMESTAMP_X']; } } else { $arBasketData['TIMESTAMP_X'] = (string) $arItem['TIMESTAMP_X']; if ($arBasketData['TIMESTAMP_X'] != '') { $arBasketData['TIMESTAMP_X'] = (int) MakeTimeStamp($arBasketData['TIMESTAMP_X']); } } $arProductSections = self::__GetSectionList($arItem['IBLOCK_ID'], $arItem['ID']); if ($arProductSections !== false) { $arBasketData['SECTION_ID'] = $arProductSections; } else { $arBasketData['SECTION_ID'] = array(); } } if ($boolProps) { $arBasketData['PROPERTIES'] = array(); } $arBasketResult[$arItem['ID']] = $arBasketData; } CTimeZone::Enable(); if ($boolProps && !empty($iblockGroup)) { foreach ($iblockGroup as $iblockID => $iblockItems) { $filter = array('ID' => $iblockItems, 'IBLOCK_ID' => $iblockID); CIBlockElement::GetPropertyValuesArray($arBasketResult, $iblockID, $filter); } unset($iblockItems, $iblockID); foreach ($arBasketResult as &$basketItem) { self::__ConvertProperties($basketItem, $basketItem['PROPERTIES'], array('TIME_ZONE' => 'N')); } unset($basketItem); } $rsProducts = CCatalogProduct::GetList(array(), array('@ID' => $arIDS), false, false, $arCatFields); while ($arProduct = $rsProducts->Fetch()) { $arProduct['ID'] = (int) $arProduct['ID']; if (!isset($arBasketResult[$arProduct['ID']])) { $arBasketResult[$arProduct['ID']] = array(); } foreach ($arProduct as $productKey => $productValue) { if ($productKey == 'ID') { continue; } $arBasketResult[$arProduct['ID']]['CATALOG_' . $productKey] = $productValue; } unset($productKey, $productValue); } if (!empty($iblockGroup)) { foreach ($iblockGroup as $iblockID => $iblockItems) { $sku = CCatalogSKU::GetInfoByOfferIBlock($iblockID); if (!empty($sku)) { foreach ($iblockItems as $itemID) { $isSku = self::__GenerateParent($arBasketResult[$itemID], $sku); } unset($isSku, $itemID); } } unset($sku, $iblockItems, $iblockID); } if (!empty($arBasketResult)) { foreach ($arBasketResult as $intProductID => $arBasketData) { foreach ($arMap[$intProductID] as $mxRowID) { $arBasket[$mxRowID]['CATALOG'] = $arBasketData; } } } } } }
$ar_res = CIBlockElement::GetByID($arItem["ITEM_ID"])->GetNextElement(); if ($ar_res) { $field = $ar_res->GetFields(); $props = $ar_res->GetProperties(); if ($field['PREVIEW_PICTURE']) { $arResult["SEARCH"][$i]["PREVIEW_PICTURE"] = CFile::GetPath($field['PREVIEW_PICTURE']); } $arResult["SEARCH"][$i]["FOR_ORDER"] = $props['FOR_ORDER']; if (!is_array($arResult["SEARCH"][$i]["PRICES"]) && is_array($props['PRICE_BASE'])) { $arResult["SEARCH"][$i]["PRICES"] = array(); $arResult["SEARCH"][$i]["PRICES"]["PRICE"] = $props['PRICE_BASE']["VALUE"] . " <span class='rubl'>" . GetMessage('RUB') . "</span>"; } } } if (CModule::IncludeModule("catalog")) { $db_res = CCatalogProduct::GetList(array(), array("ID" => $arItem["ITEM_ID"]), false, false, array("QUANTITY", "QUANTITY_TRACE", "CAN_BUY_ZERO")); while ($ar_res = $db_res->Fetch()) { $arResult["SEARCH"][$i]["QUANTITY"] = $ar_res["QUANTITY"]; $arResult["SEARCH"][$i]["QUANTITY_TRACE"] = $ar_res["QUANTITY_TRACE"]; $arResult["SEARCH"][$i]["CAN_BUY_ZERO"] = $ar_res["CAN_BUY_ZERO"]; } } /* preview end */ break; } } $arParams['PHOTO_SIZE'] = $arParams['PHOTO_SIZE'] ? intval($arParams['PHOTO_SIZE']) : 5; if (!empty($arResult["CATEGORIES"])) { // ----- find photo --------- $arParams['IMAGE'] = 'MORE_PHOTO'; $arParams['HEIGHT'] = '50';
/** * <p>Уменьшает количество на складе товара с кодом PRODUCT_ID на величину DELTA_QUANTITY, если указанное количество есть на складе и у товара установлен флаг "уменьшать количество товара при заказе" </p> * * * * * @param int $PRODUCT_ID Код товара. * * * * @param int $DELTA_QUANTITY Число, на которое нужно уменьшить количество товара на складе. * * * * @return bool <p>Возвращает <i>true</i> в случае успешного уменьшения и <i>false</i> - в * противном случае </p><a name="examples"></a> * * * <h4>Example</h4> * <pre> * <? * // Уменьшим количество на складе товара 5 на 12 штук * CCatalogProduct::QuantityTracer(5, 12); * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/ccatalogproduct__quantitytracer.8cc817fa.php * @author Bitrix */ public static function QuantityTracer($ProductID, $DeltaQuantity) { global $DB; global $CACHE_MANAGER; $boolClearCache = false; $ProductID = intval($ProductID); if (0 >= $ProductID) return false; $DeltaQuantity = doubleval($DeltaQuantity); if ($DeltaQuantity==0) return false; $rsProducts = CCatalogProduct::GetList( array(), array('ID' => $ProductID), false, false, array('ID', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE', 'QUANTITY_TRACE', 'QUANTITY', 'ELEMENT_IBLOCK_ID') ); if (($arProduct = $rsProducts->Fetch()) && ($arProduct["QUANTITY_TRACE"]=="Y")) { $strAllowNegativeAmount = $arProduct["NEGATIVE_AMOUNT_TRACE"]; $arFields = array(); $arFields["QUANTITY"] = doubleval($arProduct["QUANTITY"]) - $DeltaQuantity; if ('Y' != $arProduct['CAN_BUY_ZERO']) { if (defined("BX_COMP_MANAGED_CACHE")) { $boolClearCache = (0 >= $arFields["QUANTITY"]*$arProduct["QUANTITY"]); } } if ('Y' != $arProduct['CAN_BUY_ZERO'] || 'Y' != $strAllowNegativeAmount) { if (0 >= $arFields["QUANTITY"]) $arFields["QUANTITY"] = 0; } $arFields['OLD_QUANTITY'] = $arProduct["QUANTITY"]; CCatalogProduct::Update($arProduct["ID"], $arFields); if ($boolClearCache) $CACHE_MANAGER->ClearByTag('iblock_id_'.$arProduct['ELEMENT_IBLOCK_ID']); $arProduct['OLD_QUANTITY'] = $arFields['OLD_QUANTITY']; $arProduct['QUANTITY'] = $arFields['QUANTITY']; $arProduct['ALLOW_NEGATIVE_AMOUNT'] = $strAllowNegativeAmount; $arProduct['DELTA'] = $DeltaQuantity; foreach (GetModuleEvents("catalog", "OnProductQuantityTrace", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arProduct["ID"], $arProduct)); } return true; } return false; }
if (array_key_exists("QUANTITY_" . $val["ID"], $_POST)) { $_POST["QUANTITY_" . $val["ID"]] = str_replace(",", ".", $_POST["QUANTITY_" . $val["ID"]]); $dblQuantity = $arParams['QUANTITY_FLOAT'] == 'Y' ? DoubleVal($_POST["QUANTITY_" . $val["ID"]]) : intval($_POST["QUANTITY_" . $val["ID"]]); if ($dblQuantity != $val['QUANTITY']) { if ('catalog' == $val['MODULE']) { $arProductIDs[$val["PRODUCT_ID"]] = $key; $arNewQuantity[$val["PRODUCT_ID"]] = $dblQuantity; } else { $arFields = array("QUANTITY" => $dblQuantity); CSaleBasket::Update($val["ID"], $arFields); } } } } if (!empty($arProductIDs) && Loader::includeModule('catalog')) { $rsProducts = CCatalogProduct::GetList(array(), array('ID' => array_keys($arProductIDs)), false, false, $arSelect); while ($arProduct = $rsProducts->Fetch()) { if (array_key_exists($arProduct['ID'], $arProductIDs)) { $key = $arProductIDs[$arProduct['ID']]; if ($arNewQuantity[$arProduct['ID']] > $arProduct['QUANTITY'] && 'Y' == $arProduct['QUANTITY_TRACE'] && 'N' == $arProduct['CAN_BUY_ZERO']) { $arNewQuantity[$arProduct['ID']] = $arProduct['QUANTITY']; $productLimit .= GetMessage("STOF_WARNING_LIMIT_PRODUCT") . " " . $arShoppingCart[$key]["NAME"] . "<br>"; } if ($arNewQuantity[$arProduct['ID']] != $arShoppingCart[$key]['QUANTITY']) { $arShoppingCart[$key]['QUANTITY'] = $arNewQuantity[$arProduct['ID']]; $arFields = array("QUANTITY" => $arNewQuantity[$arProduct['ID']], 'TYPE' => $arShoppingCart[$key]['TYPE'], 'SET_PARENT_ID' => $arShoppingCart[$key]['SET_PARENT_ID']); CSaleBasket::Update($arShoppingCart[$key]["ID"], $arFields); } } } }
$arCatalogProduct[$val["PRODUCT_ID"]] = $val["TABLE_ROW_ID"]; } $orderDiscount += $val["DISCOUNT_PRICE"] * $val["QUANTITY"]; $arFilterRecommended[] = $val["PRODUCT_ID"]; $priceBaseTotal += ($priceBase * $val["QUANTITY"]); } } if (!empty($arCatalogProduct) && $bUseCatalog) { $rsItems = CCatalogProduct::GetList( array(), array('ID' => array_keys($arCatalogProduct)), false, false, array('ID', 'QUANTITY') ); while ($arItem = $rsItems->Fetch()) { $strKey = $arCatalogProduct[$arItem['ID']]; $arData[$strKey]["BALANCE"] = floatval($arItem['QUANTITY']); } } } $arData[0]["ORDER_ERROR"] = "N"; //change delivery price $deliveryChangePrice = false; if ($delpricechange == "Y")
function getProductDataToFillBasket($productId, $quantity, $userId, $LID, $userColumns, $tmpId = "") { if (!\Bitrix\Main\Loader::includeModule("catalog")) return array(); $arParams = array(); $productId = (int)$productId; if ($productId <= 0) { return $arParams; } $iblockId = (int)CIBlockElement::GetIBlockByID($productId); if ($iblockId <= 0) { return $arParams; } $arSku2Parent = array(); $arElementId = array(); $arElementId[] = $productId; $arParent = CCatalogSku::GetProductInfo($productId, $iblockId); if ($arParent) { $arElementId[] = $arParent["ID"]; $arSku2Parent[$productId] = $arParent["ID"]; } $arPropertyInfo = array(); $userColumns = (string)$userColumns; $arUserColumns = ($userColumns != '') ? explode(",", $userColumns) : array(); foreach ($arUserColumns as $key => $column) { if (strncmp($column, 'PROPERTY_', 9) != 0) { unset($arUserColumns[$key]); } else { $propertyCode = substr($column, 9); if ($propertyCode == '') { unset($arUserColumns[$key]); continue; } $dbres = CIBlockProperty::GetList(array(), array("CODE" => $propertyCode)); if ($arPropData = $dbres->GetNext()) $arPropertyInfo[$column] = $arPropData; } } $arSelect = array_merge( array("ID", "NAME", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "DETAIL_PAGE_URL", "XML_ID", "IBLOCK_XML_ID"), $arUserColumns ); $arProductData = getProductProps($arElementId, $arSelect); $defaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true); if (!empty($arProductData)) { $arElementInfo = array(); foreach ($arProductData as $elemId => &$arElement) { foreach ($arElement as $key => $value) { if (strncmp($key, 'PROPERTY_', 9) == 0 && substr($key, -6) == "_VALUE") { $columnCode = str_replace("_VALUE", "", $key); $arElement[$key] = getIblockPropInfo($value, $arPropertyInfo[$columnCode], array("WIDTH" => 90, "HEIGHT" => 90)); } } } unset($arElement); if (isset($arProductData[$productId])) $arElementInfo = $arProductData[$productId]; if (isset( $arSku2Parent[$productId])) $arParent = $arProductData[$arSku2Parent[$productId]]; if (!empty($arSku2Parent)) // if sku element doesn't have value of some property - we'll show parent element value instead { foreach ($arUserColumns as $field) { $fieldVal = $field."_VALUE"; $parentId = $arSku2Parent[$productId]; if ((!isset($arElementInfo[$fieldVal]) || (isset($arElementInfo[$fieldVal]) && strlen($arElementInfo[$fieldVal]) == 0)) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) // can be array or string { $arElementInfo[$fieldVal] = $arProductData[$parentId][$fieldVal]; } } if (strpos($arElementInfo["~XML_ID"], '#') === false) { $arElementInfo["~XML_ID"] = $arParent['~XML_ID'].'#'.$arElementInfo["~XML_ID"]; } } $arElementInfo["MODULE"] = "catalog"; $arElementInfo["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider"; $arElementInfo["PRODUCT_ID"] = $arElementInfo["ID"]; if ($arElementInfo["IBLOCK_ID"] > 0) { $arElementInfo["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arElementInfo["IBLOCK_ID"], $arElementInfo["PRODUCT_ID"], array( "find_section_section" => $arElementInfo["IBLOCK_SECTION_ID"], 'WF' => 'Y', )); } $arBuyerGroups = CUser::GetUserGroup($userId); // price $arPrice = CCatalogProduct::GetOptimalPrice($arElementInfo["ID"], 1, $arBuyerGroups, "N", array(), $LID); $currentPrice = $arPrice["DISCOUNT_PRICE"]; $arElementInfo["PRICE"] = $currentPrice; $arElementInfo["CURRENCY"] = $arPrice["PRICE"]["CURRENCY"]; $arElementInfo["DISCOUNT_PRICE"] = $arPrice["PRICE"]["PRICE"] - $arPrice["DISCOUNT_PRICE"]; $currentTotalPrice = ($arElementInfo["PRICE"] + $arElementInfo["DISCOUNT_PRICE"]); $discountPercent = 0; if ($arElementInfo["DISCOUNT_PRICE"] > 0) $discountPercent = intval(($arElementInfo["DISCOUNT_PRICE"] * 100) / $currentTotalPrice); $rsProducts = CCatalogProduct::GetList( array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY', 'WEIGHT', 'MEASURE', 'TYPE', 'BARCODE_MULTI') ); if (!($arProduct = $rsProducts->Fetch())) { return array(); } $balance = floatval($arProduct["QUANTITY"]); // sku props $arSkuData = array(); $arProps[] = array( "NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $arElementInfo['~IBLOCK_XML_ID'] ); $arSkuProperty = CSaleProduct::GetProductSkuProps($productId, '', true); if (!empty($arSkuProperty)) { foreach ($arSkuProperty as &$val) { $arSkuData[] = array( 'NAME' => $val['NAME'], 'VALUE' => $val['VALUE'], 'CODE' => $val['CODE'] ); } unset($val); } $arSkuData[] = array( "NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arElementInfo["~XML_ID"] ); // currency $arCurFormat = CCurrencyLang::GetCurrencyFormat($arElementInfo["CURRENCY"]); $priceValutaFormat = str_replace("#", "", $arCurFormat["FORMAT_STRING"]); $arElementInfo["WEIGHT"] = $arProduct["WEIGHT"]; // measure $arElementInfo["MEASURE_TEXT"] = ""; if ((int)$arProduct["MEASURE"] > 0) { $dbMeasure = CCatalogMeasure::GetList(array(), array("ID" => intval($arProduct["MEASURE"])), false, false, array("ID", "SYMBOL_RUS", "SYMBOL_INTL")); if ($arMeasure = $dbMeasure->Fetch()) $arElementInfo["MEASURE_TEXT"] = ($arMeasure["SYMBOL_RUS"] != '' ? $arMeasure["SYMBOL_RUS"] : $arMeasure["SYMBOL_INTL"]); } if ($arElementInfo["MEASURE_TEXT"] == '') { $arElementInfo["MEASURE_TEXT"] = ($defaultMeasure["SYMBOL_RUS"] != '' ? $defaultMeasure["SYMBOL_RUS"] : $defaultMeasure["SYMBOL_INTL"]); } // ratio $arElementInfo["RATIO"] = 1; $dbratio = CCatalogMeasureRatio::GetList(array(), array("PRODUCT_ID" => $productId)); if ($arRatio = $dbratio->Fetch()) $arElementInfo["RATIO"] = $arRatio["RATIO"]; // image if ($arElementInfo["PREVIEW_PICTURE"] > 0) $imgCode = $arElementInfo["PREVIEW_PICTURE"]; elseif ($arElementInfo["DETAIL_PICTURE"] > 0) $imgCode = $arElementInfo["DETAIL_PICTURE"]; if ($imgCode == "" && count($arParent) > 0) { if ($arParent["PREVIEW_PICTURE"] > 0) $imgCode = $arParent["PREVIEW_PICTURE"]; elseif ($arParent["DETAIL_PICTURE"] > 0) $imgCode = $arParent["DETAIL_PICTURE"]; } if ($imgCode > 0) { $arFile = CFile::GetFileArray($imgCode); $arImgProduct = CFile::ResizeImageGet($arFile, array('width'=>80, 'height'=>80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false); if (is_array($arImgProduct)) $imgUrl = $arImgProduct["src"]; } $arSetInfo = array(); $arStores = array(); /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider(array("MODULE" => $arElementInfo["MODULE"], "PRODUCT_PROVIDER_CLASS" => $arElementInfo["PRODUCT_PROVIDER_CLASS"]))) { // get set items if it is set if ($arProduct["TYPE"] == CCatalogProduct::TYPE_SET) { if (method_exists($productProvider, "GetSetItems")) { $arSets = $productProvider::GetSetItems($productId, CSaleBasket::TYPE_SET); if ($tmpId == "") $tmpId = randString(7); if (!empty($arSets)) { foreach ($arSets as $arSetData) { foreach ($arSetData["ITEMS"] as $setItem) { $arSetItemParams = getProductDataToFillBasket($setItem["PRODUCT_ID"], $setItem["QUANTITY"], $userId, $LID, $userColumns, $tmpId); // recursive call // re-define some fields with set data values $arSetItemParams["id"] = $setItem["PRODUCT_ID"]; $arSetItemParams["name"] = $setItem["NAME"]; $arSetItemParams["module"] = $setItem["MODULE"]; $arSetItemParams["productProviderClass"] = $setItem["PRODUCT_PROVIDER_CLASS"]; $arSetItemParams["url"] = $setItem["DETAIL_PAGE_URL"]; $arSetItemParams["quantity"] = $setItem["QUANTITY"] * $quantity; $arSetItemParams["barcodeMulti"] = $setItem["BARCODE_MULTI"]; $arSetItemParams["productType"] = $setItem["TYPE"]; $arSetItemParams["weight"] = $setItem["WEIGHT"]; $arSetItemParams["vatRate"] = $setItem["VAT_RATE"]; $arSetItemParams["setItems"] = ""; $arSetItemParams["setParentId"] = $productId."_tmp".$tmpId; $arSetItemParams["isSetItem"] = "Y"; $arSetItemParams["isSetParent"] = "N"; $arSetInfo[] = $arSetItemParams; } } } } } // get stores $storeCount = $productProvider::GetStoresCount(array("SITE_ID" => $LID)); // with exact SITE_ID or SITE_ID = NULL if ($storeCount > 0) { if ($arProductStore = $productProvider::GetProductStores(array("PRODUCT_ID" => $productId, "SITE_ID" => $LID))) $arStores = $arProductStore; } } $currentTotalPrice = (float)$currentTotalPrice; // params array $arParams["id"] = $productId; $arParams["name"] = $arElementInfo["~NAME"]; $arParams["url"] = htmlspecialcharsex($arElementInfo["~DETAIL_PAGE_URL"]); $arParams["urlEdit"] = $arElementInfo["EDIT_PAGE_URL"]; $arParams["urlImg"] = $imgUrl; $arParams["price"] = floatval($arElementInfo["PRICE"]); $arParams["priceBase"] = $currentTotalPrice; $arParams["priceBaseFormat"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], false); $arParams["priceFormated"] = CCurrencyLang::CurrencyFormat(floatval($arElementInfo["PRICE"]), $arElementInfo["CURRENCY"], false); $arParams["valutaFormat"] = $priceValutaFormat; $arParams["dimensions"] = serialize(array("WIDTH" => $arElementInfo["WIDTH"], "HEIGHT" => $arElementInfo["HEIGHT"], "LENGTH" => $arElementInfo["LENGTH"])); $arParams["priceDiscount"] = floatval($arElementInfo["DISCOUNT_PRICE"]); $arParams["priceTotalFormated"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], true); $arParams["discountPercent"] = $discountPercent; $arParams["summaFormated"] = CCurrencyLang::CurrencyFormat($arElementInfo["PRICE"], $arElementInfo["CURRENCY"], false); $arParams["quantity"] = $quantity; $arParams["module"] = $arElementInfo["MODULE"]; $arParams["currency"] = $arElementInfo["CURRENCY"]; $arParams["weight"] = $arElementInfo["WEIGHT"]; $arParams["vatRate"] = $arPrice["PRICE"]["VAT_RATE"]; $arParams["priceType"] = $arPrice["PRICE"]["CATALOG_GROUP_NAME"]; $arParams["balance"] = $balance; $arParams["notes"] = (is_array($arPrice["PRICE"]) && array_key_exists("CATALOG_GROUP_NAME", $arPrice["PRICE"])) ? $arPrice["PRICE"]["CATALOG_GROUP_NAME"] : ""; $arParams["catalogXmlID"] = $arElementInfo["~IBLOCK_XML_ID"]; $arParams["productXmlID"] = $arElementInfo["~XML_ID"]; $arParams["callback"] = ""; $arParams["orderCallback"] = ""; $arParams["cancelCallback"] = ""; $arParams["payCallback"] = ""; $arParams["productProviderClass"] = $arElementInfo["PRODUCT_PROVIDER_CLASS"]; $arParams["skuProps"] = $arSkuData; $arParams["measureText"] = $arElementInfo["MEASURE_TEXT"]; $arParams["ratio"] = $arElementInfo["RATIO"]; $arParams["barcodeMulti"] = $arProduct["BARCODE_MULTI"]; $arParams["productType"] = empty($arSetInfo) ? "" : CSaleBasket::TYPE_SET; $arParams["setParentId"] = empty($arSetInfo) ? "" : $productId."_tmp".$tmpId; $arParams["setItems"] = $arSetInfo; $arParams["isSetItem"] = "N"; $arParams["isSetParent"] = empty($arSetInfo) ? "N" : "Y"; $arParams["stores"] = empty($arSetInfo) ? $arStores : array(); $arParams["productPropsValues"] = $arElementInfo; // along with other information also contains values of properties with correct keys (after getProductProps) } return $arParams; }
$boolIBlockElementAdd = CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $find_section_section, "section_element_bind"); $arElementOps = CIBlockElementRights::UserHasRightTo( $IBLOCK_ID, array_keys($arRows), "", CIBlockRights::RETURN_OPERATIONS ); $availQuantityTrace = COption::GetOptionString("catalog", "default_quantity_trace", 'N'); $arQuantityTrace = array( "D" => GetMessage("IBEL_DEFAULT_VALUE") . " (" . ($availQuantityTrace == 'Y' ? GetMessage("IBEL_YES_VALUE") : GetMessage("IBEL_NO_VALUE")) . ")", "Y" => GetMessage("IBEL_YES_VALUE"), "N" => GetMessage("IBEL_NO_VALUE"), ); if ($bCatalog && !empty($arRows)) { $arRowKeys = array_keys($arRows); if ($strUseStoreControl == "Y" && in_array("CATALOG_BAR_CODE", $arSelectedFields)) { $rsProducts = CCatalogProduct::GetList( array(), array('@ID' => $arRowKeys), false, false, array('ID', 'BARCODE_MULTI') ); $productsWithBarCode = array(); while ($product = $rsProducts->Fetch()) { if (isset($arRows[$product["ID"]])) { if ($product["BARCODE_MULTI"] == "Y") $arRows[$product["ID"]]->arRes["CATALOG_BAR_CODE"] = GetMessage("IBEL_CATALOG_BAR_CODE_MULTI"); else $productsWithBarCode[] = $product["ID"]; } } if (!empty($productsWithBarCode)) { $rsProducts = CCatalogStoreBarCode::getList(array(), array( "PRODUCT_ID" => $productsWithBarCode, )); while ($product = $rsProducts->Fetch()) {
public function recalculateSetsByProduct($product) { global $DB; if (self::$recalculateSet < 0) { return; } $setsList = array(); $setsID = array(); $product = (int) $product; $query = 'select SET_ID, OWNER_ID, ITEM_ID from b_catalog_product_sets where ITEM_ID=' . $product . ' and TYPE=' . self::TYPE_SET; $setIterator = $DB->Query($query, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); while ($setItem = $setIterator->Fetch()) { $setItem['SET_ID'] = (int) $setItem['SET_ID']; $setItem['OWNER_ID'] = (int) $setItem['OWNER_ID']; $setItem['ITEM_ID'] = (int) $setItem['ITEM_ID']; if ($setItem['ITEM_ID'] === $setItem['OWNER_ID']) { continue; } $setsList[$setItem['SET_ID']] = array(); $setsID[] = $setItem['SET_ID']; } if (isset($setItem)) { unset($setItem); } unset($setIterator, $query); if (!empty($setsID)) { $productMap = array(); $query = 'select SET_ID, OWNER_ID, ITEM_ID, QUANTITY as QUANTITY_IN_SET from b_catalog_product_sets where SET_ID IN(' . implode(',', $setsID) . ')'; $setIterator = $DB->Query($query, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); while ($setItem = $setIterator->Fetch()) { $setItem['SET_ID'] = (int) $setItem['SET_ID']; $setItem['OWNER_ID'] = (int) $setItem['OWNER_ID']; $setItem['ITEM_ID'] = (int) $setItem['ITEM_ID']; if ($setItem['ITEM_ID'] === $setItem['OWNER_ID']) { continue; } if (!isset($setsList[$setItem['OWNER_ID']])) { $setsList[$setItem['OWNER_ID']] = array(); } $setsList[$setItem['OWNER_ID']][$setItem['ITEM_ID']] = $setItem; if (!isset($productMap[$setItem['ITEM_ID']])) { $productMap[$setItem['ITEM_ID']] = array(); } $productMap[$setItem['ITEM_ID']][] = $setItem['OWNER_ID']; } unset($setItem, $setIterator, $query); $productIterator = CCatalogProduct::GetList(array(), array('=ID' => array_keys($productMap)), false, false, array('ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO', 'WEIGHT')); while ($item = $productIterator->Fetch()) { $item['ID'] = (int) $item['ID']; if (!isset($productMap[$item['ID']])) { continue; } foreach ($productMap[$item['ID']] as &$setKey) { $setsList[$setKey][$item['ID']] = array_merge($setsList[$setKey][$item['ID']], $item); } unset($setKey); } if (isset($item)) { unset($item); } unset($productIterator); foreach ($setsList as $setKey => $oneSet) { self::calculateSetParams($setKey, $oneSet); } } }
$boolIBlockElementAdd = CIBlockSectionRights::UserHasRightTo($intSubIBlockID, $find_section_section, "section_element_bind"); $availQuantityTrace = COption::GetOptionString("catalog", "default_quantity_trace", 'N'); $arQuantityTrace = array( "D" => GetMessage("IBEL_DEFAULT_VALUE")." (".($availQuantityTrace=='Y' ? GetMessage("IBEL_YES_VALUE") : GetMessage("IBEL_NO_VALUE")).")", "Y" => GetMessage("IBEL_YES_VALUE"), "N" => GetMessage("IBEL_NO_VALUE"), ); if (COption::GetOptionString("catalog", "default_use_store_control") == "Y" && in_array("CATALOG_BAR_CODE", $arSelectedFields)) { $rsProducts = CCatalogProduct::GetList( array(), array("ID" => array_keys($arRows)), false, false, array('ID', 'BARCODE_MULTI') ); $productsWithBarCode = array(); while ($product = $rsProducts->Fetch()) { if (isset($arRows[$product["ID"]])) { if ($product["BARCODE_MULTI"] == "Y") $arRows[$product["ID"]]->arRes["CATALOG_BAR_CODE"] = GetMessage("IBEL_CATALOG_BAR_CODE_MULTI"); else $productsWithBarCode[] = $product["ID"]; } } if (!empty($productsWithBarCode))
function CatalogGetPriceTableEx($ID, $filterQauntity = 0, $arFilterType = array(), $VAT_INCLUDE = 'Y', $arCurrencyParams = array()) { global $USER; static $arPriceTypes = array(); $ID = (int) $ID; if ($ID <= 0) { return false; } $filterQauntity = (int) $filterQauntity; if (!is_array($arFilterType)) { $arFilterType = array($arFilterType); } $boolConvert = false; $strCurrencyID = ''; $arCurrencyList = array(); if (!empty($arCurrencyParams) && is_array($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID'])) { $boolConvert = true; $strCurrencyID = $arCurrencyParams['CURRENCY_ID']; } $arResult = array(); $arResult["ROWS"] = array(); $arResult["COLS"] = array(); $arResult["MATRIX"] = array(); $arResult["CAN_BUY"] = array(); $arResult["AVAILABLE"] = "N"; $cacheTime = CATALOG_CACHE_DEFAULT_TIME; if (defined("CATALOG_CACHE_TIME")) { $cacheTime = intval(CATALOG_CACHE_TIME); } $arUserGroups = $USER->GetUserGroupArray(); CatalogClearArray($arUserGroups, true); $strCacheID = 'UG_' . implode('_', $arUserGroups); if (isset($arPriceTypes[$strCacheID])) { $arPriceGroups = $arPriceTypes[$strCacheID]; } else { $arPriceGroups = CCatalogGroup::GetGroupsPerms($arUserGroups, array()); $arPriceTypes[$strCacheID] = $arPriceGroups; } if (empty($arPriceGroups["view"])) { return $arResult; } $currentQuantity = -1; $rowsCnt = -1; $arFilter = array("PRODUCT_ID" => $ID); if ($filterQauntity > 0) { $arFilter["+<=QUANTITY_FROM"] = $filterQauntity; $arFilter["+>=QUANTITY_TO"] = $filterQauntity; } if (!empty($arFilterType)) { $arTmp = array(); foreach ($arPriceGroups["view"] as &$intOneGroup) { if (in_array($intOneGroup, $arFilterType)) { $arTmp[] = $intOneGroup; } } if (isset($intOneGroup)) { unset($intOneGroup); } if (empty($arTmp)) { return $arResult; } $arFilter["CATALOG_GROUP_ID"] = $arTmp; } else { $arFilter["CATALOG_GROUP_ID"] = $arPriceGroups["view"]; } $productQuantity = 0; $productQuantityTrace = "N"; $dbRes = CCatalogProduct::GetVATInfo($ID); if ($arVatInfo = $dbRes->Fetch()) { $fVatRate = floatval($arVatInfo['RATE'] * 0.01); $bVatIncluded = $arVatInfo['VAT_INCLUDED'] == 'Y'; } else { $fVatRate = 0.0; $bVatIncluded = false; } $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('ID', 'CAN_BUY_ZERO', 'QUANTITY_TRACE', 'QUANTITY')); if ($arProduct = $rsProducts->Fetch()) { $intIBlockID = CIBlockElement::GetIBlockByID($arProduct['ID']); if (!$intIBlockID) { return false; } $arProduct['IBLOCK_ID'] = $intIBlockID; } else { return false; } $dbPrice = CPrice::GetListEx(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC"), $arFilter, false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")); while ($arPrice = $dbPrice->Fetch()) { if ($VAT_INCLUDE == 'N') { if ($bVatIncluded) { $arPrice['PRICE'] /= 1 + $fVatRate; } } else { if (!$bVatIncluded) { $arPrice['PRICE'] *= 1 + $fVatRate; } } $arPrice['VAT_RATE'] = $fVatRate; CCatalogDiscountSave::Disable(); $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arProduct["IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $arUserGroups, "N", SITE_ID, array()); CCatalogDiscountSave::Enable(); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_PRICE"] = $discountPrice; $arPrice["QUANTITY_FROM"] = doubleval($arPrice["QUANTITY_FROM"]); if ($currentQuantity != $arPrice["QUANTITY_FROM"]) { $rowsCnt++; $arResult["ROWS"][$rowsCnt]["QUANTITY_FROM"] = $arPrice["QUANTITY_FROM"]; $arResult["ROWS"][$rowsCnt]["QUANTITY_TO"] = doubleval($arPrice["QUANTITY_TO"]); $currentQuantity = $arPrice["QUANTITY_FROM"]; } if ($boolConvert && $strCurrencyID != $arPrice["CURRENCY"]) { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "ORIG_PRICE" => $arPrice["PRICE"], "ORIG_DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "ORIG_CURRENCY" => $arPrice["CURRENCY"], "ORIG_VAT_RATE" => $arPrice["VAT_RATE"], 'PRICE' => CCurrencyRates::ConvertCurrency($arPrice["PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'DISCOUNT_PRICE' => CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT_PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'CURRENCY' => $strCurrencyID, 'VAT_RATE' => CCurrencyRates::ConvertCurrency($arPrice["VAT_RATE"], $arPrice["CURRENCY"], $strCurrencyID)); $arCurrencyList[] = $arPrice["CURRENCY"]; } else { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "PRICE" => $arPrice["PRICE"], "DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "CURRENCY" => $arPrice["CURRENCY"], "VAT_RATE" => $arPrice["VAT_RATE"]); } } $arCatalogGroups = CCatalogGroup::GetListArray(); foreach ($arCatalogGroups as $key => $value) { if (isset($arResult["MATRIX"][$key])) { $arResult["COLS"][$value["ID"]] = $value; } } $arResult["CAN_BUY"] = $arPriceGroups["buy"]; $arResult["AVAILABLE"] = 0 >= $arProduct['QUANTITY'] && 'Y' == $arProduct['QUANTITY_TRACE'] && 'N' == $arProduct['CAN_BUY_ZERO'] ? 'N' : 'Y'; if ($boolConvert) { if (!empty($arCurrencyList)) { $arCurrencyList[] = $strCurrencyID; } $arResult['CURRENCY_LIST'] = $arCurrencyList; } return $arResult; }
/** * @param \CDBResult $dbResultList * @return array */ protected function makeItemsFromDbResult(\CDBResult $dbResultList) { $arItemsResult = $arProductIds = array(); while ($arItem = $dbResultList->Fetch()) { if ($arItem['TYPE'] != 'S') { $arProductIds[] = $arItem['ID']; $arItem['PROPERTIES'] = $this->getItemProperies($arItem['ID']); } $arItemsResult[$arItem['ID']] = $arItem; } if (!empty($arProductIds)) { $dbCatalogProduct = \CCatalogProduct::GetList(array(), array("ID" => $arProductIds)); while ($arCatalogProduct = $dbCatalogProduct->fetch()) { $arItemsResult[$arCatalogProduct["ID"]]['PRODUCT'] = $arCatalogProduct; } $offersExistsIds = \CCatalogSKU::getExistOffers($arProductIds, $this->getIblockId()); $noOffersIds = array(); if ($offersExistsIds === false) { $noOffersIds = $arProductIds; } else { $this->loadAllSku(array_keys(array_filter($offersExistsIds))); foreach ($offersExistsIds as $id => $bExists) { $arItem =& $arItemsResult[$id]; if ($bExists) { $arItem['SKU_ITEMS'] = $this->getProductSku($arItem); } else { $noOffersIds[] = $id; } } } if (!empty($noOffersIds)) { $priceIds = $this->getVisiblePrices(); foreach ($priceIds as $priceId) { $dbPrice = \CPrice::GetList(array(), array('PRODUCT_ID' => $noOffersIds, 'CATALOG_GROUP_ID' => $priceId), false, false, array('PRODUCT_ID', 'PRICE', 'CURRENCY')); while ($arPrice = $dbPrice->fetch()) { $arItemsResult[$arPrice["PRODUCT_ID"]]['PRICES'][$priceId] = array('PRICE' => $arPrice['PRICE'], 'CURRENCY' => $arPrice['CURRENCY']); } } if ($this->getStoreId()) { $dbStoreProduct = \CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $noOffersIds, "STORE_ID" => $this->getStoreId())); while ($arStoreProduct = $dbStoreProduct->Fetch()) { $arItemsResult[$arStoreProduct["PRODUCT_ID"]]['PRODUCT']['STORE_AMOUNT'] = $arStoreProduct["AMOUNT"]; } } $groupsIterator = CCatalogProductSet::getList(array(), array('OWNER_ID' => $noOffersIds, 'SET_ID' => 0, 'TYPE' => \CCatalogProductSet::TYPE_GROUP), false, false, array('ID', 'OWNER_ID', 'ITEM_ID', 'SET_ID', 'TYPE')); while ($group = $groupsIterator->Fetch()) { if ($group['OWNER_ID'] == $group['ITEM_ID']) { $arItemsResult[$group['OWNER_ID']]['PRODUCT']['IS_GROUP'] = true; } } } } return $arItemsResult; }
/** * @param \CDBResult $dbResultList * @return array */ protected function makeItemsFromDbResult(\CDBResult $dbResultList) { $arItemsResult = $arProductIds = array(); while ($arItem = $dbResultList->Fetch()) { if ($arItem['TYPE'] != 'S') { $arProductIds[] = $arItem['ID']; $arItem['PROPERTIES'] = $this->getItemProperies($arItem['ID']); $arItemsResult[$arItem['ID']] = $arItem; } else { $arItemsResult['S' . $arItem['ID']] = $arItem; } } if (!empty($arProductIds)) { $dbCatalogProduct = \CCatalogProduct::GetList(array(), array('@ID' => $arProductIds)); while ($arCatalogProduct = $dbCatalogProduct->fetch()) { $arItemsResult[$arCatalogProduct['ID']]['PRODUCT'] = $arCatalogProduct; } $offersExistsIds = \CCatalogSKU::getExistOffers($arProductIds, $this->getIblockId()); $noOffersIds = array(); if (empty($offersExistsIds)) { $noOffersIds = $arProductIds; } else { $this->loadAllSku(array_keys(array_filter($offersExistsIds))); foreach ($offersExistsIds as $id => $bExists) { $arItem =& $arItemsResult[$id]; if ($bExists) { $arItem['SKU_ITEMS'] = $this->getProductSku($arItem); } else { $noOffersIds[] = $id; } } unset($id, $bExists); } if (!empty($noOffersIds)) { $productRatioList = Catalog\ProductTable::getCurrentRatioWithMeasure($noOffersIds); if (!empty($productRatioList)) { foreach ($productRatioList as $productId => $productRatio) { if (!isset($arItemsResult[$productId]['PRODUCT'])) { continue; } $arItemsResult[$productId]['PRODUCT']['MEASURE_RATIO'] = $productRatio['RATIO']; $arItemsResult[$productId]['PRODUCT']['MEASURE'] = $productRatio['MEASURE']; } unset($productRatio, $productId); } unset($productRatioList); $priceIds = $this->getVisiblePrices(); foreach ($priceIds as $priceId) { $dbPrice = \CPrice::GetListEx(array(), array('PRODUCT_ID' => $noOffersIds, 'CATALOG_GROUP_ID' => $priceId), false, false, array('PRODUCT_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($arPrice = $dbPrice->fetch()) { $arPrice['QUANTITY_FROM'] = (int) $arPrice['QUANTITY_FROM']; $arPrice['QUANTITY_TO'] = (int) $arPrice['QUANTITY_TO']; if (!isset($arItemsResult[$arPrice["PRODUCT_ID"]]['PRICES'][$priceId]) || $arItemsResult[$arPrice["PRODUCT_ID"]]['PRICES'][$priceId]['QUANTITY_FROM'] > $arPrice['QUANTITY_FROM']) { $arItemsResult[$arPrice["PRODUCT_ID"]]['PRICES'][$priceId] = array('PRICE' => $arPrice['PRICE'], 'CURRENCY' => $arPrice['CURRENCY'], 'QUANTITY_FROM' => $arPrice['QUANTITY_FROM'], 'QUANTITY_TO' => $arPrice['QUANTITY_TO']); } } unset($arPrice, $dbPrice); } if ($this->getStoreId()) { $dbStoreProduct = \CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $noOffersIds, "STORE_ID" => $this->getStoreId())); while ($arStoreProduct = $dbStoreProduct->Fetch()) { $arItemsResult[$arStoreProduct["PRODUCT_ID"]]['PRODUCT']['STORE_AMOUNT'] = $arStoreProduct["AMOUNT"]; } } $groupsIterator = CCatalogProductSet::getList(array(), array('OWNER_ID' => $noOffersIds, 'SET_ID' => 0, 'TYPE' => \CCatalogProductSet::TYPE_GROUP), false, false, array('ID', 'OWNER_ID', 'ITEM_ID', 'SET_ID', 'TYPE')); while ($group = $groupsIterator->Fetch()) { if ($group['OWNER_ID'] == $group['ITEM_ID']) { $arItemsResult[$group['OWNER_ID']]['PRODUCT']['IS_GROUP'] = true; } } } } return $arItemsResult; }
"TEXT" => GetMessage('MAIN_DELETE'), "TITLE" => GetMessage("IBLOCK_DELETE_ALT"), "ACTION" => "if(confirm('".GetMessageJS('IBLOCK_CONFIRM_DEL_MESSAGE')."')) ".$lAdmin->ActionDoGroup($f_TYPE.$arRes_orig['ID'], "delete", $sThisSectionUrl), ); } } $row->AddActions($arActions); } if ($bCatalog) { if ($strUseStoreControl == "Y" && in_array("CATALOG_BAR_CODE", $arSelectedFields) && !empty($arElemID)) { $rsProducts = CCatalogProduct::GetList( array(), array("ID" => $arElemID), false, false, array('ID', 'BARCODE_MULTI') ); $productsWithBarCode = array(); while ($product = $rsProducts->Fetch()) { if (isset($arRows['E'.$product["ID"]])) { if ($product["BARCODE_MULTI"] == "Y") $arRows['E'.$product["ID"]]->arRes["CATALOG_BAR_CODE"] = GetMessage("IBLIST_A_CATALOG_BAR_CODE_MULTI"); else $productsWithBarCode[] = $product["ID"]; } } if (!empty($productsWithBarCode))
public static function OnBeforePrologHandler() { global $USER_FIELD_MANAGER; if (isset($_REQUEST['action_button']) && !isset($_REQUEST['action'])) { $_REQUEST['action'] = $_REQUEST['action_button']; } if (!isset($_REQUEST['action'])) { return; } $BID = isset($_REQUEST['ID']) ? (int) $_REQUEST['ID'] : 0; if ($_REQUEST['action'] == 'asd_prop_export' && $BID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) { $strPath = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/tmp/asd.iblock/'; $strName = 'asd_props_export_' . $BID . '_' . md5(LICENSE_KEY) . '.xml'; CheckDirPath($strPath); if ($hdlOutput = fopen($strPath . $strName, 'wb')) { fwrite($hdlOutput, '<?xml version="1.0" encoding="' . SITE_CHARSET . '"?>' . "\n"); fwrite($hdlOutput, '<asd_iblock_props>' . "\n"); fwrite($hdlOutput, CASDiblockTools::ExportPropsToXML($BID, $_REQUEST['p'])); if ($_REQUEST['forms'] == 'Y') { fwrite($hdlOutput, CASDiblockTools::ExportSettingsToXML($BID, array('forms'))); } fwrite($hdlOutput, '</asd_iblock_props>' . "\n"); fclose($hdlOutput); } ?> <script type="text/javascript"> top.BX.closeWait(); top.BX.WindowManager.Get().AllowClose(); top.BX.WindowManager.Get().Close(); window.location.href = '/bitrix/tools/asd.iblock/props_export.php?ID=<?php echo $BID; ?> '; </script><?php die; } if ($_REQUEST['action'] == 'asd_prop_import' && $BID > 0 && !$_FILES['xml_file']['error'] && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($BID)) { CASDiblockTools::ImportPropsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID); CASDiblockTools::ImportFormsFromXML($BID, $_FILES['xml_file']['tmp_name'], $arOldNewID); LocalRedirect('/bitrix/admin/iblock_edit.php?type=' . $_REQUEST['type'] . '&tabControl_active_tab=edit2&lang=' . LANGUAGE_ID . '&ID=' . $BID . '&admin=Y'); } $IBLOCK_ID = 0; if (isset($_REQUEST['IBLOCK_ID'])) { $IBLOCK_ID = (int) $_REQUEST['IBLOCK_ID']; if ($IBLOCK_ID < 0) { $IBLOCK_ID = 0; } } if ($_REQUEST['action'] == 'asd_reverse' && $IBLOCK_ID > 0 && check_bitrix_sessid() && CModule::IncludeModule('iblock') && CASDIblockRights::IsIBlockEdit($IBLOCK_ID)) { $LIST_MODE = CIBlock::GetArrayByID($IBLOCK_ID, 'LIST_MODE'); if (!strlen($LIST_MODE)) { $LIST_MODE = COption::GetOptionString('iblock', 'combined_list_mode', 'N') == 'Y' ? 'C' : 'S'; } $LIST_MODE = $LIST_MODE == 'C' ? 'S' : 'C'; $ib = new CIBlock(); $ib->Update($IBLOCK_ID, array('LIST_MODE' => $LIST_MODE)); LocalRedirect('/bitrix/admin/' . ($LIST_MODE == 'S' ? 'iblock_element_admin' : 'iblock_list_admin') . '.php?IBLOCK_ID=' . $IBLOCK_ID . '&type=' . htmlspecialcharsbx($_REQUEST['type']) . '&find_section_section=' . intval($_REQUEST['find_section_section']) . '&lang=' . LANGUAGE_ID); } $strCurPage = $GLOBALS['APPLICATION']->GetCurPage(); $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php'; $bSectPage = $strCurPage == '/bitrix/admin/iblock_section_admin.php' || $strCurPage == '/bitrix/admin/cat_section_admin.php'; $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php'; $bRightPage = $bElemPage || $bSectPage || $bMixPage; $successRedirect = false; if ($bRightPage && $_REQUEST['action'] == 'asd_copy_in_list' && strlen($_REQUEST['ID']) > 0) { $bDoAction = true; $_REQUEST['action'] = 'asd_copy'; $_REQUEST['asd_ib_dest'] = $IBLOCK_ID; $_REQUEST['ID'] = array($_REQUEST['ID']); } else { $bDoAction = false; } if ($bRightPage && check_bitrix_sessid() && !empty($_REQUEST['ID']) && ($_SERVER['REQUEST_METHOD'] == 'POST' || $bDoAction) && CModule::IncludeModule('iblock') && ($_REQUEST['action'] == 'asd_copy' || $_REQUEST['action'] == 'asd_move') && isset($_REQUEST['asd_ib_dest']) && (int) $_REQUEST['asd_ib_dest'] > 0 && CASDIblockRights::IsIBlockDisplay($_REQUEST['asd_ib_dest'])) { $intSrcIBlockID = $IBLOCK_ID; $intDestIBlockID = (int) $_REQUEST['asd_ib_dest']; $intSetSectID = 0; if (isset($_REQUEST['asd_sect_dest'])) { $intSetSectID = (int) $_REQUEST['asd_sect_dest']; if ($intSetSectID < 0) { $intSetSectID = 0; } } $boolCreateElement = false; $boolCreateSection = false; if ($bElemPage || $bMixPage) { $boolCreateElement = CASDIblockRights::IsSectionElementCreate($intDestIBlockID, $intSetSectID); } if ($bSectPage || $bMixPage) { $boolCreateSection = CASDIblockRights::IsSectionSectionCreate($intDestIBlockID, $intSetSectID); } if ($boolCreateElement || $boolCreateSection) { $arPropListCache = array(); $arOldPropListCache = array(); $arNamePropListCache = array(); $arOldNamePropListCache = array(); $boolUFListCache = false; $arUFListCache = array(); $arOldUFListCache = array(); $arUFEnumCache = array(); $arOldUFEnumCache = array(); $arUFNameEnumCache = array(); $arOldUFNameEnumCache = array(); $arDestIBlock = CIBlock::GetArrayByID($intDestIBlockID); $arDestIBFields = $arDestIBlock['FIELDS']; $boolCodeUnique = false; if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolCodeUnique = $intSrcIBlockID == $intDestIBlockID; } $boolSectCodeUnique = false; if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolSectCodeUnique = $intSrcIBlockID == $intDestIBlockID; } $boolCatalog = CModule::IncludeModule('catalog'); $boolCopyCatalog = false; $boolNewCatalog = false; if ($boolCatalog) { $boolCopyCatalog = is_array(CCatalog::GetByID($intDestIBlockID)); $boolNewCatalog = $boolCopyCatalog; if ($boolCopyCatalog) { $boolCopyCatalog = is_array(CCatalog::GetByID($intSrcIBlockID)); } } $el = new CIBlockElement(); $sc = new CIBlockSection(); $obEnum = new CUserFieldEnum(); foreach ($_REQUEST['ID'] as $eID) { $boolCopyElem = false; $boolCopySect = false; if ($bMixPage) { if (substr($eID, 0, 1) != 'E') { $boolCopySect = true; } else { $boolCopyElem = true; } $ID = (int) substr($eID, 1); } else { $boolCopyElem = $bElemPage; $boolCopySect = $bSectPage; $ID = (int) $eID; } if ($boolCreateElement && $boolCopyElem) { if ($obSrc = CIBlockElement::GetByID($ID)->GetNextElement()) { $arSrc = $obSrc->GetFields(); $arSrcPr = $obSrc->GetProperties(false, array('EMPTY' => 'N')); $arSrc['PREVIEW_PICTURE'] = (int) $arSrc['PREVIEW_PICTURE']; if ($arSrc['PREVIEW_PICTURE'] > 0) { $arSrc['PREVIEW_PICTURE'] = CFile::MakeFileArray($arSrc['PREVIEW_PICTURE']); if (empty($arSrc['PREVIEW_PICTURE'])) { $arSrc['PREVIEW_PICTURE'] = false; } else { $arSrc['PREVIEW_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arSrc['PREVIEW_PICTURE'] = false; } $arSrc['DETAIL_PICTURE'] = (int) $arSrc['DETAIL_PICTURE']; if ($arSrc['DETAIL_PICTURE'] > 0) { $arSrc['DETAIL_PICTURE'] = CFile::MakeFileArray($arSrc['DETAIL_PICTURE']); if (empty($arSrc['DETAIL_PICTURE'])) { $arSrc['DETAIL_PICTURE'] = false; } else { $arSrc['DETAIL_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arSrc['DETAIL_PICTURE'] = false; } $arSrc = array('IBLOCK_ID' => $intDestIBlockID, 'ACTIVE' => $arSrc['ACTIVE'], 'ACTIVE_FROM' => $arSrc['ACTIVE_FROM'], 'ACTIVE_TO' => $arSrc['ACTIVE_TO'], 'SORT' => $arSrc['SORT'], 'NAME' => $arSrc['~NAME'], 'PREVIEW_PICTURE' => $arSrc['PREVIEW_PICTURE'], 'PREVIEW_TEXT' => $arSrc['~PREVIEW_TEXT'], 'PREVIEW_TEXT_TYPE' => $arSrc['PREVIEW_TEXT_TYPE'], 'DETAIL_TEXT' => $arSrc['~DETAIL_TEXT'], 'DETAIL_TEXT_TYPE' => $arSrc['DETAIL_TEXT_TYPE'], 'DETAIL_PICTURE' => $arSrc['DETAIL_PICTURE'], 'WF_STATUS_ID' => $arSrc['WF_STATUS_ID'], 'CODE' => $arSrc['~CODE'], 'TAGS' => $arSrc['~TAGS'], 'XML_ID' => $arSrc['~XML_ID'], 'PROPERTY_VALUES' => array()); if ($arDestIBFields['CODE']['IS_REQUIRED'] == 'Y') { if (!strlen($arSrc['CODE'])) { $arSrc['CODE'] = mt_rand(100000, 1000000); } } if ($arDestIBFields['CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolElCodeUnique = $boolCodeUnique; if (!$boolCodeUnique) { $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID')); if ($arCheck = $rsCheckItems->Fetch()) { $boolElCodeUnique = true; } } if ($boolElCodeUnique) { $arSrc['CODE'] .= mt_rand(100, 10000); } } if ($intSetSectID > 0) { $arSrc['IBLOCK_SECTION_ID'] = $intSetSectID; } elseif ($intSrcIBlockID == $intDestIBlockID) { $arSectionList = array(); $rsSections = CIBlockElement::GetElementGroups($ID, true); while ($arSection = $rsSections->Fetch()) { $arSectionList[] = $arSection['ID']; } $arSrc['IBLOCK_SECTION'] = $arSectionList; } if ($intSrcIBlockID != $intDestIBlockID) { if (empty($arPropListCache)) { $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')); while ($arProp = $rsProps->Fetch()) { $arValueList = array(); $arNameList = array(); $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']); while ($arValue = $rsValues->Fetch()) { $arValueList[$arValue['XML_ID']] = $arValue['ID']; $arNameList[$arValue['ID']] = trim($arValue['VALUE']); } if (!empty($arValueList)) { $arPropListCache[$arProp['CODE']] = $arValueList; } if (!empty($arNameList)) { $arNamePropListCache[$arProp['CODE']] = $arNameList; } } } if (empty($arOldPropListCache)) { $rsProps = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $intSrcIBlockID, 'PROPERTY_TYPE' => 'L', 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')); while ($arProp = $rsProps->Fetch()) { $arValueList = array(); $arNameList = array(); $rsValues = CIBlockProperty::GetPropertyEnum($arProp['ID']); while ($arValue = $rsValues->Fetch()) { $arValueList[$arValue['ID']] = $arValue['XML_ID']; $arNameList[$arValue['ID']] = trim($arValue['VALUE']); } if (!empty($arValueList)) { $arOldPropListCache[$arProp['CODE']] = $arValueList; } if (!empty($arNameList)) { $arOldNamePropListCache[$arProp['CODE']] = $arNameList; } } } } foreach ($arSrcPr as &$arProp) { if ($arProp['USER_TYPE'] == 'HTML') { if (is_array($arProp['~VALUE'])) { if ($arProp['MULTIPLE'] == 'N') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array('VALUE' => array('TEXT' => $arProp['~VALUE']['TEXT'], 'TYPE' => $arProp['~VALUE']['TYPE'])); if ($arProp['WITH_DESCRIPTION'] == 'Y') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']]['DESCRIPTION'] = $arProp['~DESCRIPTION']; } } else { if (!empty($arProp['~VALUE'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['~VALUE'] as $propValueKey => $propValue) { $oneNewValue = array('VALUE' => array('TEXT' => $propValue['TEXT'], 'TYPE' => $propValue['TYPE'])); if ($arProp['WITH_DESCRIPTION'] == 'Y') { $oneNewValue['DESCRIPTION'] = $arProp['~DESCRIPTION'][$propValueKey]; } $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $oneNewValue; unset($oneNewValue); } unset($propValue, $propValueKey); } } } } elseif ($arProp['PROPERTY_TYPE'] == 'F') { if (is_array($arProp['VALUE'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['VALUE'] as $propValueKey => $file) { if ($file > 0) { $tmpValue = CFile::MakeFileArray($file); if (!is_array($tmpValue)) { continue; } if ($arProp['WITH_DESCRIPTION'] == 'Y') { $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]); } $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $tmpValue; } } } elseif ($arProp['VALUE'] > 0) { $tmpValue = CFile::MakeFileArray($arProp['VALUE']); if (is_array($tmpValue)) { if ($arProp['WITH_DESCRIPTION'] == 'Y') { $tmpValue = array('VALUE' => $tmpValue, 'DESCRIPTION' => $arProp['~DESCRIPTION']); } $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $tmpValue; } } } elseif ($arProp['PROPERTY_TYPE'] == 'L') { if (!empty($arProp['VALUE_ENUM_ID'])) { if ($intSrcIBlockID == $arSrc['IBLOCK_ID']) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['VALUE_ENUM_ID']; } else { if (isset($arPropListCache[$arProp['CODE']]) && isset($arOldPropListCache[$arProp['CODE']])) { if (is_array($arProp['VALUE_ENUM_ID'])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['VALUE_ENUM_ID'] as &$intValueID) { $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$intValueID]; if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $arPropListCache[$arProp['CODE']][$strValueXmlID]; } else { $strValueName = $arOldNamePropListCache[$arProp['CODE']][$intValueID]; $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]); if ($intValueKey !== false) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = $intValueKey; } } } if (isset($intValueID)) { unset($intValueID); } if (empty($arSrc['PROPERTY_VALUES'][$arProp['CODE']])) { unset($arSrc['PROPERTY_VALUES'][$arProp['CODE']]); } } else { $strValueXmlID = $arOldPropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']]; if (isset($arPropListCache[$arProp['CODE']][$strValueXmlID])) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arPropListCache[$arProp['CODE']][$strValueXmlID]; } else { $strValueName = $arOldNamePropListCache[$arProp['CODE']][$arProp['VALUE_ENUM_ID']]; $intValueKey = array_search($strValueName, $arNamePropListCache[$arProp['CODE']]); if ($intValueKey !== false) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $intValueKey; } } } } } } } elseif ($arProp['PROPERTY_TYPE'] == 'S' || $arProp['PROPERTY_TYPE'] == 'N') { if ($arProp['MULTIPLE'] == 'Y') { if (is_array($arProp['~VALUE'])) { if ($arProp['WITH_DESCRIPTION'] == 'Y') { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = array(); foreach ($arProp['~VALUE'] as $propValueKey => $propValue) { $arSrc['PROPERTY_VALUES'][$arProp['CODE']][] = array('VALUE' => $propValue, 'DESCRIPTION' => $arProp['~DESCRIPTION'][$propValueKey]); } unset($propValue, $propValueKey); } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE']; } } } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['WITH_DESCRIPTION'] == 'Y' ? array('VALUE' => $arProp['~VALUE'], 'DESCRIPTION' => $arProp['~DESCRIPTION']) : $arProp['~VALUE']; } } else { $arSrc['PROPERTY_VALUES'][$arProp['CODE']] = $arProp['~VALUE']; } } if (isset($arProp)) { unset($arProp); } AddMessage2Log($arSrc['PROPERTY_VALUES']); $intNewID = $el->Add($arSrc, true, true, true); if ($intNewID) { if ($boolCatalog && $boolCopyCatalog) { $priceRes = CPrice::GetListEx(array(), array('PRODUCT_ID' => $ID), false, false, array('PRODUCT_ID', 'EXTRA_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($arPrice = $priceRes->Fetch()) { $arPrice['PRODUCT_ID'] = $intNewID; CPrice::Add($arPrice); } } if ($boolCatalog && $boolNewCatalog) { $arProduct = array('ID' => $intNewID); if ($boolCopyCatalog) { $productRes = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('QUANTITY', 'QUANTITY_TRACE_ORIG', 'CAN_BUY_ZERO_ORIG', 'NEGATIVE_AMOUNT_TRACE_ORIG', 'SUBSCRIBE_ORIG', 'WEIGHT', 'PRICE_TYPE', 'RECUR_SCHEME_TYPE', 'RECUR_SCHEME_LENGTH', 'TRIAL_PRICE_ID', 'WITHOUT_ORDER', 'SELECT_BEST_PRICE', 'VAT_ID', 'VAT_INCLUDED', 'WIDTH', 'LENGTH', 'HEIGHT', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY', 'MEASURE')); if ($arCurProduct = $productRes->Fetch()) { $arProduct = $arCurProduct; $arProduct['ID'] = $intNewID; $arProduct['QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE_ORIG']; $arProduct['CAN_BUY_ZERO'] = $arProduct['CAN_BUY_ZERO_ORIG']; $arProduct['NEGATIVE_AMOUNT_TRACE'] = $arProduct['NEGATIVE_AMOUNT_TRACE_ORIG']; if (isset($arProduct['SUBSCRIBE_ORIG'])) { $arProduct['SUBSCRIBE'] = $arProduct['SUBSCRIBE_ORIG']; } foreach ($arProduct as $productKey => $productValue) { if ($productValue === null) { unset($arProduct[$productKey]); } } } } CCatalogProduct::Add($arProduct, false); } if ($_REQUEST['action'] == 'asd_move') { if (CASDIblockRights::IsElementDelete($intSrcIBlockID, $ID)) { $el->Delete($ID); } else { CASDiblock::$error .= '[' . $ID . '] ' . GetMessage('ASD_ACTION_ERR_DELETE_ELEMENT_RIGHTS') . "\n"; } } } else { CASDiblock::$error .= '[' . $ID . '] ' . $el->LAST_ERROR . "\n"; } } } if ($boolCreateSection && $boolCopySect) { if ($_REQUEST['action'] == 'asd_move') { continue; } $rsSections = CIBlockSection::GetList(array(), array('ID' => $ID, 'IBLOCK_ID' => $intSrcIBlockID), false, array('ID', 'NAME', 'XML_ID', 'CODE', 'IBLOCK_SECTION_ID', 'IBLOCK_ID', 'ACTIVE', 'SORT', 'PICTURE', 'DESCRIPTION', 'DESCRIPTION_TYPE', 'DETAIL_PICTURE', 'SOCNET_GROUP_ID', 'UF_*')); if ($arSrcSect = $rsSections->Fetch()) { $arDestSect = $arSrcSect; unset($arDestSect['ID']); $arDestSect['IBLOCK_ID'] = $intDestIBlockID; if ($arDestIBFields['SECTION_CODE']['IS_REQUIRED'] == 'Y') { if (!strlen($arDestSect['CODE'])) { $arDestSect['CODE'] = mt_rand(100000, 1000000); } } if ($arDestIBFields['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] == 'Y') { $boolScCodeUnique = $boolSectCodeUnique; if (!$boolSectCodeUnique) { $rsCheckItems = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intDestIBlockID, '=CODE' => $arSrc['CODE'], 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 1), array('ID', 'IBLOCK_ID')); if ($arCheck = $rsCheckItems->Fetch()) { $boolScCodeUnique = true; } } if ($boolScCodeUnique) { $arDestSect['CODE'] .= mt_rand(100, 10000); } } if ($intSetSectID > 0) { $arDestSect['IBLOCK_SECTION_ID'] = $intSetSectID; } elseif ($intSrcIBlockID != $intDestIBlockID) { $arDestSect['IBLOCK_SECTION_ID'] = 0; } $arDestSect['PICTURE'] = (int) $arDestSect['PICTURE']; if ($arDestSect['PICTURE'] > 0) { $arDestSect['PICTURE'] = CFile::MakeFileArray($arDestSect['PICTURE']); if (empty($arDestSect['PICTURE'])) { $arDestSect['PICTURE'] = false; } else { $arDestSect['PICTURE']['COPY_FILE'] = 'Y'; } } else { $arDestSect['PICTURE'] = false; } $arDestSect['DETAIL_PICTURE'] = (int) $arDestSect['DETAIL_PICTURE']; if ($arDestSect['DETAIL_PICTURE'] > 0) { $arDestSect['DETAIL_PICTURE'] = CFile::MakeFileArray($arDestSect['DETAIL_PICTURE']); if (empty($arDestSect['DETAIL_PICTURE'])) { $arDestSect['DETAIL_PICTURE'] = false; } else { $arDestSect['DETAIL_PICTURE']['COPY_FILE'] = 'Y'; } } else { $arDestSect['DETAIL_PICTURE'] = false; } if (!$boolUFListCache) { $boolUFListCache = true; $arUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intDestIBlockID . '_SECTION'); if (!empty($arUFListCache)) { if ($intSrcIBlockID != $intDestIBlockID) { $arOldUFListCache = $USER_FIELD_MANAGER->GetUserFields('IBLOCK_' . $intSrcIBlockID . '_SECTION'); if (empty($arOldUFListCache)) { $arUFListCache = array(); } } else { $arOldUFListCache = $arUFListCache; } } if (!empty($arUFListCache)) { if ($intSrcIBlockID != $intDestIBlockID) { foreach ($arUFListCache as &$arOneUserField) { if ('enum' == $arOneUserField['USER_TYPE']['BASE_TYPE']) { $arUFEnumCache[$arOneUserField['FIELD_NAME']] = array(); $arUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array(); $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID'])); while ($arEnum = $rsEnum->Fetch()) { $arUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['XML_ID']] = $arEnum['ID']; $arUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']); } } } if (isset($arOneUserField)) { unset($arOneUserField); } foreach ($arOldUFListCache as &$arOneUserField) { if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') { $arOldUFEnumCache[$arOneUserField['FIELD_NAME']] = array(); $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']] = array(); $rsEnum = $obEnum->GetList(array(), array('USER_FIELD_ID' => $arOneUserField['ID'])); while ($arEnum = $rsEnum->Fetch()) { $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = $arEnum['XML_ID']; $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arEnum['ID']] = trim($arEnum['VALUE']); } } } if (isset($arOneUserField)) { unset($arOneUserField); } } } } if (!empty($arUFListCache)) { foreach ($arUFListCache as &$arOneUserField) { if (!isset($arDestSect[$arOneUserField['FIELD_NAME']])) { continue; } if ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'file') { if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) { if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) { $arNewFileList = array(); foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intFileID) { $arNewFile = false; $intFileID = (int) $intFileID; if ($intFileID > 0) { $arNewFile = CFile::MakeFileArray($intFileID); } if (!empty($arNewFile)) { $arNewFileList[] = $arNewFile; } } if (isset($intFileID)) { unset($intFileID); } $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFileList) ? $arNewFileList : false; } else { $arNewFile = false; $intFileID = (int) $arDestSect[$arOneUserField['FIELD_NAME']]; if ($intFileID > 0) { $arNewFile = CFile::MakeFileArray($intFileID); } $arDestSect[$arOneUserField['FIELD_NAME']] = !empty($arNewFile) ? $arNewFile : false; } } else { $arDestSect[$arOneUserField['FIELD_NAME']] = false; } } elseif ($arOneUserField['USER_TYPE']['BASE_TYPE'] == 'enum') { if (!empty($arDestSect[$arOneUserField['FIELD_NAME']])) { if ($intSrcIBlockID != $intDestIBlockID) { if (array_key_exists($arOneUserField['FIELD_NAME'], $arUFEnumCache) && array_key_exists($arOneUserField['FIELD_NAME'], $arOldUFEnumCache)) { if (is_array($arDestSect[$arOneUserField['FIELD_NAME']])) { $arNewEnumList = array(); foreach ($arDestSect[$arOneUserField['FIELD_NAME']] as &$intValueID) { $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$intValueID]; if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) { $arNewEnumList[] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID]; } else { $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$intValueID]; $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]); if ($intValueKey !== false) { $arNewEnumList[] = $intValueKey; } } } if (isset($intValueID)) { unset($intValueID); } if (!empty($arNewEnumList)) { $arDestSect[$arOneUserField['FIELD_NAME']] = $arNewEnumList; } } else { $strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]]; if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) { $arDestSect[$arOneUserField['FIELD_NAME']] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID]; } else { $strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]]; $intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]); if ($intValueKey !== false) { $arDestSect[$arOneUserField['FIELD_NAME']] = $intValueKey; } } } } } } else { $arDestSect[$arOneUserField['FIELD_NAME']] = false; } } } if (isset($arOneUserField)) { unset($arOneUserField); } } $intNewID = $sc->Add($arDestSect); if (!$intNewID) { CASDiblock::$error .= '[' . $ID . '] ' . $sc->LAST_ERROR . "\n"; } } } } $successRedirect = true; } unset($_REQUEST['action']); if (isset($_REQUEST['action_button'])) { unset($_REQUEST['action_button']); } if ($successRedirect) { LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button', 'asd_ib_dest', 'asd_sect_dest', 'ID'))); } } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'asd_remove' && $IBLOCK_ID > 0 && isset($_REQUEST['find_section_section']) && check_bitrix_sessid() && CASDIblockRights::IsIBlockDisplay($IBLOCK_ID)) { $intSectionID = (int) $_REQUEST['find_section_section']; if ($intSectionID > 0) { $strCurPage = $GLOBALS['APPLICATION']->GetCurPage(); $bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php'; $bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php'; if ($bElemPage || $bMixPage) { foreach ($_REQUEST['ID'] as $eID) { if ($bMixPage) { if (substr($eID, 0, 1) != 'E') { continue; } $ID = (int) substr($eID, 1); } else { $ID = (int) $eID; } if ($ID <= 0) { continue; } if (CASDIblockRights::IsElementEdit($IBLOCK_ID, $ID)) { $arSectionList = array(); $rsSections = CIBlockElement::GetElementGroups($ID, true); while ($arSection = $rsSections->Fetch()) { $arSection['ID'] = (int) $arSection['ID']; if ($arSection['ID'] != $intSectionID) { $arSectionList[] = $arSection['ID']; } } CIBlockElement::SetElementSection($ID, $arSectionList, false); $successRedirect = true; } } } } unset($_REQUEST['action']); if (isset($_REQUEST['action_button'])) { unset($_REQUEST['action_button']); } if ($successRedirect) { LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button'))); } } }
$arBaseProduct = false; $periodTimeTypes = array(); if ($arMainCatalog['SUBSCRIPTION'] == 'Y') { $arDefProduct = array('QUANTITY' => '', 'QUANTITY_RESERVED' => '', 'VAT_ID' => 0, 'VAT_INCLUDED' => 'N', 'QUANTITY_TRACE_ORIG' => 'D', 'CAN_BUY_ZERO_ORIG' => 'D', 'PRICE_TYPE' => '', 'RECUR_SCHEME_TYPE' => '', 'RECUR_SCHEME_LENGTH' => '', 'TRIAL_PRICE_ID' => '', 'WITHOUT_ORDER' => '', 'PURCHASING_PRICE' => '', 'PURCHASING_CURRENCY' => '', 'BARCODE_MULTI' => '', 'SUBSCRIBE_ORIG' => 'D'); $periodTimeTypes = CCatalogProduct::GetTimePeriodTypes(true); } else { $arDefProduct = array('QUANTITY' => '', 'QUANTITY_RESERVED' => '', 'WEIGHT' => '', 'WIDTH' => '', 'LENGTH' => '', 'HEIGHT' => '', 'MEASURE' => '', 'VAT_ID' => 0, 'VAT_INCLUDED' => 'N', 'QUANTITY_TRACE_ORIG' => 'D', 'CAN_BUY_ZERO_ORIG' => 'D', 'PURCHASING_PRICE' => '', 'PURCHASING_CURRENCY' => '', 'BARCODE_MULTI' => '', 'SUBSCRIBE_ORIG' => 'D'); } if ($PRODUCT_ID > 0) { $bReadOnly = !($USER->CanDoOperation('catalog_price') && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $PRODUCT_ID, "element_edit_price")); if ($arMainCatalog['SUBSCRIPTION'] == 'Y') { $arProductSelect = array('ID', 'QUANTITY', 'QUANTITY_RESERVED', 'QUANTITY_TRACE_ORIG', 'VAT_ID', 'VAT_INCLUDED', 'CAN_BUY_ZERO_ORIG', 'PRICE_TYPE', 'RECUR_SCHEME_TYPE', 'RECUR_SCHEME_LENGTH', 'TRIAL_PRICE_ID', 'WITHOUT_ORDER', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY', 'BARCODE_MULTI', 'SUBSCRIBE_ORIG', 'TYPE'); } else { $arProductSelect = array('ID', 'QUANTITY', 'QUANTITY_RESERVED', 'QUANTITY_TRACE_ORIG', 'WEIGHT', 'WIDTH', 'LENGTH', 'HEIGHT', 'MEASURE', 'VAT_ID', 'VAT_INCLUDED', 'CAN_BUY_ZERO_ORIG', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY', 'BARCODE_MULTI', 'SUBSCRIBE_ORIG', 'TYPE'); } $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $PRODUCT_ID), false, false, $arProductSelect); $arBaseProduct = $rsProducts->Fetch(); if ($bCopy) { $arBaseProduct['QUANTITY'] = ''; $arBaseProduct['QUANTITY_RESERVED'] = ''; } } else { $bReadOnly = !($USER->CanDoOperation('catalog_price') && CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $MENU_SECTION_ID, "element_edit_price")); } if (empty($arBaseProduct)) { $arBaseProduct = $arDefProduct; } $productIsSet = CBXFeatures::IsFeatureEnabled('CatCompleteSet') && ($arBaseProduct['TYPE'] == CCatalogProduct::TYPE_SET || $arShowTabs['product_set']); $bDiscount = $USER->CanDoOperation('catalog_discount'); $bStore = $USER->CanDoOperation('catalog_store'); $bUseStoreControl = COption::GetOptionString('catalog', 'default_use_store_control') == 'Y';
/** * @param $productId * @param null $userId * @return bool * @throws Main\ArgumentException */ public static function getProductAvailableQuantity($productId, $userId = null) { $adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true; $userId = isset($userId) ? (int) $userId : 0; if ($userId < 0) { $userId = 0; } static $arUserCache = array(); if ($adminSection) { if ($userId == 0) { return false; } if (!isset($arUserCache[$userId])) { $userIterator = Main\UserTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $userId))); if ($userDat = $userIterator->fetch()) { $userDat['ID'] = (int) $userDat['ID']; $arUserCache[$userDat['ID']] = CUser::GetUserGroup($userDat['ID']); } else { return false; } } $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 false; } $iblockRights = null; if (!($iblockRights = static::getHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID']))) { if ($iblockRights = CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'RIGHTS_MODE')) { static::setHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID'], $iblockRights); } } if ($iblockRights == 'E') { $proxyUserPermissionKey = $productId . "|" . $userId; if (!($arUserRights = static::getHitCache('USER_RIGHT', $proxyUserPermissionKey))) { if ($arUserRights = CIBlockElementRights::GetUserOperations($productId, $userId)) { static::setHitCache('USER_RIGHT', $proxyUserPermissionKey, $arUserRights); } } if (empty($arUserRights) || !isset($arUserRights['element_read'])) { return false; } unset($arUserRights); } else { if (CIBlock::GetPermission($arProduct['IBLOCK_ID'], $userId) < 'R') { return false; } } } 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 false; } } $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY')); if ($arCatalogProduct = $rsProducts->Fetch()) { return $arCatalogProduct['QUANTITY']; } return false; }
protected function getProductIds() { $ids = array(); if (!empty($this->ajaxItemsIds)) { $recommendationId = Main\Context::getCurrent()->getRequest()->get('RID'); $ids = $this->ajaxItemsIds; } else { $bestsellers = parent::getProductIds(); if (!empty($bestsellers)) { $recommendationId = 'bestsellers'; $ids = Main\Analytics\Catalog::getProductIdsByOfferIds($bestsellers); } if (empty($ids)) { $recommendationId = 'mostviewed'; $dublicate = array(); // top viewed $result = CatalogViewedProductTable::getList(array('select' => array('ELEMENT_ID', new Main\Entity\ExpressionField('SUM_HITS', 'SUM(%s)', 'VIEW_COUNT')), 'filter' => array('=SITE_ID' => $this->getSiteId(), '>ELEMENT_ID' => 0), 'order' => array('SUM_HITS' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT'])); while ($row = $result->fetch()) { if (!isset($dublicate[$row['ELEMENT_ID']])) { $ids[] = $row['ELEMENT_ID']; } $dublicate[$row['ELEMENT_ID']] = true; } unset($row, $result, $dublicate); } } if (!empty($ids) && $this->arParams['HIDE_NOT_AVAILABLE'] == 'Y') { $filter = count($ids) > 1000 ? array('ID' => $ids) : array('@ID' => $ids); $ids = array_fill_keys($ids, true); $productIterator = CCatalogProduct::GetList(array(), $filter, false, false, array('ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO')); while ($product = $productIterator->Fetch()) { if (isset($ids[$product['ID']]) && !CCatalogProduct::isAvailable($product)) { unset($ids[$product['ID']]); } } unset($product, $productIterator, $filter); $ids = array_keys($ids); } $ids = array_slice($ids, 0, $this->arParams['PAGE_ELEMENT_COUNT']); // remember recommendation id $this->arResult['RID'] = $recommendationId; return $ids; }
protected function getQuantity($productId) { $result = 0; $rsProducts = \CCatalogProduct::GetList(array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO')); if ($arProduct = $rsProducts->Fetch()) { $arProduct['QUANTITY'] = doubleval($arProduct['QUANTITY']); if (0 >= $arProduct['QUANTITY'] && ('Y' != $arProduct['QUANTITY_TRACE'] || 'N' != $arProduct['CAN_BUY_ZERO'])) { $result = 1; } else { $result = $arProduct['QUANTITY']; } } return $result; }
} else { $val = $res ? "Y" : "N"; } $arBasket["STORES"][$storeId]["BARCODE"][] = $arRes["BARCODE"]; $arBasket["STORES"][$storeId]["BARCODE_FOUND"][] = $val; } else { $arBasket["STORES"][$storeId]["QUANTITY"] = $arRes["QUANTITY"]; $arBasket["STORES"][$storeId]["QUANTITY_DEDUCTED"] = $arRes["DEDUCTED"] == "Y" ? "Y" : "N"; } } } } $arBasket["HAS_SAVED_QUANTITY"] = "Y"; $arBasket["HAS_SAVED_BARCODES"] = true; $ind++; } } } } $arResult["BASKET"][$arBasket["ID"]] = $arBasket; } if (CModule::IncludeModule('catalog')) { $rsCatProd = CCatalogProduct::GetList(array(), array("ID" => $arProdIds), false, false, array("ID", "QUANTITY")); while ($arCatProd = $rsCatProd->Fetch()) { if ($arResult["BASKET"][$arProdIdsPrIds[$arCatProd["ID"]]]["MODULE"] == "catalog") { $arResult["BASKET"][$arProdIdsPrIds[$arCatProd["ID"]]]["BALANCE"] = FloatVal($arCatProd["QUANTITY"]); } } } $arResult["USE_STORES"] = $useStores; $this->IncludeComponentTemplate($templatePage);
function getMeasures($arBasketItems) { if (Loader::includeModule('catalog')) { $arDefaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true); $arElementId = array(); $basketLinks = array(); foreach ($arBasketItems as $keyBasket => $arItem) { $productID = (int) $arItem["PRODUCT_ID"]; if (!isset($basketLinks[$productID])) { $basketLinks[$productID] = array(); } $basketLinks[$productID][] = $keyBasket; $arElementId[] = $productID; $arBasketItems[$keyBasket]['MEASURE_TEXT'] = $arDefaultMeasure['~SYMBOL_RUS']; $arBasketItems[$keyBasket]['MEASURE'] = 0; } unset($productID, $keyBasket, $arItem); if (!empty($arElementId)) { $arBasket2Measure = array(); $dbres = CCatalogProduct::GetList(array(), array("ID" => $arElementId), false, false, array("ID", "MEASURE")); while ($arRes = $dbres->Fetch()) { $arRes['ID'] = (int) $arRes['ID']; $arRes['MEASURE'] = (int) $arRes['MEASURE']; if (!isset($arBasket2Measure[$arRes['MEASURE']])) { $arBasket2Measure[$arRes['MEASURE']] = array(); } $arBasket2Measure[$arRes['MEASURE']][] = $arRes['ID']; } unset($arRes, $dbres); if (!empty($arBasket2Measure)) { $dbMeasure = CCatalogMeasure::GetList(array(), array("ID" => array_keys($arBasket2Measure)), false, false, array('ID', 'SYMBOL_RUS')); while ($arMeasure = $dbMeasure->Fetch()) { $arMeasure['ID'] = (int) $arMeasure['ID']; if (isset($arBasket2Measure[$arMeasure['ID']]) && !empty($arBasket2Measure[$arMeasure['ID']])) { foreach ($arBasket2Measure[$arMeasure['ID']] as &$productID) { if (isset($basketLinks[$productID]) && !empty($basketLinks[$productID])) { foreach ($basketLinks[$productID] as &$keyBasket) { $arBasketItems[$keyBasket]['MEASURE_TEXT'] = $arMeasure['SYMBOL_RUS']; $arBasketItems[$keyBasket]['MEASURE'] = $arMeasure['ID']; } unset($keyBasket); } } unset($productID); } } } } } return $arBasketItems; }
$sum += $store['AMOUNT']; } else { $amount[$store['STORE_ID']] = 0; $amount[$store['STORE_ID']] += $store['AMOUNT']; } } unset($store, $storeIterator, $filter); if ($arParams["SHOW_GENERAL_STORE_INFORMATION"] == "Y") { $productSku[$sku['ID']][] = $sum; } else { $productSku[$sku['ID']] = $amount; } $arParams["ELEMENT_ID"] = $sku['ID']; } } $res = CCatalogProduct::GetList(array(), array("ID" => $arParams["ELEMENT_ID"]), false, false, array("TYPE", "QUANTITY", "ID")); $data = $res->Fetch(); if ($data["TYPE"] == CCatalogProduct::TYPE_SET) { $arParams["SHOW_GENERAL_STORE_INFORMATION"] = "Y"; $arParams["~SHOW_GENERAL_STORE_INFORMATION"] = "Y"; $quantity = $data["QUANTITY"]; $arResult["IS_SKU"] = false; } else { if (in_array('COORDINATES', $arParams['FIELDS'])) { $arParams['FIELDS'] = array_merge($arParams['FIELDS'], array('GPS_N', 'GPS_S')); } $select = array_merge(array("ID", "ACTIVE", "PRODUCT_AMOUNT", "TITLE", "TYPE"), $arParams["FIELDS"], $arParams["USER_FIELDS"]); foreach ($select as $key => $value) { if (empty($value) || $value == 'COORDINATES') { unset($select[$key]); }
function exportElement($arElement, $SECTION_MAP, $PROPERTY_MAP) { if (strlen($arElement["XML_ID"]) > 0) { $xml_id = $arElement["XML_ID"]; } else { $xml_id = $arElement["ID"]; } if ($this->PRODUCT_IBLOCK_ID > 0) { $arPropOrder = array("sort" => "asc", "id" => "asc", "enum_sort" => "asc", "value_id" => "asc"); $rsLink = CIBlockElement::GetProperty($this->arIBlock["ID"], $arElement["ID"], $arPropOrder, array("ACTIVE" => "Y", "CODE" => "CML2_LINK")); $arLink = $rsLink->Fetch(); if (is_array($arLink) && !is_array($arLink["VALUE"]) && $arLink["VALUE"] > 0) { $xml_id = $this->GetElementXML_ID($this->PRODUCT_IBLOCK_ID, $arLink["VALUE"]) . "#" . $xml_id; } } fwrite($this->fp, "\t\t\t\t<" . GetMessage("IBLOCK_XML2_ID") . ">" . htmlspecialcharsbx($xml_id) . "</" . GetMessage("IBLOCK_XML2_ID") . ">\n"); if (!$this->only_price) { $this->exportElementFields($arElement, $SECTION_MAP); if ($this->next_step["catalog"] && !$this->bExtended) { fwrite($this->fp, "\t\t\t\t<" . GetMessage("IBLOCK_XML2_ITEM_ATTRIBUTES") . ">\n"); } else { fwrite($this->fp, "\t\t\t\t<" . GetMessage("IBLOCK_XML2_PROPERTIES_VALUES") . ">\n"); } $this->exportElementProperties($arElement, $PROPERTY_MAP); if ($this->next_step["catalog"] && !$this->bExtended) { fwrite($this->fp, "\t\t\t\t</" . GetMessage("IBLOCK_XML2_ITEM_ATTRIBUTES") . ">\n"); } else { fwrite($this->fp, "\t\t\t\t</" . GetMessage("IBLOCK_XML2_PROPERTIES_VALUES") . ">\n"); } if ($this->bExtended) { $elementTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($this->arIBlock["ID"], $arElement["ID"]); $this->exportInheritedTemplates(4, $elementTemplates); } } if ($this->next_step["catalog"]) { $rsProduct = CCatalogProduct::GetList(array(), array("ID" => $arElement["ID"])); $arProduct = $rsProduct->Fetch(); static $measure = null; if (!isset($measure)) { $measure = array(); $rsBaseUnit = CCatalogMeasure::GetList(array(), array()); while ($arIDUnit = $rsBaseUnit->Fetch()) { $measure[$arIDUnit["ID"]] = $arIDUnit["CODE"]; } } $xmlMeasure = GetMessage("IBLOCK_XML2_PCS"); if ($arProduct["MEASURE"] > 0 && isset($measure[$arProduct["MEASURE"]])) { $xmlMeasure = $measure[$arProduct["MEASURE"]]; } $arPrices = array(); $rsPrices = CPrice::GetList(array(), array("PRODUCT_ID" => $arElement["ID"])); while ($arPrice = $rsPrices->Fetch()) { if (!$arPrice["QUANTITY_FROM"] && !$arPrice["QUANTITY_TO"]) { $arPrices[] = array(GetMessage("IBLOCK_XML2_PRICE_TYPE_ID") => $this->prices[$arPrice["CATALOG_GROUP_ID"]], GetMessage("IBLOCK_XML2_PRICE_FOR_ONE") => $arPrice["PRICE"], GetMessage("IBLOCK_XML2_CURRENCY") => $arPrice["CURRENCY"], GetMessage("IBLOCK_XML2_MEASURE") => $xmlMeasure); } } if (count($arPrices) > 0) { fwrite($this->fp, "\t\t\t\t<" . GetMessage("IBLOCK_XML2_PRICES") . ">\n"); foreach ($arPrices as $arPrice) { fwrite($this->fp, "\t\t\t\t\t<" . GetMessage("IBLOCK_XML2_PRICE") . ">\n"); foreach ($arPrice as $key => $value) { fwrite($this->fp, "\t\t\t\t\t\t<" . $key . ">" . htmlspecialcharsbx($value) . "</" . $key . ">\n"); } fwrite($this->fp, "\t\t\t\t\t</" . GetMessage("IBLOCK_XML2_PRICE") . ">\n"); } fwrite($this->fp, "\t\t\t\t</" . GetMessage("IBLOCK_XML2_PRICES") . ">\n"); $arCatalogProduct = CCatalogProduct::GetByID($arElement["ID"]); if ($arCatalogProduct) { fwrite($this->fp, "\t\t\t\t<" . GetMessage("IBLOCK_XML2_AMOUNT") . ">" . htmlspecialcharsbx($arCatalogProduct["QUANTITY"]) . "</" . GetMessage("IBLOCK_XML2_AMOUNT") . ">\n"); } } } }