diff --git a/module/sCommerceModule.php b/module/sCommerceModule.php index 91d638c..242e592 100644 --- a/module/sCommerceModule.php +++ b/module/sCommerceModule.php @@ -472,12 +472,31 @@ $q->whereIn('category', $categoryParentsIds); })->orderBy('position')->get(); - $attrValues = $product->attrValues->mapWithKeys(function ($value) { - return [$value->id => $value]; - })->all(); + $attrValues = []; + foreach ($product->attrValues as $value) { + if ($value->type == sAttribute::TYPE_ATTR_MULTISELECT) { + $attrValues[$value->id][] = $value; + } else { + $attrValues[$value->id] = $value; + } + } $attributes->mapWithKeys(function ($attribute) use ($attrValues) { - $attribute->value = $attrValues[$attribute->id]->pivot->value ?? ''; + if (isset($attrValues[$attribute->id])) { + if (is_array($attrValues[$attribute->id])) { + $value = []; + foreach ($attrValues[$attribute->id] as $attrValue) { + if ($attrValue->type == sAttribute::TYPE_ATTR_MULTISELECT) { + $value[] = intval($attrValue->pivot->valueid); + } + } + $attribute->value = $value; + } else { + $attribute->value = $attrValues[$attribute->id]->pivot->value ?? ''; + } + } else { + $attribute->value = ''; + } return $attribute; }); @@ -529,6 +548,22 @@ $product->attrValues()->attach($key, ['valueid' => 0, 'value' => $value]); } break; + case sAttribute::TYPE_ATTR_SELECT : // 3 + if (trim($value)) { + $valueId = intval($value); + $product->attrValues()->attach($key, ['valueid' => $valueId, 'value' => $value]); + } + break; + case sAttribute::TYPE_ATTR_MULTISELECT : // 4 + if (is_array($value) && count($value)) { + foreach ($value as $k => $v) { + if (trim($v)) { + $vId = intval($v); + $product->attrValues()->attach($key, ['valueid' => $vId, 'value' => $v]); + } + } + } + break; case sAttribute::TYPE_ATTR_TEXT : // 5 if (is_array($value) && count($value)) { $vals = []; diff --git a/views/partials/attributeMultiselect.blade.php b/views/partials/attributeMultiselect.blade.php index aab9368..458e543 100644 --- a/views/partials/attributeMultiselect.blade.php +++ b/views/partials/attributeMultiselect.blade.php @@ -8,8 +8,8 @@
@lang('sCommerce::global.type_attr_multiselect')
diff --git a/views/partials/attributeSelect.blade.php b/views/partials/attributeSelect.blade.php index 4b3457e..373b5a0 100644 --- a/views/partials/attributeSelect.blade.php +++ b/views/partials/attributeSelect.blade.php @@ -8,8 +8,8 @@
@lang('sCommerce::global.type_attr_select')
diff --git a/views/prodattributesTab.blade.php b/views/prodattributesTab.blade.php index 08e2154..475461f 100644 --- a/views/prodattributesTab.blade.php +++ b/views/prodattributesTab.blade.php @@ -17,14 +17,16 @@ @include('sCommerce::partials.attributeCheckbox') @break @case(sAttribute::TYPE_ATTR_SELECT) + @php($options = $attribute->values->pluck('base', 'avid')->toArray()) @include('sCommerce::partials.attributeSelect') @break @case(sAttribute::TYPE_ATTR_MULTISELECT) - @php($value = json_decode($attribute->value ?? '', true)) + @php($options = $attribute->values->pluck('base', 'avid')->toArray()) + @php($value = is_array($attribute->value) ? $attribute->value : []) @include('sCommerce::partials.attributeMultiselect') @break @case(sAttribute::TYPE_ATTR_TEXT) - @php($value = json_decode($attribute->value ?? '', true)) + @php($value = json_decode($attribute->value ?? '', true) ?? []) @include('sCommerce::partials.attributeText') @break @case(sAttribute::TYPE_ATTR_CUSTOM) diff --git a/views/productTab.blade.php b/views/productTab.blade.php index 2feec54..eefcc9a 100644 --- a/views/productTab.blade.php +++ b/views/productTab.blade.php @@ -274,10 +274,12 @@ @break @case(sAttribute::TYPE_ATTR_SELECT) @php($options = $attribute->options) + @php($options = array_combine(array_values($options), $options)) @include('sCommerce::partials.attributeSelect') @break @case(sAttribute::TYPE_ATTR_MULTISELECT) @php($options = $attribute->options) + @php($options = array_combine(array_values($options), $options)) @php($value = is_array($attribute->value) ? $attribute->value : []) @include('sCommerce::partials.attributeMultiselect') @break