Improvements for v3 of subscriptions

This commit is contained in:
David Bomba 2025-10-27 10:07:34 +11:00
parent f51f0c0c37
commit 38c0d8dd95
4 changed files with 47 additions and 5 deletions

View File

@ -57,6 +57,11 @@ class Cart extends Component
return count($optional) > 0;
}
public function payableAmount()
{
return isset($this->context['products']) && collect($this->context['products'])->sum('total_raw') > 0;
}
public function render()
{
return view('billing-portal.v3.cart.cart');

View File

@ -53,38 +53,68 @@ class Summary extends Component
];
foreach ($subscription->service()->recurring_products() as $key => $product) {
$default_quantity = $bundle['recurring_products'][$product->hashed_id]['quantity'] ?? 1;
if($subscription->use_inventory_management && $product['in_stock_quantity'] < 1){
$default_quantity = 0;
}
$bundle['recurring_products'][$product->hashed_id] = [
'product' => $product,
'quantity' => $bundle['recurring_products'][$product->hashed_id]['quantity'] ?? 1,
'quantity' => $default_quantity,
'notes' => $product->markdownNotes(),
];
$bundle['recurring_products'][$product->hashed_id]['product']['is_recurring'] = true;
}
foreach ($subscription->service()->products() as $key => $product) {
$default_quantity = $bundle['one_time_products'][$product->hashed_id]['quantity'] ?? 1;
if($subscription->use_inventory_management && $product['in_stock_quantity'] < 1){
$default_quantity = 0;
}
$bundle['one_time_products'][$product->hashed_id] = [
'product' => $product,
'quantity' => $bundle['one_time_products'][$product->hashed_id]['quantity'] ?? 1,
'quantity' => $default_quantity,
'notes' => $product->markdownNotes(),
];
$bundle['one_time_products'][$product->hashed_id]['product']['is_recurring'] = false;
}
foreach ($subscription->service()->optional_recurring_products() as $key => $product) {
$default_quantity = $bundle['optional_recurring_products'][$product->hashed_id]['quantity'] ?? 0;
if($subscription->use_inventory_management && $product['in_stock_quantity'] < 1){
$default_quantity = 0;
}
$bundle['optional_recurring_products'][$product->hashed_id] = [
'product' => $product,
'quantity' => $bundle['optional_recurring_products'][$product->hashed_id]['quantity'] ?? 0,
'quantity' => $default_quantity,
'notes' => $product->markdownNotes(),
];
$bundle['optional_recurring_products'][$product->hashed_id]['product']['is_recurring'] = true;
}
foreach ($subscription->service()->optional_products() as $key => $product) {
$default_quantity = $bundle['optional_one_time_products'][$product->hashed_id]['quantity'] ?? 0;
if($subscription->use_inventory_management && $product['in_stock_quantity'] < 1){
$default_quantity = 0;
}
$bundle['optional_one_time_products'][$product->hashed_id] = [
'product' => $product,
'quantity' => $bundle['optional_one_time_products'][$product->hashed_id]['quantity'] ?? 0,
'quantity' => $default_quantity,
'notes' => $product->markdownNotes(),
];
$bundle['optional_one_time_products'][$product->hashed_id]['product']['is_recurring'] = false;
}

View File

@ -36,6 +36,7 @@
:context="$context"
/>
@if($this->payableAmount())
<div class="mt-3">
<form wire:submit="handleSubmit">
<button
@ -46,4 +47,5 @@
</button>
</form>
</div>
@endif
</div>

View File

@ -47,7 +47,12 @@
class="block w-20 rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
{{ $this->subscription->use_inventory_management && $product['in_stock_quantity'] < 1 ? 'disabled' : '' }}
>
<option value="1" {{ $entry['quantity'] == 1 ? 'selected' : '' }}>1</option>
@if($this->subscription->use_inventory_management && $product['in_stock_quantity'] < 1)
<option value="0" {{ $entry['quantity'] == 0 ? 'selected' : '' }}>0</option>
@else
<option value="1" {{ $entry['quantity'] == 1 ? 'selected' : '' }}>1</option>
@endif
@for ($i = 2; $i <= $this->subscription->maxQuantity($product); $i++)
<option {{ $entry['quantity'] == $i ? 'selected' : '' }} value="{{ $i }}">{{ $i }}</option>
@endfor