From 976008b4e49060fe3388a5d58b24d3b52327d38c Mon Sep 17 00:00:00 2001 From: Iftakharul Alam Date: Sun, 23 Aug 2020 04:42:29 +0600 Subject: [PATCH 1/5] add feature and refactoring --- database/seeds/BrandSeeder.php | 9 ++++++++- database/seeds/DatabaseSeeder.php | 1 + resources/views/admin/brand/index.blade.php | 6 +++++- resources/views/admin/category/create.blade.php | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/database/seeds/BrandSeeder.php b/database/seeds/BrandSeeder.php index d820c74..4a65f18 100644 --- a/database/seeds/BrandSeeder.php +++ b/database/seeds/BrandSeeder.php @@ -1,6 +1,7 @@ ucfirst($faker->word), + 'description' => $faker->paragraph, + ]); + } } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 765ecc8..e353604 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -14,5 +14,6 @@ public function run() $this->call(UserSeeder::class); $this->call(CustomerGroupSeeder::class); $this->call(CategorySeeder::class); + $this->call(BrandSeeder::class); } } diff --git a/resources/views/admin/brand/index.blade.php b/resources/views/admin/brand/index.blade.php index 3d11511..17c4c05 100644 --- a/resources/views/admin/brand/index.blade.php +++ b/resources/views/admin/brand/index.blade.php @@ -31,7 +31,7 @@ @foreach($brands as $key => $c) - {{$key+1}} + {{$c->id}} {{$c->name}} @if($c->logo) @@ -51,6 +51,10 @@ @endforeach + + diff --git a/resources/views/admin/category/create.blade.php b/resources/views/admin/category/create.blade.php index d4f4662..736197b 100644 --- a/resources/views/admin/category/create.blade.php +++ b/resources/views/admin/category/create.blade.php @@ -36,7 +36,7 @@ placeholder="Name" required> - +
From a7e7403b9a31a0768d637cc5da7681fb59928582 Mon Sep 17 00:00:00 2001 From: Iftakharul Alam Date: Sun, 23 Aug 2020 05:05:57 +0600 Subject: [PATCH 2/5] add feature and refactoring --- ...020_08_17_074106_create_products_table.php | 4 +- database/seeds/CategorySeeder.php | 83 +++++++++---------- database/seeds/DatabaseSeeder.php | 1 + database/seeds/ProductSeeder.php | 23 +++-- 4 files changed, 61 insertions(+), 50 deletions(-) diff --git a/database/migrations/2020_08_17_074106_create_products_table.php b/database/migrations/2020_08_17_074106_create_products_table.php index ce78f6f..223a6cf 100644 --- a/database/migrations/2020_08_17_074106_create_products_table.php +++ b/database/migrations/2020_08_17_074106_create_products_table.php @@ -26,8 +26,8 @@ public function up() $table->boolean('stock_status')->default(1); $table->decimal('weight')->default(1); $table->integer('visibility')->default(3); - $table->decimal('price'); - $table->decimal('special_price')->default(0.00); + $table->integer('price'); + $table->integer('special_price')->default(0.00); $table->dateTime('special_price_from')->nullable(); $table->dateTime('special_price_to')->nullable(); $table->text('short_description')->nullable(); diff --git a/database/seeds/CategorySeeder.php b/database/seeds/CategorySeeder.php index 244a365..fe8ebe9 100644 --- a/database/seeds/CategorySeeder.php +++ b/database/seeds/CategorySeeder.php @@ -1,5 +1,6 @@ 1, - 'name' => 'Men', - 'position' => 1, - 'status' => 1, - 'url_key' => 'men', - 'parent_id' => 0 - ], - [ - 'id' => 2, - 'name' => 'Women', - 'position' => 2, - 'status' => 1, - 'url_key' => 'women', - 'parent_id' => 0 - ], - [ - 'id' => 3, - 'name' => 'Dress', - 'position' => 3, - 'status' => 1, - 'url_key' => 'dress', - 'parent_id' => 2 - ], - [ - 'id' => 4, - 'name' => 'Kids', - 'position' => 4, - 'status' => 1, - 'url_key' => 'kids', - 'parent_id' => 2 - ], - [ - 'id' => 5, - 'name' => 'Shoes', - 'position' => 4, - 'status' => 1, - 'url_key' => 'shoes', - 'parent_id' => 4 - ] - ]; + $faker = Faker::create(); - \App\Models\Category::insert($categories); + for ($i = 1; $i <= 5; $i++) { + $category = \App\Models\Category::create([ + 'name' => ucfirst($faker->word), + 'description' => $faker->paragraph, + 'url_key' => $faker->word, + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'featured' => rand(0, 1), + 'position' => $i, + 'status' => 1, + ]); + + for ($j = 1; $j <= 5; $j++) { + $childCategory = $category->childCategories()->create([ + 'name' => $faker->sentence(2), + 'description' => $faker->paragraph, + 'url_key' => $faker->word, + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'position' => $i . $j, + 'featured' => rand(0, 1), + 'status' => 1, + ]); + + for ($k = 1; $k <= 5; $k++) { + $childCategory->childCategories()->create([ + 'name' => $faker->sentence(3), + 'description' => $faker->paragraph, + 'url_key' => $faker->word, + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'position' => $i . $j . $k, + 'featured' => rand(0, 1), + 'status' => 1, + ]); + } + } + } } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e353604..8da6768 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -15,5 +15,6 @@ public function run() $this->call(CustomerGroupSeeder::class); $this->call(CategorySeeder::class); $this->call(BrandSeeder::class); + $this->call(ProductSeeder::class); } } diff --git a/database/seeds/ProductSeeder.php b/database/seeds/ProductSeeder.php index efaa570..2b0b2f4 100644 --- a/database/seeds/ProductSeeder.php +++ b/database/seeds/ProductSeeder.php @@ -1,5 +1,6 @@ ucfirst($faker->word), + 'name' => ucfirst($faker->word), + 'url_key' => ucfirst($faker->word), + 'product_type' => 'simple', + 'qty' => rand(5, 100), + 'is_new' => rand(0, 1), + 'featured' => rand(0, 1), + 'price' => rand(1000, 99900), + 'short_description' => $faker->paragraph, + 'description' => $faker->paragraph, + 'meta_title' => $faker->word, + 'meta_description' => $faker->paragraph, + ]); + } } } From 82a9cbff100faad2f6e0d6b7d0835a9e44195695 Mon Sep 17 00:00:00 2001 From: Iftakharul Alam Date: Sun, 23 Aug 2020 14:41:23 +0600 Subject: [PATCH 3/5] add feature and refactoring --- app/Models/Category.php | 5 + app/Models/Product.php | 12 ++- database/factories/CatalogFactory.php | 27 +++++ ...0_08_17_074058_create_categories_table.php | 2 +- ...020_08_17_074106_create_products_table.php | 7 +- .../2020_08_17_102256_product_links_table.php | 4 +- ...0_08_17_102335_category_product_table.php} | 10 +- ...8_18_154511_create_url_resolvers_table.php | 3 +- database/seeds/CategorySeeder.php | 40 +------ database/seeds/ProductSeeder.php | 100 +++++++++++++++++- 10 files changed, 155 insertions(+), 55 deletions(-) create mode 100644 database/factories/CatalogFactory.php rename database/migrations/{2020_08_17_102335_product_categories_table.php => 2020_08_17_102335_category_product_table.php} (57%) diff --git a/app/Models/Category.php b/app/Models/Category.php index c174c3d..7465677 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -19,4 +19,9 @@ public function childCategories() return $this->hasMany(Category::class, 'parent_id'); } + + public function products() + { + return $this->belongsToMany(Product::class); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 7fb8e6b..f1e75b6 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -6,5 +6,15 @@ class Product extends Model { - // + public $guarded = []; + + public function categories() + { + return $this->belongsToMany(Category::class); + } + + public function associcateProducts() + { + return $this->hasManyThrough(Product::class,'product_links','product_id','child_id','id','id'); + } } diff --git a/database/factories/CatalogFactory.php b/database/factories/CatalogFactory.php new file mode 100644 index 0000000..ab1dde5 --- /dev/null +++ b/database/factories/CatalogFactory.php @@ -0,0 +1,27 @@ +define(\App\Models\Product::class, function (Faker $faker) { + $color = ['Blue', 'Green', 'Red', 'White', 'Purple', 'Violet', 'Pink', 'Gray', 'Navy Blue']; + $size = ['22', '23', '25', 'M', 'L', 'XL', 'XXL', 'S']; + return [ + 'sku' => ucfirst($faker->word), + 'name' => ucfirst($faker->word), + 'url_key' => ucfirst($faker->word), + 'product_type' => 'simple', + 'qty' => rand(5, 100), + 'color' => $color[rand(0, count($color) - 1)], + 'size' => $size[rand(0, count($size) - 1)], + 'is_new' => rand(0, 1), + 'featured' => rand(0, 1), + 'price' => rand(1000, 99900), + 'short_description' => $faker->paragraph, + 'description' => $faker->paragraph, + 'meta_title' => $faker->word, + 'meta_description' => $faker->paragraph, + ]; +}); diff --git a/database/migrations/2020_08_17_074058_create_categories_table.php b/database/migrations/2020_08_17_074058_create_categories_table.php index 9498638..728d718 100644 --- a/database/migrations/2020_08_17_074058_create_categories_table.php +++ b/database/migrations/2020_08_17_074058_create_categories_table.php @@ -20,7 +20,7 @@ public function up() $table->integer('position')->nullable(); $table->text('description')->nullable(); $table->string('image')->nullable(); - $table->string('url_key'); + $table->string('url_key')->unique(); $table->string('url_path')->nullable(); $table->boolean('status')->default(1); $table->boolean('include_in_menu')->default(1); diff --git a/database/migrations/2020_08_17_074106_create_products_table.php b/database/migrations/2020_08_17_074106_create_products_table.php index 223a6cf..1d6cd3f 100644 --- a/database/migrations/2020_08_17_074106_create_products_table.php +++ b/database/migrations/2020_08_17_074106_create_products_table.php @@ -19,11 +19,14 @@ public function up() $table->string('name'); $table->enum('product_type',['simple','configurable','group','virtual']); $table->boolean('status')->default(1); - $table->string('url_key'); + $table->string('url_key')->unique(); $table->boolean('is_new')->default(0); $table->boolean('featured')->default(0); - $table->decimal('qty'); + $table->decimal('qty')->default(30); + $table->string('color')->nullable(); + $table->string('size')->nullable(); $table->boolean('stock_status')->default(1); + $table->boolean('enable_stock')->default(1); $table->decimal('weight')->default(1); $table->integer('visibility')->default(3); $table->integer('price'); diff --git a/database/migrations/2020_08_17_102256_product_links_table.php b/database/migrations/2020_08_17_102256_product_links_table.php index fee6bb9..a73ccf8 100644 --- a/database/migrations/2020_08_17_102256_product_links_table.php +++ b/database/migrations/2020_08_17_102256_product_links_table.php @@ -14,8 +14,8 @@ class ProductLinksTable extends Migration public function up() { Schema::create('product_links', function (Blueprint $table) { - $table->id(); - $table->timestamps(); + $table->unsignedInteger('product_id'); + $table->unsignedInteger('child_id'); }); } diff --git a/database/migrations/2020_08_17_102335_product_categories_table.php b/database/migrations/2020_08_17_102335_category_product_table.php similarity index 57% rename from database/migrations/2020_08_17_102335_product_categories_table.php rename to database/migrations/2020_08_17_102335_category_product_table.php index b5ef536..7178cae 100644 --- a/database/migrations/2020_08_17_102335_product_categories_table.php +++ b/database/migrations/2020_08_17_102335_category_product_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class ProductCategoriesTable extends Migration +class CategoryProductTable extends Migration { /** * Run the migrations. @@ -13,9 +13,9 @@ class ProductCategoriesTable extends Migration */ public function up() { - Schema::create('product_categories', function (Blueprint $table) { - $table->id(); - $table->timestamps(); + Schema::create('category_product', function (Blueprint $table) { + $table->unsignedInteger('product_id'); + $table->unsignedInteger('category_id'); }); } @@ -26,6 +26,6 @@ public function up() */ public function down() { - Schema::dropIfExists('product_categories'); + Schema::dropIfExists('category_product'); } } diff --git a/database/migrations/2020_08_18_154511_create_url_resolvers_table.php b/database/migrations/2020_08_18_154511_create_url_resolvers_table.php index c9c8ebc..53fdbeb 100644 --- a/database/migrations/2020_08_18_154511_create_url_resolvers_table.php +++ b/database/migrations/2020_08_18_154511_create_url_resolvers_table.php @@ -17,7 +17,8 @@ public function up() $table->id(); $table->string('entity_id'); $table->enum('entity_type',['product','category','cmspage']); - $table->string('url_path'); + $table->string('url_key')->unique(); + $table->string('url_path')->nullable(); $table->timestamps(); }); } diff --git a/database/seeds/CategorySeeder.php b/database/seeds/CategorySeeder.php index fe8ebe9..f3964d8 100644 --- a/database/seeds/CategorySeeder.php +++ b/database/seeds/CategorySeeder.php @@ -2,6 +2,7 @@ use Faker\Factory as Faker; use Illuminate\Database\Seeder; +use Illuminate\Support\Str; class CategorySeeder extends Seeder { @@ -12,45 +13,6 @@ class CategorySeeder extends Seeder */ public function run() { - $faker = Faker::create(); - for ($i = 1; $i <= 5; $i++) { - $category = \App\Models\Category::create([ - 'name' => ucfirst($faker->word), - 'description' => $faker->paragraph, - 'url_key' => $faker->word, - 'meta_title' => ucfirst($faker->word), - 'meta_description' => $faker->paragraph, - 'featured' => rand(0, 1), - 'position' => $i, - 'status' => 1, - ]); - - for ($j = 1; $j <= 5; $j++) { - $childCategory = $category->childCategories()->create([ - 'name' => $faker->sentence(2), - 'description' => $faker->paragraph, - 'url_key' => $faker->word, - 'meta_title' => ucfirst($faker->word), - 'meta_description' => $faker->paragraph, - 'position' => $i . $j, - 'featured' => rand(0, 1), - 'status' => 1, - ]); - - for ($k = 1; $k <= 5; $k++) { - $childCategory->childCategories()->create([ - 'name' => $faker->sentence(3), - 'description' => $faker->paragraph, - 'url_key' => $faker->word, - 'meta_title' => ucfirst($faker->word), - 'meta_description' => $faker->paragraph, - 'position' => $i . $j . $k, - 'featured' => rand(0, 1), - 'status' => 1, - ]); - } - } - } } } diff --git a/database/seeds/ProductSeeder.php b/database/seeds/ProductSeeder.php index 2b0b2f4..3f522d1 100644 --- a/database/seeds/ProductSeeder.php +++ b/database/seeds/ProductSeeder.php @@ -2,6 +2,7 @@ use Faker\Factory as Faker; use Illuminate\Database\Seeder; +use Illuminate\Support\Str; class ProductSeeder extends Seeder { @@ -10,16 +11,99 @@ class ProductSeeder extends Seeder * * @return void */ + public $color = ['Blue', 'Green', 'Red', 'White', 'Purple', 'Violet', 'Pink', 'Gray', 'Navy Blue']; + public $size = ['22', '23', '25', 'M', 'L', 'XL', 'XXL', 'S']; + public $productType = ['simple','configurable']; + public function run() { $faker = Faker::create(); - for ($i = 1; $i <= 200; $i++) { + $category_ids = []; + + /** + * Category + */ + for ($i = 1; $i <= 5; $i++) { + $category = \App\Models\Category::create([ + 'name' => ucfirst($faker->word), + 'description' => $faker->paragraph, + 'url_key' => Str::slug(($faker->word) . $i), + 'url_path' => Str::slug(($faker->word) . $i), + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'featured' => rand(0, 1), + 'position' => $i, + 'status' => 1, + ]); + \App\Models\UrlResolver::create([ + 'entity_id' => $category->id, + 'entity_type' => 'category', + 'url_key' => $category->url_key, + 'url_path' => $category->url_path + ]); + + $category_ids[] = $category->id; + + for ($j = 1; $j <= 5; $j++) { + $childCategory = $category->childCategories()->create([ + 'name' => ucfirst($faker->word), + 'description' => $faker->paragraph, + 'url_key' => Str::slug($faker->word . $i . $j), + 'url_path' => $category->url_path . '/' . Str::slug($faker->word . $i . $j), + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'position' => $i, + 'featured' => rand(0, 1), + 'status' => 1, + ]); + + \App\Models\UrlResolver::create([ + 'entity_id' => $childCategory->id, + 'entity_type' => 'category', + 'url_key' => $childCategory->url_key, + 'url_path' => $childCategory->url_path + ]); + + $category_ids[] = $childCategory->id; + + for ($k = 1; $k <= 5; $k++) { + $grandChildCategory = $childCategory->childCategories()->create([ + 'name' => ucfirst($faker->word), + 'description' => $faker->paragraph, + 'url_key' => Str::slug($faker->word . $i . $j . $k), + 'url_path' => $category->url_path . '/' . $childCategory->url_path . '/' . Str::slug($faker->word . $i . $j . $k), + 'meta_title' => ucfirst($faker->word), + 'meta_description' => $faker->paragraph, + 'position' => $i, + 'featured' => rand(0, 1), + 'status' => 1, + ]); + \App\Models\UrlResolver::create([ + 'entity_id' => $grandChildCategory->id, + 'entity_type' => 'category', + 'url_key' => $grandChildCategory->url_key, + 'url_path' => $grandChildCategory->url_path + ]); + + $category_ids[] = $grandChildCategory->id; + + } + } + } + + /** + * Product + */ + for ($i = 1; $i <= 500; $i++) { + $productType = $this->productType[rand(0,1)]; $product = \App\Models\Product::create([ - 'sku' => ucfirst($faker->word), + 'sku' => 1000 + $i, 'name' => ucfirst($faker->word), - 'url_key' => ucfirst($faker->word), - 'product_type' => 'simple', + 'url_key' => 'p'.Str::slug($faker->word.$i), + 'product_type' => $productType, 'qty' => rand(5, 100), + 'color' => $productType=='simple'?$this->color[rand(0, count($this->color) - 1)]:null, + 'size' => $productType=='simple'?$this->size[rand(0, count($this->size) - 1)]:null, 'is_new' => rand(0, 1), 'featured' => rand(0, 1), 'price' => rand(1000, 99900), @@ -28,6 +112,14 @@ public function run() 'meta_title' => $faker->word, 'meta_description' => $faker->paragraph, ]); + + \App\Models\UrlResolver::create([ + 'entity_id' => $product->id, + 'entity_type' => 'product', + 'url_key' => $product->url_key + ]); + + $product->categories()->sync($category_ids[rand(0,count($category_ids)-1)]); } } } From 16f3ae2e498ee3c66d2eb04c2ae20855013dd11c Mon Sep 17 00:00:00 2001 From: Iftakharul Alam Date: Sun, 23 Aug 2020 17:40:29 +0600 Subject: [PATCH 4/5] on progress --- app/Models/Product.php | 14 ++++- ...0_08_17_074058_create_categories_table.php | 1 + ...020_08_17_074106_create_products_table.php | 2 + ...20_08_17_074139_create_customers_table.php | 1 + database/seeds/DatabaseSeeder.php | 2 +- database/seeds/ProductSeeder.php | 51 +++++++++++++++---- 6 files changed, 59 insertions(+), 12 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index f1e75b6..734c597 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -13,8 +13,18 @@ public function categories() return $this->belongsToMany(Category::class); } - public function associcateProducts() + public function associcatedProducts() { - return $this->hasManyThrough(Product::class,'product_links','product_id','child_id','id','id'); + return $this->hasMany(Product::class, 'parent_id'); + } + + public function relatedProducts() + { +// return $this->hasMany(Product::class, 'parent_id'); + } + + public function parentProduct() + { + return $this->belongsTo(Product::class, 'parent_id'); } } diff --git a/database/migrations/2020_08_17_074058_create_categories_table.php b/database/migrations/2020_08_17_074058_create_categories_table.php index 728d718..fa34db4 100644 --- a/database/migrations/2020_08_17_074058_create_categories_table.php +++ b/database/migrations/2020_08_17_074058_create_categories_table.php @@ -29,6 +29,7 @@ public function up() $table->text('meta_keywords')->nullable(); $table->text('meta_description')->nullable(); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/migrations/2020_08_17_074106_create_products_table.php b/database/migrations/2020_08_17_074106_create_products_table.php index 1d6cd3f..f29c85b 100644 --- a/database/migrations/2020_08_17_074106_create_products_table.php +++ b/database/migrations/2020_08_17_074106_create_products_table.php @@ -38,7 +38,9 @@ public function up() $table->string('meta_title')->nullable(); $table->text('meta_keywords')->nullable(); $table->text('meta_description')->nullable(); + $table->unsignedInteger('parent_id')->nullable(); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/migrations/2020_08_17_074139_create_customers_table.php b/database/migrations/2020_08_17_074139_create_customers_table.php index f6f0d4a..59ead32 100644 --- a/database/migrations/2020_08_17_074139_create_customers_table.php +++ b/database/migrations/2020_08_17_074139_create_customers_table.php @@ -23,6 +23,7 @@ public function up() $table->string('country'); $table->boolean('status')->default(1); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 8da6768..f9f55d3 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -13,7 +13,7 @@ public function run() { $this->call(UserSeeder::class); $this->call(CustomerGroupSeeder::class); - $this->call(CategorySeeder::class); + //$this->call(CategorySeeder::class); $this->call(BrandSeeder::class); $this->call(ProductSeeder::class); } diff --git a/database/seeds/ProductSeeder.php b/database/seeds/ProductSeeder.php index 3f522d1..57ac82b 100644 --- a/database/seeds/ProductSeeder.php +++ b/database/seeds/ProductSeeder.php @@ -11,9 +11,9 @@ class ProductSeeder extends Seeder * * @return void */ - public $color = ['Blue', 'Green', 'Red', 'White', 'Purple', 'Violet', 'Pink', 'Gray', 'Navy Blue']; - public $size = ['22', '23', '25', 'M', 'L', 'XL', 'XXL', 'S']; - public $productType = ['simple','configurable']; + public $color = ['Blue', 'Green', 'Red', 'White', 'Purple', 'Violet', 'Pink', 'Gray', 'Navy Blue']; + public $size = ['22', '23', '25', 'M', 'L', 'XL', 'XXL', 'S']; + public $productType = ['simple', 'configurable']; public function run() { @@ -95,15 +95,15 @@ public function run() * Product */ for ($i = 1; $i <= 500; $i++) { - $productType = $this->productType[rand(0,1)]; + $productType = $this->productType[rand(0, 1)]; $product = \App\Models\Product::create([ 'sku' => 1000 + $i, 'name' => ucfirst($faker->word), - 'url_key' => 'p'.Str::slug($faker->word.$i), + 'url_key' => 'p' . Str::slug($faker->word . $i), 'product_type' => $productType, 'qty' => rand(5, 100), - 'color' => $productType=='simple'?$this->color[rand(0, count($this->color) - 1)]:null, - 'size' => $productType=='simple'?$this->size[rand(0, count($this->size) - 1)]:null, + 'color' => $productType == 'simple' ? $this->color[rand(0, count($this->color) - 1)] : null, + 'size' => $productType == 'simple' ? $this->size[rand(0, count($this->size) - 1)] : null, 'is_new' => rand(0, 1), 'featured' => rand(0, 1), 'price' => rand(1000, 99900), @@ -116,10 +116,43 @@ public function run() \App\Models\UrlResolver::create([ 'entity_id' => $product->id, 'entity_type' => 'product', - 'url_key' => $product->url_key + 'url_key' => $product->url_key ]); + $cat_id = $category_ids[rand(0, count($category_ids) - 1)]; + $product->categories()->sync($cat_id); - $product->categories()->sync($category_ids[rand(0,count($category_ids)-1)]); + /** + * Associcated products + */ + if ($productType == 'configurable') { + for ($j = 1; $j <= 5; $j++) { + $associatedProduct = $product->associcatedProducts()->create([ + 'sku' => 1000 + $i, + 'name' => ucfirst($faker->word), + 'url_key' => 'p' . Str::slug($faker->word . $i.$j), + 'product_type' => 'simple', + 'qty' => rand(5, 100), + 'color' => $this->color[rand(0, count($this->color) - 1)], + 'size' => $this->size[rand(0, count($this->size) - 1)], + 'is_new' => rand(0, 1), + 'featured' => rand(0, 1), + 'visibility' => 1, + 'price' => rand(1000, 99900), + 'short_description' => $faker->paragraph, + 'description' => $faker->paragraph, + 'meta_title' => $faker->word, + 'meta_description' => $faker->paragraph, + ]); + + \App\Models\UrlResolver::create([ + 'entity_id' => $associatedProduct->id, + 'entity_type' => 'product', + 'url_key' => $associatedProduct->url_key + ]); + + $associatedProduct->categories()->sync($cat_id); + } + } } } } From 9ea4b293aeedff1610403b8fe24e2ec13b100ce9 Mon Sep 17 00:00:00 2001 From: Iftakharul Alam Date: Sun, 23 Aug 2020 22:32:03 +0600 Subject: [PATCH 5/5] add feature and refactoring --- .../Controllers/Admin/CategoryController.php | 3 +- .../Controllers/Admin/ProductController.php | 16 +- app/helpers.php | 26 ++++ composer.json | 4 + composer.lock | 52 ++++++- .../2014_10_12_000000_create_users_table.php | 1 - ...20_08_17_074139_create_customers_table.php | 1 + ...074221_create_customer_addresses_table.php | 6 +- database/seeds/ProductSeeder.php | 20 ++- database/seeds/UserSeeder.php | 45 +++++- public/adminhtml/dist/css/custom.css | 20 +++ .../views/admin/category/index.blade.php | 26 ++-- .../views/admin/product/create.blade.php | 33 ++-- resources/views/admin/product/index.blade.php | 142 ++++++++++++------ .../components/admin/form/button.blade.php | 2 +- 15 files changed, 306 insertions(+), 91 deletions(-) create mode 100644 app/helpers.php diff --git a/app/Http/Controllers/Admin/CategoryController.php b/app/Http/Controllers/Admin/CategoryController.php index 0a46f7a..27ae173 100644 --- a/app/Http/Controllers/Admin/CategoryController.php +++ b/app/Http/Controllers/Admin/CategoryController.php @@ -5,12 +5,13 @@ use App\Http\Controllers\Controller; use App\Http\Requests\CategoryRequest; use App\Models\Category; +use Illuminate\Pagination\Paginator; class CategoryController extends Controller { public function index() { - $categories = Category::get(); + $categories = Category::paginate(20); return view('admin.category.index')->with([ 'categories' => $categories ]); diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 1b7f9f3..dda5036 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -11,7 +11,21 @@ class ProductController extends Controller { public function index() { - $products = Product::paginate(20); + $products = Product::query(); + $products->when(request('sku') != '', function ($q) { + return $q->where('sku', request('sku')); + }); + $products->when(request('name') != '', function ($q) { + return $q->where('name', request('name')); + }); + $products->when(request('status') != '', function ($q) { + return $q->where('status', request('status')); + }); + $products->when(request('visibility') != '', function ($q) { + return $q->where('visibility', request('visibility')); + }); + $products = $products->select(['name', 'visibility', 'product_type', 'id', 'special_price', 'price', 'sku', 'status', 'qty']) + ->paginate(20); return view('admin.product.index')->with([ 'products' => $products ]); diff --git a/app/helpers.php b/app/helpers.php new file mode 100644 index 0000000..1671204 --- /dev/null +++ b/app/helpers.php @@ -0,0 +1,26 @@ +Active'; + } + return 'Inactive'; +} + +function visibility($visibility) +{ + switch ($visibility){ + case 1: + return 'Not visible'; + break; + case 2: + return 'Catalog'; + break; + case 3: + return 'Search'; + break; + default: + return 'Catalog, Search'; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index c7827c7..afd97d9 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "barryvdh/laravel-debugbar": "^3.4", "facade/ignition": "^2.0", "fzaninotto/faker": "^1.9.1", + "mbezhanov/faker-provider-collection": "^1.2", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^4.1", "phpunit/phpunit": "^8.5" @@ -50,6 +51,9 @@ "classmap": [ "database/seeds", "database/factories" + ], + "files": [ + "app/helpers.php" ] }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index 8c005ab..bfa83e9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cb1004b22afb82e27e8ad32b83769699", + "content-hash": "ff372c2a67347f8defb7983a0bf8c951", "packages": [ { "name": "asm89/stack-cors", @@ -5253,6 +5253,53 @@ ], "time": "2020-05-06T07:06:27+00:00" }, + { + "name": "mbezhanov/faker-provider-collection", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/mbezhanov/faker-provider-collection.git", + "reference": "076c00f0d438f12ec7da0fdaadbfb7940913763e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mbezhanov/faker-provider-collection/zipball/076c00f0d438f12ec7da0fdaadbfb7940913763e", + "reference": "076c00f0d438f12ec7da0fdaadbfb7940913763e", + "shasum": "" + }, + "require": { + "fzaninotto/faker": "^1.6", + "php": "^7.0" + }, + "require-dev": { + "php-mock/php-mock": "^2.0", + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Bezhanov\\Faker\\": "src/Faker" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marin Bezhanov", + "email": "marin.bezhanov@gmail.com", + "homepage": "http://marinbezhanov.com" + } + ], + "description": "A collection of custom providers for the Faker library", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2018-11-22T06:55:34+00:00" + }, { "name": "mockery/mockery", "version": "1.4.2", @@ -6925,6 +6972,5 @@ "platform": { "php": "^7.2.5" }, - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform-dev": [] } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index cda938a..de78ee0 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -17,7 +17,6 @@ public function up() $table->id(); $table->uuid('uuid'); $table->string('name'); - $table->string('username'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); diff --git a/database/migrations/2020_08_17_074139_create_customers_table.php b/database/migrations/2020_08_17_074139_create_customers_table.php index 59ead32..d3a84c2 100644 --- a/database/migrations/2020_08_17_074139_create_customers_table.php +++ b/database/migrations/2020_08_17_074139_create_customers_table.php @@ -21,6 +21,7 @@ public function up() $table->string('last_name'); $table->enum('gender',['male','female']); $table->string('country'); + $table->string('vat_id')->nullable(); $table->boolean('status')->default(1); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2020_08_17_074221_create_customer_addresses_table.php b/database/migrations/2020_08_17_074221_create_customer_addresses_table.php index 0b5bf6f..3473066 100644 --- a/database/migrations/2020_08_17_074221_create_customer_addresses_table.php +++ b/database/migrations/2020_08_17_074221_create_customer_addresses_table.php @@ -19,12 +19,12 @@ public function up() $table->string('first_name'); $table->string('last_name'); $table->string('address_line_1'); - $table->string('address_line_2'); + $table->string('address_line_2')->nullable(); $table->string('city'); - $table->string('state'); + $table->string('state')->nullable(); $table->string('country'); $table->string('postcode'); - $table->string('telephone'); + $table->string('telephone')->nullable(); $table->string('fax')->nullable(); $table->boolean('default_shipping')->default(0); $table->boolean('default_billing')->default(0); diff --git a/database/seeds/ProductSeeder.php b/database/seeds/ProductSeeder.php index 57ac82b..49d9624 100644 --- a/database/seeds/ProductSeeder.php +++ b/database/seeds/ProductSeeder.php @@ -18,6 +18,7 @@ class ProductSeeder extends Seeder public function run() { $faker = Faker::create(); + $faker->addProvider(new \Bezhanov\Faker\Provider\Commerce($faker)); $category_ids = []; /** @@ -25,7 +26,7 @@ public function run() */ for ($i = 1; $i <= 5; $i++) { $category = \App\Models\Category::create([ - 'name' => ucfirst($faker->word), + 'name' => ucfirst($faker->department(1, true)), 'description' => $faker->paragraph, 'url_key' => Str::slug(($faker->word) . $i), 'url_path' => Str::slug(($faker->word) . $i), @@ -46,7 +47,7 @@ public function run() for ($j = 1; $j <= 5; $j++) { $childCategory = $category->childCategories()->create([ - 'name' => ucfirst($faker->word), + 'name' => ucfirst($faker->department(1, true)), 'description' => $faker->paragraph, 'url_key' => Str::slug($faker->word . $i . $j), 'url_path' => $category->url_path . '/' . Str::slug($faker->word . $i . $j), @@ -94,19 +95,22 @@ public function run() /** * Product */ - for ($i = 1; $i <= 500; $i++) { + for ($i = 1; $i <= 1000; $i++) { $productType = $this->productType[rand(0, 1)]; + $price = rand(1000, 99900); $product = \App\Models\Product::create([ 'sku' => 1000 + $i, - 'name' => ucfirst($faker->word), - 'url_key' => 'p' . Str::slug($faker->word . $i), + 'name' => ucfirst($faker->productName), + 'url_key' => $faker->uuid, 'product_type' => $productType, 'qty' => rand(5, 100), 'color' => $productType == 'simple' ? $this->color[rand(0, count($this->color) - 1)] : null, 'size' => $productType == 'simple' ? $this->size[rand(0, count($this->size) - 1)] : null, 'is_new' => rand(0, 1), 'featured' => rand(0, 1), - 'price' => rand(1000, 99900), + 'price' => $price, + 'visibility' => rand(2, 4), + 'special_price' => $productType == 'simple' ? $price * (rand(99, 50) / 100) : 0, 'short_description' => $faker->paragraph, 'description' => $faker->paragraph, 'meta_title' => $faker->word, @@ -128,8 +132,8 @@ public function run() for ($j = 1; $j <= 5; $j++) { $associatedProduct = $product->associcatedProducts()->create([ 'sku' => 1000 + $i, - 'name' => ucfirst($faker->word), - 'url_key' => 'p' . Str::slug($faker->word . $i.$j), + 'name' => ucfirst($faker->productName), + 'url_key' => $faker->uuid, 'product_type' => 'simple', 'qty' => rand(5, 100), 'color' => $this->color[rand(0, count($this->color) - 1)], diff --git a/database/seeds/UserSeeder.php b/database/seeds/UserSeeder.php index 05bcd28..fe7b2f5 100644 --- a/database/seeds/UserSeeder.php +++ b/database/seeds/UserSeeder.php @@ -1,5 +1,6 @@ forgetCachedPermissions(); @@ -52,12 +54,12 @@ public function run() $role2->givePermissionTo('configuration'); $role3 = Role::create(['name' => 'super-admin']); + $role4 = Role::create(['name' => 'ccustomer']); // gets all permissions via Gate::before rule; see AuthServiceProvider // create demo users $user = Factory(App\User::class)->create([ 'name' => 'Example User', - 'username' => 'admin1', 'password' => bcrypt('password'), 'email' => 'test@example.com', ]); @@ -65,7 +67,6 @@ public function run() $user = Factory(App\User::class)->create([ 'name' => 'Example Admin User', - 'username' => 'admin2', 'password' => bcrypt('password'), 'email' => 'admin@example.com', ]); @@ -73,10 +74,48 @@ public function run() $user = Factory(App\User::class)->create([ 'name' => 'Super-Admin', - 'username' => 'admin', 'password' => bcrypt('password'), 'email' => 'super@admin.com', ]); $user->assignRole($role3); + + for ($i = 1; $i <= 50; $i++) { + $user = Factory(App\User::class)->create([ + 'name' => $faker->name, + 'password' => bcrypt('password'), + 'email' => $faker->email, + ]); + $user->assignRole($role4); + + $customer = \App\Models\Customer::create([ + 'user_id' => $user->id, + 'first_name' => $faker->firstName, + 'last_name' => $faker->lastName, + 'gender' => 'male', + 'customer_group_id' => 1, + 'country' => $faker->country + ]); + + $on = 1; + for ($j = 1; $j <= 2; $j++) { + + \App\Models\CustomerAddress::create([ + 'customer_id' => $customer->id, + 'first_name' => $faker->firstName, + 'last_name' => $faker->lastName, + 'address_line_1' => $faker->streetAddress, + 'telephone' => $faker->phoneNumber, + 'city' => $faker->city, + 'default_shipping' => $on ? 1 : 0, + 'default_billing' => $on ? 1 : 0, + 'postcode' => $faker->postcode, + 'country' => $faker->country, + ]); + + $on = 0; + } + } + + } } diff --git a/public/adminhtml/dist/css/custom.css b/public/adminhtml/dist/css/custom.css index db9b47a..eac2a50 100644 --- a/public/adminhtml/dist/css/custom.css +++ b/public/adminhtml/dist/css/custom.css @@ -83,3 +83,23 @@ .main-footer { background-color: #f4f6f9; } + +.card-footer nav{ + justify-content: flex-end; + display: flex; + align-items: center; +} + +ul.pagination{ + margin-bottom: 0; +} + +.btn{ + border:none; +} + +.card-footer.clearfix.flex { + display: flex; + align-items: center; + justify-content: space-between; +} \ No newline at end of file diff --git a/resources/views/admin/category/index.blade.php b/resources/views/admin/category/index.blade.php index 41d6119..f211a00 100644 --- a/resources/views/admin/category/index.blade.php +++ b/resources/views/admin/category/index.blade.php @@ -23,17 +23,17 @@
-
+

Categories

- + @@ -43,17 +43,17 @@ - @foreach($categories as $key => $c) + @foreach($categories as $key => $category) - - - - + + + + @@ -61,6 +61,12 @@ @endforeach
ID Name
{{$key+1}}{{$c->name}}{{$c->parentCategory->name ?? ""}}{{$c->url_key}}{{$category->id}}{{$category->name}}{{$category->parentCategory->name ?? ""}}{{$category->url_key}} - +   - +
+
diff --git a/resources/views/admin/product/create.blade.php b/resources/views/admin/product/create.blade.php index c95c0ca..8caf7bf 100644 --- a/resources/views/admin/product/create.blade.php +++ b/resources/views/admin/product/create.blade.php @@ -27,8 +27,13 @@
-
+

New Product

+
+ +
@@ -86,7 +91,8 @@ placeholder="Special Price To" required>
-
+ +
@@ -97,13 +103,15 @@
-
+ +
+
@@ -193,6 +201,9 @@ class="form-control form-control-sm editor"
+
@@ -202,6 +213,10 @@ class="form-control form-control-sm editor" @endsection +@section('style') + +@endsection + @section('script') @@ -210,14 +225,12 @@ class="form-control form-control-sm editor" let editor_config = { path_absolute: "/", + branding: false, + statusbar: false, + menubar: false, selector: "textarea.editor", - plugins: [ - "autolink lists link image hr anchor", - "wordcount visualblocks visualchars code", - "insertdatetime table directionality", - "emoticons paste textcolor textpattern" - ], - toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image", + plugins: ["image link"], + toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | link image", relative_urls: false, file_browser_callback: function (field_name, url, type, win) { let x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth; diff --git a/resources/views/admin/product/index.blade.php b/resources/views/admin/product/index.blade.php index d8474bc..8ccbdd6 100644 --- a/resources/views/admin/product/index.blade.php +++ b/resources/views/admin/product/index.blade.php @@ -1,74 +1,116 @@ @extends('admin.layouts.app') @section('title','Product | ') @section('content') - -
-
-
-
-

Products

-
-
- -
-
-
-
- + +
-
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ Reset + +
+
+
+
+
+
+
+ -
- - - - - - - - - - - - +
IDSkuProductPriceSalesMore
+ + + + + + + + + + + + + + + + + @foreach($products as $product) + + - - - + + + + + + + - - -
IDSkuThumbnailNameTypeStatusQtyPriceSpecial PriceVisibilityAction
{{$product->id}}{{$product->sku}} - Product 1 - Some Product - $13 USD{{$product->name}}{{$product->product_type}}{!! status($product->status) !!}{{$product->qty}}{{$product->price/100}}{{$product->special_price/100}}{!! visibility($product->visibility) !!} - - - 12% - - 12,000 Sold - - - + + +   + +
+ @endforeach + + +
diff --git a/resources/views/components/admin/form/button.blade.php b/resources/views/components/admin/form/button.blade.php index 20a087b..5ed60f1 100644 --- a/resources/views/components/admin/form/button.blade.php +++ b/resources/views/components/admin/form/button.blade.php @@ -1,4 +1,4 @@
- +
\ No newline at end of file