From 87df61fa6713e3ea32546f360e94b269dcc74fdc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 22 Feb 2024 14:36:59 +1100 Subject: [PATCH] Fixes for broken Markdown Parsing --- app/Models/Product.php | 14 +++++++ lang/en/texts.php | 1 + .../v3/cart/one-time-products.blade.php | 42 +++++++++++++++---- .../cart/optional-one-time-products.blade.php | 26 ++++++------ .../optional-recurring-products.blade.php | 28 ++++++------- .../v3/cart/recurring-products.blade.php | 8 ++-- 6 files changed, 78 insertions(+), 41 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index e4736a0f7ca7..7c49afc9338f 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -148,6 +148,20 @@ class Product extends BaseModel return $converter->convert($this->notes ?? ''); } + public static function markdownHelp(string $notes = '') + { + + $converter = new CommonMarkConverter([ + 'allow_unsafe_links' => false, + 'renderer' => [ + 'soft_break' => '
', + ], + ]); + + return $converter->convert($notes); + + } + public function portalUrl($use_react_url): string { return $use_react_url ? config('ninja.react_url') . "/#/products/{$this->hashed_id}/edit" : config('ninja.app_url'); diff --git a/lang/en/texts.php b/lang/en/texts.php index 8b6027093966..fbcda6317ac5 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5237,6 +5237,7 @@ $lang = array( 'user_sales' => 'User Sales', 'iframe_url' => 'iFrame URL', 'user_unsubscribed' => 'User unsubscribed from emails :link', + 'out_of_stock' => 'Out of stock', ); return $lang; diff --git a/resources/views/billing-portal/v3/cart/one-time-products.blade.php b/resources/views/billing-portal/v3/cart/one-time-products.blade.php index a2da7c89101c..12ed06f652ca 100644 --- a/resources/views/billing-portal/v3/cart/one-time-products.blade.php +++ b/resources/views/billing-portal/v3/cart/one-time-products.blade.php @@ -1,15 +1,20 @@
- @unless(empty($subscription->product_ids)) - @foreach($subscription->service()->products() as $index => $product) + @isset($context['bundle']['one_time_products']) + @foreach($context['bundle']['one_time_products'] as $key => $entry) + + @php + $product = $entry['product']; + @endphp +
- @if(filter_var($product->product_image, FILTER_VALIDATE_URL)) + @if(filter_var($product['product_image'], FILTER_VALIDATE_URL))
@@ -17,16 +22,35 @@ @endif
-

{{ $product->product_key }}

-

{{ \App\Utils\Number::formatMoney($product->price, $subscription->company) }}

+

{{ $product['product_key'] }}

+

{{ \App\Utils\Number::formatMoney($product['price'], $subscription['company']) }}

+
+
+ +
+
+ @if($subscription->per_seat_enabled) + @if($subscription->use_inventory_management && $product['in_stock_quantity'] <= 0) +

{{ ctrans('texts.out_of_stock') }}

+ @else +

{{ ctrans('texts.qty') }}

+ @endif + + + @endif
- {!! $product->markdownNotes() !!} + {!! \App\Models\Product::markdownHelp($product['notes']) !!}
@endforeach - @endunless -
+ @endisset +
\ No newline at end of file diff --git a/resources/views/billing-portal/v3/cart/optional-one-time-products.blade.php b/resources/views/billing-portal/v3/cart/optional-one-time-products.blade.php index 0e206333710b..5b5839c1cac4 100644 --- a/resources/views/billing-portal/v3/cart/optional-one-time-products.blade.php +++ b/resources/views/billing-portal/v3/cart/optional-one-time-products.blade.php @@ -29,26 +29,24 @@
- @if($subscription->per_seat_enabled) - @if($subscription->use_inventory_management && $product['in_stock_quantity'] == 0) -

{{ ctrans('texts.out_of_stock') }}

- @else -

{{ ctrans('texts.qty') }}

- @endif - - + @if($subscription->use_inventory_management && $product['in_stock_quantity'] <= 0) +

{{ ctrans('texts.out_of_stock') }}

+ @else +

{{ ctrans('texts.qty') }}

@endif + +
- {!! $product['notes'] !!} + {!! \App\Models\Product::markdownHelp($product['notes']) !!}
@endforeach diff --git a/resources/views/billing-portal/v3/cart/optional-recurring-products.blade.php b/resources/views/billing-portal/v3/cart/optional-recurring-products.blade.php index 5a4b0b129c50..92b3bdba98cb 100644 --- a/resources/views/billing-portal/v3/cart/optional-recurring-products.blade.php +++ b/resources/views/billing-portal/v3/cart/optional-recurring-products.blade.php @@ -29,26 +29,26 @@
- @if($subscription->per_seat_enabled) - @if($subscription->use_inventory_management && $product['in_stock_quantity'] == 0) -

{{ ctrans('texts.out_of_stock') }}

- @else -

{{ ctrans('texts.qty') }}

- @endif - - + + @if($subscription->use_inventory_management && $product['in_stock_quantity'] <= 0) +

{{ ctrans('texts.out_of_stock') }}

+ @else +

{{ ctrans('texts.qty') }}

@endif + + +
- {!! $product['notes'] !!} + {!! \App\Models\Product::markdownHelp($product['notes']) !!}
@endforeach diff --git a/resources/views/billing-portal/v3/cart/recurring-products.blade.php b/resources/views/billing-portal/v3/cart/recurring-products.blade.php index 1ecbe0020ba5..d7793f383fe2 100644 --- a/resources/views/billing-portal/v3/cart/recurring-products.blade.php +++ b/resources/views/billing-portal/v3/cart/recurring-products.blade.php @@ -30,7 +30,7 @@
@if($subscription->per_seat_enabled) - @if($subscription->use_inventory_management && $product['in_stock_quantity'] == 0) + @if($subscription->use_inventory_management && $product['in_stock_quantity'] < 1)

{{ ctrans('texts.out_of_stock') }}

@else

{{ ctrans('texts.qty') }}

@@ -40,7 +40,7 @@ id="{{ $product['hashed_id'] }}" class="rounded-md border-gray-300 shadow-sm sm:text-sm" wire:change="quantity($event.target.id, $event.target.value)" - @if($subscription->use_inventory_management && $product['in_stock_quantity'] == 0) disabled @endif + {{ $subscription->use_inventory_management && $product['in_stock_quantity'] < 1 ? 'disabled' : '' }} > @@ -49,7 +49,7 @@ @endfor @else - @for ($i = 2; $i <= ($subscription->use_inventory_management ? min($product['in_stock_quantity'], max(100,$product['max_quantity'])) : max(100,$product['max_quantity'])); $i++) + @for ($i = 2; $i <= ($subscription->use_inventory_management ? min($product['in_stock_quantity'], min(100,$product['max_quantity'])) : min(100,$product['max_quantity'])); $i++) @endfor @endif @@ -60,7 +60,7 @@
- {!! $product['notes'] !!} + {!! \App\Models\Product::markdownHelp($product['notes']) !!}
@endforeach