Generate Facebook Product Catalog Feed (XML)

Facebook Doc: https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/product-catalog#feed-format

CodeIgniter XML Helper:

Sample Code:

	function catalog(){
		$site = $this->options_m->get_site_settings(2);

		$dom = xml_dom();
		$rss = xml_add_child($dom, 'rss');
		xml_add_attribute($rss, 'xmlns:g', 'http://base.google.com/ns/1.0');
		xml_add_attribute($rss, 'version', '2.0');

		$channel = xml_add_child($rss, 'channel');
		xml_add_child($channel, 'title', $site->title);
		xml_add_child($channel, 'link', 'https://xxx.com');
		xml_add_child($channel, 'description', $site->site_desc);

		$prods = $this->products_m->get_products(2);
		//logg($prods);
		foreach ($prods as $key => $prod) {
			$item = xml_add_child($channel, 'item');
			xml_add_child($item, 'g:id', $prod->id);
			xml_add_child($item, 'g:title', $prod->title);
			xml_add_child($item, 'g:description', $prod->summary);
			xml_add_child($item, 'g:link', base_url() . 'shop/product/' . $prod->id);
			xml_add_child($item, 'g:image_link', $prod->photo);
			xml_add_child($item, 'g:brand', 'XXX');
			xml_add_child($item, 'g:condition', 'new');
			xml_add_child($item, 'g:availability', 'in stock');
			xml_add_child($item, 'g:price', $prod->price . ' TWD');
			//https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt
			xml_add_child($item, 'g:google_product_category', 'Health & Beauty > Personal Care > Hair Care > Shampoo & Conditioner');
			//xml_add_child($item, 'g:custom_label_0', $prod->);
		}

		xml_print($dom);
	}