Авторизация

UMI выгрузка из 1C поиск страницы копии, удаление копии

Заходим в файл custom_events.php ( classes/modules/exchange/custom_events.php ) назначаем обработчик события.

new umiEventListener("exchangeOnAddElement", "exchange", "exchangeOnAddElementBefore_event");

Затем описал обработчик события exchangeOnAddElementBefore_event в файле __custom_adm.php ( classes/modules/exchange/__custom_adm.php )

public function exchangeOnAddElementBefore_event(iUmiEventPoint $eList){
// выполняется после сохранения из выгрузки
if ($eList->getMode() === "after") {
    
    $element = $eList->getRef('element');
    if ($element->getHierarchyType()->getMethod() !== 'object') {
        return;
    }
    
    // element_info это xml из выгрузки
    $info = $eList->getParam('element_info');
    
    $id_1c = $element->getValue('1c_product_id');
    
    
    $sel = new selector('pages');
    $sel->types('hierarchy-type')->name('catalog', 'object');
    $sel->where('1c_product_id')->equals( $id_1c );
    $sel->where('id')->notequals( $element->id );
    $sel->limit(0, 100);
    //$len = $sel->length();
    
    // проверим все страницы есть ли они в бд таблицы: cms3_import_relations
    // ------------- http://wiki.umisoft.ru/Класс_umiImportRelations
    $relations = umiImportRelations::getInstance();
    $source_id = $relations->getSourceId('commerceML2');
    
    
    if( $sel->length() > 0 ){
        
        $hierarchy = umiHierarchy::getInstance();
        $i = 0;
        
        foreach($sel as $p){ $i++;
            if($i == 1){
                
                
                $relations->setIdRelation($source_id, $id_1c, $p->id);
                
                
                // копируем все поля в созданную ранее копию страницы и удаляем текущую стр
                $p->name = $element->name;
                
                $price = (int)$element->getValue('price') ? $element->getValue('price') : false;
                if ($price) $p->setValue( 'price', $price );
                
                
                $old_price = (int)$element->getValue('old_price') ? $element->getValue('old_price') : false;
                if ($old_price) $p->setValue( 'old_price', $old_price );
                
                $content = $element->getValue('content') ? $element->getValue('content') : false;
                if ($content) $p->setValue( 'content', $content );
                
                $artikul = $element->getValue('artikul') ? $element->getValue('artikul') : false;
                if ($artikul) $p->setValue( 'artikul', $element->getValue('artikul') );
                
                $brend = $element->getValue('brend') ? $element->getValue('brend') : false;
                if ($brend) $p->setValue( 'brend', $brend );
                
                $izobrazhenie_1 = $element->getValue('izobrazhenie_1') ? $element->getValue('izobrazhenie_1') : false;
                if ($izobrazhenie_1) $p->setValue( 'izobrazhenie_1', $izobrazhenie_1 );
                
                $izobrazhenie_2 = $element->getValue('izobrazhenie_2') ? $element->getValue('izobrazhenie_2') : false;
                if ($izobrazhenie_2) $p->setValue( 'izobrazhenie_2', $izobrazhenie_2 );
                
                $izobrazhenie_3 = $element->getValue('izobrazhenie_3') ? $element->getValue('izobrazhenie_3') : false;
                if ($izobrazhenie_3) $p->setValue( 'izobrazhenie_3', $izobrazhenie_3 );
                
                $izgotovitel = count($element->getValue('izgotovitel')) ? $element->getValue('izgotovitel') : false;
                if ($izgotovitel) $p->setValue( 'izgotovitel', $izgotovitel );
                
                $common_quantity = $element->getValue('common_quantity') ? $element->getValue('common_quantity') : false;
                if ($common_quantity) $p->setValue( 'common_quantity', $common_quantity );
                
                $photo = $element->getValue('photo') ? $element->getValue('photo') : false;
                if ($photo) $p->setValue( 'photo', $photo );
                
                $_1c_catalog_id = count($element->getValue('1c_catalog_id')) ? $element->getValue('1c_catalog_id') : false;
                if ($_1c_catalog_id) $p->setValue( '1c_catalog_id', $_1c_catalog_id );
                
                $_1c_product_id = count($element->getValue('1c_product_id')) ? $element->getValue('1c_product_id') : false;
                if ($_1c_product_id) $p->setValue( '1c_product_id', $_1c_product_id );
                
                $bar_code = count($element->getValue('bar_code')) ? $element->getValue('bar_code') : false;
                if ($bar_code) $p->setValue( 'bar_code', $bar_code );
                
                $weight = count($element->getValue('weight')) ? $element->getValue('weight') : false;
                if ($weight) $p->setValue( 'weight', $weight );
                
                $p->commit();
                
                // удаление 
                $hierarchy->delElement($element->id);
                $hierarchy->removeDeletedElement($element->id);
            }
        }
    } //foreach
}

[ Saitadmin.ru || с 2006 по текущий год || Санкт-Петербург ]