Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant creation enhancement #798

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b59e4b6
show selected options
wychoong Jan 10, 2023
fc00123
open option selector panel
wychoong Jan 10, 2023
dd4819d
wip: variants creation
wychoong Jan 11, 2023
5b812df
wip
wychoong Jan 11, 2023
062b2b3
wip: variants edit from main
wychoong Jan 11, 2023
bb9ea0c
cleanup
wychoong Jan 11, 2023
57b58b6
show selected options
wychoong Jan 10, 2023
b500a2f
open option selector panel
wychoong Jan 10, 2023
df6b0a2
wip: variants creation
wychoong Jan 11, 2023
0eb15e5
wip
wychoong Jan 11, 2023
3c2d7df
wip: variants edit from main
wychoong Jan 11, 2023
c907cfc
cleanup
wychoong Jan 11, 2023
3d7ff4a
Merge branch 'feat/variant-creation-enhancement' of https://github.co…
wychoong Jan 11, 2023
ccc64aa
Merge branch 'main' into feat/variant-creation-enhancement
wychoong Jan 16, 2023
07928ac
fix: dom diffing for shipping section
wychoong Jan 16, 2023
5c3e744
fix: variants/edit condition
wychoong Jan 16, 2023
198f3e9
fix: variant manager price
wychoong Jan 16, 2023
616c8cb
ux: variant options label by sequence
wychoong Jan 16, 2023
04a820f
fix test
wychoong Jan 16, 2023
fa3c15e
fix: L* compat
wychoong Jan 16, 2023
ed96f43
fix: rule L8 compat
wychoong Jan 16, 2023
9874409
pint
wychoong Jan 16, 2023
df04281
pls last fix for L8..
wychoong Jan 16, 2023
1852a53
Update sections.blade.php
wychoong Jan 17, 2023
dccea83
Merge branch 'main' into feat/variant-creation-enhancement
glennjacobs Jan 26, 2023
ff4d950
Merge branch 'main' into feat/variant-creation-enhancement
wychoong Jan 27, 2023
85f2a74
Merge branch 'main' into feat/variant-creation-enhancement
wychoong Feb 14, 2023
f9d5c63
Merge branch '0.2' into feat/variant-creation-enhancement
wychoong Feb 20, 2023
be5c400
Adding Validations menu item which was missing
glennjacobs Feb 23, 2023
fd88d2c
Merge branch '0.2' into feat/variant-creation-enhancement
wychoong Feb 24, 2023
186daec
bug fix
wychoong Feb 24, 2023
9be15bf
bug fix
wychoong Feb 24, 2023
58954dc
customer group price in quick edit
wychoong Feb 24, 2023
c62d9c2
Merge branch 'main' into feat/variant-creation-enhancement
wychoong Feb 24, 2023
6e2dac2
fix test
wychoong Feb 25, 2023
1945574
Merge branch 'main' into feat/variant-creation-enhancement
wychoong May 25, 2023
0dbc1b7
handle click outside close toggle panel
wychoong May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/admin/resources/lang/en/inputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'type.instructions' => 'Choose what type of attribute this will be.',
'required' => 'Required',
'tags.label' => 'Tags',
'base_price.label' => 'Base price',
'base_price_excl_tax.label' => 'Base price (excl. Tax)',
'base_price_excl_tax.instructions' => 'The base price for the product, excluding tax',
'compare_at_price_excl_tax.label' => 'Compare at price (excl. tax)',
Expand Down
1 change: 1 addition & 0 deletions packages/admin/resources/lang/en/partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
'products.variants.table_row_action_text' => 'Edit',
'products.variants.table_row_delete_text' => 'Delete',
'products.variants.removal_message' => 'This will remove all variants from this product',
'products.variants.empty_message' => 'Select option values',
/**
* Product type.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<div>
@livewire('hub.components.product-options.option-manager', [
'options' => $options,
'selectedValues' => $optionValues,
])

@livewire('hub.components.products.options.option-selector', [
'selected' => $options->pluck('id')->toArray(),
'openPanel' => $openPanel ?? true,
])
<div>
<div class="pt-4 mt-4 space-x-4 border-t">
@livewire('hub.components.products.options.option-selector')
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ class="w-8 h-8" />
<div id="variants">
@include('adminhub::partials.products.editing.variants')
</div>

@if (!$product->id && $this->variantsEnabled)
<div id="variants-shipping">
@include('adminhub::partials.shipping')
</div>
@endif
@endif

@if ($this->getVariantsCount() <= 1)
@if ($this->getVariantsCount() <= 1 && !$this->variantsEnabled)
<div id="pricing">
@include('adminhub::partials.pricing')
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
</h3>
<p class="text-sm text-gray-500">{{ __('adminhub::partials.products.variants.strapline') }}</p>
</div>
<div>
<div class="flex items-center gap-2">
@if($variantsEnabled)
<x-hub::button x-on:click="Livewire.emit('toggleOptionSelector')" theme="gray" size="sm" type="button">
Select option
</x-hub::button>
@endif
<x-hub::input.toggle wire:model="variantsEnabled" />
</div>
</header>
Expand All @@ -26,12 +31,14 @@
</x-hub::alert>
@endif
@if($variantsEnabled)
@if($this->getVariantsCount() <= 1)
@include('adminhub::partials.products.editing.options')
@else
@livewire('hub.components.products.variants.table', [
'product' => $this->product,
])
@include('adminhub::partials.products.editing.options', [
'openPanel' => $this->getVariantsCount() <= 1
])

@if(count($this->optionValues))
<div class="pt-4 border-t">
@include('adminhub::partials.products.variants.manager')
</div>
@endif
@endif
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<div class="flex flex-col gap-2">
@if(sizeof($variants))
<div class="flex items-center justify-end space-x-2">
<div>
<select wire:change="setCurrency($event.target.value)" class="block w-full py-1 pl-2 pr-8 text-base text-gray-600 bg-gray-100 border-none rounded-md form-select focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
@foreach($this->currencies as $c)
<option value="{{ $c->id }}" @if($currency->id == $c->id) selected @endif>{{ $c->code }}</option>
@endforeach
</select>
</div>
</div>

<div class="space-y-4">
@foreach($variants as $key => $variant)
<div class="space-y-2 px-1.5 py-2 even:bg-gray-50 even:rounded-md even:border">
<div class="flex justify-between items-center">
<div class="flex gap-2">
@foreach($variant['labels'] as $label)
<span class="text-sm text-gray-800">{{ $label['option'] }}: {{ $label['value'] }}</span>
@endforeach
</div>

@if(!empty($variant['id']))
<a href="{{ route('hub.products.variants.show', [
'product' => $product->id,
'variant' => $variant['id'],
]) }}">
<x-hub::icon ref="pencil"
style="solid"
class="text-gray-400 hover:text-indigo-500" />
</a>
@endif
</div>

<div class="flex gap-2">

<div class="grid gap-2">
@foreach(['sku', 'gtin', 'mpn', 'ean'] as $identifier)
@if(config("lunar-hub.products.{$identifier}.required", false))
<x-hub::input.group :label="__('adminhub::inputs.'.$identifier.'.label')" :for="$identifier.'-'.$key" :error="$errors->first('variants.'.$key.'.'.$identifier)" required>
<x-hub::input.text wire:model="variants.{{ $key }}.{{ $identifier }}" :error="$errors->first('variant.'.$key.'.'.$identifier)" :id="$identifier.'-'.$key"/>
</x-hub::input.group>
@endif
@endforeach
</div>

<div class="grid gap-2">
<x-hub::input.group
:label="__('adminhub::inputs.base_price_excl_tax.label')"
:instructions="__('adminhub::inputs.base_price_excl_tax.instructions')"
:for="'basePrices'.$key"
:errors="$errors->get('variants.'.$key.'.basePrices.*.price')"
required
>
<x-hub::input.price
wire:model="variants.{{ $key }}.basePrices.{{ $this->currency->code }}.price"
:error="$errors->first('variants.'.$key.'.basePrices.'.$this->currency->code.'.price')"
:currencyCode="$this->currency->code"
:id="'basePrices'.$key"
required
/>
</x-hub::input.group>

<div x-data="{ expand: false }">
<x-hub::input.group
:label="__('adminhub::partials.pricing.customer_groups.title')"
for=""
>
<x-slot name="labelPrefix">
<button x-cloak
x-on:click.prevent="expand = !expand"
class="mr-2 text-gray-600 hover:text-gray-900 hover:bg-gray-50 bg-white rounded border border-gray-200 p-1">
<span :class="{ 'rotate-90': expand }"
class="block transition">
<x-hub::icon ref="chevron-right"
class="w-3 h-3" />
</span>
</button>
</x-slot>

<div class="mt-2 bg-gray-100/60 border border-gray-200 p-2 rounded-lg" x-show="expand" x-transition>
@foreach($this->customerGroups as $group)
<div wire:key="variant_{{ $key }}_group_price_{{ $group->id }}">
<div class="grid items-center grid-cols-2 gap-4">
<span class="text-sm text-gray-700">{{ $group->name }}</span>
<x-hub::input.group
:label="null"
for="customerGroupPrices"
:errors="$errors->get('variants.'.$key.'.customerGroupPrices.'.$group->id.'.*.price')"
:error-icon="false"
>
<x-hub::input.price
wire:model="variants.{{ $key }}.customerGroupPrices.{{ $group->id }}.{{ $this->currency->code }}.price"
:currencyCode="$this->currency->code"
:error="$errors->first('variants.'.$key.'.customerGroupPrices.'.$group->id.'.'.$this->currency->code.'.price')"
:error-icon="false"
/>
</x-hub::input.group>
</div>
</div>
@endforeach
</div>
</x-hub::input.group>
</div>
</div>

<x-hub::input.group :label="__('adminhub::inputs.stock.label')" :for="'stock'.$key" :error="$errors->first('variants.'.$key.'.stock')">
<x-hub::input.text type="number" wire:model="variants.{{ $key }}.stock" :id="'stock'.$key" :error="$errors->first('variants.'.$key.'.stock')" />
</x-hub::input.group>

<x-hub::input.group :label="__('adminhub::inputs.backorder.label')" :for="'backorder'.$key" :error="$errors->first('variants.'.$key.'.backorder')">
<x-hub::input.text type="number" wire:model="variants.{{ $key }}.backorder" :id="'backorder'.$key" :error="$errors->first('variants.'.$key.'.backorder')" />
</x-hub::input.group>
</div>
</div>

@endforeach
</div>
@else
<p class="text-md text-gray-500">{{ __('adminhub::partials.products.variants.empty_message') }}</p>
@endif
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function toggle($optionId)
*/
public function syncOptions($ids)
{
$this->options = ProductOption::with('values')->findMany($ids);
$this->options = ProductOption::with('values')->orderBy('position')->findMany($ids);
}

/**
Expand All @@ -94,7 +94,7 @@ public function refreshOptions($event)
{
$this->selectedValues[] = $event['value'];
$this->emit('option-manager.selectedValues', $this->selectedValues);
$this->options = ProductOption::with('values')->findMany($this->options->pluck('id'));
$this->options = ProductOption::with('values')->orderBy('position')->findMany($this->options->pluck('id'));
}

/**
Expand Down
Loading