mivita/app/Http/Controllers/Api/GoogleMerchantController.php
2025-08-12 18:01:59 +02:00

61 lines
2 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Product as ModelsProduct;
use Illuminate\Http\Response;
use Wearepixel\LaravelGoogleShoppingFeed\LaravelGoogleShoppingFeed;
use App\Services\Util;
class GoogleMerchantController extends Controller
{
public function __construct() {}
/**
* Generate Google Merchant feed
*
* @return Response
*/
public function feed()
{
$products = ModelsProduct::where('active', true)->whereJsonContains('show_on', '1')->orderBy('pos', 'DESC')->get();
// Create feed object
$feed = LaravelGoogleShoppingFeed::init(
'mivita shop',
'Bio Aloe Vera & Naturkosmetik',
'https://mivita.shop'
);
// Put products to the feed
foreach ($products as $product) {
$feed->addItem([
'id' => $product->id,
'title' => $product->name,
'description' => $product->copy,
'link' => $product->getProductUrl(),
'g:image_link' => $product->getImageUrl(),
'g:availability' => 'in stock',
'g:price' => "{$product->price} EUR",
'g:brand' => 'MIVITA',
'g:gtin' => $product->ean,
'g:condition' => 'new',
'g:custom_label_0' => $product->weight,
'g:custom_label_1' => $product->contents_total,
'g:custom_label_2' => $product->getUnitType(),
'g:custom_label_3' => $product->contents_str,
'g:custom_label_4' => $product->ingredients,
'g:unit_pricing_measure' => $product->getBasePriceFormattedFullWith(false, false, null)
]);
}
return $feed->generate();
// Get the feed XML
//$feedXml = $feed->toString();
//return response($feedXml)->header('Content-Type', 'application/xml');
}
// http://api.mivita.test/google/merchant/feed
}