diff --git a/packages/Webkul/Attribute/src/Models/AttributeFamily.php b/packages/Webkul/Attribute/src/Models/AttributeFamily.php
index 7146bf597..92279a82f 100755
--- a/packages/Webkul/Attribute/src/Models/AttributeFamily.php
+++ b/packages/Webkul/Attribute/src/Models/AttributeFamily.php
@@ -24,6 +24,16 @@ class AttributeFamily extends Model implements AttributeFamilyContract
->select('attributes.*');
}
+
+ /**
+ * Get all of the comparable attributes which belongs to attribute family.
+ */
+ public function getComparableAttributesBelongsToFamily()
+ {
+ return (AttributeProxy::modelClass())::join('attribute_group_mappings', 'attribute_group_mappings.attribute_id', '=', 'attributes.id')
+ ->select('attributes.*')->where('attributes.is_comparable', 1)->get();
+ }
+
/**
* Get all of the attributes for the attribute groups.
*/
diff --git a/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php b/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php
index 3cad11be0..cba9eff37 100644
--- a/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php
@@ -1,6 +1,10 @@
@php
- $attributeRepository = app('\Webkul\Attribute\Repositories\AttributeRepository');
- $comparableAttributes = $attributeRepository->findByField('is_comparable', 1);
+ $attributeRepository = app('\Webkul\Attribute\Repositories\AttributeFamilyRepository');
+ $comparableAttributes = $attributeRepository->getComparableAttributesBelongsToFamily();
+
+ $locale = request()->get('locale') ?: app()->getLocale();
+
+ $attributeOptionTranslations = DB::table(DB::getTablePrefix() . 'attribute_option_translations')->where('locale', $locale)->get()->toJson();
@endphp
@push('scripts')
@@ -25,13 +29,13 @@
$comparableAttributes = $comparableAttributes->toArray();
array_splice($comparableAttributes, 1, 0, [[
- 'admin_name' => 'Product Image',
- 'type' => 'product_image'
+ 'code' => 'product_image',
+ 'admin_name' => __('velocity::app.customer.compare.product_image'),
]]);
array_splice($comparableAttributes, 2, 0, [[
- 'admin_name' => 'Actions',
- 'type' => 'action'
+ 'code' => 'addToCartHtml',
+ 'admin_name' => __('velocity::app.customer.compare.actions'),
]]);
@endphp
@@ -42,67 +46,83 @@
- @switch ($attribute['type'])
- @case('text')
+ @switch ($attribute['code'])
+ @case('name')
- @break;
-
- @case('textarea')
-
- @break;
-
- @case('price')
-
- @break;
-
- @case('boolean')
-
- @break;
-
- @case('select')
-
- @break;
-
- @case('multiselect')
-
@break
- @case('file')
-
-
-
-
- __
- @break;
-
- @case('image')
-
- @break;
-
@case('product_image')
- @break
+ @break
- @case('action')
+ @case('price')
+
+ @break
+
+ @case('addToCartHtml')
- @break;
+ @break
- @endswitch
+ @case('color')
+
+ @break
+
+ @case('size')
+
+ @break
+
+ @case('description')
+
+ @break
+
+ @default
+ @switch ($attribute['type'])
+ @case('boolean')
+
+ @break;
+
+ @case('checkbox')
+
+ __
+ @break;
+
+ @case('select')
+
+ __
+ @break;
+
+ @case ('file')
+ @case ('image')
+
+
+
+ @break;
+ @default
+
+ @break;
+ @endswitch
+
+ @break
+
+ @endswitch
|
@endforeach
@@ -126,6 +146,7 @@
'products': [],
'isProductListLoaded': false,
'baseUrl': "{{ url()->to('/') }}",
+ 'attributeOptions': JSON.parse(@json($attributeOptionTranslations)),
'isCustomer': '{{ auth()->guard('customer')->user() ? "true" : "false" }}' == "true",
}
},
@@ -255,6 +276,42 @@
return true;
},
+
+ 'getAttributeOptions': function (productDetails, attributeValues, type) {
+ var attributeOptions = '__';
+
+ if (productDetails && attributeValues) {
+ var attributeItems;
+
+ if (type == "multiple") {
+ attributeItems = productDetails[attributeValues].split(',');
+ } else if (type == "single") {
+ attributeItems = productDetails[attributeValues];
+ }
+
+ attributeOptions = this.attributeOptions.filter(option => {
+ if (type == "multiple") {
+ if (attributeItems.indexOf(option.attribute_option_id.toString()) > -1) {
+ return true;
+ }
+ } else if (type == "single") {
+ if (attributeItems == option.attribute_option_id.toString()) {
+ return true;
+ }
+ }
+
+ return false;
+ });
+
+ attributeOptions = attributeOptions.map(option => {
+ return option.label;
+ });
+
+ attributeOptions = attributeOptions.join(', ');
+ }
+
+ return attributeOptions;
+ }
}
});
diff --git a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php
index 175c7abc2..9aeea6461 100755
--- a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php
@@ -70,8 +70,8 @@
@endguest
style="color: #242424;"
>
- {{ __('velocity::app.customer.compare.text') }}
-
+ {{ __('velocity::app.customer.compare.text') }}
+ ()
@endif
@@ -336,6 +336,9 @@
toggleDropdown(e);
});
+ let comparedItems = JSON.parse(localStorage.getItem('compared_product'));
+ $('#compare-items-count').append(comparedItems.length);
+
function toggleDropdown(e) {
var currentElement = $(e.currentTarget);
diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php
index 76fa6ff6f..83266e50f 100644
--- a/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php
+++ b/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php
@@ -1,6 +1,6 @@
@php
- $attributeRepository = app('\Webkul\Attribute\Repositories\AttributeRepository');
- $comparableAttributes = $attributeRepository->findByField('is_comparable', 1);
+ $attributeRepository = app('\Webkul\Attribute\Repositories\AttributeFamilyRepository');
+ $comparableAttributes = $attributeRepository->getComparableAttributesBelongsToFamily();
$locale = request()->get('locale') ?: app()->getLocale();
@@ -43,13 +43,13 @@
$comparableAttributes = $comparableAttributes->toArray();
array_splice($comparableAttributes, 1, 0, [[
- 'admin_name' => 'Product Image',
- 'type' => 'product_image'
+ 'code' => 'product_image',
+ 'admin_name' => __('velocity::app.customer.compare.product_image'),
]]);
array_splice($comparableAttributes, 2, 0, [[
- 'admin_name' => 'Actions',
- 'type' => 'action'
+ 'code' => 'addToCartHtml',
+ 'admin_name' => __('velocity::app.customer.compare.actions'),
]]);
@endphp
@@ -60,65 +60,51 @@
- @switch ($attribute['type'])
- @case('text')
-
-
+ @switch ($attribute['code'])
+ @case('name')
+
+
- @break;
-
- @case('textarea')
-
- @break;
-
- @case('price')
-
- @break;
-
- @case('boolean')
-
- @break;
-
- @case('select')
-
- @break;
-
- @case('multiselect')
-
@break
- @case('file')
-
-
-
-
- __
- @break;
-
- @case('image')
-
- @break;
-
@case('product_image')
-
+
+ :src="product['{{ $attribute['code'] }}']"
+ onload="window.updateHeight ? window.updateHeight() : ''"
+ :onerror="`this.src='${$root.baseUrl}/vendor/webkul/ui/assets/images/product/large-product-placeholder.png'`" />
- @break
+ @break
- @case('action')
+ @case('price')
+
+ @break
+
+ @case('addToCartHtml')
- @break;
+ @break
+
+ @case('color')
+
+ @break
+
+ @case('size')
+
+ @break
+
+ @case('description')
+
+ @break
@default
@switch ($attribute['type'])
@@ -129,13 +115,6 @@
: '{{ __('velocity::app.shop.general.no') }}'"
>
@break;
- @case('file')
-
-
- arrow_downward
-
- __
- @break;
@case('checkbox')
@@ -146,6 +125,17 @@
__
@break;
+
+ @case ('file')
+ @case ('image')
+
+
+
+ @break;
+
@default
@break;
|