public static function checkQuantity($ID, $productFields) { $checkNeed = isset($productFields['QUANTITY']) || isset($productFields['QUANTITY_TRACE']) || isset($productFields['CAN_BUY_ZERO']); if (!$checkNeed) { return; } $productIterator = ProductTable::getList(array('filter' => array('=ID' => $ID), 'select' => array('QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO'))); $product = $productIterator->fetch(); if ($product) { if ($product["QUANTITY_TRACE"] == "Y" && $product['CAN_BUY_ZERO'] == 'N') { $linkIterator = LinkTable::getList(array("filter" => array("=LINK_TYPE" => LinkTable::TYPE_IBLOCK_ELEMENT, "=LINK_ID" => $ID, array(array("=BANNER.AUTO_QUANTITY_OFF" => YandexBannerTable::ACTIVE), array("=BANNER.AUTO_QUANTITY_ON" => YandexBannerTable::ACTIVE), 'LOGIC' => "OR")), "select" => array("BANNER_ID", "AUTO_QUANTITY_ON" => "BANNER.AUTO_QUANTITY_ON", "AUTO_QUANTITY_OFF" => "BANNER.AUTO_QUANTITY_OFF"))); $zeroQuantity = $product['QUANTITY'] <= 0; $linkIdMark = array(); $linkIdUnMark = array(); while ($link = $linkIterator->fetch()) { $linkIdMark[] = $link["BANNER_ID"]; if ($zeroQuantity && $link["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED || !$zeroQuantity && $link["AUTO_QUANTITY_OFF"] == YandexBannerTable::MARKED) { $linkIdUnMark[] = $link["BANNER_ID"]; } } if (count($linkIdMark) > 0) { if ($zeroQuantity) { YandexBannerTable::markStopped($linkIdMark); } else { YandexBannerTable::markResumed($linkIdMark); } if (count($linkIdUnMark) > 0) { if ($zeroQuantity) { YandexBannerTable::unMarkResumed($linkIdUnMark); } else { YandexBannerTable::unMarkStopped($linkIdUnMark); } } } } } }
/** * Returns product data. * * @param array &$productData Product data. * @param array $entityData Entity data. * @param array $iblockData Iblock list data. * @return void */ protected static function getProductData(&$productData, $entityData, $iblockData) { if (!empty($iblockData['iblockElement'])) { $productList = array_keys($productData); if (!empty($entityData['iblockFields'])) { $elementIterator = Iblock\ElementTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['iblockFields'])), 'filter' => array('@ID' => $productList))); while ($element = $elementIterator->fetch()) { $element['ID'] = (int) $element['ID']; $fields = array(); foreach ($entityData['iblockFields'] as $key => $alias) { $fields[$alias] = $element[$key]; } unset($key, $alias); $productData[$element['ID']] = empty($productData[$element['ID']]) ? $fields : array_merge($productData[$element['ID']], $fields); unset($fields); } } if ($entityData['sections']) { $productSection = array_fill_keys($productList, array()); $elementSectionIterator = Iblock\SectionElementTable::getList(array('select' => array('*'), 'filter' => array('@IBLOCK_ELEMENT_ID' => $productList))); while ($elementSection = $elementSectionIterator->fetch()) { $elementSection['IBLOCK_ELEMENT_ID'] = (int) $elementSection['IBLOCK_ELEMENT_ID']; $elementSection['IBLOCK_SECTION_ID'] = (int) $elementSection['IBLOCK_SECTION_ID']; $elementSection['ADDITIONAL_PROPERTY_ID'] = (int) $elementSection['ADDITIONAL_PROPERTY_ID']; if ($elementSection['ADDITIONAL_PROPERTY_ID'] > 0) { continue; } $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$elementSection['IBLOCK_SECTION_ID']] = true; $parentSectionIterator = \CIBlockSection::getNavChain(0, $elementSection['IBLOCK_SECTION_ID'], array('ID')); while ($parentSection = $parentSectionIterator->fetch()) { $parentSection['ID'] = (int) $parentSection['ID']; $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$parentSection['ID']] = true; } unset($parentSection, $parentSectionIterator); } unset($elementSection, $elementSectionIterator); foreach ($productSection as $element => $sections) { $productData[$element]['SECTION_ID'] = array_keys($sections); } unset($element, $sections, $productSection); } if (!empty($entityData['needProperties'])) { $propertyValues = array_fill_keys($productList, array()); foreach ($entityData['needProperties'] as $iblock => $propertyList) { if (empty($iblockData['iblockElement'][$iblock])) { continue; } $filter = array('ID' => $iblockData['iblockElement'][$iblock], 'IBLOCK_ID' => $iblock); \CTimeZone::disable(); \CIBlockElement::getPropertyValuesArray($propertyValues, $iblock, $filter, array('ID' => $propertyList)); \CTimeZone::enable(); } unset($filter, $iblock, $propertyList); self::convertProperties($productData, $propertyValues, $entityData, $iblockData); } if (!empty($entityData['catalogFields'])) { $productIterator = Catalog\ProductTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['catalogFields'])), 'filter' => array('@ID' => $productList))); while ($product = $productIterator->fetch()) { $product['ID'] = (int) $product['ID']; $fields = array(); foreach ($entityData['catalogFields'] as $key => $alias) { $fields[$alias] = $product[$key]; } unset($key, $alias); $productData[$product['ID']] = empty($productData[$product['ID']]) ? $fields : array_merge($productData[$product['ID']], $fields); unset($fields); } unset($product, $productIterator); } if (!empty($iblockData['skuIblockList'])) { self::getParentProducts($productData, $entityData, $iblockData); } } }
public function Delete($ID) { global $DB; $ID = (int) $ID; if ($ID <= 0) { return false; } $DB->Query('delete from b_catalog_price where PRODUCT_ID = ' . $ID, true); $DB->Query('delete from b_catalog_product2group where PRODUCT_ID = ' . $ID, true); $DB->Query('delete from b_catalog_product_sets where ITEM_ID = ' . $ID . ' or OWNER_ID = ' . $ID, true); $DB->Query('delete from b_catalog_measure_ratio where PRODUCT_ID = ' . $ID, true); Catalog\ProductTable::clearProductCache($ID); if (isset(self::$arProductCache[$ID])) { unset(self::$arProductCache[$ID]); if (defined('CATALOG_GLOBAL_VARS') && CATALOG_GLOBAL_VARS == 'Y') { /** @var array $CATALOG_PRODUCT_CACHE */ global $CATALOG_PRODUCT_CACHE; $CATALOG_PRODUCT_CACHE = self::$arProductCache; } } return $DB->Query("delete from b_catalog_product where ID = " . $ID, true); }
$countSetDefaultItems = 0; $select = array('ID', 'NAME', 'CODE', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'DETAIL_PAGE_URL', 'PREVIEW_PICTURE', 'DETAIL_PICTURE', 'PREVIEW_TEXT', 'CATALOG_AVAILABLE', 'CATALOG_MEASURE'); $arResult["PRICES"] = CIBlockPriceTools::GetCatalogPrices($arResult['PRODUCT_IBLOCK_ID'], $arParams["PRICE_CODE"]); foreach ($arResult["PRICES"] as $key => $value) { if (!$value['CAN_VIEW'] && !$value['CAN_BUY']) { continue; } $select[] = $value["SELECT"]; } $arResult["SET_ITEMS"]["DEFAULT"] = array(); $arResult["SET_ITEMS"]["OTHER"] = array(); $arResult["SET_ITEMS"]["PRICE"] = 0; $arResult["SET_ITEMS"]["OLD_PRICE"] = 0; $arResult["SET_ITEMS"]["PRICE_DISCOUNT_DIFFERENCE"] = 0; $arResult['ITEMS_RATIO'] = array_fill_keys($arSetItemsID, 1); $ratioResult = Catalog\ProductTable::getCurrentRatioWithMeasure($arSetItemsID); foreach ($ratioResult as $ratioProduct => $ratioData) { $arResult['ITEMS_RATIO'][$ratioProduct] = $ratioData['RATIO']; } unset($ratioProduct, $ratioData); $tagIblockList = array(); $tagIblockList[$arResult['PRODUCT_IBLOCK_ID']] = $arResult['PRODUCT_IBLOCK_ID']; $tagIblockList[$arResult['ELEMENT_IBLOCK_ID']] = $arResult['ELEMENT_IBLOCK_ID']; $tagCurrencyList = array(); $found = false; $itemsIterator = CIBlockElement::GetList(array(), array('ID' => $arSetItemsID), false, false, $select); while ($item = $itemsIterator->GetNext()) { $found = true; $item['ID'] = (int) $item['ID']; $item['IBLOCK_ID'] = (int) $item['IBLOCK_ID']; $tagIblockList[$item['IBLOCK_ID']] = $item['IBLOCK_ID'];
/** * @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; }
/** * <p>Метод проверяет наличие записи в таблице <i>b_catalog_product</i> с информацией (доступное количество, разрешена ли покупка при отсутствии товара и т.д.) для товара с кодом <i>intID</i>. Метод статический.</p> * * * @param int $intID Код товара. * * @return bool <p> В случае наличия информации о товаре возвращает true, иначе - * false.</p> <br><br> * * @static * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/isexistproduct.php * @author Bitrix * @deprecated deprecated since catalog 15.5.2 -> \Bitrix\Catalog\ProductTable::isExistProduct() */ public static function IsExistProduct($intID) { return Catalog\ProductTable::isExistProduct($intID); }
public static function getItemsInfo(&$arSets) { $itemList = array(); $itemIds = array(); if (empty($arSets) || !is_array($arSets)) { return; } foreach ($arSets as $key => $arOneSet) { foreach ($arOneSet['ITEMS'] as $keyItem => $arItem) { if ('' == $arItem['ITEM_ID']) { continue; } $intItemID = (int) $arItem['ITEM_ID']; if (0 >= $intItemID) { continue; } if (!isset($itemList[$intItemID])) { $itemList[$intItemID] = array(); $itemIds[] = $intItemID; } $itemList[$intItemID][] =& $arSets[$key]['ITEMS'][$keyItem]; } } if (!empty($itemList)) { $productIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('@ID' => $itemIds))); while ($product = $productIterator->fetch()) { $product['ID'] = (int) $product['ID']; if (!isset($itemList[$product['ID']])) { continue; } foreach ($itemList[$product['ID']] as &$setItem) { $setItem['ITEM_NAME'] = $product['NAME']; } unset($setItem); } unset($product, $productIterator); $productRatio = Catalog\ProductTable::getCurrentRatioWithMeasure($itemIds); if (!empty($productRatio)) { foreach ($productRatio as $productId => $productData) { if (!isset($itemList[$productId])) { continue; } foreach ($itemList[$productId] as &$setItem) { $setItem['RATIO'] = $productData['RATIO']; $setItem['MEASURE'] = $productData['MEASURE']; } unset($setItem); } unset($productId, $productData); } unset($productRatio); } unset($itemIds, $itemList); }