Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error Cdata::__construct() #12

Open
jagaib opened this issue Nov 11, 2020 · 2 comments
Open

error Cdata::__construct() #12

jagaib opened this issue Nov 11, 2020 · 2 comments

Comments

@jagaib
Copy link

jagaib commented Nov 11, 2020

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
Copy link
Author

jagaib commented Nov 11, 2020

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

@ahmed-el-khoribi
Copy link

ahmed-el-khoribi commented Dec 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants