User Tools

Site Tools


urapidflow:disable_missing_products

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
urapidflow:disable_missing_products [2010/09/09 18:12]
unirgy
urapidflow:disable_missing_products [2011/07/06 19:11] (current)
unirgy
Line 1: Line 1:
 +====== Disable existing products that missing in the new products feed ======
  
 +<file php urapidflow.php>​
 +<?php
 +
 +// initialize Magento environment
 +require_once "​app/​Mage.php";​
 +Mage::​app('​admin'​)->​setCurrentStore(0);​
 +
 +// the export file contains SKUs and Status columns
 +// in file var/​urapidflow/​export/​existing_products.csv
 +Mage::​helper('​urapidflow'​)->​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
 +Mage::​helper('​urapidflow'​)->​run("​Import Products"​);​
 +
 +// update missing products status, uses file var/​urapidflow/​import/​update_status.csv
 +Mage::​helper('​urapidflow'​)->​run("​Update Product Status"​);​
 +
 +</​file>​
urapidflow/disable_missing_products.txt · Last modified: 2011/07/06 19:11 by unirgy