• Hello,

    First of all, thak you for your great plugin!

    I’m using it and using a TXT output for my feed. But I’ve noticed that it has some limitations that XML output doesn’t have. Mostly because the TXT output file is written in multiple batch but the header is computed only the first time.
    So I made changes I’d like to share with you and others, changes that maybe you’ll commit into your code. Here they are:

    Insert at line 2089 in class-get-products.php the following:

    // Read header if we continue file !
    if ($header == "true") {
    	$headerrow = $products[0][0];
    	$aHeader = explode("','", $headerrow);
    	$aHeader = str_replace("g:", "", $aHeader);
    }
    else {
    	$fp = fopen($file, 'r');
    	$sHeadline = fgets($fp);
    	$sHeadline = str_replace(array(
    		"\r",
    		"\n"
    	) , '', $sHeadline);
    	$aHeader = preg_split("/\t/", $sHeadline);
    	fclose($fp);
    }

    Once the header is retrieved we can add services limitations (number of values by attribute ofr different attributes…) as done for XML feed, right between line 2171 and line 2172:

    foreach ($pieces as $t_key => $t_value) {
    	if ($aHeader[$t_key] == "color" || $aHeader[$t_key] == "size" || $aHeader[$t_key] == "material") {
    		if (!empty($t_value)) {
    			$attr_split = explode(",", $t_value);
    			$nr_attr = count($attr_split) - 1;
    			$iMaxAttr = 2; // Bing and Google allow only 3 attributes (so indexes from 0 to 2)
    			$nr_attr = min($nr_attr, $iMaxAttr);
    			$attr_value = "";
    
    			for ($x = 0;$x <= $nr_attr;$x++) {
    				$attr_value .= trim($attr_split[$x]) . "/";
    			}
    			$attr_value = rtrim($attr_value, "/");
    			$pieces[$t_key] = $attr_value;
    		}
    	}
    	elseif ($aHeader[$t_key] == "shipping") {
    	    // Remove useless leading space in price...
    	    if (!empty($t_value)) {
    		$attr_value = preg_replace('/:\s/', ':', $t_value);
    		$pieces[$t_key] = $attr_value;
    	    }
    	}
    }

    Of course, this is just a suggestion and my code may need your changes to meet your best practices…

    At least, it may help others having the same issues I had ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    Thanks for using our plugin, reaching out to us and sharing code with us. At first glance however its not entirely clear to us what your code is exactly doing. Can you explain what it does and how it changes the output for TXT/CSV files?

    Thread Starter madmax4ever

    (@madmax4ever)

    Hello,

    In the second code snippet:

    Well, I inspired myself from what you’ve written for XML format between line 1328 and line 1341 in order to limit the number of different values sent in the feed for attributes color, size and material. As you can read in google specs (here for colors), google manages up to 3 colors, no more. More than that an you get an error… The same applies to size and material.

    This “max number of attributes” limit, is a limit you could also add in XML treatment I think.

    I also remove a leading shipping that seemed to bother Google.

    In the first code snippet, in order to be able to do such treatment from the second batch, as output is TXT, I read the already written file to parse its header and load it. This way, I can know, during other batch runs, which value is for which information.

    Hope it’s clearer. Let me know otherwise.

    Thread Starter madmax4ever

    (@madmax4ever)

    Correction:
    => I also remove a leading space in shipping that seemed to bother Google.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Missing values treatments in TXT output’ is closed to new replies.