06 2022
This commit is contained in:
parent
9b0b5feb7e
commit
7a040c3e19
106 changed files with 4074 additions and 1349 deletions
97
app/Http/Controllers/Api/GoogleMerchantController.php
Normal file
97
app/Http/Controllers/Api/GoogleMerchantController.php
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
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 App\Services\Util;
|
||||
|
||||
|
||||
class GoogleMerchantController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
|
||||
// Put products to the feed ($products - some data from database for example)
|
||||
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);
|
||||
}
|
||||
|
||||
// Here we get complete XML of the feed, that we could write to file or send directly
|
||||
$feedXml = $feed->build();
|
||||
print ($feedXml);
|
||||
}
|
||||
|
||||
// http://api.mivita.test/google/merchant/feed
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue