From 7899bddebdd58061c7865b1f62c28cdf43bd74f3 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Mon, 8 Jul 2019 13:14:22 +1200 Subject: [PATCH 01/16] updated doc block --- src/Database/Contracts/CategoryFilterModelInterface.php | 4 ++-- src/Database/Repository/CategoryRepository.php | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Database/Contracts/CategoryFilterModelInterface.php b/src/Database/Contracts/CategoryFilterModelInterface.php index febe1a6d3..0c0f2a0a2 100644 --- a/src/Database/Contracts/CategoryFilterModelInterface.php +++ b/src/Database/Contracts/CategoryFilterModelInterface.php @@ -32,9 +32,9 @@ public function findByCategoryId(int $id) : Collection; /** * Delete CategoryFilter Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All CategoryFilter from the database diff --git a/src/Database/Repository/CategoryRepository.php b/src/Database/Repository/CategoryRepository.php index 6a1b65eef..01b2ddbfe 100644 --- a/src/Database/Repository/CategoryRepository.php +++ b/src/Database/Repository/CategoryRepository.php @@ -53,15 +53,12 @@ public function getCategoryProducts(Request $request) : Collection $query->whereSlug('avored'); }); - - $i = 0; foreach ($request->except(['slug', '_token']) as $key => $values) { list ($filterType , $paramSuffix) = $this->splitParam($key); if ($filterType === 'PROPERTY') { - $builder = $this->filterProperties($builder, $paramSuffix, $values, $i); + $builder = $this->filterProperties($builder, $paramSuffix, $values); } - $i++; } return $builder->get(); @@ -98,7 +95,7 @@ public function options() : SupportCollection * filter properties via builder * @return \Illuminate\Database\Eloquent\Builder $builder */ - private function filterProperties($builder, $paramSuffix, $values, $index) + private function filterProperties($builder, $paramSuffix, $values) { $property = Property::whereSlug($paramSuffix)->first(); From 1e351319f58e517f531ba3e3f377ab7d51e5fb7c Mon Sep 17 00:00:00 2001 From: Purvesh Date: Wed, 10 Jul 2019 14:43:12 +1200 Subject: [PATCH 02/16] tab setup for system configuration --- resources/lang/en/system.php | 9 +++ .../configuration/cards/basic.blade.php | 22 ++++++ .../configuration/cards/payment.blade.php | 22 ++++++ .../configuration/cards/shipping.blade.php | 22 ++++++ .../system/configuration/cards/user.blade.php | 22 ++++++ .../system/configuration/index.blade.php | 72 ++++++------------- src/Support/Providers/TabProvider.php | 27 ++++++- .../Controllers/ConfigurationController.php | 4 ++ 8 files changed, 146 insertions(+), 54 deletions(-) create mode 100644 resources/views/system/configuration/cards/basic.blade.php create mode 100644 resources/views/system/configuration/cards/payment.blade.php create mode 100644 resources/views/system/configuration/cards/shipping.blade.php create mode 100644 resources/views/system/configuration/cards/user.blade.php diff --git a/resources/lang/en/system.php b/resources/lang/en/system.php index d7dad87b5..50321df29 100644 --- a/resources/lang/en/system.php +++ b/resources/lang/en/system.php @@ -38,6 +38,15 @@ 'cancel' => 'Cancel', 'create' => 'Create' ], + 'tab' => [ + 'basic_info' => 'Basic Info', + 'images' => 'Images', + 'property' => 'Property', + 'basic_configuration' => 'Basic Settings', + 'user_configuration' => 'User Settings', + 'payment_configuration' => 'Payment Settings', + 'shipping_configuration' => 'Shipping Settings', + ], 'admin-user' => [ 'first_name' => 'First Name', 'last_name' => 'Last Name', diff --git a/resources/views/system/configuration/cards/basic.blade.php b/resources/views/system/configuration/cards/basic.blade.php new file mode 100644 index 000000000..11531ae4d --- /dev/null +++ b/resources/views/system/configuration/cards/basic.blade.php @@ -0,0 +1,22 @@ + has('site_name')) + validate-status="error" + help="{{ $errors->first('site_name') }}" + @endif + label="{{ __('avored::system.configuration.basic.site_name') }}"> + + diff --git a/resources/views/system/configuration/cards/payment.blade.php b/resources/views/system/configuration/cards/payment.blade.php new file mode 100644 index 000000000..1e603fedf --- /dev/null +++ b/resources/views/system/configuration/cards/payment.blade.php @@ -0,0 +1,22 @@ + has('site_name')) + validate-status="error" + help="{{ $errors->first('site_name') }}" + @endif + label="{{ __('avored::system.configuration.basic.payment_name') }}"> + + diff --git a/resources/views/system/configuration/cards/shipping.blade.php b/resources/views/system/configuration/cards/shipping.blade.php new file mode 100644 index 000000000..e150c9733 --- /dev/null +++ b/resources/views/system/configuration/cards/shipping.blade.php @@ -0,0 +1,22 @@ + has('site_name')) + validate-status="error" + help="{{ $errors->first('site_name') }}" + @endif + label="{{ __('avored::system.configuration.basic.shipping_name') }}"> + + diff --git a/resources/views/system/configuration/cards/user.blade.php b/resources/views/system/configuration/cards/user.blade.php new file mode 100644 index 000000000..9ffc140fa --- /dev/null +++ b/resources/views/system/configuration/cards/user.blade.php @@ -0,0 +1,22 @@ + has('site_name')) + validate-status="error" + help="{{ $errors->first('site_name') }}" + @endif + label="{{ __('avored::system.configuration.basic.user_name') }}"> + + diff --git a/resources/views/system/configuration/index.blade.php b/resources/views/system/configuration/index.blade.php index 12c754722..340a58db3 100644 --- a/resources/views/system/configuration/index.blade.php +++ b/resources/views/system/configuration/index.blade.php @@ -11,59 +11,31 @@ @section('content') - - - + + diff --git a/src/Support/Providers/TabProvider.php b/src/Support/Providers/TabProvider.php index ac769ec21..0c3ca8ae7 100644 --- a/src/Support/Providers/TabProvider.php +++ b/src/Support/Providers/TabProvider.php @@ -61,18 +61,39 @@ public function registerTabs() { Tab::put('catalog.product', function (TabItem $tab) { $tab->key('catalog.product.info') - ->label('Basic Info') + ->label('avored::system.tab.basic_info') ->view('avored::catalog.product._fields'); }); Tab::put('catalog.product', function (TabItem $tab) { $tab->key('catalog.product.image') - ->label('Images') + ->label('avored::system.tab.images') ->view('avored::catalog.product.cards.images'); }); Tab::put('catalog.product', function (TabItem $tab) { $tab->key('catalog.product.property') - ->label('Property') + ->label('avored::system.tab.property') ->view('avored::catalog.product.cards.property'); }); + + Tab::put('system.configuration', function (TabItem $tab) { + $tab->key('system.configuration.basic') + ->label('avored::system.tab.basic_configuration') + ->view('avored::system.configuration.cards.basic'); + }); + Tab::put('system.configuration', function (TabItem $tab) { + $tab->key('system.configuration.user') + ->label('avored::system.tab.user_configuration') + ->view('avored::system.configuration.cards.user'); + }); + Tab::put('system.configuration', function (TabItem $tab) { + $tab->key('system.configuration.shipping') + ->label('avored::system.tab.shipping_configuration') + ->view('avored::system.configuration.cards.shipping'); + }); + Tab::put('system.configuration', function (TabItem $tab) { + $tab->key('system.configuration.payment') + ->label('avored::system.tab.payment_configuration') + ->view('avored::system.configuration.cards.payment'); + }); } } diff --git a/src/System/Controllers/ConfigurationController.php b/src/System/Controllers/ConfigurationController.php index 0003da094..03de586a6 100644 --- a/src/System/Controllers/ConfigurationController.php +++ b/src/System/Controllers/ConfigurationController.php @@ -3,6 +3,7 @@ use Illuminate\Http\Request; use AvoRed\Framework\Database\Contracts\ConfigurationModelInterface; +use AvoRed\Framework\Support\Facades\Tab; class ConfigurationController { @@ -28,7 +29,10 @@ public function __construct( */ public function index() { + $tabs = Tab::get('system.configuration'); + return view('avored::system.configuration.index') + ->with('tabs', $tabs) ->with('repository', $this->configurationRepository); } From af6406c4e8cc046befd01acfe81fa5c511b419d5 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Thu, 11 Jul 2019 11:01:50 +1200 Subject: [PATCH 03/16] fixed the bug.. few updates --- src/Database/Repository/CategoryRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database/Repository/CategoryRepository.php b/src/Database/Repository/CategoryRepository.php index 01b2ddbfe..15ea67f09 100644 --- a/src/Database/Repository/CategoryRepository.php +++ b/src/Database/Repository/CategoryRepository.php @@ -49,8 +49,8 @@ public function findBySlug(string $slug): Category */ public function getCategoryProducts(Request $request) : Collection { - $builder = Product::whereHas('categories', function ($query) { - $query->whereSlug('avored'); + $builder = Product::whereHas('categories', function ($query) use ($request) { + $query->whereSlug($request->get('slug')); }); foreach ($request->except(['slug', '_token']) as $key => $values) { From e6e74243ef2c1265638392247af2d5f0b5351852 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Sat, 13 Jul 2019 12:44:26 +1200 Subject: [PATCH 04/16] updated doc block --- src/Database/Contracts/AddressModelInterface.php | 4 ++-- src/Database/Contracts/AttributeModelInterface.php | 4 ++-- src/Database/Contracts/CategoryModelInterface.php | 4 ++-- src/Database/Contracts/CurrencyModelInterface.php | 4 ++-- src/Database/Contracts/MenuModelInterface.php | 4 ++-- src/Database/Contracts/OrderModelInterface.php | 4 ++-- src/Database/Contracts/OrderStatusModelInterface.php | 4 ++-- src/Database/Contracts/PageModelInterface.php | 4 ++-- src/Database/Contracts/PropertyModelInterface.php | 4 ++-- src/Database/Contracts/StateModelInterface.php | 4 ++-- src/Database/Models/Product.php | 10 ++++++++++ src/Database/Repository/AddressRepository.php | 4 ++-- src/Database/Repository/AttributeRepository.php | 4 ++-- src/Database/Repository/CategoryRepository.php | 4 ++-- src/Database/Repository/CurrencyRepository.php | 4 ++-- src/Database/Repository/MenuRepository.php | 4 ++-- src/Database/Repository/OrderRepository.php | 4 ++-- src/Database/Repository/OrderStatusRepository.php | 4 ++-- src/Database/Repository/PageRepository.php | 4 ++-- src/Database/Repository/PropertyRepository.php | 4 ++-- src/Database/Repository/StateRepository.php | 4 ++-- src/Support/Providers/TabProvider.php | 5 +++++ 22 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/Database/Contracts/AddressModelInterface.php b/src/Database/Contracts/AddressModelInterface.php index 8f14b72fe..bdad7c22a 100644 --- a/src/Database/Contracts/AddressModelInterface.php +++ b/src/Database/Contracts/AddressModelInterface.php @@ -32,9 +32,9 @@ public function getByUserId(int $userId) : Collection; /** * Delete Address Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Address from the database diff --git a/src/Database/Contracts/AttributeModelInterface.php b/src/Database/Contracts/AttributeModelInterface.php index 7c10a75fd..140baafd4 100644 --- a/src/Database/Contracts/AttributeModelInterface.php +++ b/src/Database/Contracts/AttributeModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : Attribute; /** * Delete Attribute Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Attribute from the database diff --git a/src/Database/Contracts/CategoryModelInterface.php b/src/Database/Contracts/CategoryModelInterface.php index 2b5d5cb62..eea2c4d22 100644 --- a/src/Database/Contracts/CategoryModelInterface.php +++ b/src/Database/Contracts/CategoryModelInterface.php @@ -32,9 +32,9 @@ public function findBySlug(string $slug) : Category; /** * Delete Category Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Category from the database diff --git a/src/Database/Contracts/CurrencyModelInterface.php b/src/Database/Contracts/CurrencyModelInterface.php index 443fdea78..4e4d0b52f 100644 --- a/src/Database/Contracts/CurrencyModelInterface.php +++ b/src/Database/Contracts/CurrencyModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : Currency; /** * Delete Currency Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Currency from the database diff --git a/src/Database/Contracts/MenuModelInterface.php b/src/Database/Contracts/MenuModelInterface.php index f74e664f6..20a714cf8 100644 --- a/src/Database/Contracts/MenuModelInterface.php +++ b/src/Database/Contracts/MenuModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : Menu; /** * Delete Menu Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Menu from the database diff --git a/src/Database/Contracts/OrderModelInterface.php b/src/Database/Contracts/OrderModelInterface.php index 36aa93091..1e9aafe5a 100644 --- a/src/Database/Contracts/OrderModelInterface.php +++ b/src/Database/Contracts/OrderModelInterface.php @@ -31,9 +31,9 @@ public function findByUserId(int $id) : Collection; /** * Delete Order Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Order from the database diff --git a/src/Database/Contracts/OrderStatusModelInterface.php b/src/Database/Contracts/OrderStatusModelInterface.php index 2fe968680..51dc05390 100644 --- a/src/Database/Contracts/OrderStatusModelInterface.php +++ b/src/Database/Contracts/OrderStatusModelInterface.php @@ -31,9 +31,9 @@ public function findDefault() : OrderStatus; /** * Delete OrderStatus Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All OrderStatus from the database diff --git a/src/Database/Contracts/PageModelInterface.php b/src/Database/Contracts/PageModelInterface.php index b4ff2b983..0669a7f36 100644 --- a/src/Database/Contracts/PageModelInterface.php +++ b/src/Database/Contracts/PageModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : Page; /** * Delete Page Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Page from the database diff --git a/src/Database/Contracts/PropertyModelInterface.php b/src/Database/Contracts/PropertyModelInterface.php index 014de5483..b902806d3 100644 --- a/src/Database/Contracts/PropertyModelInterface.php +++ b/src/Database/Contracts/PropertyModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : Property; /** * Delete Property Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All Property from the database diff --git a/src/Database/Contracts/StateModelInterface.php b/src/Database/Contracts/StateModelInterface.php index 956c2d9ca..bfd548f84 100644 --- a/src/Database/Contracts/StateModelInterface.php +++ b/src/Database/Contracts/StateModelInterface.php @@ -24,9 +24,9 @@ public function find(int $id) : State; /** * Delete State Resource from a database * @param int $id - * @return bool + * @return int */ - public function delete(int $id) : bool; + public function delete(int $id) : int; /** * Get All State from the database diff --git a/src/Database/Models/Product.php b/src/Database/Models/Product.php index 43810aafe..e03e71dee 100644 --- a/src/Database/Models/Product.php +++ b/src/Database/Models/Product.php @@ -132,6 +132,16 @@ public function productPropertyDatetimeValues() return $this->hasMany(ProductPropertyDatetimeValue::class); } + /** + * Create Product Variation and Store it into DB + * @param \Illiminate\Http\Request $request + * @return mixed + */ + public function createProductVariation($request) + { + dd($request->all()); + } + /** * Get to Many Properties * @return \Illuminate\Database\Eloquent\Collection diff --git a/src/Database/Repository/AddressRepository.php b/src/Database/Repository/AddressRepository.php index ec5bb4301..4ed23169c 100644 --- a/src/Database/Repository/AddressRepository.php +++ b/src/Database/Repository/AddressRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Address /** * Delete Address Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Address $address + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Address::destroy($id); } diff --git a/src/Database/Repository/AttributeRepository.php b/src/Database/Repository/AttributeRepository.php index 251cb5627..a82d0fb96 100644 --- a/src/Database/Repository/AttributeRepository.php +++ b/src/Database/Repository/AttributeRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Attribute /** * Delete Attribute Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Attribute $property + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Attribute::destroy($id); } diff --git a/src/Database/Repository/CategoryRepository.php b/src/Database/Repository/CategoryRepository.php index 15ea67f09..8c61b48a0 100644 --- a/src/Database/Repository/CategoryRepository.php +++ b/src/Database/Repository/CategoryRepository.php @@ -66,9 +66,9 @@ public function getCategoryProducts(Request $request) : Collection /** * Delete Category Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Category $category + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Category::destroy($id); } diff --git a/src/Database/Repository/CurrencyRepository.php b/src/Database/Repository/CurrencyRepository.php index 5f8b0f6f5..6c15b27fa 100644 --- a/src/Database/Repository/CurrencyRepository.php +++ b/src/Database/Repository/CurrencyRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Currency /** * Delete Currency Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Currency $currency + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Currency::destroy($id); } diff --git a/src/Database/Repository/MenuRepository.php b/src/Database/Repository/MenuRepository.php index 116dc10ef..c0b3fd154 100644 --- a/src/Database/Repository/MenuRepository.php +++ b/src/Database/Repository/MenuRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Menu /** * Delete Menu Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Menu $menu + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Menu::destroy($id); } diff --git a/src/Database/Repository/OrderRepository.php b/src/Database/Repository/OrderRepository.php index 062faa01e..7cbd5abd6 100644 --- a/src/Database/Repository/OrderRepository.php +++ b/src/Database/Repository/OrderRepository.php @@ -41,9 +41,9 @@ public function findByUserId(int $id) : Collection /** * Delete Order Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Order $order + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Order::destroy($id); } diff --git a/src/Database/Repository/OrderStatusRepository.php b/src/Database/Repository/OrderStatusRepository.php index 1742aa8ec..18e0b1d71 100644 --- a/src/Database/Repository/OrderStatusRepository.php +++ b/src/Database/Repository/OrderStatusRepository.php @@ -41,9 +41,9 @@ public function findDefault(): OrderStatus /** * Delete OrderStatus Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\OrderStatus $orderStatus + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return OrderStatus::destroy($id); } diff --git a/src/Database/Repository/PageRepository.php b/src/Database/Repository/PageRepository.php index 122704155..9c4ac1695 100644 --- a/src/Database/Repository/PageRepository.php +++ b/src/Database/Repository/PageRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Page /** * Delete Page Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Page $page + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Page::destroy($id); } diff --git a/src/Database/Repository/PropertyRepository.php b/src/Database/Repository/PropertyRepository.php index 6191201a7..9b2f3f598 100644 --- a/src/Database/Repository/PropertyRepository.php +++ b/src/Database/Repository/PropertyRepository.php @@ -31,9 +31,9 @@ public function find(int $id): Property /** * Delete Property Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Property $property + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return Property::destroy($id); } diff --git a/src/Database/Repository/StateRepository.php b/src/Database/Repository/StateRepository.php index e035ba56d..37b22f756 100644 --- a/src/Database/Repository/StateRepository.php +++ b/src/Database/Repository/StateRepository.php @@ -31,9 +31,9 @@ public function find(int $id): State /** * Delete State Resource from a database * @param int $id - * @return \AvoRed\Framework\Database\Models\State $state + * @return int */ - public function delete(int $id): bool + public function delete(int $id): int { return State::destroy($id); } diff --git a/src/Support/Providers/TabProvider.php b/src/Support/Providers/TabProvider.php index 0c3ca8ae7..a3a65a116 100644 --- a/src/Support/Providers/TabProvider.php +++ b/src/Support/Providers/TabProvider.php @@ -74,6 +74,11 @@ public function registerTabs() ->label('avored::system.tab.property') ->view('avored::catalog.product.cards.property'); }); + Tab::put('catalog.product', function (TabItem $tab) { + $tab->key('catalog.product.attribute') + ->label('avored::system.tab.attribute') + ->view('avored::catalog.product.cards.attribute'); + }); Tab::put('system.configuration', function (TabItem $tab) { $tab->key('system.configuration.basic') From 9b3fef1b31999cd9a604a91adcb085823cd4bb3f Mon Sep 17 00:00:00 2001 From: Purvesh Date: Sat, 13 Jul 2019 17:40:10 +1200 Subject: [PATCH 05/16] product attribute in progress --- ...7_03_29_000000_avored_framework_schema.php | 36 +++++++ .../catalog/product/ProductSave.vue | 68 +++++++++++++ resources/lang/en/catalog.php | 3 + resources/lang/en/system.php | 1 + resources/less/app.less | 5 + .../catalog/product/cards/attribute.blade.php | 39 ++++++++ routes/web.php | 4 + src/Breadcrumb/Breadcrumb.php | 9 +- src/Catalog/Controllers/ProductController.php | 96 ++++++++++++++++++- src/Database/Models/Attribute.php | 11 ++- src/Database/Models/Product.php | 22 +++-- .../Controllers/DashboardController.php | 35 +++++++ 12 files changed, 309 insertions(+), 20 deletions(-) create mode 100644 resources/views/catalog/product/cards/attribute.blade.php 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 1ec9a3f96..a6f29b83d 100644 --- a/database/migrations/2017_03_29_000000_avored_framework_schema.php +++ b/database/migrations/2017_03_29_000000_avored_framework_schema.php @@ -428,6 +428,38 @@ public function up() $table->timestamps(); }); + Schema::create('attribute_product', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('attribute_id'); + $table->unsignedBigInteger('product_id'); + + $table->foreign('attribute_id')->references('id')->on('attributes'); + $table->foreign('product_id')->references('id')->on('products'); + $table->timestamps(); + }); + + Schema::create('attribute_product_values', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('attribute_id'); + $table->unsignedBigInteger('product_id'); + $table->unsignedBigInteger('attribute_dropdown_option_id'); + + $table->foreign('attribute_id')->references('id')->on('attributes'); + $table->foreign('product_id')->references('id')->on('products'); + $table->foreign('attribute_dropdown_option_id')->references('id')->on('attribute_dropdown_options'); + $table->timestamps(); + }); + + Schema::create('product_variations', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('variation_id'); + $table->unsignedBigInteger('product_id'); + + $table->foreign('variation_id')->references('id')->on('products'); + $table->foreign('product_id')->references('id')->on('products'); + $table->timestamps(); + }); + $path = __DIR__ . '/../../assets/countries.json'; $json = json_decode(file_get_contents($path), true); foreach ($json as $country) { @@ -451,6 +483,10 @@ public function down() { Schema::disableForeignKeyConstraints(); + + Schema::dropIfExists('attribute_product'); + Schema::dropIfExists('attribute_product_values'); + Schema::dropIfExists('product_variations'); Schema::dropIfExists('category_filters'); Schema::dropIfExists('addresses'); Schema::dropIfExists('order_product'); diff --git a/resources/components/catalog/product/ProductSave.vue b/resources/components/catalog/product/ProductSave.vue index 8143f9225..e5a895b6f 100644 --- a/resources/components/catalog/product/ProductSave.vue +++ b/resources/components/catalog/product/ProductSave.vue @@ -4,6 +4,55 @@ import isObject from 'lodash/isObject'; import { quillEditor } from 'vue-quill-editor'; import axios from 'axios' +const columns = [{ + dataIndex: 'name', + key: 'name', + title: 'Name' +}, { + title: 'Price', + dataIndex: 'price', + key: 'price', +}, { + title: 'Qty', + dataIndex: 'qty', + key: 'qty', +}, { + title: 'Attributes', + key: 'attributes', + dataIndex: 'attributes', + scopedSlots: { customRender: 'attributes' }, +}, { + title: 'Action', + key: 'action', + scopedSlots: { customRender: 'action' }, +}]; + +const variationData = [ + { + key: '1', + name: 'Product 1', + price: 32, + qty: 3, + attributes: ['color', 'size'], + }, + { + key: '2', + name: 'Product 2', + price: 32, + qty: 3, + attributes: ['color', 'size'], + }, + { + key: '3', + name: 'Product 3', + price: 32, + qty: 3, + attributes: ['color', 'size'], + }, +]; + + + export default { props: ['product', 'baseUrl', 'productProperties'], components: { @@ -20,6 +69,9 @@ export default { categories: [], property: {}, productImages: [], + productAttribute: [], + columns, + variationData }; }, methods: { @@ -30,6 +82,22 @@ export default { } }); }, + handleVariationBtnClick(e) { + let data = { attributes: this.productAttribute}; + let url = '/admin/variation/'+ this.product.id +'/create-variation'; + axios.post(url, data) + .then(res => { + console.log(res); + }); + + //@todo make ajax request + + }, + changeVariation(values) { + this.productAttribute = []; + let app = this; + values.forEach(val => app.productAttribute.push(val)); + }, handlePropertyChange(id, val) { let propertyValue = '' propertyValue = val diff --git a/resources/lang/en/catalog.php b/resources/lang/en/catalog.php index f162fb561..374da25ce 100644 --- a/resources/lang/en/catalog.php +++ b/resources/lang/en/catalog.php @@ -30,8 +30,10 @@ ], ], 'product' => [ + 'variation_title' => 'Product Variations', 'basic_card_title' => 'Basic Information', 'property_card_title' => 'Product Property', + 'attribute_card_title' => 'Attribute', 'title' => 'Product', 'name' => 'Name', 'slug' => 'Slug', @@ -54,6 +56,7 @@ 'meta_description' => 'Meta Description', 'image_title' => 'Product Images', 'upload_btn' => 'Upload', + 'variation_btn' => 'Make Variation', 'index' => [ 'title' => 'Product List' ], diff --git a/resources/lang/en/system.php b/resources/lang/en/system.php index 50321df29..9d4c656a8 100644 --- a/resources/lang/en/system.php +++ b/resources/lang/en/system.php @@ -42,6 +42,7 @@ 'basic_info' => 'Basic Info', 'images' => 'Images', 'property' => 'Property', + 'attribute' => 'Attribute', 'basic_configuration' => 'Basic Settings', 'user_configuration' => 'User Settings', 'payment_configuration' => 'Payment Settings', diff --git a/resources/less/app.less b/resources/less/app.less index 73598113f..5ddeed286 100644 --- a/resources/less/app.less +++ b/resources/less/app.less @@ -9,6 +9,11 @@ @import 'helper/margin'; @import 'helper/padding'; +.attribute-dropdown .ant-select-arrow{ + top: 5px; + right: 0px; +} + .header-avtar .anticon { margin-right: 0px; } diff --git a/resources/views/catalog/product/cards/attribute.blade.php b/resources/views/catalog/product/cards/attribute.blade.php new file mode 100644 index 000000000..b7e03484a --- /dev/null +++ b/resources/views/catalog/product/cards/attribute.blade.php @@ -0,0 +1,39 @@ + + +
+ Add Variation +
+

Attribute Content

+

+ + @foreach ($attributes as $attribute) + + {{ $attribute->name }} + + @endforeach + +

+ + {{ __('avored::catalog.product.variation_btn') }} + +
+

+ +

{{ __('avored::catalog.product.variation_title') }}

+ + + @{{text}} + Name + + @{{attribute}} + + + Edit + + Delete + + + + + +
diff --git a/routes/web.php b/routes/web.php index 575ee1353..c5f1739f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,6 +48,10 @@ Route::post('admin-user-image', 'System\Controllers\AdminUserController@upload') ->name('admin-user-image-upload'); + Route::post( + 'variation/{product}/create-variation', + 'Catalog\Controllers\ProductController@createVariation' + )->name('product.create.variation'); Route::post( 'product-image/{product}/upload', 'Catalog\Controllers\ProductController@upload' diff --git a/src/Breadcrumb/Breadcrumb.php b/src/Breadcrumb/Breadcrumb.php index c19787423..b9b6e96fd 100644 --- a/src/Breadcrumb/Breadcrumb.php +++ b/src/Breadcrumb/Breadcrumb.php @@ -22,23 +22,16 @@ class Breadcrumb implements BreadcrumbInterface /** * Breadcrumb Route Parents. - * @var string + * @var \Illuminate\Support\Collection */ public $parents = null; - /** - * Breadcrumb Callable. - * @var callable - */ - protected $callable = null; - /** * AvoRed BreakCrumb Construct method. * @param callable $callable */ public function __construct($callable) { - $this->callback = $callable; $this->parents = new Collection(); $callable($this); diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index 37e193f84..8bc236981 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -14,6 +14,9 @@ use AvoRed\Framework\Database\Models\Property; use AvoRed\Framework\Database\Contracts\CategoryFilterModelInterface; use AvoRed\Framework\Database\Models\CategoryFilter; +use AvoRed\Framework\Database\Contracts\AttributeModelInterface; +use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; class ProductController { @@ -40,6 +43,12 @@ class ProductController * @var \AvoRed\Framework\Database\Repository\PropertyRepository $propertyRepository */ protected $propertyRepository; + + /** + * Attribute Repository for the Product Controller + * @var \AvoRed\Framework\Database\Repository\AttributeRepository $attributeRepository + */ + protected $attributeRepository; /** * Construct for the AvoRed install command @@ -47,17 +56,20 @@ class ProductController * @param \AvoRed\Framework\Database\Contracts\CategoryModelInterface $categoryRepository * @param \AvoRed\Framework\Database\Contracts\PropertyModelInterface $propertyRepository * @param \AvoRed\Framework\Database\Contracts\CategoryFilterModelInterface $categoryFilterRepository + * @param \AvoRed\Framework\Database\Contracts\AttributeModelInterface $attributeRepository */ public function __construct( ProductModelInterface $productRepository, CategoryModelInterface $categoryRepository, PropertyModelInterface $propertyRepository, - CategoryFilterModelInterface $categoryFilterRepository + CategoryFilterModelInterface $categoryFilterRepository, + AttributeModelInterface $attributeRepository ) { $this->productRepository = $productRepository; $this->categoryRepository = $categoryRepository; $this->propertyRepository = $propertyRepository; $this->categoryFilterRepository = $categoryFilterRepository; + $this->attributeRepository = $attributeRepository; } /** @@ -112,12 +124,14 @@ public function edit(Product $product) $typeOptions = Product::PRODUCT_TYPES; $categoryOptions = $this->categoryRepository->options(); $properties = $this->propertyRepository->allPropertyToUseInProduct(); + $attributes = $this->attributeRepository->all(); return view('avored::catalog.product.edit') ->with('product', $product) ->with('categoryOptions', $categoryOptions) ->with('typeOptions', $typeOptions) ->with('properties', $properties) + ->with('attributes', $attributes) ->with('tabs', $tabs); } @@ -182,6 +196,19 @@ public function upload(ProductImageRequest $request, Product $product) return response()->json(['image' => $imageModel]); } + /** + * Create Product Variation based on given Attributes + * @param \Illuminate\Http\Request $request + * @param \AvoRed\Framework\Database\Models\Product $product + * @return \Illuminate\Http\JsonResponse + */ + public function createVariation(Request $request, Product $product) + { + $this->createProductVariation($product, $request); + + return response()->json(['success' => true]); + } + /** * Destroy Product Images * @param \AvoRed\Framework\Database\Models\ProductImage $productImage @@ -297,4 +324,71 @@ private function attachePropertyWithCategories(Property $property, Product $prod } } } + + /** + * @param \AvoRed\Framework\Database\Models\Product $product + * @param \Illuminate\Http\Request $request + * @return mixed + */ + private function createProductVariation($product, $request) + { + $variations = $this->getVariationsCollection($product, $request); + + //Store Product Attribute Values + //Create Variable Profile + // Store PRoduct and Variation Product IdS + + dd($variations); + } + + /** + * Get the Attribute Model from Request + * @param \AvoRed\Framework\Database\Models\Product $product + * @param \Illuminate\Http\Request $request + * @return array $variations + */ + private function getVariationsCollection($product, $request) + { + $attributeOptions = Collection::make([]); + $variations = Collection::make([]); + if ($request->get('attributes') !== null && count($request->get('attributes')) > 0) { + foreach ($request->get('attributes') as $attributeId) { + $attributeModel = $this->attributeRepository->find($attributeId); + $attributeOptions->push($attributeModel->dropdownOptions->pluck('id')); + } + $product->attributes()->sync($request->get('attributes')); + } + + return $this->makeCombinations($attributeOptions->toArray()); + } + + /** + * Generate all the possible combinations among a set of nested arrays. + * + * @param array $data The entrypoint array container. + * @param array $all The final container (used internally). + * @param array $group The sub container (used internally). + * @param mixed $val The value to append (used internally). + * @param int $i The key index (used internally). + */ + private function makeCombinations(array $data, array &$all = array(), array $group = array(), $value = null, $i = 0) + { + $keys = array_keys($data); + + if (isset($value) === true) { + array_push($group, $value); + } + + if ($i >= count($data)) { + array_push($all, $group); + } else { + $currentKey = $keys[$i]; + $currentElement = $data[$currentKey]; + foreach ($currentElement as $val) { + $this->makeCombinations($data, $all, $group, $val, $i + 1); + } + } + + return $all; + } } diff --git a/src/Database/Models/Attribute.php b/src/Database/Models/Attribute.php index 95e7d4562..5dcca6ee3 100644 --- a/src/Database/Models/Attribute.php +++ b/src/Database/Models/Attribute.php @@ -19,7 +19,7 @@ class Attribute extends Model protected $appends = ['dropdown']; /** - * Property has many dropdown options + * Attribute has many dropdown options * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function dropdownOptions() @@ -27,6 +27,15 @@ public function dropdownOptions() return $this->hasMany(AttributeDropdownOption::class); } + /** + * Attribute Belongs to many Products + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function products() + { + return $this->belongsToMany(Product::class); + } + /** * Get the Dropdown Options for Select * @return \Illuminate\Database\Eloquent\Collection diff --git a/src/Database/Models/Product.php b/src/Database/Models/Product.php index e03e71dee..8771328cc 100644 --- a/src/Database/Models/Product.php +++ b/src/Database/Models/Product.php @@ -107,6 +107,7 @@ public function productPropertyDecimalValues() { return $this->hasMany(ProductPropertyDecimalValue::class); } + /** * Product has many Product Text Property Values * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -115,6 +116,16 @@ public function productPropertyTextValues() { return $this->hasMany(ProductPropertyTextValue::class); } + + /** + * Product has many Product Text Property Values + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function attributes() + { + return $this->belongsToMany(Attribute::class); + } + /** * Product has many Product Boolean Property Values * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -123,6 +134,7 @@ public function productPropertyBooleanValues() { return $this->hasMany(ProductPropertyBooleanValue::class); } + /** * Product has many Product Date Time Property Values * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -132,16 +144,6 @@ public function productPropertyDatetimeValues() return $this->hasMany(ProductPropertyDatetimeValue::class); } - /** - * Create Product Variation and Store it into DB - * @param \Illiminate\Http\Request $request - * @return mixed - */ - public function createProductVariation($request) - { - dd($request->all()); - } - /** * Get to Many Properties * @return \Illuminate\Database\Eloquent\Collection diff --git a/src/System/Controllers/DashboardController.php b/src/System/Controllers/DashboardController.php index cb117ffb2..256b20737 100644 --- a/src/System/Controllers/DashboardController.php +++ b/src/System/Controllers/DashboardController.php @@ -1,6 +1,9 @@ bigIncrements('id'); + $table->unsignedBigInteger('attribute_id'); + $table->unsignedBigInteger('product_id'); + + $table->foreign('attribute_id')->references('id')->on('attributes'); + $table->foreign('product_id')->references('id')->on('products'); + $table->timestamps(); + }); + + Schema::create('attribute_product_values', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('attribute_id'); + $table->unsignedBigInteger('product_id'); + $table->unsignedBigInteger('attribute_dropdown_option_id'); + + $table->foreign('attribute_id')->references('id')->on('attributes'); + $table->foreign('product_id')->references('id')->on('products'); + $table->foreign('attribute_dropdown_option_id')->references('id')->on('attribute_dropdown_options'); + $table->timestamps(); + }); + + Schema::create('product_variations', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('variation_id'); + $table->unsignedBigInteger('product_id'); + + $table->foreign('variation_id')->references('id')->on('products'); + $table->foreign('product_id')->references('id')->on('products'); + $table->timestamps(); + }); + return view('avored::admin'); } } From 5a8f8d8015a83907bf2763538251659722ae66c2 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Sat, 13 Jul 2019 17:42:57 +1200 Subject: [PATCH 06/16] fixed the test --- .../Controllers/DashboardController.php | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/src/System/Controllers/DashboardController.php b/src/System/Controllers/DashboardController.php index 256b20737..cb117ffb2 100644 --- a/src/System/Controllers/DashboardController.php +++ b/src/System/Controllers/DashboardController.php @@ -1,9 +1,6 @@ bigIncrements('id'); - $table->unsignedBigInteger('attribute_id'); - $table->unsignedBigInteger('product_id'); - - $table->foreign('attribute_id')->references('id')->on('attributes'); - $table->foreign('product_id')->references('id')->on('products'); - $table->timestamps(); - }); - - Schema::create('attribute_product_values', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->unsignedBigInteger('attribute_id'); - $table->unsignedBigInteger('product_id'); - $table->unsignedBigInteger('attribute_dropdown_option_id'); - - $table->foreign('attribute_id')->references('id')->on('attributes'); - $table->foreign('product_id')->references('id')->on('products'); - $table->foreign('attribute_dropdown_option_id')->references('id')->on('attribute_dropdown_options'); - $table->timestamps(); - }); - - Schema::create('product_variations', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->unsignedBigInteger('variation_id'); - $table->unsignedBigInteger('product_id'); - - $table->foreign('variation_id')->references('id')->on('products'); - $table->foreign('product_id')->references('id')->on('products'); - $table->timestamps(); - }); - return view('avored::admin'); } } From 0608d2d0a32476adc235a715cea3fa0883b0d568 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Sun, 14 Jul 2019 11:27:37 +1200 Subject: [PATCH 07/16] product attribute feautre in progress --- ...7_03_29_000000_avored_framework_schema.php | 2 +- .../catalog/product/ProductSave.vue | 11 +- resources/lang/en/catalog.php | 1 + src/Catalog/Controllers/ProductController.php | 120 ++++++++++++++++-- .../AttributeDropdownOptionModelInterface.php | 36 ++++++ .../Contracts/AttributeModelInterface.php | 6 +- .../AttributeProductValueModelInterface.php | 45 +++++++ .../Contracts/ProductModelInterface.php | 7 + .../ProductVariationModelInterface.php | 36 ++++++ src/Database/Models/AttributeProductValue.php | 14 ++ src/Database/Models/Product.php | 10 ++ src/Database/Models/ProductVariation.php | 14 ++ .../AttributeDropdownOptionRepository.php | 49 +++++++ .../AttributeProductValueRepository.php | 64 ++++++++++ .../Repository/AttributeRepository.php | 8 +- src/Database/Repository/ProductRepository.php | 10 ++ .../Repository/ProductVariationRepository.php | 49 +++++++ src/Support/Providers/ModelProvider.php | 9 ++ 18 files changed, 473 insertions(+), 18 deletions(-) create mode 100644 src/Database/Contracts/AttributeDropdownOptionModelInterface.php create mode 100644 src/Database/Contracts/AttributeProductValueModelInterface.php create mode 100644 src/Database/Contracts/ProductVariationModelInterface.php create mode 100644 src/Database/Models/AttributeProductValue.php create mode 100644 src/Database/Models/ProductVariation.php create mode 100644 src/Database/Repository/AttributeDropdownOptionRepository.php create mode 100644 src/Database/Repository/AttributeProductValueRepository.php create mode 100644 src/Database/Repository/ProductVariationRepository.php 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 a6f29b83d..9183e248a 100644 --- a/database/migrations/2017_03_29_000000_avored_framework_schema.php +++ b/database/migrations/2017_03_29_000000_avored_framework_schema.php @@ -455,7 +455,7 @@ public function up() $table->unsignedBigInteger('variation_id'); $table->unsignedBigInteger('product_id'); - $table->foreign('variation_id')->references('id')->on('products'); + $table->foreign('variation_id')->references('id')->on('products')->onDelete('cascade'); $table->foreign('product_id')->references('id')->on('products'); $table->timestamps(); }); diff --git a/resources/components/catalog/product/ProductSave.vue b/resources/components/catalog/product/ProductSave.vue index e5a895b6f..a696080d2 100644 --- a/resources/components/catalog/product/ProductSave.vue +++ b/resources/components/catalog/product/ProductSave.vue @@ -85,9 +85,18 @@ export default { handleVariationBtnClick(e) { let data = { attributes: this.productAttribute}; let url = '/admin/variation/'+ this.product.id +'/create-variation'; + var app = this; axios.post(url, data) .then(res => { - console.log(res); + if (res.success) { + app.$notification.success({ + key: 'product.create.variation.success', + message: res.message, + }); + } + + window.location.reload(); + }); //@todo make ajax request diff --git a/resources/lang/en/catalog.php b/resources/lang/en/catalog.php index 374da25ce..d709bc947 100644 --- a/resources/lang/en/catalog.php +++ b/resources/lang/en/catalog.php @@ -31,6 +31,7 @@ ], 'product' => [ 'variation_title' => 'Product Variations', + 'variation_create_msg' => 'Product Variation Created Successfully!', 'basic_card_title' => 'Basic Information', 'property_card_title' => 'Product Property', 'attribute_card_title' => 'Attribute', diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index 8bc236981..43f6d0727 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -17,6 +17,10 @@ use AvoRed\Framework\Database\Contracts\AttributeModelInterface; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; +use AvoRed\Framework\Database\Contracts\AttributeProductValueModelInterface; +use AvoRed\Framework\Database\Contracts\AttributeDropdownOptionModelInterface; +use Illuminate\Support\Str; +use AvoRed\Framework\Database\Contracts\ProductVariationModelInterface; class ProductController { @@ -49,6 +53,24 @@ class ProductController * @var \AvoRed\Framework\Database\Repository\AttributeRepository $attributeRepository */ protected $attributeRepository; + + /** + * Attribute product value repository for the product controller + * @var \AvoRed\Framework\Database\Repository\AttributeProductValueRepository $attributeProductValueRepository + */ + protected $attributeProductValueRepository; + + /** + * Attribute product value repository for the product controller + * @var \AvoRed\Framework\Database\Repository\AttributeDropdownOptionModelInterface $attributeDropdownOptionRepository + */ + protected $attributeDropdownOptionRepository; + + /** + * Attribute product value repository for the product controller + * @var \AvoRed\Framework\Database\Repository\ProductVariationModelInterface $productVariationRepository + */ + protected $productVariationRepository; /** * Construct for the AvoRed install command @@ -57,19 +79,28 @@ class ProductController * @param \AvoRed\Framework\Database\Contracts\PropertyModelInterface $propertyRepository * @param \AvoRed\Framework\Database\Contracts\CategoryFilterModelInterface $categoryFilterRepository * @param \AvoRed\Framework\Database\Contracts\AttributeModelInterface $attributeRepository + * @param \AvoRed\Framework\Database\Contracts\AttributeProductValueModelInterface $attributeProductValueRepository + * @param \AvoRed\Framework\Database\Contracts\AttributeDropdownOptionModelInterface $attributeDropdownOptionRepository + * @param \AvoRed\Framework\Database\Contracts\ProductVariationModelInterface $productVariationRepository */ public function __construct( ProductModelInterface $productRepository, CategoryModelInterface $categoryRepository, PropertyModelInterface $propertyRepository, CategoryFilterModelInterface $categoryFilterRepository, - AttributeModelInterface $attributeRepository + AttributeModelInterface $attributeRepository, + AttributeProductValueModelInterface $attributeProductValueRepository, + AttributeDropdownOptionModelInterface $attributeDropdownOptionRepository, + ProductVariationModelInterface $productVariationRepository ) { $this->productRepository = $productRepository; $this->categoryRepository = $categoryRepository; $this->propertyRepository = $propertyRepository; $this->categoryFilterRepository = $categoryFilterRepository; $this->attributeRepository = $attributeRepository; + $this->attributeProductValueRepository = $attributeProductValueRepository; + $this->attributeDropdownOptionRepository = $attributeDropdownOptionRepository; + $this->productVariationRepository = $productVariationRepository; } /** @@ -204,9 +235,9 @@ public function upload(ProductImageRequest $request, Product $product) */ public function createVariation(Request $request, Product $product) { - $this->createProductVariation($product, $request); + $this->makeProductVariation($product, $request); - return response()->json(['success' => true]); + return response()->json(['success' => true, 'message' => __('avored::catalog.product.variation_create_msg')]); } /** @@ -330,15 +361,57 @@ private function attachePropertyWithCategories(Property $property, Product $prod * @param \Illuminate\Http\Request $request * @return mixed */ - private function createProductVariation($product, $request) + private function makeProductVariation($product, $request) { $variations = $this->getVariationsCollection($product, $request); + $this->createProductVariations($product, $variations); + } + + /** + * @param \AvoRed\Framework\Database\Models\Product $product + * @param \Illuminate\Support\Collection $variations + * @return void + */ + private function createProductVariations($product, $variations) + { + $variationIds = $product->variations->pluck('variation_id'); + + foreach ($variationIds as $variationId) { + $this->productRepository->delete($variationId); + } + foreach ($variations as $variation) { + $this->generateProductData($product, $variation); + } + } + + /** + * Generate Product Data based on given variation id + * @param \AvoRed\Framework\Database\Models\Product $product + * @param array $variation + * @return array $data + */ + private function generateProductData($product, $variation) + { + $data = [ + 'name' => $product->name, + 'type' => 'VARIATION', + 'qty' => $product->qty, + 'price' => $product->price, + 'cost_price' => $product->cost_price, + 'weight' => $product->weight, + 'height' => $product->height, + 'width' => $product->width, + 'length' => $product->length, + ]; + foreach ($variation as $optionId) { + $optionModel = $this->attributeDropdownOptionRepository->find($optionId); + $data['name'] .= ' ' . $optionModel->display_text; + } - //Store Product Attribute Values - //Create Variable Profile - // Store PRoduct and Variation Product IdS + $data['sku'] = Str::slug($data['name']); - dd($variations); + $variation = $this->productRepository->create($data); + $this->productVariationRepository->create(['product_id' => $product->id, 'variation_id' => $variation->id]); } /** @@ -354,7 +427,9 @@ private function getVariationsCollection($product, $request) if ($request->get('attributes') !== null && count($request->get('attributes')) > 0) { foreach ($request->get('attributes') as $attributeId) { $attributeModel = $this->attributeRepository->find($attributeId); - $attributeOptions->push($attributeModel->dropdownOptions->pluck('id')); + $optionIds = $attributeModel->dropdownOptions->pluck('id'); + $attributeOptions->push($optionIds); + $this->saveAttributeProductValue($product, $attributeId, $optionIds); } $product->attributes()->sync($request->get('attributes')); } @@ -362,6 +437,33 @@ private function getVariationsCollection($product, $request) return $this->makeCombinations($attributeOptions->toArray()); } + /** + * Store attribute product values into database + * @param Product $product + * @param int $attributeId + * @param Collection $attributeOptionIds + * @return void + */ + private function saveAttributeProductValue($product, $attributeId, $attributeOptionIds) + { + foreach ($attributeOptionIds as $optionId) { + $model = $this->attributeProductValueRepository->findByAttributeProductValues( + $product->id, + $attributeId, + $optionId + ); + + if ($model === null) { + $data = [ + 'product_id' => $product->id, + 'attribute_id' => $attributeId, + 'attribute_dropdown_option_id' => $optionId + ]; + $this->attributeProductValueRepository->create($data); + } + } + } + /** * Generate all the possible combinations among a set of nested arrays. * diff --git a/src/Database/Contracts/AttributeDropdownOptionModelInterface.php b/src/Database/Contracts/AttributeDropdownOptionModelInterface.php new file mode 100644 index 000000000..a54801098 --- /dev/null +++ b/src/Database/Contracts/AttributeDropdownOptionModelInterface.php @@ -0,0 +1,36 @@ +hasMany(ProductImage::class); } + + /** + * Belongs to Many Product Images + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function variations() + { + return $this->hasMany(ProductVariation::class, 'product_id'); + } + /** * Get Main Image Url * @return string $mainImageUrl diff --git a/src/Database/Models/ProductVariation.php b/src/Database/Models/ProductVariation.php new file mode 100644 index 000000000..2f1529228 --- /dev/null +++ b/src/Database/Models/ProductVariation.php @@ -0,0 +1,14 @@ +whereAttributeId($attributeId) + ->whereAttributeDropdownOptionId($optionId) + ->first(); + } + + /** + * Get all the attribute product values from the connected database + * @return \Illuminate\Database\Eloquent\Collection $attributeProductValues + */ + public function all() : Collection + { + return AttributeProductValue::all(); + } +} diff --git a/src/Database/Repository/AttributeRepository.php b/src/Database/Repository/AttributeRepository.php index a82d0fb96..bc0170659 100644 --- a/src/Database/Repository/AttributeRepository.php +++ b/src/Database/Repository/AttributeRepository.php @@ -11,7 +11,7 @@ class AttributeRepository implements AttributeModelInterface /** * Create Attribute Resource into a database * @param array $data - * @return \AvoRed\Framework\Database\Models\Attribute $property + * @return \AvoRed\Framework\Database\Models\Attribute $attribute */ public function create(array $data): Attribute { @@ -21,7 +21,7 @@ public function create(array $data): Attribute /** * Find Attribute Resource into a database * @param int $id - * @return \AvoRed\Framework\Database\Models\Attribute $property + * @return \AvoRed\Framework\Database\Models\Attribute $attribute */ public function find(int $id): Attribute { @@ -39,8 +39,8 @@ public function delete(int $id): int } /** - * Get all the properties from the connected database - * @return \Illuminate\Database\Eloquent\Collection $properties + * Get all the attributes from the connected database + * @return \Illuminate\Database\Eloquent\Collection $attributes */ public function all() : Collection { diff --git a/src/Database/Repository/ProductRepository.php b/src/Database/Repository/ProductRepository.php index d909493aa..5b1f6af78 100644 --- a/src/Database/Repository/ProductRepository.php +++ b/src/Database/Repository/ProductRepository.php @@ -36,4 +36,14 @@ public function all() : Collection { return Product::all(); } + + /** + * Delete Product Resource from a database + * @param int $id + * @return int + */ + public function delete(int $id): int + { + return Product::destroy($id); + } } diff --git a/src/Database/Repository/ProductVariationRepository.php b/src/Database/Repository/ProductVariationRepository.php new file mode 100644 index 000000000..b7a2060ea --- /dev/null +++ b/src/Database/Repository/ProductVariationRepository.php @@ -0,0 +1,49 @@ + AddressRepository::class, AdminUserModelInterface::class => AdminUserRepository::class, AttributeModelInterface::class => AttributeRepository::class, + AttributeDropdownOptionModelInterface::class => AttributeDropdownOptionRepository::class, + AttributeProductValueModelInterface::class => AttributeProductValueRepository::class, CategoryModelInterface::class => CategoryRepository::class, CategoryFilterModelInterface::class => CategoryFilterRepository::class, ConfigurationModelInterface::class => ConfigurationRepository::class, @@ -77,6 +85,7 @@ class ModelProvider extends ServiceProvider PermissionModelInterface::class => PermissionRepository::class, PageModelInterface::class => PageRepository::class, ProductModelInterface::class => ProductRepository::class, + ProductVariationModelInterface::class => ProductVariationRepository::class, ProductImageModelInterface::class => ProductImageRepository::class, MenuModelInterface::class => MenuRepository::class, PropertyModelInterface::class => PropertyRepository::class, From ad48916128e4b857eb02dd70b59e2f7a92980c34 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Sun, 14 Jul 2019 17:18:46 +1200 Subject: [PATCH 08/16] product attribute backend feature almost finished --- .../catalog/product/ProductSave.vue | 96 +++---- resources/lang/en/catalog.php | 3 + .../catalog/product/cards/attribute.blade.php | 236 +++++++++++++++++- .../views/catalog/product/edit.blade.php | 2 + routes/web.php | 5 + src/Catalog/Controllers/ProductController.php | 19 +- .../Contracts/ProductModelInterface.php | 15 ++ src/Database/Models/ProductVariation.php | 25 ++ src/Database/Repository/ProductRepository.php | 19 ++ 9 files changed, 362 insertions(+), 58 deletions(-) diff --git a/resources/components/catalog/product/ProductSave.vue b/resources/components/catalog/product/ProductSave.vue index a696080d2..4ef691fb6 100644 --- a/resources/components/catalog/product/ProductSave.vue +++ b/resources/components/catalog/product/ProductSave.vue @@ -7,60 +7,33 @@ import axios from 'axios' const columns = [{ dataIndex: 'name', key: 'name', - title: 'Name' + title: 'Name', + scopedSlots: { customRender: 'name' }, }, { title: 'Price', dataIndex: 'price', key: 'price', + scopedSlots: { customRender: 'price' }, }, { title: 'Qty', dataIndex: 'qty', key: 'qty', -}, { - title: 'Attributes', - key: 'attributes', - dataIndex: 'attributes', - scopedSlots: { customRender: 'attributes' }, + scopedSlots: { customRender: 'qty' }, }, { title: 'Action', key: 'action', scopedSlots: { customRender: 'action' }, }]; -const variationData = [ - { - key: '1', - name: 'Product 1', - price: 32, - qty: 3, - attributes: ['color', 'size'], - }, - { - key: '2', - name: 'Product 2', - price: 32, - qty: 3, - attributes: ['color', 'size'], - }, - { - key: '3', - name: 'Product 3', - price: 32, - qty: 3, - attributes: ['color', 'size'], - }, -]; - - - export default { - props: ['product', 'baseUrl', 'productProperties'], + props: ['product', 'baseUrl', 'productProperties', 'productAttributes', 'productVariations'], components: { 'quil-editor': quillEditor, }, data () { return { productForm: this.$form.createForm(this), + variationForm: this.$form.createForm(this), type: null, description: null, status: 0, @@ -69,12 +42,54 @@ export default { categories: [], property: {}, productImages: [], - productAttribute: [], columns, - variationData + variationModelVisible: false, + variationFields: ['id', 'name', 'slug', 'barcode', 'sku', 'qty', 'price', 'weight', 'length', 'width', 'height'] }; }, + computed: { + // a computed getter + productAttributeIds: function () { + let ids = []; + + this.productAttributes.forEach(element => { + ids.push(element.id) + }); + + return ids; + } + }, methods: { + clickVariationSave(e) { + this.variationForm.validateFields((err, data) => { + if (isNil(err)) { + let url = '/admin/variation/'+ this.product.id +'/save-variation'; + var app = this; + + axios.post(url, data) + .then(res => { + if (res.data.success) { + app.$notification.success({ + key: 'product.save.variation.success', + message: res.data.message, + }); + window.location.reload(); + } else { + alert('there is an error') + } + }) + } + }); + }, + showVariationModel(model) { + this.variationModelVisible = true; + var variationModel = model.variationModel; + + this.variationFields.forEach(field => { + this.variationForm.getFieldDecorator(field, {initialValue: variationModel[field]}) + }); + + }, handleSubmit(e) { this.productForm.validateFields((err, values) => { if (err !== null) { @@ -93,14 +108,11 @@ export default { key: 'product.create.variation.success', message: res.message, }); + window.location.reload(); + } else { + alert('there is an error') } - - window.location.reload(); - - }); - - //@todo make ajax request - + }) }, changeVariation(values) { this.productAttribute = []; diff --git a/resources/lang/en/catalog.php b/resources/lang/en/catalog.php index d709bc947..f93b9014f 100644 --- a/resources/lang/en/catalog.php +++ b/resources/lang/en/catalog.php @@ -32,9 +32,12 @@ 'product' => [ 'variation_title' => 'Product Variations', 'variation_create_msg' => 'Product Variation Created Successfully!', + 'variation_save_msg' => 'Product Variation Save Successfully!', 'basic_card_title' => 'Basic Information', 'property_card_title' => 'Product Property', 'attribute_card_title' => 'Attribute', + 'variation_save_btn' => 'Save Variation', + 'variation_model_title' => 'Save Variation', 'title' => 'Product', 'name' => 'Name', 'slug' => 'Slug', diff --git a/resources/views/catalog/product/cards/attribute.blade.php b/resources/views/catalog/product/cards/attribute.blade.php index b7e03484a..51cc8a232 100644 --- a/resources/views/catalog/product/cards/attribute.blade.php +++ b/resources/views/catalog/product/cards/attribute.blade.php @@ -5,9 +5,9 @@

Attribute Content

- + @foreach ($attributes as $attribute) - + {{ $attribute->name }} @endforeach @@ -21,19 +21,229 @@

{{ __('avored::catalog.product.variation_title') }}

- - @{{text}} - Name - - @{{attribute}} - + + @{{ record.variationModel.name }} + @{{ record.variationModel.price }} + @{{ record.variationModel.qty }} + - Edit - - Delete - + Edit + + Delete - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/views/catalog/product/edit.blade.php b/resources/views/catalog/product/edit.blade.php index a2d1cf9e9..a6a42971d 100644 --- a/resources/views/catalog/product/edit.blade.php +++ b/resources/views/catalog/product/edit.blade.php @@ -15,6 +15,8 @@ base-url="{{ asset(config('avored.admin_url')) }}" :product="{{ $product }}" :product-properties="{{ $product->getProperties() }}" + :product-attributes="{{ $product->attributes }}" + :product-variations="{{ $product->variations }}" inline-template>
name('product.create.variation'); + Route::post( + 'variation/{product}/save-variation', + 'Catalog\Controllers\ProductController@saveVariation' + )->name('product.save.variation'); + Route::post( 'product-image/{product}/upload', 'Catalog\Controllers\ProductController@upload' diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index 43f6d0727..d3b1de3ad 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -156,7 +156,7 @@ public function edit(Product $product) $categoryOptions = $this->categoryRepository->options(); $properties = $this->propertyRepository->allPropertyToUseInProduct(); $attributes = $this->attributeRepository->all(); - + return view('avored::catalog.product.edit') ->with('product', $product) ->with('categoryOptions', $categoryOptions) @@ -240,6 +240,20 @@ public function createVariation(Request $request, Product $product) return response()->json(['success' => true, 'message' => __('avored::catalog.product.variation_create_msg')]); } + /** + * Save Product Variation based on given Attributes + * @param \Illuminate\Http\Request $request + * @param \AvoRed\Framework\Database\Models\Product $product + * @return \Illuminate\Http\JsonResponse + */ + public function saveVariation(Request $request, Product $product) + { + $productModel = $this->productRepository->find($request->get('id')); + $productModel->update($request->all()); + + return response()->json(['success' => true, 'message' => __('avored::catalog.product.variation_save_msg')]); + } + /** * Destroy Product Images * @param \AvoRed\Framework\Database\Models\ProductImage $productImage @@ -407,9 +421,8 @@ private function generateProductData($product, $variation) $optionModel = $this->attributeDropdownOptionRepository->find($optionId); $data['name'] .= ' ' . $optionModel->display_text; } - $data['sku'] = Str::slug($data['name']); - + $data['slug'] = Str::slug($data['name']); $variation = $this->productRepository->create($data); $this->productVariationRepository->create(['product_id' => $product->id, 'variation_id' => $variation->id]); } diff --git a/src/Database/Contracts/ProductModelInterface.php b/src/Database/Contracts/ProductModelInterface.php index 53599700d..00de9ff30 100644 --- a/src/Database/Contracts/ProductModelInterface.php +++ b/src/Database/Contracts/ProductModelInterface.php @@ -20,6 +20,21 @@ public function create(array $data) : Product; */ public function all() : Collection; + + /** + * Get all the products from the connected database + * @return \Illuminate\Database\Eloquent\Collection $products + */ + public function getAllWithoutVaiation() : Collection; + + + /** + * Find a Product by given id + * @param int $id + * @return \AvoRed\Framework\Database\Models\Product $product + */ + public function find(int $id): Product; + /** * Find a Product by given slug * @param string $slug diff --git a/src/Database/Models/ProductVariation.php b/src/Database/Models/ProductVariation.php index 2f1529228..def6d87d1 100644 --- a/src/Database/Models/ProductVariation.php +++ b/src/Database/Models/ProductVariation.php @@ -11,4 +11,29 @@ class ProductVariation extends Model * @var array */ protected $fillable = ['product_id', 'variation_id']; + + /** + * Appended attribute for the model + * @var array $appends + */ + protected $appends = ['variationModel']; + + /** + * Get the Productfor Select + * @return \AvoRed\Framework\Database\Models\Product + */ + public function getVariationModelAttribute() + { + return $this->variation; + } + + + /** + * Property has many datetime value + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function variation() + { + return $this->belongsTo(Product::class, 'variation_id'); + } } diff --git a/src/Database/Repository/ProductRepository.php b/src/Database/Repository/ProductRepository.php index 5b1f6af78..aaab663ee 100644 --- a/src/Database/Repository/ProductRepository.php +++ b/src/Database/Repository/ProductRepository.php @@ -28,6 +28,16 @@ public function findBySlug(string $slug): Product return Product::whereSlug($slug)->first(); } + /** + * Find a Product by given id + * @param int $id + * @return \AvoRed\Framework\Database\Models\Product $product + */ + public function find(int $id): Product + { + return Product::find($id); + } + /** * Get all the products from the connected database * @return \Illuminate\Database\Eloquent\Collection $products @@ -37,6 +47,15 @@ public function all() : Collection return Product::all(); } + /** + * Get all the products from the connected database + * @return \Illuminate\Database\Eloquent\Collection $products + */ + public function getAllWithoutVaiation() : Collection + { + return Product::where('type', '!=', 'VARIATION')->get(); + } + /** * Delete Product Resource from a database * @param int $id From 4f1345071bdd58e5ce82ef626aed9c23e50c2087 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Mon, 15 Jul 2019 09:29:02 +1200 Subject: [PATCH 09/16] product attribute in progress --- .../catalog/product/ProductSave.vue | 21 +++++++++++++++++-- resources/lang/en/catalog.php | 1 + .../catalog/product/cards/attribute.blade.php | 2 +- routes/web.php | 4 ++++ src/Catalog/Controllers/ProductController.php | 12 +++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/resources/components/catalog/product/ProductSave.vue b/resources/components/catalog/product/ProductSave.vue index 4ef691fb6..f192f82b1 100644 --- a/resources/components/catalog/product/ProductSave.vue +++ b/resources/components/catalog/product/ProductSave.vue @@ -63,7 +63,7 @@ export default { clickVariationSave(e) { this.variationForm.validateFields((err, data) => { if (isNil(err)) { - let url = '/admin/variation/'+ this.product.id +'/save-variation'; + let url = this.baseUrl + '/variation/'+ this.product.id +'/save-variation'; var app = this; axios.post(url, data) @@ -81,6 +81,23 @@ export default { } }); }, + deleteVariation(model) { + let url = this.baseUrl + '/variation/' + model.variation_id; + var app = this; + axios.delete(url) + .then(res => { + if (res.data.success) { + app.$notification.success({ + key: 'product.delete.variation.success', + message: res.data.message, + }); + window.location.reload(); + } else { + alert('there is an error') + } + }) + + }, showVariationModel(model) { this.variationModelVisible = true; var variationModel = model.variationModel; @@ -99,7 +116,7 @@ export default { }, handleVariationBtnClick(e) { let data = { attributes: this.productAttribute}; - let url = '/admin/variation/'+ this.product.id +'/create-variation'; + let url = this.baseUrl + '/variation/'+ this.product.id +'/create-variation'; var app = this; axios.post(url, data) .then(res => { diff --git a/resources/lang/en/catalog.php b/resources/lang/en/catalog.php index f93b9014f..2197d4e81 100644 --- a/resources/lang/en/catalog.php +++ b/resources/lang/en/catalog.php @@ -33,6 +33,7 @@ 'variation_title' => 'Product Variations', 'variation_create_msg' => 'Product Variation Created Successfully!', 'variation_save_msg' => 'Product Variation Save Successfully!', + 'variation_delete_msg' => 'Product Variation Destroy Successfully!', 'basic_card_title' => 'Basic Information', 'property_card_title' => 'Product Property', 'attribute_card_title' => 'Attribute', diff --git a/resources/views/catalog/product/cards/attribute.blade.php b/resources/views/catalog/product/cards/attribute.blade.php index 51cc8a232..0cc246b54 100644 --- a/resources/views/catalog/product/cards/attribute.blade.php +++ b/resources/views/catalog/product/cards/attribute.blade.php @@ -29,7 +29,7 @@ Edit - Delete + Delete diff --git a/routes/web.php b/routes/web.php index 5a8daee58..b2af1d880 100644 --- a/routes/web.php +++ b/routes/web.php @@ -56,6 +56,10 @@ 'variation/{product}/save-variation', 'Catalog\Controllers\ProductController@saveVariation' )->name('product.save.variation'); + Route::delete( + 'variation/{product}', + 'Catalog\Controllers\ProductController@destroyVariation' + )->name('product.destroy.variation'); Route::post( 'product-image/{product}/upload', diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index d3b1de3ad..adf3b9c09 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -254,6 +254,18 @@ public function saveVariation(Request $request, Product $product) return response()->json(['success' => true, 'message' => __('avored::catalog.product.variation_save_msg')]); } + /** + * Delete Product Variation based on given Attributes + * @param \AvoRed\Framework\Database\Models\Product $product + * @return \Illuminate\Http\JsonResponse + */ + public function destroyVariation(Product $product) + { + $product->delete(); + + return response()->json(['success' => true, 'message' => __('avored::catalog.product.variation_delete_msg')]); + } + /** * Destroy Product Images * @param \AvoRed\Framework\Database\Models\ProductImage $productImage From b8a0418d76cbbb6aab293834de97ad928892f21a Mon Sep 17 00:00:00 2001 From: Purvesh Date: Mon, 15 Jul 2019 13:21:29 +1200 Subject: [PATCH 10/16] fixed product attribute backend bug --- .../catalog/product/ProductSave.vue | 32 ++++++------ .../catalog/product/cards/attribute.blade.php | 2 +- src/Catalog/Controllers/ProductController.php | 50 ++++++++++++++++--- .../CategoryFilterModelInterface.php | 10 ++++ .../Repository/CategoryFilterRepository.php | 20 ++++++++ 5 files changed, 89 insertions(+), 25 deletions(-) diff --git a/resources/components/catalog/product/ProductSave.vue b/resources/components/catalog/product/ProductSave.vue index f192f82b1..e73ca2861 100644 --- a/resources/components/catalog/product/ProductSave.vue +++ b/resources/components/catalog/product/ProductSave.vue @@ -42,23 +42,12 @@ export default { categories: [], property: {}, productImages: [], + attributeIds: [], columns, variationModelVisible: false, variationFields: ['id', 'name', 'slug', 'barcode', 'sku', 'qty', 'price', 'weight', 'length', 'width', 'height'] }; }, - computed: { - // a computed getter - productAttributeIds: function () { - let ids = []; - - this.productAttributes.forEach(element => { - ids.push(element.id) - }); - - return ids; - } - }, methods: { clickVariationSave(e) { this.variationForm.validateFields((err, data) => { @@ -115,15 +104,16 @@ export default { }); }, handleVariationBtnClick(e) { - let data = { attributes: this.productAttribute}; + let data = { attributes: this.attributeIds}; let url = this.baseUrl + '/variation/'+ this.product.id +'/create-variation'; var app = this; + axios.post(url, data) .then(res => { - if (res.success) { + if (res.data.success) { app.$notification.success({ key: 'product.create.variation.success', - message: res.message, + message: res.data.message, }); window.location.reload(); } else { @@ -132,9 +122,10 @@ export default { }) }, changeVariation(values) { - this.productAttribute = []; - let app = this; - values.forEach(val => app.productAttribute.push(val)); + var app = this; + values.forEach(val => { + app.attributeIds.push(val) + }); }, handlePropertyChange(id, val) { let propertyValue = '' @@ -200,6 +191,11 @@ export default { this.productProperties.forEach(record => { this.property[record.id] = record.product_value.value }); + + this.productAttributes.forEach(record => { + this.attributeIds.push(record.id) + }); + this.product.images.forEach(record => { this.productImages.push(record) }); diff --git a/resources/views/catalog/product/cards/attribute.blade.php b/resources/views/catalog/product/cards/attribute.blade.php index 0cc246b54..77a5b16e3 100644 --- a/resources/views/catalog/product/cards/attribute.blade.php +++ b/resources/views/catalog/product/cards/attribute.blade.php @@ -5,7 +5,7 @@

Attribute Content

- + @foreach ($attributes as $attribute) {{ $attribute->name }} diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index adf3b9c09..fd7b5ec7b 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -21,6 +21,7 @@ use AvoRed\Framework\Database\Contracts\AttributeDropdownOptionModelInterface; use Illuminate\Support\Str; use AvoRed\Framework\Database\Contracts\ProductVariationModelInterface; +use AvoRed\Framework\Database\Models\Attribute; class ProductController { @@ -362,6 +363,33 @@ private function saveProductImages(Product $product, $request) } } + /** + * Attach Given Property Model to a Product Categories + * @param \AvoRed\Framework\Database\Models\Attribute $attribute + * @param \AvoRed\Framework\Database\Models\Product $product + * @return void + */ + private function attacheAttributeWithCategories(Attribute $attribute, Product $product) + { + if ($product->categories !== null && $product->categories->count() > 0) { + foreach ($product->categories as $category) { + $categoryFilterFlag = $this->categoryFilterRepository->isCategoryFilterModelExist( + $category->id, + $attribute->id, + CategoryFilter::ATTRIBUTE_FILTER_TYPE + ); + if (!$categoryFilterFlag) { + $data = [ + 'category_id' => $category->id, + 'filter_id' => $attribute->id, + 'type' => CategoryFilter::ATTRIBUTE_FILTER_TYPE + ]; + $this->categoryFilterRepository->create($data); + } + } + } + } + /** * Attach Given Property Model to a Product Categories * @param \AvoRed\Framework\Database\Models\Property $property @@ -370,14 +398,22 @@ private function saveProductImages(Product $product, $request) */ private function attachePropertyWithCategories(Property $property, Product $product) { + if ($product->categories !== null && $product->categories->count() > 0) { foreach ($product->categories as $category) { - $data = [ - 'category_id' => $category->id, - 'filter_id' => $property->id, - 'type' => CategoryFilter::PROPERTY_FILTER_TYPE - ]; - $this->categoryFilterRepository->create($data); + $categoryFilterFlag = $this->categoryFilterRepository->isCategoryFilterModelExist( + $category->id, + $property->id, + CategoryFilter::PROPERTY_FILTER_TYPE + ); + if (!$categoryFilterFlag) { + $data = [ + 'category_id' => $category->id, + 'filter_id' => $property->id, + 'type' => CategoryFilter::PROPERTY_FILTER_TYPE + ]; + $this->categoryFilterRepository->create($data); + } } } } @@ -447,11 +483,13 @@ private function generateProductData($product, $variation) */ private function getVariationsCollection($product, $request) { + $attributeOptions = Collection::make([]); $variations = Collection::make([]); if ($request->get('attributes') !== null && count($request->get('attributes')) > 0) { foreach ($request->get('attributes') as $attributeId) { $attributeModel = $this->attributeRepository->find($attributeId); + $this->attacheAttributeWithCategories($attributeModel, $product); $optionIds = $attributeModel->dropdownOptions->pluck('id'); $attributeOptions->push($optionIds); $this->saveAttributeProductValue($product, $attributeId, $optionIds); diff --git a/src/Database/Contracts/CategoryFilterModelInterface.php b/src/Database/Contracts/CategoryFilterModelInterface.php index 0c0f2a0a2..fa801d708 100644 --- a/src/Database/Contracts/CategoryFilterModelInterface.php +++ b/src/Database/Contracts/CategoryFilterModelInterface.php @@ -29,6 +29,16 @@ public function find(int $id) : CategoryFilter; */ public function findByCategoryId(int $id) : Collection; + /** + * Find Category filter by given category and filter and type + * @param int $cateogryId + * @param int $filterId + * @param string $type + * @return mixex $categoryFilter + */ + public function isCategoryFilterModelExist(int $categoryId, int $filterId, $type); + + /** * Delete CategoryFilter Resource from a database * @param int $id diff --git a/src/Database/Repository/CategoryFilterRepository.php b/src/Database/Repository/CategoryFilterRepository.php index 82e9ad7d4..47e89f5b4 100644 --- a/src/Database/Repository/CategoryFilterRepository.php +++ b/src/Database/Repository/CategoryFilterRepository.php @@ -29,6 +29,26 @@ public function find(int $id): CategoryFilter { return CategoryFilter::find($id); } + + /** + * Find Category filter by given category and filter and type + * @param int $cateogryId + * @param int $filterId + * @param string $type + * @return mixex $categoryFilter + */ + public function isCategoryFilterModelExist(int $categoryId, int $filterId, $type) + { + $model = CategoryFilter::whereCategoryId($categoryId) + ->whereFilterId($filterId) + ->whereType($type)->first(); + + if ($model !== null) { + return true; + } + + return false; + } /** * Find CategoryFilters by given category id From faf9b75a7177f391af2d220c4c1edb51788270de Mon Sep 17 00:00:00 2001 From: Purvesh Date: Tue, 16 Jul 2019 10:44:20 +1200 Subject: [PATCH 11/16] product attribute few bug fixed --- ...7_03_29_000000_avored_framework_schema.php | 2 + src/Catalog/Controllers/ProductController.php | 42 +++++++++++-------- src/Catalog/Requests/ProductRequest.php | 4 -- .../Models/AttributeDropdownOption.php | 10 +++++ src/Database/Models/AttributeProductValue.php | 2 +- src/Database/Models/Product.php | 9 ++++ .../Repository/CategoryFilterRepository.php | 2 +- .../Repository/CategoryRepository.php | 23 ++++++++++ 8 files changed, 71 insertions(+), 23 deletions(-) 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 9183e248a..d6da2f24d 100644 --- a/database/migrations/2017_03_29_000000_avored_framework_schema.php +++ b/database/migrations/2017_03_29_000000_avored_framework_schema.php @@ -442,10 +442,12 @@ public function up() $table->bigIncrements('id'); $table->unsignedBigInteger('attribute_id'); $table->unsignedBigInteger('product_id'); + $table->unsignedBigInteger('variation_id'); $table->unsignedBigInteger('attribute_dropdown_option_id'); $table->foreign('attribute_id')->references('id')->on('attributes'); $table->foreign('product_id')->references('id')->on('products'); + $table->foreign('variation_id')->references('id')->on('products'); $table->foreign('attribute_dropdown_option_id')->references('id')->on('attribute_dropdown_options'); $table->timestamps(); }); diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index fd7b5ec7b..1fc147488 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -350,16 +350,18 @@ private function saveProductProperty($product, $request) private function saveProductImages(Product $product, $request) { $images = $request->get('images'); - $isMainImage = $request->get('is_main_image'); - foreach ($images as $id => $data) { - $imageModel = $product->images()->find($id); - $imageModel->alt_text = $data['alt_text'] ?? ''; - if ($isMainImage == $imageModel->id) { - $imageModel->is_main_image = 1; - } else { - $imageModel->is_main_image = 0; + if ($images !== null && $images->count() > 0) { + $isMainImage = $request->get('is_main_image'); + foreach ($images as $id => $data) { + $imageModel = $product->images()->find($id); + $imageModel->alt_text = $data['alt_text'] ?? ''; + if ($isMainImage == $imageModel->id) { + $imageModel->is_main_image = 1; + } else { + $imageModel->is_main_image = 0; + } + $imageModel->save(); } - $imageModel->save(); } } @@ -426,7 +428,7 @@ private function attachePropertyWithCategories(Property $property, Product $prod private function makeProductVariation($product, $request) { $variations = $this->getVariationsCollection($product, $request); - $this->createProductVariations($product, $variations); + //$this->createProductVariations($product, $variations); } /** @@ -449,10 +451,10 @@ private function createProductVariations($product, $variations) /** * Generate Product Data based on given variation id * @param \AvoRed\Framework\Database\Models\Product $product - * @param array $variation + * @param array $options * @return array $data */ - private function generateProductData($product, $variation) + private function generateProductData($product, $options) { $data = [ 'name' => $product->name, @@ -465,13 +467,17 @@ private function generateProductData($product, $variation) 'width' => $product->width, 'length' => $product->length, ]; - foreach ($variation as $optionId) { + foreach ($options as $optionId) { $optionModel = $this->attributeDropdownOptionRepository->find($optionId); $data['name'] .= ' ' . $optionModel->display_text; } $data['sku'] = Str::slug($data['name']); $data['slug'] = Str::slug($data['name']); + $variation = $this->productRepository->create($data); + $attributeId = $optionModel->attribute->id; + $this->saveAttributeProductValue($product, $attributeId, $options, $variation); + $this->productVariationRepository->create(['product_id' => $product->id, 'variation_id' => $variation->id]); } @@ -492,12 +498,12 @@ private function getVariationsCollection($product, $request) $this->attacheAttributeWithCategories($attributeModel, $product); $optionIds = $attributeModel->dropdownOptions->pluck('id'); $attributeOptions->push($optionIds); - $this->saveAttributeProductValue($product, $attributeId, $optionIds); } $product->attributes()->sync($request->get('attributes')); } - return $this->makeCombinations($attributeOptions->toArray()); + $combinations = $this->makeCombinations($attributeOptions->toArray()); + $this->createProductVariations($product, $combinations); } /** @@ -505,9 +511,10 @@ private function getVariationsCollection($product, $request) * @param Product $product * @param int $attributeId * @param Collection $attributeOptionIds + * @param \AvoRed\Framework\Database\Models\Product $variation * @return void */ - private function saveAttributeProductValue($product, $attributeId, $attributeOptionIds) + private function saveAttributeProductValue($product, $attributeId, $attributeOptionIds, $variation) { foreach ($attributeOptionIds as $optionId) { $model = $this->attributeProductValueRepository->findByAttributeProductValues( @@ -520,7 +527,8 @@ private function saveAttributeProductValue($product, $attributeId, $attributeOpt $data = [ 'product_id' => $product->id, 'attribute_id' => $attributeId, - 'attribute_dropdown_option_id' => $optionId + 'attribute_dropdown_option_id' => $optionId, + 'variation_id' => $variation->id ]; $this->attributeProductValueRepository->create($data); } diff --git a/src/Catalog/Requests/ProductRequest.php b/src/Catalog/Requests/ProductRequest.php index a2e46a585..61d6078c6 100644 --- a/src/Catalog/Requests/ProductRequest.php +++ b/src/Catalog/Requests/ProductRequest.php @@ -31,10 +31,6 @@ public function rules() $rules['type'] = 'required'; } - if (strtolower($this->method()) == 'put') { - $rules['is_main_image'] = 'required'; - } - return $rules; } } diff --git a/src/Database/Models/AttributeDropdownOption.php b/src/Database/Models/AttributeDropdownOption.php index 53f981458..dd688b1dd 100644 --- a/src/Database/Models/AttributeDropdownOption.php +++ b/src/Database/Models/AttributeDropdownOption.php @@ -11,4 +11,14 @@ class AttributeDropdownOption extends Model * @var array */ protected $fillable = ['attribute_id', 'display_text']; + + + /** + * Attribute dropdown option belongs to one attribute + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function attribute() + { + return $this->belongsTo(Attribute::class); + } } diff --git a/src/Database/Models/AttributeProductValue.php b/src/Database/Models/AttributeProductValue.php index 8e95e4c7d..a022211f6 100644 --- a/src/Database/Models/AttributeProductValue.php +++ b/src/Database/Models/AttributeProductValue.php @@ -10,5 +10,5 @@ class AttributeProductValue extends Model * The attributes that are mass assignable. * @var array */ - protected $fillable = ['attribute_id', 'product_id', 'attribute_dropdown_option_id']; + protected $fillable = ['attribute_id', 'product_id', 'variation_id', 'attribute_dropdown_option_id']; } diff --git a/src/Database/Models/Product.php b/src/Database/Models/Product.php index 4a2dd9071..a3b7c0804 100644 --- a/src/Database/Models/Product.php +++ b/src/Database/Models/Product.php @@ -92,6 +92,15 @@ public function properties() return $this->belongsToMany(Property::class); } + /** + * Product has many Product Interger Property Values + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function attributeProductValues() + { + return $this->hasMany(AttributeProductValue::class); + } + /** * Product has many Product Interger Property Values * @return \Illuminate\Database\Eloquent\Relations\HasMany diff --git a/src/Database/Repository/CategoryFilterRepository.php b/src/Database/Repository/CategoryFilterRepository.php index 47e89f5b4..5f87e2b67 100644 --- a/src/Database/Repository/CategoryFilterRepository.php +++ b/src/Database/Repository/CategoryFilterRepository.php @@ -57,7 +57,7 @@ public function isCategoryFilterModelExist(int $categoryId, int $filterId, $type */ public function findByCategoryId(int $id) : Collection { - return CategoryFilter::whereCategoryId($id)->get()->unique('filter_id'); + return CategoryFilter::whereCategoryId($id)->get(); } /** diff --git a/src/Database/Repository/CategoryRepository.php b/src/Database/Repository/CategoryRepository.php index 8c61b48a0..c76310431 100644 --- a/src/Database/Repository/CategoryRepository.php +++ b/src/Database/Repository/CategoryRepository.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\DB; use AvoRed\Framework\Database\Models\Product; use AvoRed\Framework\Database\Models\Property; +use AvoRed\Framework\Database\Models\Attribute; class CategoryRepository implements CategoryModelInterface { @@ -59,8 +60,14 @@ public function getCategoryProducts(Request $request) : Collection if ($filterType === 'PROPERTY') { $builder = $this->filterProperties($builder, $paramSuffix, $values); } + + if ($filterType === 'ATTRIBUTE') { + $builder = $this->filterAttributes($builder, $paramSuffix, $values); + } } + $builder->where('type', '!=', 'VARIATION'); + return $builder->get(); } /** @@ -108,6 +115,22 @@ private function filterProperties($builder, $paramSuffix, $values) return $builder; } + /** + * filter attributes via builder + * @return \Illuminate\Database\Eloquent\Builder $builder + */ + private function filterAttributes($builder, $paramSuffix, $values) + { + $attribute = Attribute::whereSlug($paramSuffix)->first(); + $builder->whereHas('attributeProductValues', function ($query) use ($attribute, $values) { + $query + ->whereAttributeId($attribute->id) + ->whereIn('attribute_dropdown_option_id', $values); + }); + + return $builder; + } + /** * Split the param and find out which type and etc * @return array From 0e6dbe622a5ecb67949f097dc742f7fbe7d538d4 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Tue, 16 Jul 2019 11:04:27 +1200 Subject: [PATCH 12/16] updated doc blocks --- .../Controllers/AttributeController.php | 17 ++++++------ .../Controllers/CategoryController.php | 18 ++++++------- src/Catalog/Controllers/ProductController.php | 14 +++++----- .../Controllers/PropertyController.php | 18 ++++++------- src/Cms/Controllers/MenuController.php | 18 ++----------- src/Cms/Controllers/PageController.php | 16 ++++++------ src/Models/Repository/MenuRepository.php | 6 ++--- .../Controllers/AdminUserController.php | 22 ++++++++-------- .../Controllers/ConfigurationController.php | 4 +-- src/System/Controllers/CurrencyController.php | 16 ++++++------ .../Controllers/DashboardController.php | 2 +- src/System/Controllers/LanguageController.php | 16 ++++++------ src/System/Controllers/RoleController.php | 26 ++++++------------- src/System/Controllers/StateController.php | 16 ++++++------ src/System/Controllers/TaxGroupController.php | 16 ++++++------ src/System/Controllers/TaxRateController.php | 16 ++++++------ src/User/Controllers/UserGroupController.php | 16 ++++++------ 17 files changed, 116 insertions(+), 141 deletions(-) diff --git a/src/Catalog/Controllers/AttributeController.php b/src/Catalog/Controllers/AttributeController.php index 565a32f22..46868217e 100644 --- a/src/Catalog/Controllers/AttributeController.php +++ b/src/Catalog/Controllers/AttributeController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -37,18 +37,17 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { - return view('avored::catalog.attribute.create'); } /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Catalog\Requests\AttributeRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(AttributeRequest $request) { @@ -65,7 +64,7 @@ public function store(AttributeRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Attribute $attribute - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Attribute $attribute) { @@ -77,7 +76,7 @@ public function edit(Attribute $attribute) * Update the specified resource in storage. * @param \AvoRed\Framework\Catalog\Requests\AttributeRequest $request * @param \AvoRed\Framework\Database\Models\Attribute $attribute - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(AttributeRequest $request, Attribute $attribute) { @@ -94,19 +93,19 @@ public function update(AttributeRequest $request, Attribute $attribute) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Attribute $attribute - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Attribute $attribute) { $attribute->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::catalog.attribute.title')] ) - ]; + ]); } /** diff --git a/src/Catalog/Controllers/CategoryController.php b/src/Catalog/Controllers/CategoryController.php index 7febad3dc..8ab649e2b 100644 --- a/src/Catalog/Controllers/CategoryController.php +++ b/src/Catalog/Controllers/CategoryController.php @@ -24,8 +24,8 @@ public function __construct( } /** - * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * Show Category Index Page + * @return \Illuminate\View\View */ public function index() { @@ -37,7 +37,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -47,7 +47,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Catalog\Requests\CategoryRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(CategoryRequest $request) { @@ -63,7 +63,7 @@ public function store(CategoryRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Category $category - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Category $category) { @@ -75,7 +75,7 @@ public function edit(Category $category) * Update the specified resource in storage. * @param \AvoRed\Framework\Catalog\Requests\CategoryRequest $request * @param \AvoRed\Framework\Database\Models\Category $category - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(CategoryRequest $request, Category $category) { @@ -91,18 +91,18 @@ public function update(CategoryRequest $request, Category $category) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Category $category - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Category $category) { $category->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::catalog.category.title')] ) - ]; + ]); } } diff --git a/src/Catalog/Controllers/ProductController.php b/src/Catalog/Controllers/ProductController.php index 1fc147488..c1c8cfc1a 100644 --- a/src/Catalog/Controllers/ProductController.php +++ b/src/Catalog/Controllers/ProductController.php @@ -106,7 +106,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Contracts\Support\Renderable + * @return \Illuminate\View\View */ public function index() { @@ -118,7 +118,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -130,7 +130,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Catalog\Requests\ProductRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(ProductRequest $request) { @@ -146,7 +146,7 @@ public function store(ProductRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Product $product - * @return \Illuminate\Contracts\Support\Renderable + * @return \Illuminate\View\View */ public function edit(Product $product) { @@ -191,19 +191,19 @@ public function update(ProductRequest $request, Product $product) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Product $product - * @return \Illuminate\Http\RedirectResponse + * @return \Illuminate\Http\JsonResponse */ public function destroy(Product $product) { $product->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::catalog.product.title')] ) - ]; + ]); } /** diff --git a/src/Catalog/Controllers/PropertyController.php b/src/Catalog/Controllers/PropertyController.php index 4828b8c3d..76795ebb6 100644 --- a/src/Catalog/Controllers/PropertyController.php +++ b/src/Catalog/Controllers/PropertyController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -37,7 +37,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -52,7 +52,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Catalog\Requests\PropertyRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(PropertyRequest $request) { @@ -69,7 +69,7 @@ public function store(PropertyRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Property $property - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Property $property) { @@ -86,7 +86,7 @@ public function edit(Property $property) * Update the specified resource in storage. * @param \AvoRed\Framework\Catalog\Requests\PropertyRequest $request * @param \AvoRed\Framework\Database\Models\Property $property - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(PropertyRequest $request, Property $property) { @@ -103,19 +103,19 @@ public function update(PropertyRequest $request, Property $property) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Property $property - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Property $property) { $property->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::catalog.property.title')] ) - ]; + ]); } /** @@ -124,7 +124,7 @@ public function destroy(Property $property) * @param \AvoRed\Framework\Catalog\Requests\PropertyRequest $request * @return void */ - public function savePropertyDropdownOptions(Property $property, PropertyRequest $request) + private function savePropertyDropdownOptions(Property $property, PropertyRequest $request) { if (!($request->get('field_type') === 'RADIO' || $request->get('field_type') === 'SELECT')) { $property->dropdownOptions()->delete(); diff --git a/src/Cms/Controllers/MenuController.php b/src/Cms/Controllers/MenuController.php index 3e903c710..f5209b5cb 100644 --- a/src/Cms/Controllers/MenuController.php +++ b/src/Cms/Controllers/MenuController.php @@ -35,7 +35,7 @@ public function __construct( /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -48,25 +48,11 @@ public function index() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Cms\Requests\MenuRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(MenuRequest $request) { -<<<<<<< HEAD $this->menuRepository->create($request->all()); -======= - $menuGroup = $this->menuGroupRepository - ->find($request->get('menu_group_id')); - if (null === $menuGroup) { - $menuGroup = $this->menuGroupRepository->create($request->all()); - } else { - $menuGroup->update($request->all()); - } - $menuJson = $request->get('menu_json'); - $menuArray = json_decode($menuJson); - - $this->repository->truncateAndCreateMenus($menuGroup, $menuArray); ->>>>>>> parent of 6f1e4cb... Merge pull request #69 from avored/dev return redirect()->route('admin.menu.index') ->with('successNotification', __('avored::system.notification.store', ['attribute' => 'Menu'])); diff --git a/src/Cms/Controllers/PageController.php b/src/Cms/Controllers/PageController.php index 4850da8e2..7ef8dd969 100644 --- a/src/Cms/Controllers/PageController.php +++ b/src/Cms/Controllers/PageController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -37,7 +37,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -47,7 +47,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Cms\Requests\PageRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(PageRequest $request) { @@ -60,7 +60,7 @@ public function store(PageRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Page $page - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Page $page) { @@ -72,7 +72,7 @@ public function edit(Page $page) * Update the specified resource in storage. * @param \AvoRed\Framework\Cms\Requests\PageRequest $request * @param \AvoRed\Framework\Database\Models\Page $page - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(PageRequest $request, Page $page) { @@ -85,15 +85,15 @@ public function update(PageRequest $request, Page $page) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Page $page - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Page $page) { $page->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => 'Page']) - ]; + ]); } } diff --git a/src/Models/Repository/MenuRepository.php b/src/Models/Repository/MenuRepository.php index 782849a1b..41e5afd84 100644 --- a/src/Models/Repository/MenuRepository.php +++ b/src/Models/Repository/MenuRepository.php @@ -78,11 +78,11 @@ public function truncateAndCreateMenus($menuGroup, $menus) { $menuGroup->menus()->delete(); foreach ($menus as $menu) { - $this->_saveMenu($menuGroup, $menu); + $this->saveMenu($menuGroup, $menu); } } - private function _saveMenu($menuGroup, $menus, $parentId = null) + private function saveMenu($menuGroup, $menus, $parentId = null) { foreach ($menus as $menu) { if (isset($menu->name)) { @@ -96,7 +96,7 @@ private function _saveMenu($menuGroup, $menus, $parentId = null) } if (isset($menu->children) && count($menu->children[0]) > 0) { - $this->_saveMenu($menuGroup, $menu->children[0], $menuModel->id); + $this->saveMenu($menuGroup, $menu->children[0], $menuModel->id); } } } diff --git a/src/System/Controllers/AdminUserController.php b/src/System/Controllers/AdminUserController.php index 005935162..8a4f39aff 100644 --- a/src/System/Controllers/AdminUserController.php +++ b/src/System/Controllers/AdminUserController.php @@ -37,7 +37,7 @@ public function __construct( } /** * Display a listing of the resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -49,7 +49,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -61,7 +61,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\System\Requests\AdminUserRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(AdminUserRequest $request) { @@ -76,7 +76,7 @@ public function store(AdminUserRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\AdminUser $adminUser - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(AdminUser $adminUser) { @@ -90,7 +90,7 @@ public function edit(AdminUser $adminUser) * Update the specified resource in storage. * @param \AvoRed\Framework\System\Requests\AdminUserRequest $request * @param \AvoRed\Framework\Database\Models\AdminUser $adminUser - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(AdminUserRequest $request, AdminUser $adminUser) { @@ -103,32 +103,32 @@ public function update(AdminUserRequest $request, AdminUser $adminUser) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\AdminUser $adminUser - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(AdminUser $adminUser) { $adminUser->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => 'AdminUser']) - ]; + ]); } /** * upload user image to file system. * @param \AvoRed\Framework\System\Requests\AdminUserImageRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function upload(AdminUserImageRequest $request) { $image = $request->file('image_file'); $path = $image->store('uploads/users', 'public'); - return [ + return response()->json([ 'success' => true, 'path' => $path, 'message' => __('avored::system.notification.upload', ['attribute' => 'Admin User Image']) - ]; + ]); } } diff --git a/src/System/Controllers/ConfigurationController.php b/src/System/Controllers/ConfigurationController.php index 03de586a6..0c3881630 100644 --- a/src/System/Controllers/ConfigurationController.php +++ b/src/System/Controllers/ConfigurationController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Configuration of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -38,7 +38,7 @@ public function index() /** * Show Configuration of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { diff --git a/src/System/Controllers/CurrencyController.php b/src/System/Controllers/CurrencyController.php index 56b9e2120..1a68d8631 100644 --- a/src/System/Controllers/CurrencyController.php +++ b/src/System/Controllers/CurrencyController.php @@ -36,7 +36,7 @@ public function __construct( } /** * Display a listing of the resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -48,7 +48,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -63,7 +63,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\System\Requests\CurrencyRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(CurrencyRequest $request) { @@ -79,7 +79,7 @@ public function store(CurrencyRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Currency $currency - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Currency $currency) { @@ -96,7 +96,7 @@ public function edit(Currency $currency) * Update the specified resource in storage. * @param \AvoRed\Framework\System\Requests\CurrencyRequest $request * @param \AvoRed\Framework\Database\Models\Currency $currency - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(CurrencyRequest $request, Currency $currency) { @@ -112,15 +112,15 @@ public function update(CurrencyRequest $request, Currency $currency) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Currency $currency - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Currency $currency) { $currency->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => __('avored::system.currency.title')]) - ]; + ]); } } diff --git a/src/System/Controllers/DashboardController.php b/src/System/Controllers/DashboardController.php index cb117ffb2..619614377 100644 --- a/src/System/Controllers/DashboardController.php +++ b/src/System/Controllers/DashboardController.php @@ -5,7 +5,7 @@ class DashboardController { /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { diff --git a/src/System/Controllers/LanguageController.php b/src/System/Controllers/LanguageController.php index da7ea429e..aca1df415 100644 --- a/src/System/Controllers/LanguageController.php +++ b/src/System/Controllers/LanguageController.php @@ -27,7 +27,7 @@ public function __construct( } /** * Display a listing of the resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -39,7 +39,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -49,7 +49,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\System\Requests\LanguageRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(LanguageRequest $request) { @@ -62,7 +62,7 @@ public function store(LanguageRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Language $language - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Language $language) { @@ -74,7 +74,7 @@ public function edit(Language $language) * Update the specified resource in storage. * @param \AvoRed\Framework\System\Requests\LanguageRequest $request * @param \AvoRed\Framework\Database\Models\Language $language - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(LanguageRequest $request, Language $language) { @@ -87,15 +87,15 @@ public function update(LanguageRequest $request, Language $language) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Language $language - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Language $language) { $language->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => 'Language']) - ]; + ]); } } diff --git a/src/System/Controllers/RoleController.php b/src/System/Controllers/RoleController.php index c5710e3d0..674d56c02 100644 --- a/src/System/Controllers/RoleController.php +++ b/src/System/Controllers/RoleController.php @@ -38,7 +38,7 @@ public function __construct( } /** * Display a listing of the resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -50,7 +50,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -62,7 +62,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\System\Requests\RoleRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(RoleRequest $request) { @@ -73,20 +73,10 @@ public function store(RoleRequest $request) ->with('successNotification', __('avored::system.notification.store', ['attribute' => 'Role'])); } - /** - * Display the specified resource. - * @param \AvoRed\Framework\Database\Models\Role $role - * @return \Illuminate\Http\Response - */ - public function show(Role $role) - { - // - } - /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\Role $role - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(Role $role) { @@ -100,7 +90,7 @@ public function edit(Role $role) * Update the specified resource in storage. * @param \AvoRed\Framework\System\Requests\RoleRequest $request * @param \AvoRed\Framework\Database\Models\Role $role - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(RoleRequest $request, Role $role) { @@ -114,16 +104,16 @@ public function update(RoleRequest $request, Role $role) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\Role $role - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(Role $role) { $role->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => 'Role']) - ]; + ]); } diff --git a/src/System/Controllers/StateController.php b/src/System/Controllers/StateController.php index c25c88f99..d9816f51a 100644 --- a/src/System/Controllers/StateController.php +++ b/src/System/Controllers/StateController.php @@ -36,7 +36,7 @@ public function __construct( } /** * Display a listing of the resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -48,7 +48,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -60,7 +60,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\System\Requests\StateRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(StateRequest $request) { @@ -76,7 +76,7 @@ public function store(StateRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\State $state - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(State $state) { @@ -90,7 +90,7 @@ public function edit(State $state) * Update the specified resource in storage. * @param \AvoRed\Framework\System\Requests\StateRequest $request * @param \AvoRed\Framework\Database\Models\State $state - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(StateRequest $request, State $state) { @@ -106,15 +106,15 @@ public function update(StateRequest $request, State $state) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\State $state - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(State $state) { $state->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __('avored::system.notification.delete', ['attribute' => __('avored:system.state.title')]) - ]; + ]); } } diff --git a/src/System/Controllers/TaxGroupController.php b/src/System/Controllers/TaxGroupController.php index 685640eeb..c4529ed96 100644 --- a/src/System/Controllers/TaxGroupController.php +++ b/src/System/Controllers/TaxGroupController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -37,7 +37,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -47,7 +47,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Cms\Requests\TaxGroupRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(TaxGroupRequest $request) { @@ -63,7 +63,7 @@ public function store(TaxGroupRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\TaxGroup $taxGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(TaxGroup $taxGroup) { @@ -75,7 +75,7 @@ public function edit(TaxGroup $taxGroup) * Update the specified resource in storage. * @param \AvoRed\Framework\Cms\Requests\TaxGroupRequest $request * @param \AvoRed\Framework\Database\Models\TaxGroup $taxGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(TaxGroupRequest $request, TaxGroup $taxGroup) { @@ -91,18 +91,18 @@ public function update(TaxGroupRequest $request, TaxGroup $taxGroup) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\TaxGroup $taxGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(TaxGroup $taxGroup) { $taxGroup->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::system.tax-group.title')] ) - ]; + ]); } } diff --git a/src/System/Controllers/TaxRateController.php b/src/System/Controllers/TaxRateController.php index 03ce42508..4f6cc42f7 100644 --- a/src/System/Controllers/TaxRateController.php +++ b/src/System/Controllers/TaxRateController.php @@ -34,7 +34,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -46,7 +46,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -61,7 +61,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Cms\Requests\TaxRateRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(TaxRateRequest $request) { @@ -77,7 +77,7 @@ public function store(TaxRateRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\TaxRate $taxRate - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(TaxRate $taxRate) { @@ -94,7 +94,7 @@ public function edit(TaxRate $taxRate) * Update the specified resource in storage. * @param \AvoRed\Framework\Cms\Requests\TaxRateRequest $request * @param \AvoRed\Framework\Database\Models\TaxRate $taxRate - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(TaxRateRequest $request, TaxRate $taxRate) { @@ -110,18 +110,18 @@ public function update(TaxRateRequest $request, TaxRate $taxRate) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\TaxRate $taxRate - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(TaxRate $taxRate) { $taxRate->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::system.tax-rate.title')] ) - ]; + ]); } } diff --git a/src/User/Controllers/UserGroupController.php b/src/User/Controllers/UserGroupController.php index ea7aaa6d6..55ca76bbc 100644 --- a/src/User/Controllers/UserGroupController.php +++ b/src/User/Controllers/UserGroupController.php @@ -25,7 +25,7 @@ public function __construct( /** * Show Dashboard of an AvoRed Admin - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -37,7 +37,7 @@ public function index() /** * Show the form for creating a new resource. - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function create() { @@ -47,7 +47,7 @@ public function create() /** * Store a newly created resource in storage. * @param \AvoRed\Framework\Cms\Requests\UserGroupRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function store(UserGroupRequest $request) { @@ -63,7 +63,7 @@ public function store(UserGroupRequest $request) /** * Show the form for editing the specified resource. * @param \AvoRed\Framework\Database\Models\UserGroup $userGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function edit(UserGroup $userGroup) { @@ -75,7 +75,7 @@ public function edit(UserGroup $userGroup) * Update the specified resource in storage. * @param \AvoRed\Framework\Cms\Requests\UserGroupRequest $request * @param \AvoRed\Framework\Database\Models\UserGroup $userGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse */ public function update(UserGroupRequest $request, UserGroup $userGroup) { @@ -91,18 +91,18 @@ public function update(UserGroupRequest $request, UserGroup $userGroup) /** * Remove the specified resource from storage. * @param \AvoRed\Framework\Database\Models\UserGroup $userGroup - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function destroy(UserGroup $userGroup) { $userGroup->delete(); - return [ + return response()->json([ 'success' => true, 'message' => __( 'avored::system.notification.delete', ['attribute' => __('avored::user.user-group.title')] ) - ]; + ]); } } From 7e1aa1d9ecaed5581a42321dccbf1027e5e422ef Mon Sep 17 00:00:00 2001 From: Purvesh Date: Tue, 16 Jul 2019 12:34:30 +1200 Subject: [PATCH 13/16] cart manager product attribute changes --- resources/lang/en/catalog.php | 2 ++ src/Cart/CartProduct.php | 21 +++++++++++ src/Cart/Manager.php | 35 ++++++++++++++----- .../Contracts/CartProductInterface.php | 7 ++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/resources/lang/en/catalog.php b/resources/lang/en/catalog.php index 2197d4e81..3b171e028 100644 --- a/resources/lang/en/catalog.php +++ b/resources/lang/en/catalog.php @@ -109,5 +109,7 @@ ], ], + 'cart_success_notification' => 'Product added to cart successfully.', + 'cart_variable_product_error_notification' => 'There is an error while adding product to cart.' ]; diff --git a/src/Cart/CartProduct.php b/src/Cart/CartProduct.php index b24171b9f..38a07b0f8 100644 --- a/src/Cart/CartProduct.php +++ b/src/Cart/CartProduct.php @@ -13,6 +13,12 @@ class CartProduct implements CartProductInterface */ protected $name; + /** + * Cart Product Attributes + * @var array $attributes + */ + protected $attributes; + /** * Cart Product Slug * @var string $slug @@ -52,6 +58,21 @@ public function name($name = null) } } + /** + * Set/Get Cart Product Name + * @param mixed $attributes + * @return mixed $attributes + */ + public function attributes(array $attributes) + { + if ($attributes === null || count($attributes) <= 0) { + return $this->attributes; + } else { + $this->attributes = $attributes; + return $this; + } + } + /** * Set/Get Cart Product Image * @param mixed $image diff --git a/src/Cart/Manager.php b/src/Cart/Manager.php index c34051297..58f841e3d 100644 --- a/src/Cart/Manager.php +++ b/src/Cart/Manager.php @@ -6,6 +6,7 @@ use Illuminate\Session\SessionManager; use AvoRed\Framework\Database\Contracts\ProductModelInterface; use AvoRed\Framework\Cart\CartProduct; +use AvoRed\Framework\Database\Models\Product; class Manager { @@ -42,40 +43,56 @@ public function __construct(SessionManager $manager) * Add Product to Cart By Given Slug. * @param string $slug * @param int $qty + * @param array $attributes * @return void */ - public function add(string $slug, $qty = 1) + public function add(string $slug, $qty = 1, $attributes = []) { - + $this->clear(); + $status = false; + $message = ''; + $product = $this->productRepository->findBySlug($slug); if ($this->getSession()->has($slug)) { - $cartProduct = $this->cartCollection->get($slug); - + $cartProduct = $this->cartCollection->get($product); + $existingQty = $cartProduct->qty() ?? 0; - + $cartProduct->qty($qty + $existingQty); $this->cartCollection->put($slug, $cartProduct); $this->updateSessionCollection(); + $status = true; + $message = __('avored::catalog.cart_success_notification'); + } elseif ($product->type === 'VARIABLE_PRODUCT') { + if ($attributes === null || count($attributes) <= 0) { + $status = false; + $message = __('avored::catalog.cart_variable_product_error_notification'); + } else { + $cartProduct = $this->createCartProductFromSlug($product, $attributes); + } } else { - $cartProduct = $this->createCartProductFromSlug($slug); + $cartProduct = $this->createCartProductFromSlug($product); $cartProduct->qty($qty); $this->cartCollection->put($slug, $cartProduct); $this->updateSessionCollection(); } + + return [$status, $message]; } /** * Create Cart Product From slug. - * @param string $slug + * @param \AvoRed\Framework\Database\Models\Product $product + * @param array $attributes * @return \AvoRed\Framework\Cart\CartProduct $cartProduct */ - public function createCartProductFromSlug(string $slug): CartProduct + public function createCartProductFromSlug(Product $product, array $attributes): CartProduct { - $product = $this->productRepository->findBySlug($slug); $cartProduct = new CartProduct; $cartProduct->name($product->name) ->slug($product->slug) ->price($product->price) + ->attributes($attributes) ->image($product->main_image_url); return $cartProduct; diff --git a/src/Support/Contracts/CartProductInterface.php b/src/Support/Contracts/CartProductInterface.php index efab665ef..81faf74b5 100644 --- a/src/Support/Contracts/CartProductInterface.php +++ b/src/Support/Contracts/CartProductInterface.php @@ -10,6 +10,13 @@ interface CartProductInterface */ public function name(); + /** + * Get/Set CartProduct attributes. + * @param array $attributes + * @return mixed $name|$this + */ + public function attributes(array $attributes); + /** * Get/Set CartProduct image. * @return mixed $image|$this From c24447594dbb2d25a10baf7c840262fa1c3e6784 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Wed, 17 Jul 2019 10:02:42 +1200 Subject: [PATCH 14/16] product attribute in progress --- src/Cart/CartProduct.php | 2 +- src/Cart/Manager.php | 40 +++++++++++++++++-- src/Database/Models/AttributeProductValue.php | 18 +++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Cart/CartProduct.php b/src/Cart/CartProduct.php index 38a07b0f8..8faa0bc20 100644 --- a/src/Cart/CartProduct.php +++ b/src/Cart/CartProduct.php @@ -63,7 +63,7 @@ public function name($name = null) * @param mixed $attributes * @return mixed $attributes */ - public function attributes(array $attributes) + public function attributes(array $attributes = []) { if ($attributes === null || count($attributes) <= 0) { return $this->attributes; diff --git a/src/Cart/Manager.php b/src/Cart/Manager.php index 58f841e3d..c84e07567 100644 --- a/src/Cart/Manager.php +++ b/src/Cart/Manager.php @@ -7,6 +7,7 @@ use AvoRed\Framework\Database\Contracts\ProductModelInterface; use AvoRed\Framework\Cart\CartProduct; use AvoRed\Framework\Database\Models\Product; +use AvoRed\Framework\Database\Contracts\AttributeProductValueModelInterface; class Manager { @@ -16,6 +17,12 @@ class Manager */ protected $productRepository; + /** + * Product Repository. + * @var \AvoRed\Framework\Database\Repository\AttributeProductValueRepository + */ + protected $attributeProductValueRepository; + /** * Cart Product collection. * @var \Illuminate\Support\Collection @@ -35,6 +42,7 @@ class Manager public function __construct(SessionManager $manager) { $this->productRepository = app(ProductModelInterface::class); + $this->attributeProductValueRepository = app(AttributeProductValueModelInterface::class); $this->sessionManager = $manager; $this->cartCollection = $this->getSession(); } @@ -67,7 +75,27 @@ public function add(string $slug, $qty = 1, $attributes = []) $status = false; $message = __('avored::catalog.cart_variable_product_error_notification'); } else { - $cartProduct = $this->createCartProductFromSlug($product, $attributes); + $attrs = Collection::make([]); + foreach ($attributes as $valueId) { + $valueModel = $this->attributeProductValueRepository->find($valueId); + + $attributeData = [ + 'attribute_id' => $valueModel->attribute_id, + 'attribute_name' => $valueModel->attribute->name, + 'attribute_dropdown_option_id' => $valueModel->attribute_dropdown_option_id, + 'attribute_dropdown_text' => $valueModel->attributeDropdownOption->display_text, + 'variation_id' => $valueModel->variation_id + ]; + + $attrs->push($attributeData); + } + $cartProduct = $this->createCartProductFromSlug($product, $attrs); + $cartProduct->qty($qty); + + $this->cartCollection->put($slug, $cartProduct); + $this->updateSessionCollection(); + $status = true; + $message = __('avored::catalog.cart_success_notification'); } } else { $cartProduct = $this->createCartProductFromSlug($product); @@ -75,6 +103,8 @@ public function add(string $slug, $qty = 1, $attributes = []) $this->cartCollection->put($slug, $cartProduct); $this->updateSessionCollection(); + $status = true; + $message = __('avored::catalog.cart_success_notification'); } return [$status, $message]; @@ -86,13 +116,14 @@ public function add(string $slug, $qty = 1, $attributes = []) * @param array $attributes * @return \AvoRed\Framework\Cart\CartProduct $cartProduct */ - public function createCartProductFromSlug(Product $product, array $attributes): CartProduct + public function createCartProductFromSlug(Product $product, Collection $attributes): CartProduct { + $cartProduct = new CartProduct; $cartProduct->name($product->name) ->slug($product->slug) ->price($product->price) - ->attributes($attributes) + ->attributes($attributes->toArray()) ->image($product->main_image_url); return $cartProduct; @@ -163,7 +194,8 @@ public function toArray() 'image' => $product->image(), 'price' => $product->price(), 'qty' => $product->qty(), - 'name' => $product->name() + 'name' => $product->name(), + 'attributes' => $product->attributes() ]); } return $items; diff --git a/src/Database/Models/AttributeProductValue.php b/src/Database/Models/AttributeProductValue.php index a022211f6..206b3e75c 100644 --- a/src/Database/Models/AttributeProductValue.php +++ b/src/Database/Models/AttributeProductValue.php @@ -11,4 +11,22 @@ class AttributeProductValue extends Model * @var array */ protected $fillable = ['attribute_id', 'product_id', 'variation_id', 'attribute_dropdown_option_id']; + + /** + * Attribute product value belongs to a attribute dropdown option + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function attributeDropdownOption() + { + return $this->belongsTo(AttributeDropdownOption::class); + } + + /** + * Attribute product value belongs to a attribute + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function attribute() + { + return $this->belongsTo(Attribute::class); + } } From bd4acfe64ac7a88ccc9cbcf5a311a883c8dd13eb Mon Sep 17 00:00:00 2001 From: Purvesh Date: Wed, 17 Jul 2019 13:10:57 +1200 Subject: [PATCH 15/16] order product sync with attribute --- ...7_03_29_000000_avored_framework_schema.php | 15 +++++- src/Cart/CartProduct.php | 44 ++++++++++++++++- src/Cart/Manager.php | 2 + .../OrderProductAttributeModelInterface.php | 36 ++++++++++++++ .../Contracts/OrderProductModelInterface.php | 36 ++++++++++++++ src/Database/Models/OrderProduct.php | 29 +++++++++++ src/Database/Models/OrderProductAttribute.php | 27 ++++++++++ .../OrderProductAttributeRepository.php | 49 +++++++++++++++++++ .../Repository/OrderProductRepository.php | 49 +++++++++++++++++++ src/Support/Providers/ModelProvider.php | 6 +++ 10 files changed, 290 insertions(+), 3 deletions(-) create mode 100644 src/Database/Contracts/OrderProductAttributeModelInterface.php create mode 100644 src/Database/Contracts/OrderProductModelInterface.php create mode 100644 src/Database/Models/OrderProduct.php create mode 100644 src/Database/Models/OrderProductAttribute.php create mode 100644 src/Database/Repository/OrderProductAttributeRepository.php create mode 100644 src/Database/Repository/OrderProductRepository.php 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 d6da2f24d..dcdeb0cc9 100644 --- a/database/migrations/2017_03_29_000000_avored_framework_schema.php +++ b/database/migrations/2017_03_29_000000_avored_framework_schema.php @@ -405,19 +405,30 @@ public function up() $table->foreign('order_status_id')->references('id')->on('order_statuses'); }); - Schema::create('order_product', function (Blueprint $table) { + Schema::create('order_products', function (Blueprint $table) { $table->bigIncrements('id'); $table->unsignedBigInteger('product_id'); $table->unsignedBigInteger('order_id'); $table->decimal('qty', 11, 6); $table->decimal('price', 11, 6); $table->decimal('tax_amount', 11, 6); - $table->json('product_info')->nullable()->default(null); $table->timestamps(); $table->foreign('order_id')->references('id')->on('orders'); $table->foreign('product_id')->references('id')->on('products'); }); + Schema::create('order_product_attributes', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->unsignedBigInteger('order_product_id'); + $table->unsignedBigInteger('attribute_id'); + $table->unsignedBigInteger('attribute_dropdown_option_id'); + $table->timestamps(); + + $table->foreign('order_product_id')->references('id')->on('order_products'); + $table->foreign('attribute_id')->references('id')->on('attributes'); + $table->foreign('attribute_dropdown_option_id')->references('id')->on('attribute_dropdown_options'); + }); + Schema::create('category_filters', function (Blueprint $table) { $table->bigIncrements('id'); $table->unsignedBigInteger('category_id'); diff --git a/src/Cart/CartProduct.php b/src/Cart/CartProduct.php index 8faa0bc20..56f7f0bce 100644 --- a/src/Cart/CartProduct.php +++ b/src/Cart/CartProduct.php @@ -7,6 +7,12 @@ class CartProduct implements CartProductInterface { + /** + * Cart Product Name + * @var int $id + */ + protected $id; + /** * Cart Product Name * @var string $name @@ -33,9 +39,15 @@ class CartProduct implements CartProductInterface /** * Cart Product Price - * @var int $price + * @var float $price */ protected $price; + + /** + * Cart Product Tax Amount + * @var float $taxAmount + */ + protected $taxAmount = 0; /** * Cart Product Image @@ -58,6 +70,36 @@ public function name($name = null) } } + /** + * Set/Get Cart Product id + * @param mixed $id + * @return mixed $id + */ + public function id($id = null) + { + if ($id === null) { + return $this->id; + } else { + $this->id = $id; + return $this; + } + } + + /** + * Set/Get Cart Product Tax Amount + * @param mixed $taxAmount + * @return mixed $taxAmount + */ + public function taxAmount($taxAmount = null) + { + if ($taxAmount === null) { + return $this->taxAmount; + } else { + $this->taxAmount = $taxAmount; + return $this; + } + } + /** * Set/Get Cart Product Name * @param mixed $attributes diff --git a/src/Cart/Manager.php b/src/Cart/Manager.php index c84e07567..2d8a2a6c4 100644 --- a/src/Cart/Manager.php +++ b/src/Cart/Manager.php @@ -121,8 +121,10 @@ public function createCartProductFromSlug(Product $product, Collection $attribut $cartProduct = new CartProduct; $cartProduct->name($product->name) + ->id($product->id) ->slug($product->slug) ->price($product->price) + ->taxAmount(0) ->attributes($attributes->toArray()) ->image($product->main_image_url); diff --git a/src/Database/Contracts/OrderProductAttributeModelInterface.php b/src/Database/Contracts/OrderProductAttributeModelInterface.php new file mode 100644 index 000000000..db723319e --- /dev/null +++ b/src/Database/Contracts/OrderProductAttributeModelInterface.php @@ -0,0 +1,36 @@ +belongsTo(Order::class); + } +} diff --git a/src/Database/Models/OrderProductAttribute.php b/src/Database/Models/OrderProductAttribute.php new file mode 100644 index 000000000..ec3e762f9 --- /dev/null +++ b/src/Database/Models/OrderProductAttribute.php @@ -0,0 +1,27 @@ +belongsTo(Order::class); + } +} diff --git a/src/Database/Repository/OrderProductAttributeRepository.php b/src/Database/Repository/OrderProductAttributeRepository.php new file mode 100644 index 000000000..d33863422 --- /dev/null +++ b/src/Database/Repository/OrderProductAttributeRepository.php @@ -0,0 +1,49 @@ + CurrencyRepository::class, LanguageModelInterface::class => LanguageRepository::class, OrderModelInterface::class => OrderRepository::class, + OrderProductModelInterface::class => OrderProductRepository::class, + OrderProductAttributeModelInterface::class => OrderProductAttributeRepository::class, OrderStatusModelInterface::class => OrderStatusRepository::class, PermissionModelInterface::class => PermissionRepository::class, PageModelInterface::class => PageRepository::class, From c4db02307755c1c51ab3ddd2e0fa74ede9a7d1b2 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Wed, 17 Jul 2019 18:07:07 +1200 Subject: [PATCH 16/16] added sorting in table components --- ...{AttributeIndex.vue => AttributeTable.vue} | 25 ++++++++++++++++- .../{CategoryIndex.vue => CategoryTable.vue} | 27 +++++++++++++++++-- .../{PropertyIndex.vue => PropertyTable.vue} | 25 ++++++++++++++++- .../cms/page/{PageIndex.vue => PageTable.vue} | 25 ++++++++++++++++- ...erStatusIndex.vue => OrderStatusTable.vue} | 25 ++++++++++++++++- ...{AdminUserIndex.vue => AdminUserTable.vue} | 24 +++++++++++++++-- .../{LanguageIndex.vue => LanguageTable.vue} | 24 +++++++++++++++-- .../role/{RoleIndex.vue => RoleTable.vue} | 24 +++++++++++++++-- .../state/{StateIndex.vue => StateTable.vue} | 24 +++++++++++++++-- .../{TaxGroupIndex.vue => TaxGroupTable.vue} | 25 ++++++++++++++++- .../{TaxRateIndex.vue => TaxRateTable.vue} | 26 +++++++++++++++++- ...{UserGroupIndex.vue => UserGroupTable.vue} | 25 ++++++++++++++++- resources/js/app.js | 24 ++++++++--------- .../views/catalog/attribute/index.blade.php | 4 +-- .../views/catalog/category/index.blade.php | 11 +++++--- .../views/catalog/property/index.blade.php | 9 ++++--- resources/views/cms/page/index.blade.php | 4 +-- .../views/order/order-status/index.blade.php | 4 +-- .../views/system/admin-user/index.blade.php | 2 +- .../views/system/language/index.blade.php | 8 ++++-- resources/views/system/role/index.blade.php | 2 +- resources/views/system/state/index.blade.php | 2 +- .../views/system/tax-group/index.blade.php | 4 +-- .../views/system/tax-rate/index.blade.php | 4 +-- .../views/user/user-group/index.blade.php | 4 +-- .../Controllers/AttributeController.php | 4 +-- 26 files changed, 331 insertions(+), 54 deletions(-) rename resources/components/catalog/attribute/{AttributeIndex.vue => AttributeTable.vue} (68%) rename resources/components/catalog/category/{CategoryIndex.vue => CategoryTable.vue} (68%) rename resources/components/catalog/property/{PropertyIndex.vue => PropertyTable.vue} (68%) rename resources/components/cms/page/{PageIndex.vue => PageTable.vue} (69%) rename resources/components/order/order-status/{OrderStatusIndex.vue => OrderStatusTable.vue} (67%) rename resources/components/system/admin-user/{AdminUserIndex.vue => AdminUserTable.vue} (71%) rename resources/components/system/language/{LanguageIndex.vue => LanguageTable.vue} (70%) rename resources/components/system/role/{RoleIndex.vue => RoleTable.vue} (68%) rename resources/components/system/state/{StateIndex.vue => StateTable.vue} (69%) rename resources/components/system/tax-group/{TaxGroupIndex.vue => TaxGroupTable.vue} (67%) rename resources/components/system/tax-rate/{TaxRateIndex.vue => TaxRateTable.vue} (67%) rename resources/components/user/user-group/{UserGroupIndex.vue => UserGroupTable.vue} (68%) diff --git a/resources/components/catalog/attribute/AttributeIndex.vue b/resources/components/catalog/attribute/AttributeTable.vue similarity index 68% rename from resources/components/catalog/attribute/AttributeIndex.vue rename to resources/components/catalog/attribute/AttributeTable.vue index 21b460794..173d0ea95 100644 --- a/resources/components/catalog/attribute/AttributeIndex.vue +++ b/resources/components/catalog/attribute/AttributeTable.vue @@ -1,4 +1,5 @@