Compare commits

..
6 Commits
Author SHA1 Message Date
Joel Male 8f0ae03c4b v5.0.0 2026-01-05 10:56:11 +10:00
Joel Male 428c310525 feat: laravel 12 support 2026-01-05 10:35:36 +10:00
Joel Male f9dcce39b9 chore: support Laravel 10 & 11 2024-01-08 09:26:53 +10:00
Joel Male a7e22e8fce update price to g:price as per google changes 2023-01-06 09:28:12 +10:00
Joel Male 5a1c822810 bump version 2023-01-03 14:50:47 +10:00
Joel Male fb85d49e88 update google image field as per latest google update 2023-01-03 14:45:20 +10:00
5 changed files with 805 additions and 251 deletions
-29
View File
@@ -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);
+2 -2
View File
@@ -25,8 +25,8 @@ ## Example
'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,
'g:image_link' => 'https://mystore.com/images/blue-nikes-001.jpg',
'g:price' => 29.99,
]);
return $feed->generate();
+8 -4
View File
@@ -6,7 +6,7 @@
"laravel",
"google-shopping-feed"
],
"version": "1.1.1",
"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
View File
File diff suppressed because it is too large Load Diff
+18 -14
View File
@@ -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',
'price',
'image_link'
'g:price',
'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");
}
}
@@ -53,7 +57,7 @@ public function addItem(array $item): bool
public function generate()
{
$this->xml = [
'rss' => [
'rss' => [
'_attributes' => [
'xmlns:g' => 'http://base.google.com/ns/1.0',
'version' => '2.0',
@@ -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']);
}
}