Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions assets/js/theme/common/product-details-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export default class ProductDetailsBase {
$text: $('.incrementTotal', $scope),
$input: $('[name=qty\\[\\]]', $scope),
},
backorderAvailabilityPrompt: {
$container: $('[data-backorder-availability-prompt]', $scope),
},
$bulkPricing: $('.productView-info-bulkPricing', $scope),
$walletButtons: $('[data-add-to-cart-wallet-buttons]', $scope),
};
Expand Down Expand Up @@ -273,6 +276,29 @@ export default class ProductDetailsBase {
viewModel.stock.$input.text(data.stock);
}

// Update backorder availability prompt for complex products
const $backorderAvailabilityPromptContainer = viewModel.backorderAvailabilityPrompt.$container;

if ($backorderAvailabilityPromptContainer.length && this.context.showBackorderAvailabilityPrompt) {
const $prompt = $backorderAvailabilityPromptContainer.find('.productView-backorder-availability-prompt');

if (typeof data.stock === 'number' && data.stock > 0) {
if ($prompt.length) {
$prompt.show();
} else {
const promptText = this.context.backorderAvailabilityPrompt;

if (promptText) {
$backorderAvailabilityPromptContainer.html(
`<span class="productView-backorder-availability-prompt">(${promptText})</span>`,
);
}
}
} else {
$prompt.hide();
}
}

this.updateDefaultAttributesForOOS(data);
this.updateWalletButtonsView(data);

Expand Down
6 changes: 5 additions & 1 deletion templates/components/products/product-view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{inject 'outOfStockDefaultMessage' (lang 'products.out_of_stock_default_message')}}
{{inject 'showBackorderAvailabilityPrompt' product.show_backorder_availability_prompt}}
{{inject 'backorderAvailabilityPrompt' product.backorder_availability_prompt}}

<div class="productView"
data-event-type="product"
Expand Down Expand Up @@ -247,7 +249,9 @@ <h2 class="productView-brand">
<label class="form-label form-label--alternate">
{{lang 'products.current_stock'}}
<span data-product-stock>{{product.stock_level}}</span>
{{> components/products/backorder-availability-prompt show_prompt=product.show_backorder_availability_prompt prompt=product.backorder_availability_prompt available_to_sell=product.available_to_sell available_for_backorder=product.available_for_backorder}}
<span data-backorder-availability-prompt>
{{> components/products/backorder-availability-prompt show_prompt=product.show_backorder_availability_prompt prompt=product.backorder_availability_prompt available_to_sell=product.available_to_sell available_for_backorder=product.available_for_backorder}}
</span>
</label>
</div>
{{> components/products/add-to-cart with_wallet_buttons=true}}
Expand Down