Advertisement
animdenis

AB Iblocks New

Sep 13th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. //Params:
  2. $iblockA = 44;
  3. $iblockB = 51;
  4. $pregMatchStr = '#\((.*?)\)#';
  5. $testCountElem = 10;
  6. $test = true;
  7. //Script:
  8. CModule::IncludeModule('iblock');
  9. $dbIblockB = CIblockElement::GetList([], ['IBLOCK_ID' => $iblockB], false, false, ['NAME', 'ID', 'XML_ID']);
  10. $arNamesB = [];
  11. $cnt = 0;
  12. while($obB = $dbIblockB->GetNext()){
  13. $arXmlId = explode('#', $obB['XML_ID']);
  14. if(count($arXmlId) == 2)
  15. $arNamesB[$arXmlId[1]] = $obB['XML_ID'];
  16.  
  17. if((int)$testCountElem > 0 && $cnt++ > $testCountElem)
  18. break;
  19. }
  20.  
  21.  
  22.  
  23. $dbIblockA = CIblockElement::GetList([], ['IBLOCK_ID' => $iblockA, 'XML_ID' => array_flip($arNamesB)], false, false, ['NAME', 'ID', 'XML_ID']);
  24.  
  25. if($test) {
  26. print_r(['Найдено' => $dbIblockA->SelectedRowsCount(), 'Выбрано' => count($arNamesB)]);
  27. print_r($arNamesB);
  28. die();
  29. }
  30.  
  31. $el = new CIBlockElement;
  32. $cntUpd = 0;
  33. while($obA = $dbIblockA->GetNext()){
  34. $el->Update($obA['ID'], ['XML_ID' => $arNamesB[$obA['XML_ID']]]);
  35. $cntUpd++;
  36. }
  37.  
  38. echo 'Обновлено: ' . $cntUpd;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement