PHP code example of vitalybaev / google-merchant-feed
1. Go to this page and download the library: Download vitalybaev/google-merchant-feed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vitalybaev / google-merchant-feed example snippets
use Vitalybaev\GoogleMerchant\Feed;
use Vitalybaev\GoogleMerchant\Product;
use Vitalybaev\GoogleMerchant\Product\Shipping;
use Vitalybaev\GoogleMerchant\Product\Availability\Availability;
// Create feed object
$feed = new Feed("My awesome store", "https://example.com", "My awesome description");
// 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->title);
$item->setDescription($product->description);
$item->setLink($product->getUrl());
$item->setImage($product->getImage());
if ($product->isAvailable()) {
$item->setAvailability(Availability::IN_STOCK);
} else {
$item->setAvailability(Availability::OUT_OF_STOCK);
}
$item->setPrice("{$product->price} USD");
$item->setGoogleCategory($product->category_name);
$item->setBrand($product->brand->name);
$item->setGtin($product->barcode);
$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('UPS Express');
$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('Some Label 1', 0);
$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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.