Compare commits
5 Commits
a196281a96
...
0042fda5cc
| Author | SHA1 | Date | |
|---|---|---|---|
| 0042fda5cc | |||
| 646383fb6a | |||
| f9c58edccd | |||
| 9ec3291a6a | |||
| 373fd1641b |
@@ -6,6 +6,7 @@ namespace Krzysiej\RyobiCrawler\Command;
|
|||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Country;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@@ -93,26 +94,30 @@ class Migrate extends Command
|
|||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$id = Capsule::table('countries')->insertGetId(
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Poland')->exists()) {
|
||||||
[
|
$id = Capsule::table('countries')->insertGetId(
|
||||||
'countryName' => 'Poland',
|
[
|
||||||
'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
|
'countryName' => 'Poland',
|
||||||
'cultureCode' => 'pl-PL',
|
'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
|
||||||
'currency' => 'PLN',
|
'cultureCode' => 'pl-PL',
|
||||||
'locale' => 'pl',
|
'currency' => 'PLN',
|
||||||
'created_at' => now(),
|
'locale' => 'pl',
|
||||||
'updated_at' => now(),
|
'created_at' => now(),
|
||||||
]);
|
'updated_at' => now(),
|
||||||
Capsule::table('countries')->insert([
|
]);
|
||||||
'countryName' => 'UK',
|
}
|
||||||
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) {
|
||||||
'cultureCode' => 'en-GB',
|
Capsule::table('countries')->insert([
|
||||||
'currency' => 'GBP',
|
'countryName' => 'UK',
|
||||||
'locale' => 'en',
|
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
||||||
'created_at' => now(),
|
'cultureCode' => 'en-GB',
|
||||||
'updated_at' => now(),
|
'currency' => 'GBP',
|
||||||
]
|
'locale' => 'en',
|
||||||
);
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!Capsule::schema()->hasColumn('products', 'country_id')) {
|
if (!Capsule::schema()->hasColumn('products', 'country_id')) {
|
||||||
Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
|
Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->skuID = $product->skuID;
|
$productModel->skuID = $product->skuID;
|
||||||
$productModel->name = $product->name;
|
$productModel->name = $product->name;
|
||||||
$productModel->availableQuantity = $product->availableQuantity;
|
$productModel->availableQuantity = $product->availableQuantity;
|
||||||
$productModel->categories = $product->categories;
|
$productModel->categories = str_replace(['/', ' '], '', $product->categories);
|
||||||
$productModel->image = $product->image;
|
$productModel->image = $product->image;
|
||||||
$productModel->subTitle = $product->subTitle;
|
$productModel->subTitle = $product->subTitle;
|
||||||
$productModel->variantCode = $product->variantCode;
|
$productModel->variantCode = $product->variantCode;
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ final class NewController extends BaseController
|
|||||||
if($this->cache->getItem('list_new')->isHit()) {
|
if($this->cache->getItem('list_new')->isHit()) {
|
||||||
return $this->render('productList.html.twig', ['listType' => 'new']);
|
return $this->render('productList.html.twig', ['listType' => 'new']);
|
||||||
}
|
}
|
||||||
|
$date = now()->modify('-30 days')->format('Y-m-d');
|
||||||
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
$products = Product::where('created_at', '>', $date)
|
||||||
|
->with(['country', 'stock'])
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->with(['currentPrice', 'lowestPrice'])
|
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ use function Symfony\Component\Clock\now;
|
|||||||
class Product extends Model
|
class Product extends Model
|
||||||
{
|
{
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
public $fillable = ['skuID'];
|
public $fillable = ['skuID', 'country_id'];
|
||||||
|
|
||||||
public function country(): BelongsTo
|
public function country(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
||||||
<td>
|
<td>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
{% if product.currentStock.stock > 0 %}
|
{% if product.stock > 0 %}
|
||||||
<span class="badge text-bg-light">stock: {{ product.currentStock.stock }}</span>
|
<span class="badge text-bg-light">stock: {{ product.stock }}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="badge text-bg-warning">out of stock</span>
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
{% if product.isNew() %}
|
{% if product.isNew() %}
|
||||||
<span class="badge text-bg-success">is new</span>
|
<span class="badge text-bg-success">is new</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
||||||
|
|||||||
Reference in New Issue
Block a user