Advertisement
animdenis

Shop-Elvent replace

Sep 16th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. CModule::IncludeModule("iblock");
  2.  
  3. $i = 0;
  4. $iblock_id = 16;
  5. $arSelect = Array("ID", "DETAIL_TEXT", "NAME");
  6. $arFilter = Array("IBLOCK_ID" => $iblock_id, "SECTION_ID" => 808, "INCLUDE_SUBSECTIONS"=>"Y"); // "SECTION_ID"=>52,
  7. $res = CIBlockElement::GetList(Array('ID' => 'DESC'), $arFilter, false, false, $arSelect);
  8. $arAllLog = [];
  9. $el = new CIBlockElement;
  10. while($ob = $res->GetNext()){
  11.     //print_r($ob['DETAIL_TEXT']);die();
  12.     $tmpDescr = explode('Купить ', $ob['DETAIL_TEXT']);
  13.     if(count($tmpDescr) == 2) {
  14.         if(substr_count($tmpDescr[1], '</div>') == 1){
  15.             if(substr_count($ob['DETAIL_TEXT'], 'Layta.Ru') > 0) {
  16.                 $arAllLog['SUCCESS_ERROR'][] = $ob['ID'];
  17.                 $detailText = str_replace('Layta.Ru', 'shop-elvent.ru', $ob['DETAIL_TEXT']);
  18.                 if(!$el->Update($ob['ID'], ['DETAIL_TEXT' => $detailText])) $arAllLog['ERROR_UPDATE'][] = $ob['ID'];
  19.             } else {
  20.                 $arAllLog['SUCCESS'][] = $ob['ID'];
  21.                 if(!$el->Update($ob['ID'], ['DETAIL_TEXT' => $tmpDescr[0] . '</div>'])) $arAllLog['ERROR_UPDATE'][] = $ob['ID'];
  22.             }
  23.         } else {
  24.             $arAllLog['ERROR_DIV'][] = $ob['ID'];
  25.         }
  26.     } else {
  27.         if(substr_count($ob['DETAIL_TEXT'], 'Layta.Ru') > 0) {
  28.             $arAllLog['SUCCESS_POS'][] = $ob['ID'];
  29.             $detailText = str_replace('Layta.Ru', 'shop-elvent.ru', $ob['DETAIL_TEXT']);
  30.             if(!$el->Update($ob['ID'], ['DETAIL_TEXT' => $detailText])) $arAllLog['ERROR_UPDATE'][] = $ob['ID'];
  31.         } else {
  32.             if(empty($ob['DETAIL_TEXT'])) $arAllLog['EMPTY'][] = $ob['ID'];
  33.             else $arAllLog['ERROR_EXPLODE'][] = $ob['ID'];
  34.         }
  35.     }
  36. }
  37. print_r([
  38.     'SUCCESS' => count($arAllLog['SUCCESS']),
  39.     'SUCCESS_POS' => count($arAllLog['SUCCESS_POS']),
  40.     'SUCCESS_ERROR' => count($arAllLog['SUCCESS_ERROR']),
  41.     'ERROR_UPDATE' => count($arAllLog['ERROR_UPDATE']),
  42.     'ERROR_DIV' => count($arAllLog['ERROR_DIV']),
  43.     'ERROR_EXPLODE' => count($arAllLog['ERROR_EXPLODE']),
  44.     'EMPTY' => count($arAllLog['EMPTY']),
  45. ]);
  46. print_r($arAllLog['ERROR_EXPLODE']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement