PHP code example of mannu24 / gmc-integration

1. Go to this page and download the library: Download mannu24/gmc-integration 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 / gmc-integration example snippets


use Manu\GMCIntegration\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'
        ];
    }
}

$product->syncwithgmc();
$product->syncToGMC();
$product->forceSyncToGMC();

$gmcService = app(GMCService::class);
$result = $gmcService->syncMultipleProducts($products, 25);

$status = $product->getGMCSyncStatus();
if ($product->isSyncedWithGMC()) {
    echo "Product is synced with GMC";
}

$gmcService = app(GMCService::class);
$gmcService->setBatchSize(25);
$result = $gmcService->syncMultipleProducts($products);

try {
    $product->syncwithgmc();
} catch (\Exception $e) {
    Log::error('GMC Sync failed: ' . $e->getMessage());
}

use Manu\GMCIntegration\Models\GMCSyncLog;

$logs = GMCSyncLog::with('gmcProduct')->latest()->get();
$failedLogs = GMCSyncLog::where('status', 'failed')->get();
$avgResponseTime = GMCSyncLog::where('status', 'success')->avg('response_time_ms');
bash
php artisan vendor:publish --tag=gmc-config
bash
php artisan vendor:publish --tag=gmc-migrations
bash
php artisan migrate