Missing values treatments in TXT output
-
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 ??
- The topic ‘Missing values treatments in TXT output’ is closed to new replies.