PHP code example of mannu24 / google-merchant-center
1. Go to this page and download the library: Download mannu24/google-merchant-center 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/ */
mannu24 / google-merchant-center example snippets
use Mannu24\GoogleMerchantCenter\Traits\SyncsWithGMC;
class Product extends Model
{
use SyncsWithGMC;
protected $fillable = [
'title', 'description', 'price', 'quantity',
'image_url', 'brand', 'sku', 'status'
];
public function prepareGMCData(): array
{
return [
'offerId' => $this->sku ?: (string) $this->id,
'title' => $this->title,
'description' => $this->description,
'link' => url("/products/{$this->id}"),
'imageLink' => $this->image_url,
'price' => ['value' => (string) $this->price, 'currency' => 'USD'],
'availability' => $this->quantity > 0 ? 'in stock' : 'out of stock',
'brand' => $this->brand,
'condition' => 'new'
];
}
}
// Manual sync
$product->syncToGMC();
// Force sync (ignores cache)
$product->forceSyncToGMC();
// Check sync status
if ($product->isSyncedWithGMC()) {
echo "Product is synced!";
}
use Mannu24\GoogleMerchantCenter\Services\GMCService;
$gmcService = app(GMCService::class);
$result = $gmcService->syncMultipleProducts($products, 25);
$gmcService = app(GMCService::class);
$gmcService->setBatchSize(25);
$result = $gmcService->syncMultipleProducts($products);
try {
$product->syncToGMC();
} catch (\Exception $e) {
Log::error('GMC Sync failed: ' . $e->getMessage());
}
use Mannu24\GoogleMerchantCenter\Models\GMCSyncLog;
$logs = GMCSyncLog::with('gmcProduct')->latest()->get();
$failedLogs = GMCSyncLog::where('status', 'failed')->get();
bash
php artisan vendor:publish --tag=gmc-config
bash
php artisan vendor:publish --tag=gmc-migrations
bash
php artisan migrate