Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public function childCategories()
return $this->hasMany(Category::class, 'parent_id');

}

public function products()
{
return $this->belongsToMany(Product::class);
}
}
22 changes: 21 additions & 1 deletion app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,25 @@

class Product extends Model
{
//
public $guarded = [];

public function categories()
{
return $this->belongsToMany(Category::class);
}

public function associcatedProducts()
{
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');
}
}
26 changes: 26 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

function status($status)
{
if($status==1){
return '<span class="badge badge-success">Active</span>';
}
return '<span class="badge badge-danger">Inactive</span>';
}

function visibility($visibility)
{
switch ($visibility){
case 1:
return '<span class="badge badge-danger">Not visible</span>';
break;
case 2:
return '<span class="badge badge-info">Catalog</span>';
break;
case 3:
return '<span class="badge badge-info">Search</span>';
break;
default:
return '<span class="badge badge-success">Catalog, Search</span>';
}
}
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -50,6 +51,9 @@
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/helpers.php"
]
},
"autoload-dev": {
Expand Down
52 changes: 49 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions database/factories/CatalogFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use Faker\Generator as Faker;


$factory->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,
];
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,6 +29,7 @@ public function up()
$table->text('meta_keywords')->nullable();
$table->text('meta_description')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

Expand Down
13 changes: 9 additions & 4 deletions database/migrations/2020_08_17_074106_create_products_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ 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->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();
$table->text('description')->nullable();
$table->string('meta_title')->nullable();
$table->text('meta_keywords')->nullable();
$table->text('meta_description')->nullable();
$table->unsignedInteger('parent_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ 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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/2020_08_17_102256_product_links_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
});
}

Expand All @@ -26,6 +26,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('product_categories');
Schema::dropIfExists('category_product');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
9 changes: 8 additions & 1 deletion database/seeds/BrandSeeder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class BrandSeeder extends Seeder
{
Expand All @@ -11,6 +12,12 @@ class BrandSeeder extends Seeder
*/
public function run()
{
//
$faker = Faker::create();
for ($i = 1; $i <= 50; $i++) {
$brand = \App\Models\Brand::create([
'name' => ucfirst($faker->word),
'description' => $faker->paragraph,
]);
}
}
}
Loading