mirror of
https://github.com/wearepixel/laravel-google-shopping-feed.git
synced 2026-11-14 13:21:46 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f0ae03c4b | ||
|
|
428c310525 |
@@ -1,29 +0,0 @@
|
|||||||
<?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);
|
|
||||||
+8
-4
@@ -6,7 +6,7 @@
|
|||||||
"laravel",
|
"laravel",
|
||||||
"google-shopping-feed"
|
"google-shopping-feed"
|
||||||
],
|
],
|
||||||
"version": "4.0.0",
|
"version": "5.0.0",
|
||||||
"homepage": "https://github.com/wearepixel/laravel-google-shopping-feed",
|
"homepage": "https://github.com/wearepixel/laravel-google-shopping-feed",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -19,8 +19,12 @@
|
|||||||
"psr-4": { "Wearepixel\\LaravelGoogleShoppingFeed\\" : "src/" }
|
"psr-4": { "Wearepixel\\LaravelGoogleShoppingFeed\\" : "src/" }
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"spatie/array-to-xml": "2.8.*|3.*.*",
|
"php": ">=8.3",
|
||||||
"illuminate/support": "8.*|9.*|10.*|11.*"
|
"spatie/array-to-xml": "2.8.*|3.*",
|
||||||
|
"illuminate/support": "10.*|11.*|12.*"
|
||||||
},
|
},
|
||||||
"prefer-stable": true
|
"prefer-stable": true,
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/pint": "^1.26"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+777
-202
File diff suppressed because it is too large
Load Diff
@@ -7,24 +7,28 @@
|
|||||||
class LaravelGoogleShoppingFeed
|
class LaravelGoogleShoppingFeed
|
||||||
{
|
{
|
||||||
public $title;
|
public $title;
|
||||||
|
|
||||||
public $description;
|
public $description;
|
||||||
|
|
||||||
public $link;
|
public $link;
|
||||||
|
|
||||||
protected $xml = [];
|
protected $xml = [];
|
||||||
|
|
||||||
protected $products = [];
|
protected $products = [];
|
||||||
protected $currency = "AUD";
|
|
||||||
|
protected $currency = 'AUD';
|
||||||
|
|
||||||
protected $requiredProductFields = [
|
protected $requiredProductFields = [
|
||||||
'id',
|
'id',
|
||||||
'link',
|
'link',
|
||||||
'title',
|
'title',
|
||||||
'g:price',
|
'g:price',
|
||||||
'g:image_link'
|
'g:image_link',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function init($title = null, $description = null, $link = null)
|
public static function init($title = null, $description = null, $link = null)
|
||||||
{
|
{
|
||||||
$feed = new self();
|
$feed = new self;
|
||||||
|
|
||||||
$feed->title = $title;
|
$feed->title = $title;
|
||||||
$feed->description = $description;
|
$feed->description = $description;
|
||||||
@@ -36,7 +40,7 @@ public static function init($title = null, $description = null, $link = null)
|
|||||||
public function addItem(array $item): bool
|
public function addItem(array $item): bool
|
||||||
{
|
{
|
||||||
foreach ($this->requiredProductFields as $field) {
|
foreach ($this->requiredProductFields as $field) {
|
||||||
if (!isset($item[$field])) {
|
if (! isset($item[$field])) {
|
||||||
throw new \Exception("Required field '{$field}' is missing");
|
throw new \Exception("Required field '{$field}' is missing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +66,8 @@ public function generate()
|
|||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
'link' => $this->link,
|
'link' => $this->link,
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($this->products as $key => $product) {
|
foreach ($this->products as $key => $product) {
|
||||||
@@ -73,12 +77,12 @@ public function generate()
|
|||||||
$xml = ArrayToXml::convert($this->xml, '');
|
$xml = ArrayToXml::convert($this->xml, '');
|
||||||
$xml = str_replace([' ', '<root>', '</root>', "\n", "\r", '<remove>remove</remove>'], '', $xml);
|
$xml = str_replace([' ', '<root>', '</root>', "\n", "\r", '<remove>remove</remove>'], '', $xml);
|
||||||
$xml = preg_replace([
|
$xml = preg_replace([
|
||||||
"/item_[0-9][0-9][0-9][0-9]/",
|
'/item_[0-9][0-9][0-9][0-9]/',
|
||||||
"/item_[0-9][0-9][0-9]/",
|
'/item_[0-9][0-9][0-9]/',
|
||||||
"/item_[0-9][0-9]/",
|
'/item_[0-9][0-9]/',
|
||||||
"/item_[0-9]/",
|
'/item_[0-9]/',
|
||||||
], "item", $xml);
|
], 'item', $xml);
|
||||||
|
|
||||||
return response($xml)->header('Content-Type', 'text/xml');
|
return response($xml, 200, ['Content-Type' => 'text/xml']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user