diff --git a/database/factories/AddressFactory.php b/database/factories/AddressFactory.php new file mode 100644 index 000000000..cf7a74786 --- /dev/null +++ b/database/factories/AddressFactory.php @@ -0,0 +1,25 @@ +define(AvoRed\Framework\Models\Database\Address::class, function (Faker $faker) { + $user = factory(User::class)->create(); + $type = ['SHIPPING','BILLING']; + $country = Country::first(); + + return [ + 'user_id' => $user->id, + 'type' => $type[rand(0,1)], + 'first_name' => $faker->firstName, + 'last_name' => $faker->lastName, + 'address1' => $faker->buildingNumber . ' ' . $faker->streetName, + 'address2' => $faker->secondaryAddress, + 'state' => $faker->state, + 'city' => $faker->city, + 'postcode' => $faker->postcode, + 'phone' => $faker->phoneNumber, + 'country_id' => $country->id + ]; +}); diff --git a/database/factories/PageFactory.php b/database/factories/PageFactory.php new file mode 100644 index 000000000..b9a740591 --- /dev/null +++ b/database/factories/PageFactory.php @@ -0,0 +1,12 @@ +define(AvoRed\Framework\Models\Database\Page::class, function (Faker $faker) { + $name = $faker->text(5); + return [ + 'name' => $name, + 'slug' => str_slug($name), + 'content' => $faker->text(1000) + ]; +}); diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php new file mode 100644 index 000000000..d0e392ea0 --- /dev/null +++ b/database/factories/ProductFactory.php @@ -0,0 +1,25 @@ +define(AvoRed\Framework\Models\Database\Product::class, function (Faker $faker) { + $name = $faker->text(5); + return [ + 'type' => 'BASIC', + 'name' => $name, + 'slug' => str_slug($name), + 'sku' => str_slug($name), + 'description' => $faker->text(50), + 'status' => rand(0,1), + 'in_stock' => rand(0,1), + 'track_stock' => rand(0,1), + 'qty' => rand(1,100), + 'is_taxable' => rand(0,1), + 'price' => rand(10,1000) . '.' . rand(0,10), + 'cost_price' => rand(10,1000) . '.' . rand(0,10), + 'weight' => rand(1,100), + 'height' => rand(1,100), + 'length' => rand(1,100), + 'width' => rand(1,100), + ]; +}); diff --git a/database/factories/WishlistFactory.php b/database/factories/WishlistFactory.php new file mode 100644 index 000000000..6f8ae9f9f --- /dev/null +++ b/database/factories/WishlistFactory.php @@ -0,0 +1,16 @@ +define(AvoRed\Framework\Models\Database\Wishlist::class, function (Faker $faker) { + $user = factory(User::class)->create(); + $product = factory(Product::class)->create(); + + return [ + 'user_id' => $user->id, + 'product_id' => $product->id + ]; +}); diff --git a/database/migrations/2017_03_29_000000_avored_framework_schema.php b/database/migrations/2017_03_29_000000_avored_framework_schema.php index 17d0d9651..a03063f6b 100644 --- a/database/migrations/2017_03_29_000000_avored_framework_schema.php +++ b/database/migrations/2017_03_29_000000_avored_framework_schema.php @@ -8,6 +8,7 @@ use AvoRed\Framework\Models\Database\SiteCurrency; use AvoRed\Framework\Models\Database\Configuration; use AvoRed\Framework\Models\Database\MenuGroup; +use AvoRed\Framework\Models\Database\Menu; class AvoredFrameworkSchema extends Migration { @@ -605,6 +606,7 @@ public function up() $table->string('name')->nullable()->default(null); $table->string('route')->nullable()->default(null); $table->string('params')->nullable()->default(null); + $table->integer('sort_order')->default(0); $table->timestamps(); $table->foreign('menu_group_id')->references('id')->on('menu_groups')->onDelete('cascade'); @@ -673,7 +675,78 @@ public function up() 'configuration_key' => 'general_site_description', 'configuration_value' => 'AvoRed Laravel Ecommerce ']); + + $accountMenuGroup = MenuGroup::create([ + 'name' => 'My Account', + 'identifier' => 'my-account' + ]); + + Menu::create([ + 'name' => 'Account Overview', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.home', + ]); + Menu::create([ + 'name' => 'Edit Account', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.edit', + ]); + Menu::create([ + 'name' => 'Upload Image', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.upload-image', + ]); + Menu::create([ + 'name' => 'My Orders', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.order.list', + ]); + Menu::create([ + 'name' => 'My Addresses', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.address.index', + ]); + Menu::create([ + 'name' => 'My Wishlist', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.wishlist.list', + ]); + Menu::create([ + 'name' => 'Change Password', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'my-account.change-password', + ]); + Menu::create([ + 'name' => 'Logout', + 'menu_group_id' => $accountMenuGroup->id, + 'route' => 'logout', + ]); + + $menuGroup = MenuGroup::create([ + 'name' => 'Main Menu', + 'identifier' => 'main-menu', + 'is_default' => 1 + ]); + + Menu::create([ + 'name' => 'My Account', + 'menu_group_id' => $menuGroup->id, + 'route' => 'my-account.home', + 'sort_order' => 400 + ]); + Menu::create([ + 'name' => 'Cart', + 'menu_group_id' => $menuGroup->id, + 'route' => 'cart.view', + 'sort_order' => 500 + ]); + Menu::create([ + 'name' => 'Checkout', + 'menu_group_id' => $menuGroup->id, + 'route' => 'checkout.index', + 'sort_order' => 600 + ]); } /** diff --git a/resources/views/system/tax-rate/_fields.blade.php b/resources/views/system/tax-rate/_fields.blade.php index cc7133813..30492356f 100644 --- a/resources/views/system/tax-rate/_fields.blade.php +++ b/resources/views/system/tax-rate/_fields.blade.php @@ -1,28 +1,6 @@ @include('avored-framework::forms.text', ['name' => 'name', 'label' => 'Name']) @include('avored-framework::forms.textarea', ['name' => 'description', 'label' => 'Description']) @include('avored-framework::forms.select', ['name' => 'country_id', 'label' => 'Country', 'options' => $countryOptions]) -@include('avored-framework::forms.select', ['name' => 'state_id', 'label' => 'State', 'options' => []]) @include('avored-framework::forms.text', ['name' => 'postcode', 'label' => 'Postcode']) @include('avored-framework::forms.text', ['name' => 'rate', 'label' => 'Rate']) -@push('scripts') - -@endpush diff --git a/src/Models/Repository/CategoryRepository.php b/src/Models/Repository/CategoryRepository.php index 92e8e29da..e623ddbc8 100644 --- a/src/Models/Repository/CategoryRepository.php +++ b/src/Models/Repository/CategoryRepository.php @@ -86,7 +86,7 @@ public function create($data) */ public function getCategoryProductWithFilter($categoryId, $filters = []) { - $prefix = config('database.connections.mysql.prefix'); + $prefix = env('DB_TABLE_PREFIX', 'avored_'); $propetryInnerJoinFlag = false; $attributeInnerJoinFlag = false; diff --git a/src/Product/Controllers/ProductController.php b/src/Product/Controllers/ProductController.php index 276617078..f4aa4c373 100644 --- a/src/Product/Controllers/ProductController.php +++ b/src/Product/Controllers/ProductController.php @@ -138,7 +138,6 @@ public function update(ProductRequest $request, Product $product) public function destroy($id) { Product::destroy($id); - return redirect()->route('admin.product.index'); } diff --git a/src/System/Controllers/TaxRateController.php b/src/System/Controllers/TaxRateController.php index fae472db9..af6d6fe86 100644 --- a/src/System/Controllers/TaxRateController.php +++ b/src/System/Controllers/TaxRateController.php @@ -75,13 +75,16 @@ public function store(TaxRateRequest $request) /** * Show the form for editing the specified resource. * - * @param \AvoRed\Framework\Models\Database\State $state + * @param \AvoRed\Framework\Models\Database\TaxRate $taxRate * @return \Illuminate\Http\Response */ public function edit(TaxRate $taxRate) { + $countryOptions = $this->countryRepository->all()->pluck('name', 'id'); + return view('avored-framework::system.tax-rate.edit') - ->with('model', $taxRate); + ->with('model', $taxRate) + ->withCountryOptions($countryOptions); ; } diff --git a/src/System/Middleware/SiteCurrencyMiddleware.php b/src/System/Middleware/SiteCurrencyMiddleware.php index 2815dda93..8175ec53e 100644 --- a/src/System/Middleware/SiteCurrencyMiddleware.php +++ b/src/System/Middleware/SiteCurrencyMiddleware.php @@ -75,6 +75,9 @@ public function handle($request, Closure $next) $currencyCode = $siteCurrencyModel->code; $currencySymbol = $siteCurrencyModel->symbol; + } else { + $siteCurrencyModel = $this->curRep->findByCode($currencyCode); + $currencySymbol = $siteCurrencyModel->symbol; } $sessionCode = Session::get('currency_code', $currencyCode); diff --git a/src/System/Requests/TaxRateRequest.php b/src/System/Requests/TaxRateRequest.php index ed6b6b08a..e54b268dc 100644 --- a/src/System/Requests/TaxRateRequest.php +++ b/src/System/Requests/TaxRateRequest.php @@ -24,8 +24,7 @@ public function authorize() public function rules() { $validation['name'] = 'required|max:255'; - $validation['description'] = 'required|max:255'; - + return $validation; } } diff --git a/tests/Controller/ProductTest.php b/tests/Controller/ProductTest.php index e3a4d10ea..c8d4fa42b 100644 --- a/tests/Controller/ProductTest.php +++ b/tests/Controller/ProductTest.php @@ -58,6 +58,27 @@ public function testBasicProductRosourceRouteTest() } + /** @test */ + public function testProductEditRoute() + { + $product = factory(Product::class)->create(); + $user = $this->_getAdminUser(); + + $response = $this->actingAs($user, 'admin')->get(route('admin.product.edit', $product->id)); + $response->assertStatus(200); + } + + /** @test */ + public function testProductDeleteRoute() + { + $product = factory(Product::class)->create(); + $user = $this->_getAdminUser(); + + $response = $this->actingAs($user, 'admin')->delete(route('admin.product.destroy', $product->id)); + $response->assertStatus(302); + $response->assertRedirect(route('admin.product.index')); + } + private function _getBasicDummyData($updateData = null) { $data['name'] = 'product test name';