mirror of
https://github.com/wearepixel/laravel-facebook-feed.git
synced 2026-11-14 13:51:42 +00:00
init commit 🚀
This commit is contained in:
@@ -0,0 +1 @@
|
||||
vendor/
|
||||
@@ -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);
|
||||
@@ -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.
|
||||
@@ -0,0 +1,33 @@
|
||||
Laravel Facebook Feed
|
||||
==============
|
||||
|
||||
A simple package to easily create an XML feed for Facebooks Shipping API 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-facebook-feed
|
||||
```
|
||||
|
||||
## Example
|
||||
```php
|
||||
use Wearepixel\LaravelFacebookFeed\LaravelFacebookFeed;
|
||||
|
||||
$feed = LaravelFacebookFeed::init(
|
||||
'Product Feed',
|
||||
'App product Feed',
|
||||
'https://mystore.com'
|
||||
);
|
||||
|
||||
$feed->addItem([
|
||||
'id' => 'item_001',
|
||||
'title' => 'Blue Nikes',
|
||||
'link' => 'https://mystore.com/products/blue-nikes',
|
||||
'price' => 29.99,
|
||||
'image_link' => 'https://mystore.com/images/blue-nikes-001.jpg',
|
||||
]);
|
||||
|
||||
return $feed->generate();
|
||||
```
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "wearepixel/laravel-facebook-feed",
|
||||
"type": "library",
|
||||
"description": "Laravel Facebook Feed",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"laravel-facebook-feed"
|
||||
],
|
||||
"version": "3.0.0",
|
||||
"homepage": "https://github.com/wearepixel/laravel-facebook-feed",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Pixel",
|
||||
"email": "hello@wearepixel.com.au"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": { "Wearepixel\\LaravelFacebookFeed\\" : "src/" }
|
||||
},
|
||||
"require": {
|
||||
"spatie/array-to-xml": "2.8.*|3.*.*",
|
||||
"illuminate/support": "8.*|9.*"
|
||||
},
|
||||
"prefer-stable": true
|
||||
}
|
||||
Generated
+1055
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Wearepixel\LaravelFacebookFeed;
|
||||
|
||||
use Spatie\ArrayToXml\ArrayToXml;
|
||||
|
||||
class LaravelFacebookFeed
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($item as $key => $value) {
|
||||
$product[$key] = $value;
|
||||
}
|
||||
|
||||
$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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user