php-google-merchant-feed icon indicating copy to clipboard operation
php-google-merchant-feed copied to clipboard

error Cdata::__construct()

Open jagaib opened this issue 4 years ago • 2 comments

I am getting this error if I have made any changes to my code, can you help me? Screenshot_2020-11-10 🧨 Argument 1 passed to Sabre Xml Element Cdata __construct() must be of the type string, null given,

jagaib avatar Nov 11 '20 00:11 jagaib

$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');
}

jagaib avatar Nov 11 '20 04:11 jagaib

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');

ahmed-el-khoribi avatar Dec 14 '20 10:12 ahmed-el-khoribi