0) { foreach ($infoBlocks as $id) { $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id); $arNavStatParams = array( 'iNumPage' => 1, 'nPageSize' => self::$pageSize, ); do { $dbResProductsIds = CIBlockElement::GetList(array('ID'), array('IBLOCK_ID' => $id), false, $arNavStatParams, array('ID')); $products = array(); while ($product = $dbResProductsIds->fetch()) { $products[$product['ID']] = $product; $products[$product['ID']]['offers'] = array(); } if (!empty($iblockOffer['IBLOCK_ID'])) { $arFilterOffer = array( 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'], 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products), ); $dbResOffers = CIBlockElement::GetList(array('ID'), $arFilterOffer, false, false, array('ID', 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'])); while ($offer = $dbResOffers->fetch()) { $products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][] = $offer['ID']; } } $elems = array(); foreach ($products as $product) { if (count($product['offers']) > 0) { $elems = array_merge($elems, $product['offers']); } else { $elems[] = $product['ID']; } } $pricesUpload = array(); $dbPricesProduct = CPrice::GetList( array(), array('PRODUCT_ID' => $elems, 'CATALOG_GROUP_ID' => array_keys($prices)), false, false, array('PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE') ); while ($arPricesProduct = $dbPricesProduct->Fetch()) { foreach ($shops as $shop) { if (!isset($pricesUpload[$arPricesProduct['PRODUCT_ID'] . '-' . $shop])) { $pricesUpload[$arPricesProduct['PRODUCT_ID'] . '-' . $shop] = array( 'externalId' => $arPricesProduct['PRODUCT_ID'], 'site' => $shop ); } $pricesUpload[$arPricesProduct['PRODUCT_ID'] . '-' . $shop]['prices'][] = array( 'code' => $prices[$arPricesProduct['CATALOG_GROUP_ID']], 'price' => $arPricesProduct['PRICE'], ); } } foreach ($shops as $shop) { foreach ($elems as $value) { if (!array_key_exists($value . '-' . $shop, $pricesUpload)) { foreach ($prices as $key => $price) { $pricesUpload[$value . '-' . $shop] = array( 'externalId' => $value, 'site' => $shop ); $pricesUpload[$value . '-'. $shop]['prices'][] = array( 'code' => $prices[$key], 'remove' => true ); } } } } //for log $splitedItems = array_chunk($pricesUpload, 200); foreach ($splitedItems as $chunk) { Logger::getInstance()->write($chunk, 'storePricesUpload'); foreach ($shops as $shop) { RCrmActions::apiMethod($api, 'storePricesUpload', __METHOD__, $chunk, $shop); time_nanosleep(0, 250000000); } } $arNavStatParams['iNumPage'] = $dbResProductsIds->NavPageNomer + 1; } while($dbResProductsIds->NavPageNomer < $dbResProductsIds->NavPageCount); } } else { RCrmActions::eventLog('RetailCrmPrices::pricesUpload()', '$infoBlocks', 'No iblocks selected'); return false; } return 'RetailCrmPrices::pricesUpload();'; } }