0% found this document useful (0 votes)
4 views5 pages

Product Variant Selector Code

The document contains code for rendering product variant selectors in a web application. It processes child items and their associated variants to generate radio button options for each variant type. The code includes logic for displaying the variant options with appropriate styling and attributes based on the product data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Product Variant Selector Code

The document contains code for rendering product variant selectors in a web application. It processes child items and their associated variants to generate radio button options for each variant type. The code includes logic for displaying the variant options with appropriate styling and attributes based on the product data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

all product code

{{-- @if (isset($value['child_items']) && count($value['child_items']) > 0)


@php
$variantTypes =
[];
foreach
($value['child_items'] as $childItem) {
foreach (

$childItem['variant_id'] ?? []
as
$variant
) {

$variantData =

$variant[

'child_product_item_variant'
] ?
? null;
if
($variantData) {
$id
=

$variantData[

'product_variation_id'

] ?? null;

$type = strtolower(

$variantData[

'product_variation_type'

] ?? '',
);
if
(

$id &&

$type &&

!isset($variantTypes[$id])
) {

$variantTypes[$id] = $type;
}
}
}
}
@endphp
<div
class="variant-selectors mt-3"
data-product-
id="{{ $value['id'] }}"
data-child-
items='@json($value[' child_items'] ?? [])'>
@foreach
($variantTypes as $variationTypeId => $type)
@php
$values
= [];
foreach
(

$value['child_items']
as
$childItem
) {

foreach (

$childItem['variant_id'] ?? []

as $variant
) {

$variantData =

$variant[

'child_product_item_variant'

] ?? null;

$attrData =

$variant[

'child_product_item_variant_attribute'

] ?? null;

if (

$variantData &&

strtolower(

$variantData[

'product_variation_type'

] ?? '',

) === strtolower($type)

) {
$id =

$attrData[

'product_variation_id'

] ?? null;

$unit =

$attrData[

'product_variation_units'

] ?? null;

if (

$id &&

$unit &&

!isset($values[$id])

) {

$values[$id] = $unit;

}
}
}
@endphp
<div
class="mb-2">
<label

class="fw-medium d-block mb-1 text-capitalize text-dark">

{{ ucfirst($type) }}:

</label>
<div
class="d-flex flex-wrap gap-2 variant-group"

data-variant-attribute-type="{{ $type }}">

@foreach ($values as $id => $val)

<label

class="variant-option-label">

<input type="radio"

class="variant-option-input d-none"
name="variant_{{ $type }}"

value="{{ $id }}"

data-unit="{{ $val }}"

data-type="{{ $type }}"

data-variation-type-id="{{ $variationTypeId }}"

@if ($loop->first) checked @endif>

<div class="variant-option rounded-pill px-3 py-1 small fw-semibold border @if


($loop->first) bg-success text-success @else bg-secondary text-info @endif"

style="cursor: pointer;">

{{ $val }}

</div>

</label>

@endforeach
</div>
</div>
@endforeach
</div>
@endif --}}

{{-- <div class="d-flex flex-wrap gap-2 variant-group" data-variant-attribute-


type="{{ $type }}">

@foreach ($values as $id => $val)

<label class="variant-option-label">

<input type="radio"

class="variant-option-input d-none"

name="variant_{{ $type }}"

value="{{ $id }}"

data-unit="{{ $val }}"

data-type="{{ $type }}"

data-variation-type-id="{{ $variationTypeId }}"

@if ($loop->first) checked @endif>

<div class="variant-option rounded-pill px-3 py-1 small fw-semibold border @if


($loop->first) bg-success text-success @else bg-secondary text-info @endif"

style="cursor: pointer;">

{{ $val }}
</div>

</label>

@endforeach
</div>
--}}

You might also like