diff --git a/app/Livewire/BillingPortal/Cart/Cart.php b/app/Livewire/BillingPortal/Cart/Cart.php index 46b5c87d1e..8faacb0fb8 100644 --- a/app/Livewire/BillingPortal/Cart/Cart.php +++ b/app/Livewire/BillingPortal/Cart/Cart.php @@ -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'); diff --git a/app/Livewire/BillingPortal/Summary.php b/app/Livewire/BillingPortal/Summary.php index 596e8d5e19..0db9dd7f03 100644 --- a/app/Livewire/BillingPortal/Summary.php +++ b/app/Livewire/BillingPortal/Summary.php @@ -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; } diff --git a/resources/views/billing-portal/v3/cart/cart.blade.php b/resources/views/billing-portal/v3/cart/cart.blade.php index 3df3be7883..e3bb510bd5 100644 --- a/resources/views/billing-portal/v3/cart/cart.blade.php +++ b/resources/views/billing-portal/v3/cart/cart.blade.php @@ -36,6 +36,7 @@ :context="$context" /> + @if($this->payableAmount())