5 Commits

Author SHA1 Message Date
6cfee98a6b Country badge.
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-18 07:49:50 +01:00
bafa889c59 Merge branch 'refs/heads/master' into feature/link-badges 2026-02-17 10:23:08 +01:00
d18c735b63 Add locale badges to promos
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-16 08:59:46 +01:00
cac4e1f925 Badges as links
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-15 11:51:00 +01:00
7f7cc72647 Badges as links
All checks were successful
/ deploy-job (push) Successful in 0s
2026-02-13 08:18:51 +01:00
5 changed files with 9 additions and 59 deletions

View File

@@ -246,16 +246,6 @@ class Migrate extends Command
$table->json('promotions')->nullable(); $table->json('promotions')->nullable();
}); });
} }
if (!Capsule::schema()->hasColumn('prices', 'conversionRate')) {
Capsule::schema()->table('prices', function (Blueprint $table) {
$table->float('conversionRate')->nullable();
});
}
if (!Capsule::schema()->hasColumn('products', 'conversionRate')) {
Capsule::schema()->table('products', function (Blueprint $table) {
$table->float('conversionRate')->nullable();
});
}
} }
public function index(): void public function index(): void

View File

@@ -23,17 +23,15 @@ class ScrapeWebsite extends Command
{ {
const COUNTRY_ID = 'country'; const COUNTRY_ID = 'country';
private Client $client; private Client $client;
private array $rates;
public function __construct(protected Capsule $database) public function __construct(protected Capsule $database)
{ {
parent::__construct(); parent::__construct();
$this->client = new Client();
$this->rates = $this->getCurrencyExchange();
} }
protected function configure(): void protected function configure(): void
{ {
$this->client = new Client();
$this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id'); $this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id');
} }
@@ -70,7 +68,6 @@ class ScrapeWebsite extends Command
$product->priceLowest = $product->lowestPrice->price; $product->priceLowest = $product->lowestPrice->price;
$product->lastSeen = $newestPrice->created_at->format('Y-m-d'); $product->lastSeen = $newestPrice->created_at->format('Y-m-d');
$product->stock = $currentStock->stock; $product->stock = $currentStock->stock;
$product->conversionRate = $newestPrice->conversionRate;
$product->save(['timestamps' => false]); $product->save(['timestamps' => false]);
$progress->advance(); $progress->advance();
} }
@@ -101,7 +98,7 @@ class ScrapeWebsite extends Command
$products = array_merge($products, $responseObject->products); $products = array_merge($products, $responseObject->products);
$page++; $page++;
$canLoadMore = $responseObject->canLoadMore; $canLoadMore = $responseObject->canLoadMore;
} catch (GuzzleException) { } catch (GuzzleException $e) {
return $products; return $products;
} }
} while ($canLoadMore); } while ($canLoadMore);
@@ -135,7 +132,6 @@ class ScrapeWebsite extends Command
$price->price = $product->productPrice; $price->price = $product->productPrice;
$price->productStandardPrice = $product->productStandardPrice; $price->productStandardPrice = $product->productStandardPrice;
$price->lowestProductPrice30Days = $product->lowestProductPrice30Days; $price->lowestProductPrice30Days = $product->lowestProductPrice30Days;
$price->conversionRate = $this->getConversionRate($country->currency);
$productModel->price()->save($price); $productModel->price()->save($price);
} }
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists(); $stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
@@ -151,22 +147,4 @@ class ScrapeWebsite extends Command
$productModel->stock()->save($stock); $productModel->stock()->save($stock);
} }
} }
public function getCurrencyExchange(): array
{
$result = $this->client->request('GET', 'https://api.nbp.pl/api/exchangerates/tables/A/?format=json');
$rates = ['PLN' => 1.0];
foreach(json_decode($result->getBody()->getContents(),true)[0]['rates'] as $rate){
$rates[$rate['code']] = $rate['mid'];
}
return $rates;
}
private function getConversionRate(string $currency): float
{
$currency = strtoupper($currency);
return $this->rates[$currency];
}
} }

View File

@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property float $price * @property float $price
* @property float $productStandardPrice * @property float $productStandardPrice
* @property float $lowestProductPrice30Days * @property float $lowestProductPrice30Days
* @property float $conversionRate
*/ */
class Price extends Model class Price extends Model
{ {

View File

@@ -27,7 +27,6 @@ use function Symfony\Component\Clock\now;
* @property float $priceLowest * @property float $priceLowest
* @property float $productStandardPrice * @property float $productStandardPrice
* @property float $lowestProductPrice30Days * @property float $lowestProductPrice30Days
* @property float $conversionRate
* @property Date $lastSeen * @property Date $lastSeen
* @property integer $stock * @property integer $stock
* @property Object $promotions * @property Object $promotions
@@ -104,11 +103,6 @@ class Product extends Model
); );
} }
public function conversionRate(): ?float
{
return $this->conversionRate;
}
public function isDiscontinued(): bool public function isDiscontinued(): bool
{ {
return $this->lastSeen < now()->format('Y-m-d'); return $this->lastSeen < now()->format('Y-m-d');

View File

@@ -80,30 +80,19 @@
<td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td> <td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
<td class="align-middle text-end"> <td class="align-middle text-end">
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %} {% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %}
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}<br> {{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}
{% if product.conversionRate is not empty and product.conversionRate != 1 %}
{{ (product.priceLowest * product.conversionRate) | format_currency('PLN', {}, 'pl') }}
{% endif %}
{% else %} {% else %}
{% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %} {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %}
<span class="badge text-bg-info">now lowest</span> <span class="badge text-bg-info">now lowest</span>{% endif %}</td>
{% endif %}</td>
{% endif %} {% endif %}
<td class="align-middle text-end"> <td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td>
{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}<br>
{% if product.conversionRate is not empty and product.conversionRate != 1 %}
{{ (product.priceCurrent * product.conversionRate) | format_currency('PLN', {}, 'pl') }}
{% endif %}
</td>
<td class="align-middle"> <td class="align-middle">
<div class="d-flex flex-row"> <div class="d-flex flex-row">
{% if product.priceCurrent != product.productStandardPrice %} {% if product.priceCurrent != product.productStandardPrice %}<span
<span class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span> class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span>
{% if product.conversionRate is not empty and product.conversionRate != 1 %} <span
<span class="badge text-bg-warning text-decoration-line-through flex-fill">{{ (product.productStandardPrice * product.conversionRate) | format_currency('PLN', {}, 'pl') }}</span> class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %}
<span class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %} {% endif %}
</div> </div>
</td> </td>