mirror of
https://github.com/wearepixel/laravel-google-shopping-feed.git
synced 2026-11-14 21:31:46 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f0ae03c4b | ||
|
|
428c310525 | ||
|
|
f9dcce39b9 |
@@ -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",
|
||||
"google-shopping-feed"
|
||||
],
|
||||
"version": "3.0.0",
|
||||
"version": "5.0.0",
|
||||
"homepage": "https://github.com/wearepixel/laravel-google-shopping-feed",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
@@ -19,8 +19,12 @@
|
||||
"psr-4": { "Wearepixel\\LaravelGoogleShoppingFeed\\" : "src/" }
|
||||
},
|
||||
"require": {
|
||||
"spatie/array-to-xml": "2.8.*|3.*.*",
|
||||
"illuminate/support": "8.*|9.*"
|
||||
"php": ">=8.3",
|
||||
"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
|
||||
{
|
||||
public $title;
|
||||
|
||||
public $description;
|
||||
|
||||
public $link;
|
||||
|
||||
protected $xml = [];
|
||||
|
||||
protected $products = [];
|
||||
protected $currency = "AUD";
|
||||
|
||||
protected $currency = 'AUD';
|
||||
|
||||
protected $requiredProductFields = [
|
||||
'id',
|
||||
'link',
|
||||
'title',
|
||||
'g:price',
|
||||
'g:image_link'
|
||||
'g:image_link',
|
||||
];
|
||||
|
||||
public static function init($title = null, $description = null, $link = null)
|
||||
{
|
||||
$feed = new self();
|
||||
$feed = new self;
|
||||
|
||||
$feed->title = $title;
|
||||
$feed->description = $description;
|
||||
@@ -36,7 +40,7 @@ public static function init($title = null, $description = null, $link = null)
|
||||
public function addItem(array $item): bool
|
||||
{
|
||||
foreach ($this->requiredProductFields as $field) {
|
||||
if (!isset($item[$field])) {
|
||||
if (! isset($item[$field])) {
|
||||
throw new \Exception("Required field '{$field}' is missing");
|
||||
}
|
||||
}
|
||||
@@ -62,8 +66,8 @@ public function generate()
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'link' => $this->link,
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($this->products as $key => $product) {
|
||||
@@ -73,12 +77,12 @@ public function generate()
|
||||
$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);
|
||||
'/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');
|
||||
return response($xml, 200, ['Content-Type' => 'text/xml']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user