Skip to content

Commit

Permalink
google merchant: mejorar la gestión de URLs no encontradas en el serv…
Browse files Browse the repository at this point in the history
…icio de indexación
  • Loading branch information
cesargb committed Jan 17, 2025
1 parent c3a8063 commit 3e769f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Google/Index/Listeners/ProductUnIndexInGoogleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ public function handle(ProductUnpublished $event)
return;
}

// TODO no lo encontrará quizas sea mejor idea conectar a la DB
// $product = ProductRepository::get($event->productId);
$url = $event->attributes['url'] ?? null;

// if (! $product || ! isset($product['url'])) {
// return;
// }
if (! $url) {
return;
}

// EnqueueUrlService::unpublish($product['url']);
EnqueueUrlService::unpublish($url);
}
}
10 changes: 10 additions & 0 deletions src/Google/Index/Services/IndexUrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DescomMarket\Feeds\Google\GoogleServiceBuilder;
use Google\Service\Indexing\UrlNotification;
use Illuminate\Support\Facades\Http;

class IndexUrlService
{
Expand All @@ -15,10 +16,19 @@ public function run(string $url): void
return;
}

if ($this->isNotFound($url)) {
return;
}

$urlNotification = new UrlNotification();
$urlNotification->setType('URL_UPDATED');
$urlNotification->setUrl($url);

GoogleServiceBuilder::googleIndex()->urlNotifications->publish($urlNotification);
}

private function isNotFound(string $url): bool
{
return Http::get($url)->notFound();
}
}

0 comments on commit 3e769f9

Please # to comment.