php-google-merchant-feed
php-google-merchant-feed copied to clipboard
error Cdata::__construct()
I am getting this error if I have made any changes to my code, can you help me?
$item->setId($product->id);
$item->setTitle($product->nombre);
$item->setDescription($product->modelo->descripcion);
$item->setLink($url);
$item->setImage($imglink);
$item->setPrice("{$product->precio} ARS");
$item->setGoogleCategory('1604');
$item->setBrand($product->marca->nombre);
$item->setGtin(false);
$item->setCondition('new');
$item->setAvailability('in stock');
// $item->setShipping('');
// Some additional properties
$item->setSize($product->medida->nombre);
// Add this product to the feed
$feed->addProduct($item);
}
// Here we get complete XML of the feed, that we could write to file or send directly $feedXml = $feed->build();
Storage::disk('publicxml')->put('product.xml', $feedXml,'public');
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="product.xml"');
echo $feedXml;
// return Response::make($feedXml, 200)->header('Content-Type', 'application/xml');
}
I had the same issue its due there is a field in your query which returns null,
So the solution I made is
$item->setTitle(!is_null($product->title) ? $product->title : 'not provided');
$item->setDescription(!is_null($product->description) ? $product->description : 'not provided');
$item->setImage(!is_null($product->image_link) ? $product->image_link : 'not provided');