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 @@