@php
$existingAttrIds = $data->variantAttributes->pluck('product_attribute_id')->toArray();
$requiredMap = $data->variantAttributes->pluck('is_required', 'product_attribute_id')->toArray();
@endphp
Product Variants & Options
Update enabled variant attributes and stock matrix for this product.
Step 1: Applicable Attributes
@foreach($attributes as $attr)
@php $isSel = in_array($attr->id, $existingAttrIds); @endphp
@endforeach
Step 2: Attribute Values
@foreach($attributes as $attr)
@if($attr->type !== 'text_input')
@php
$isAttrSel = in_array($attr->id, $existingAttrIds);
// find all value IDs currently used in product variants for this attribute
$usedValIds = [];
foreach($data->variants as $var) {
foreach($var->values as $vv) {
if($vv->product_attribute_id == $attr->id) {
$usedValIds[] = $vv->product_attribute_value_id;
}
}
}
$usedValIds = array_unique($usedValIds);
@endphp
{{ $attr->name }} Values:
@foreach($attr->values as $val)
@php $isValChecked = in_array($val->id, $usedValIds); @endphp
@endforeach
@endif
@endforeach
Cancel