Files
YNWA Fawzy f927bfb6c0 - add walmart stores to the list of products.
- fix panel issue where route is wrong
- add store images for ebay
- add walmart.com and walmart.ca to the stores
- add new discount:update command to update the system
- add new discount:test-notify to test the notification system.
- fix route..page.my-profile not found
2023-12-06 12:01:31 +04:00

49 lines
1.4 KiB
PHP

<?php
namespace App\Classes;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class URLHelper
{
public string $final_url;
public string $domain;
public string $path;
public function __construct($url) {
$parsed_url=parse_url($url);
$this->domain=\Str::lower(\Str::replace("www.", "" , $parsed_url['host']));
$this->path=$parsed_url['path'] ?? "";
$this->final_url="https://$this->domain$this->path";
}
public function fill_data(& $data): void
{
if (MainStore::is_amazon($this->domain))
$data=\Arr::add($data , 'asin' , $this->get_asin());
elseif (MainStore::is_ebay($this->domain))
$data=\Arr::add($data , 'ebay_id' , $this->get_ebay_item_id());
elseif (MainStore::is_walmart($this->domain))
$data=\Arr::add($data , 'walmart_ip' , $this->get_walmart_ip());
}
public function get_asin(): string
{
$this->path=\Str::replace("/gp/product/" , "/dp/" , $this->path , false);
return Str::remove("/" , Str::squish(explode("/dp/" , $this->path)[1]) );
}
public function get_ebay_item_id(){
return explode("/itm/" , $this->path)[1];
}
public function get_walmart_ip(): string
{
return Str::remove("/" , Str::squish( \Arr::last(explode("/" , $this->path))) );
}
}