Add price and product models

This commit is contained in:
Krzysztof Płaczek
2024-03-26 12:42:06 +01:00
parent 5dc1c9d9f0
commit b4536e4c6b
6 changed files with 100 additions and 36 deletions

View File

@@ -3,6 +3,8 @@
include_once 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use Krzysiej\RyobiCrawler\Models\Price;
use Krzysiej\RyobiCrawler\Models\Product;
$capsule = new Capsule;
$capsule->addConnection([
@@ -11,29 +13,34 @@ $capsule->addConnection([
'prefix' => '',
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
echo '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"></head>';
echo "<table class='table table-hover'>";
if (isset($_GET['product_id'])) {
$products = Capsule::table('product')->leftJoin('price', 'product.id', '=', 'price.product_id')->where('product.id', '=', $_GET['product_id'])->get();
foreach ($products as $product) {
echo "<tr>
$product = Product::with('price')->find($_GET['product_id']);
echo "<tr>
<td><img src='$product->image&width=70' class='img-fluid' alt='$product->name' /></td>
<td><a href='?product_id=$product->id'>$product->name</a></td>
<td>$product->subTitle</td>
<td><a href='https://pl.ryobitools.eu/{$product->url}'>link</a></td>
<td>$product->price</td>
<td>$product->created_at</td>
<td><a href='https://pl.ryobitools.eu/{$product->url}'>link</a></td>";
/** @var Price $price */
foreach ($product->price as $price) {
echo "<tr>
<td>$price->price</td>
<td>$price->lowestProductPrice30Days</td>
<td>$price->productStandardPrice</td>
<td>$price->created_at</td>
</tr>";
}
} else {
$products = Capsule::table('product')->get();
$products = Product::with('price')->get();
foreach ($products as $product) {
echo "<tr>
<td><img src='$product->image&width=70' class='img-fluid' alt='$product->name' /></td>
<td><a href='?product_id=$product->id'>$product->name</a></td>
<td>$product->subTitle</td>
<td><a href='https://pl.ryobitools.eu/{$product->url}'>link</a></td>
<td>$product->price</td>
<td>{$product->price->last()->price}</td>
</tr>";
}
}