diff --git a/README.md b/README.md index 4e48b4f..9b87bda 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,41 @@ -# laravel-google-shopping -Laravel Google Shopping package +Laravel Google Shopping +============== + +[![Latest Stable Version](https://poser.pugx.org/deniztezcan/laravel-google-shopping/v/stable)](https://packagist.org/packages/deniztezcan/laravel-google-shopping) +[![Total Downloads](https://poser.pugx.org/deniztezcan/laravel-google-shopping/downloads)](https://packagist.org/packages/deniztezcan/laravel-google-shopping) +[![Latest Unstable Version](https://poser.pugx.org/deniztezcan/laravel-google-shopping/v/unstable)](https://packagist.org/packages/deniztezcan/laravel-google-shopping) +[![License](https://poser.pugx.org/deniztezcan/laravel-google-shopping/license)](https://packagist.org/packages/deniztezcan/laravel-google-shopping) + +## Installation + +``` +composer require deniztezcan/laravel-google-shopping +``` + +## Example +```php +use DenizTezcan\LaravelGoogleShopping\LaravelGoogleShopping; + +LaravelGoogleShopping::setTitle('Example feed'); +LaravelGoogleShopping::setDescription('Example feed of the Example shop'); +LaravelGoogleShopping::setLink('https://example.shop'); + +LaravelGoogleShopping::addItem( + "https://example.shop/p/foo-bar", + "SKU123", + "Foo bar", + "https://example.shop/images/foo-bar.png", + "Foo bar best product", + 'new', + 99.99, + 'Foo brand', + '6387712293758', + [ + 'country' => 'NL', + 'service' => 'PostNL - Gratis', + 'price' => 0 + ] +); + +return LaravelGoogleShopping::display(); +``` \ No newline at end of file diff --git a/src/Feed.php b/src/Feed.php index 637d9ee..aa60fa4 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -82,7 +82,7 @@ public function addItem( public function generate() { - $this->xml[] = [ + $this->xml = [ 'rss' => [ '_attributes' => [ 'xmlns:g' => 'http://base.google.com/ns/1.0', @@ -100,6 +100,7 @@ public function generate() foreach ($this->products as $product) { $this->xml['rss']['channel']['item_'.$i] = $product; + $i++; } $xml = ArrayToXml::convert($this->xml, ''); @@ -116,9 +117,7 @@ public function generate() public function display() { - header("Content-type: text/xml"); - print $this->generate(); - exit; + return response($this->generate())->header('Content-Type', 'text/xml'); } } \ No newline at end of file