-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12848 from rioug/12770-product-preview
Product preview
- Loading branch information
Showing
47 changed files
with
1,090 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml | ||
%li{ "ng-class": "{active: selector.active}" } | ||
%a{ tooltip: "{{selector.object.value}}", "tooltip-placement": "bottom", "ng-transclude": true, "ng-class": "{active: selector.active, 'has-tip': selector.object.value}" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- # NOTE: make sure that any changes in this template are reflected in app/views/admin/products_v3/product_preview.turbo_stream.haml | ||
%ul | ||
%active-selector{ "ng-repeat": "selector in allSelectors", "ng-show": "ifDefined(selector.fits, true)" } | ||
%span{"ng-bind" => "::selector.object.name"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdminTooltipComponent < ViewComponent::Base | ||
def initialize(text:, link_text:, placement: "top", link: "", link_class: "") | ||
@text = text | ||
@link_text = link_text | ||
@placement = placement | ||
@link = link | ||
@link_class = link_class | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
app/components/admin_tooltip_component/admin_tooltip_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%div{"data-controller": "tooltip", "data-tooltip-placement-value": @placement } | ||
%a{"data-tooltip-target": "element", href: @link, class: @link_class} | ||
= @link_text | ||
.tooltip-container | ||
.tooltip{"data-tooltip-target": "tooltip"} | ||
= sanitize @text | ||
.arrow{"data-tooltip-target": "arrow"} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class ProductPreviewController < Spree::Admin::BaseController | ||
def show | ||
@product = Spree::Product.find(params[:id]) | ||
authorize! :show, @product | ||
|
||
respond_with do |format| | ||
format.turbo_stream { | ||
render "admin/products_v3/product_preview", status: :ok | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def model_class | ||
Spree::Product | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
app/views/admin/products_v3/product_preview.turbo_stream.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
= turbo_stream.update "product-preview-modal-container" do | ||
= render ModalComponent.new(id: "product-preview-modal", instant: true, modal_class: "big") do | ||
#product-preview{ "data-controller": "tabs" } | ||
%h1 | ||
= t("admin.products_page.product_preview.product_preview") | ||
%dl.admin-tabs | ||
%dd | ||
%a{ data: { "tabs-target": "tab", "action": "tabs#select" } } | ||
= t("admin.products_page.product_preview.shop_tab") | ||
%dd | ||
%a{ data: { "tabs-target": "tab", "action": "tabs#select" } } | ||
= t("admin.products_page.product_preview.product_details_tab") | ||
.tabs-content | ||
.content.active | ||
%div{ data: { "tabs-target": "content" } } | ||
.product-thumb | ||
%a | ||
- if @product.group_buy | ||
%span.product-thumb__bulk-label | ||
= t(".bulk") | ||
= image_tag @product.image&.url(:small) || Spree::Image.default_image_url(:small) | ||
.summary | ||
.summary-header | ||
%h3 | ||
%a | ||
%span | ||
= @product.name | ||
- if @product.description | ||
.product-description{ "data-controller": "add-blank-to-link" } | ||
- # description is sanitized in Spree::Product#description method | ||
= @product.description.html_safe | ||
- if @product.variants.first.supplier.visible | ||
%div | ||
.product-producer | ||
= t :products_from | ||
%span | ||
%a | ||
= @product.variants.first.supplier.name | ||
.product-properties.filter-shopfront.property-selectors | ||
.filter-shopfront.property-selectors.inline-block | ||
%ul | ||
- @product.properties_including_inherited.each do |property| | ||
%li | ||
- if property[:value].present? | ||
= render AdminTooltipComponent.new(text: property[:value], link_text: property[:name], placement: "bottom") | ||
- else | ||
%a | ||
%span | ||
= property[:name] | ||
.shop-variants | ||
- @product.variants.sort { |v1, v2| v1.name_to_display <=> v2.name_to_display }.sort { |v1, v2| v1.unit_value <=> v2.unit_value }.each do |variant| | ||
.variants.row | ||
.small-3.columns.variant-name | ||
- if variant.display_name.present? | ||
.inline | ||
= variant.display_name | ||
.variant-unit | ||
= variant.unit_to_display | ||
.small-4.medium-3.columns.variant-price | ||
= number_to_currency(variant.price) | ||
.unit-price.variant-unit-price | ||
= render AdminTooltipComponent.new(text: t("js.shopfront.unit_price_tooltip"), link_text: "", placement: "top", link_class: "question-mark-icon") | ||
- # TODO use an helper | ||
- unit_price = UnitPrice.new(variant) | ||
- price_per_unit = variant.price / (unit_price.denominator || 1) | ||
= "#{number_to_currency(price_per_unit)} / #{unit_price.unit}".html_safe | ||
|
||
|
||
.medium-3.columns.total-price | ||
%span | ||
= number_to_currency(0.00) | ||
.small-5.medium-3.large-3.columns.variant-quantity-column.text-right | ||
.variant-quantity-inputs | ||
%button.add-variant | ||
= t("js.shopfront.variant.add_to_cart") | ||
|
||
- # TODO can't check the shop preferrence here, display by default ? | ||
- if !variant.on_demand && variant.on_hand <= 3 | ||
.variant-remaining-stock | ||
= t("js.shopfront.variant.remaining_in_stock", quantity: variant.on_hand) | ||
|
||
%div{ data: { "tabs-target": "content" } } | ||
.row | ||
.columns.small-12.medium-6.large-6.product-header | ||
%h3 | ||
= @product.name | ||
%span | ||
%em | ||
= t("products_from") | ||
%span | ||
= @product.variants.first.supplier.name | ||
%br | ||
.filter-shopfront.property-selectors.inline-block | ||
%ul | ||
- @product.properties_including_inherited.each do |property| | ||
%li | ||
- if property[:value].present? | ||
= render AdminTooltipComponent.new(text: property[:value], link_text: property[:name], placement: "bottom") | ||
- else | ||
%a | ||
%span | ||
= property[:name] | ||
- if @product.description | ||
.product-description{ 'data-controller': "add-blank-to-link" } | ||
%p.text-small | ||
- # description is sanitized in Spree::Product#description method | ||
= @product.description.html_safe | ||
.columns.small-12.medium-6.large-6.product-img | ||
- if @product.image | ||
%img{ src: @product.image.url(:large) } | ||
-else | ||
%img.placeholder{ src: Spree::Image.default_image_url(:large) } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
= render partial: 'admin/shared/tooltip', locals: {link_class: "" ,link: nil, link_text: t('admin.whats_this'), tooltip_text: tooltip_text} | ||
= render AdminTooltipComponent.new(text: tooltip_text, link_text: t('admin.whats_this'), link: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.