commit 08-2025
This commit is contained in:
parent
9ae662f63e
commit
480fdc65ed
404 changed files with 65310 additions and 2600431 deletions
|
|
@ -2,96 +2,60 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product as ModelsProduct;
|
||||
use Vitalybaev\GoogleMerchant\Feed;
|
||||
use Vitalybaev\GoogleMerchant\Product;
|
||||
use Vitalybaev\GoogleMerchant\Product\Shipping;
|
||||
use Vitalybaev\GoogleMerchant\Product\Availability\Availability;
|
||||
use Illuminate\Http\Response;
|
||||
use Wearepixel\LaravelGoogleShoppingFeed\LaravelGoogleShoppingFeed;
|
||||
use App\Services\Util;
|
||||
|
||||
|
||||
class GoogleMerchantController extends Controller
|
||||
{
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function __construct()
|
||||
/**
|
||||
* Generate Google Merchant feed
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function feed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function feed(){
|
||||
|
||||
$products = ModelsProduct::where('active', true)->whereJsonContains('show_on', '1')->orderBy('pos', 'DESC')->get();
|
||||
|
||||
// Create feed object
|
||||
$feed = new Feed("mivita shop", "https://mivita.shop", "Bio Aloe Vera & Naturkosmetuk");
|
||||
$feed = LaravelGoogleShoppingFeed::init(
|
||||
'mivita shop',
|
||||
'Bio Aloe Vera & Naturkosmetik',
|
||||
'https://mivita.shop'
|
||||
);
|
||||
|
||||
// Put products to the feed ($products - some data from database for example)
|
||||
// Put products to the feed
|
||||
foreach ($products as $product) {
|
||||
$item = new Product();
|
||||
|
||||
// Set common product properties
|
||||
$item->setId($product->id);
|
||||
$item->setTitle($product->name);
|
||||
$item->setDescription($product->copy);
|
||||
$item->setLink($product->getProductUrl());
|
||||
$item->setImage($product->getImageUrl());
|
||||
$item->setAvailability(Availability::IN_STOCK);
|
||||
|
||||
/*if ($product->isAvailable()) {
|
||||
$item->setAvailability(Availability::IN_STOCK);
|
||||
} else {
|
||||
$item->setAvailability(Availability::OUT_OF_STOCK);
|
||||
}*/
|
||||
$item->setPrice("{$product->price} EUR");
|
||||
//$item->setGoogleCategory($product->category_name);
|
||||
$item->setBrand('MIVITA');
|
||||
$item->setGtin($product->ean);
|
||||
$item->setCondition('new');
|
||||
|
||||
// Some additional properties
|
||||
//$item->setColor($product->color);
|
||||
//$item->setSize($product->size);
|
||||
|
||||
// Shipping info
|
||||
/*
|
||||
$shipping = new Shipping();
|
||||
$shipping->setCountry('US');
|
||||
$shipping->setRegion('CA, NSW, 03');
|
||||
$shipping->setPostalCode('94043');
|
||||
$shipping->setLocationId('21137');
|
||||
$shipping->setService('DHL');
|
||||
$shipping->setPrice('1300 USD');
|
||||
$item->setShipping($shipping);
|
||||
*/
|
||||
|
||||
// Set a custom shipping label and weight (optional)
|
||||
//$item->setShippingLabel('ups-ground');
|
||||
//$item->setShippingWeight('2.14');
|
||||
|
||||
// Set a custom label (optional)
|
||||
$item->setCustomLabel($product->weight, 'product_width');
|
||||
$item->setCustomLabel($product->contents_total, 'product_contents_total');
|
||||
$item->setCustomLabel($product->getUnitType(), 'product_contents_unit',);
|
||||
$item->setCustomLabel($product->contents_str, 'product_contents');
|
||||
$item->setCustomLabel($product->ingredients, 'product_ingredients');
|
||||
|
||||
$item->setCustomLabel($product->getBasePriceFormattedFullWith(false, false, null), 'product_base_pricing_unit');
|
||||
|
||||
|
||||
//$item->setCustomLabel('Some Label 2', 1);
|
||||
|
||||
// Add this product to the feed
|
||||
$feed->addProduct($item);
|
||||
$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)
|
||||
]);
|
||||
}
|
||||
|
||||
// Here we get complete XML of the feed, that we could write to file or send directly
|
||||
$feedXml = $feed->build();
|
||||
print ($feedXml);
|
||||
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
|
||||
|
||||
}
|
||||
// http://api.mivita.test/google/merchant/feed
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue