+7 495 008 8452 пн.-пт. 10:00 – 17:00
Загрузка...

Не нашли ответы на свои вопросы в наших публикациях? Задайте вопрос в службу техподдержки!


В версии модуля 1.51.5 добавлены события OnBeforeImportProfileRun - вызывается перед запуском профиля импорта, OnBeforeImportProfileRunStep - вызывается перед запуском каждого шага многошагового импорта

Рассмотрим их на примере. 

Мы столкнулись с тем, что при обновлении остатков от поставщиков - по некоторым товарам, снятым с производства, отсутствовали остатки, и такие товары не снимались с продажи в магазине. Рассмотрим решение этого вопроса через API модуля.


// init.php use Bitrix\Main\Loader; use Bitrix\Main\EventManager; use Bitrix\Catalog\ProductTable; use Bitrix\Catalog\StoreProductTable; $eventManager = EventManager::getInstance(); $eventManager->addEventHandler('acrit.import', 'OnBeforeImportProfileRun', /** * @param \Acrit\Import\Import $profile */ static function (\Acrit\Import\Import $profile) { $profileId = $profile->getArProfile()['ID']; // set quantity for all products to 0 because import file may contain no old goods if ($profileId == 6) { $iblockId = $profile->getArProfile()['IBLOCK_ID']; Loader::includeModule('iblock'); Loader::includeModule('catalog'); // drop quantity on product store ID = 2 $rsStoreProduct = StoreProductTable::getList([ 'filter' => ['>AMOUNT' => 0, '=STORE_ID' => 2], 'select' => ['ID', 'STORE_ID', 'PRODUCT_ID', 'AMOUNT', 'QUANTITY_RESERVED'] ]); while ($arStoreProduct = $rsStoreProduct->fetch()) { StoreProductTable::update($arStoreProduct['ID'], [ 'AMOUNT' => 0, 'QUANTITY_RESERVED' => 0 ]); } // drop main quantity field $arProductFields = [ 'QUANTITY' => 0 ]; $arProductFields['AVAILABLE'] = ProductTable::calculateAvailable($arProductFields); $rs = CIBlockElement::GetList(['ID' => 'ASC'], [ 'IBLOCK_ID' => (int)$iblockId, '>QUANTITY' => 0 ], false, false, ['ID']); $cnt = 0; while ($arProduct = $rs->Fetch()) { $rsUpd = ProductTable::update($arProduct['ID'], $arProductFields); if (! $rsUpd->isSuccess()) { echo implode(PHP_EOL, $rsUpd->getErrors()); } $cnt++; } // \Bitrix\Main\Diag\Debug::dump($cnt); } } ); // params example run before each import step $eventManager->addEventHandler('acrit.import', 'OnBeforeImportProfileRunStep', /** * @param \Acrit\Import\Import $profile * @param int $type internal type of run * @param int $limit step count limit * @param int $next_item start item in this limit step */ static function (\Acrit\Import\Import $profile, $type, $limit, $next_item) { } );


Назад в раздел



Часто задаваемые вопросы по модулям экспорта

Видео плейлист по настройке модулей экспорта