This shows you the differences between two versions of the page.
urapidflow:v3:disable_missing_products [2017/05/19 19:08] |
urapidflow:v3:disable_missing_products [2017/05/19 19:08] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Disable existing products that missing in the new products feed ====== | ||
+ | <file php urapidflow.php> | ||
+ | <?php | ||
+ | // initialize Magento environment | ||
+ | use Magento\Framework\ObjectManagerInterface; | ||
+ | |||
+ | try { | ||
+ | // if you move this file, adjust bootstrap.php path | ||
+ | require __DIR__ . ' | ||
+ | } catch (\Exception $e) { | ||
+ | echo <<< | ||
+ | {$e-> | ||
+ | </ | ||
+ | HTML; | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | $params = $_SERVER; | ||
+ | $params[\Magento\Store\Model\StoreManager:: | ||
+ | $params[\Magento\Store\Model\Store:: | ||
+ | $bootstrap = \Magento\Framework\App\Bootstrap:: | ||
+ | |||
+ | /** @var \Magento\Framework\App\Http $app */ | ||
+ | $app = $bootstrap-> | ||
+ | |||
+ | // configure environment | ||
+ | $om = $bootstrap-> | ||
+ | $areaList = $om-> | ||
+ | $areaCode = $areaList-> | ||
+ | /** @var \Magento\Framework\App\State $state */ | ||
+ | $state = $om-> | ||
+ | $state-> | ||
+ | /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ | ||
+ | $configLoader = $om-> | ||
+ | $om-> | ||
+ | // end initialize Magento environment | ||
+ | |||
+ | // the export file contains SKUs and Status columns | ||
+ | // in file var/ | ||
+ | |||
+ | /** @var \Unirgy\RapidFlow\Helper\Data $helper */ | ||
+ | $helper = $om-> | ||
+ | $helper-> | ||
+ | |||
+ | // collect new skus from the feed | ||
+ | $newSkus = array(); | ||
+ | |||
+ | // the new products feed | ||
+ | $fs = fopen(' | ||
+ | $columns = fgetcsv($fs); | ||
+ | while (($r = fgetcsv($fs))) { | ||
+ | $row = array_combine($columns, | ||
+ | $newSkus[$row[' | ||
+ | } | ||
+ | fclose($fs); | ||
+ | |||
+ | // the existing products export | ||
+ | $fs = fopen(' | ||
+ | $columns = fgetcsv($fs); | ||
+ | |||
+ | // new file to update products statuses | ||
+ | $fd = fopen(' | ||
+ | fputcsv($fd, | ||
+ | |||
+ | while (($r = fgetcsv($fs))) { | ||
+ | $row = array_combine($columns, | ||
+ | |||
+ | // if you're using not English as a store language, change the status text | ||
+ | if (empty($newSkus[$row[' | ||
+ | fputcsv($fd, | ||
+ | // you can also delete missing products (uRapidFlow Pro) | ||
+ | // will require profile "Data Type" = " | ||
+ | // fputcsv($fd, | ||
+ | } | ||
+ | } | ||
+ | fclose($fs); | ||
+ | fclose($fd); | ||
+ | |||
+ | // add and update feed products, uses file var/ | ||
+ | $helper-> | ||
+ | |||
+ | // update missing products status, uses file var/ | ||
+ | $helper-> | ||
+ | |||
+ | </ |