init commit 🚀

This commit is contained in:
Joel Male
2022-06-06 20:18:34 +10:00
commit cdf55fa8bf
7 changed files with 1188 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
vendor/
+29
View File
@@ -0,0 +1,29 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('bootstrap/cache')
->exclude('storage')
->exclude('vendor')
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
$rules = [
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['operators' => ['=>' => null]],
'linebreak_after_opening_tag' => true,
'ordered_imports' => ['sort_algorithm' => 'length'],
'phpdoc_order' => true,
'phpdoc_no_empty_return' => false,
'yoda_style' => false,
'no_unused_imports' => true,
];
$config = new PhpCsFixer\Config();
return $config->setRules($rules)
->setFinder($finder)
->setUsingCache(false);
+9
View File
@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) Pixel hello@wearepixel.com.au
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+33
View File
@@ -0,0 +1,33 @@
Laravel Google Shopping Feed
==============
A simple package to easily create an XML feed for Google Merchant Center to parse and retrieve your products on a frequent basis.
We recommend adding this to an API controller and generating it on the fly each time so you can be sure your products are always up to date within your merchant center.
## Installation
```
composer require wearepixel/laravel-google-shopping-feed
```
## Example
```php
use Wearepixel\LaravelGoogleShoppingFeed\LaravelGoogleShoppingFeed;
$feed = LaravelGoogleShopping::init(
'Product Feed',
'App product Feed',
'https://mystore.com'
);
$feed->addItem([
'id' => 'item_001',
'title' => 'Blue Nikes',
'link' => 'https://mystore.com/products/blue-nikes',
'image_link' => 'https://mystore.com/images/blue-nikes-001.jpg',
'price' => 29.99,
]);
return $feed->generate();
```
+26
View File
@@ -0,0 +1,26 @@
{
"name": "wearepixel/laravel-google-shopping-feed",
"type": "library",
"description": "Laravel Google Shopping Feed",
"keywords": [
"laravel",
"google-shopping-feed"
],
"version": "1.0.0",
"homepage": "https://github.com/wearepixel/laravel-google-shopping-feed",
"license": "MIT",
"authors": [
{
"name": "Pixel",
"email": "hello@wearepixel.com.au"
}
],
"autoload": {
"psr-4": { "Wearepixel\\LaravelGoogleShoppingFeed\\" : "src/" }
},
"require": {
"spatie/array-to-xml": "2.8.*|3.*.*",
"illuminate/support": "8.*|9.*"
},
"prefer-stable": true
}
Generated
+1002
View File
File diff suppressed because it is too large Load Diff
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace Wearepixel\LaravelGoogleShoppingFeed;
use Spatie\ArrayToXml\ArrayToXml;
class LaravelGoogleShoppingFeed
{
public $title;
public $description;
public $link;
protected $xml = [];
protected $products = [];
protected $currency = "AUD";
protected $requiredProductFields = [
'id',
'link',
'title',
'price',
'image_link'
];
public static function init($title = null, $description = null, $link = null)
{
$feed = new self();
$feed->title = $title;
$feed->description = $description;
$feed->link = $link;
return $feed;
}
public function addItem(array $item): bool
{
foreach ($this->requiredProductFields as $field) {
if (!isset($item[$field])) {
throw new \Exception("Required field '{$field}' is missing");
}
}
$product = [
'id' => $item['id'],
'link' => $item['link'],
'title' => $item['title'],
'price' => $item['price'],
'image_link' => $item['image_link'],
];
$this->products[] = $product;
return true;
}
public function generate()
{
$this->xml = [
'rss' => [
'_attributes' => [
'xmlns:g' => 'http://base.google.com/ns/1.0',
'version' => '2.0',
],
'channel' => [
'title' => $this->title,
'description' => $this->description,
'link' => $this->link,
]
]
];
foreach ($this->products as $key => $product) {
$this->xml['rss']['channel']['item_'.$key] = $product;
}
$xml = ArrayToXml::convert($this->xml, '');
$xml = str_replace([' ', '<root>', '</root>', "\n", "\r", '<remove>remove</remove>'], '', $xml);
$xml = preg_replace([
"/item_[0-9][0-9][0-9][0-9]/",
"/item_[0-9][0-9][0-9]/",
"/item_[0-9][0-9]/",
"/item_[0-9]/",
], "item", $xml);
return response($xml)->header('Content-Type', 'text/xml');
}
}