====== Disable existing products that missing in the new products feed ====== getMessage()} HTML; exit(1); } $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'admin'; // change this to appropriate store if needed. $params[\Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM] = true; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); // bootstrap /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication('Magento\Framework\App\Http'); // configure environment $om = $bootstrap->getObjectManager(); $areaList = $om->get('Magento\Framework\App\AreaList'); $areaCode = $areaList->getCodeByFrontName('admin'); /** @var \Magento\Framework\App\State $state */ $state = $om->get('Magento\Framework\App\State'); $state->setAreaCode($areaCode); /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ $configLoader = $om->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); $om->configure($configLoader->load($areaCode)); // end initialize Magento environment // the export file contains SKUs and Status columns // in file var/urapidflow/export/existing_products.csv /** @var \Unirgy\RapidFlow\Helper\Data $helper */ $helper = $om->get('\Unirgy\RapidFlow\Helper\Data'); $helper->run("Export Existing Products"); // collect new skus from the feed $newSkus = array(); // the new products feed $fs = fopen('var/urapidflow/import/new_feed.csv', 'r'); $columns = fgetcsv($fs); // read column titles while (($r = fgetcsv($fs))) { $row = array_combine($columns, $r); $newSkus[$row['sku']] = 1; } fclose($fs); // the existing products export $fs = fopen('var/urapidflow/export/existing_products.csv', 'r'); $columns = fgetcsv($fs); // read column titles // new file to update products statuses $fd = fopen('var/urapidflow/import/update_status.csv', 'w'); fputcsv($fd, array('sku', 'status')); while (($r = fgetcsv($fs))) { $row = array_combine($columns, $r); // if you're using not English as a store language, change the status text if (empty($newSkus[$row['sku']]) && $row['status']!='Disabled') { fputcsv($fd, array($row['sku'], 0)); // you can also delete missing products (uRapidFlow Pro) // will require profile "Data Type" = "Product Extra" // fputcsv($fd, array('-CP', $r['sku'])); } } fclose($fs); fclose($fd); // add and update feed products, uses file var/urapidflow/import/new_feed.csv $helper->run("Import Products"); // update missing products status, uses file var/urapidflow/import/update_status.csv $helper->run("Update Product Status");