Merge pull request #6905 from jibees/6498-show-unit-price-in-checkout

Show unit price in checkout process (both cart page and cart sidebar)
This commit is contained in:
Pau Pérez Fabregat
2021-02-24 11:59:25 +01:00
committed by GitHub
9 changed files with 49 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ Darkswarm.directive "questionMarkWithTooltip", ($tooltip)->
# Subsequently we patch the scope, template and restrictions
tooltip = $tooltip 'questionMarkWithTooltip', 'questionMarkWithTooltip', 'click'
tooltip.scope =
variant: "="
context: "="
tooltip.templateUrl = "question_mark_with_tooltip_icon.html"
tooltip.replace = true
tooltip.restrict = 'E'

View File

@@ -1,4 +1,4 @@
.joyride-tip-guide.question-mark-tooltip{ng: {class: "{ in: tt_isOpen, fade: tt_animation }", show: "tt_isOpen"}}
.joyride-tip-guide.question-mark-tooltip{class: "{{ context }}", ng: {class: "{ in: tt_isOpen, fade: tt_animation", show: "tt_isOpen"}}
.background{ng: {click: "tt_isOpen = false"}}
.joyride-content-wrapper
{{ "js.shopfront.unit_price_tooltip" | t }}

View File

@@ -52,6 +52,12 @@
font-size: 1.5em;
}
}
.unit-price {
justify-content: flex-end;
align-items: baseline;
}
}
.go-shopping {
@@ -82,7 +88,8 @@
padding: 0.5em 0 0.5em 1em;
}
span {
span,
.total-price {
color: $grey-800;
font-size: 16px;
line-height: 1.4em;

View File

@@ -44,6 +44,12 @@
}
}
.unit-price {
color: $grey-500;
font-size: $text-xs;
}
input {
&.ng-invalid-stock,
&.ng-invalid-number {

View File

@@ -56,4 +56,14 @@
left: 7.4rem;
z-index: -1;
}
&.cart-sidebar {
// Small size (used in the cart sidebar)
width: 13rem;
margin-left: -10.4rem;
.joyride-nub.bottom {
left: 10.4rem;
}
}
}

View File

@@ -45,3 +45,5 @@ $shop-sidebar-overlay: rgba(0, 0, 0, 0.5);
$transition-sidebar: 250ms ease-in-out 0s;
$padding-small: 0.5rem;
$text-xs: 0.75rem;

View File

@@ -219,6 +219,12 @@ module Spree
final_weight_volume / quantity
end
def unit_price_price_and_unit
price = Spree::Money.new((rand * 10).round(2), currency: currency)
unit = ["item", "kg"].sample
price.to_html + " / " + unit
end
def scoper
@scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
end

View File

@@ -22,7 +22,17 @@
%td.text-right
%span.quantity {{ line_item.quantity }}
%td
%span.total-price.right {{ line_item.total_price | localizeCurrency }}
.total-price.text-right {{ line_item.total_price | localizeCurrency }}
- if feature? :unit_price, spree_current_user
.flex.unit-price
%div{:style => "margin-right: 5px"}
%question-mark-with-tooltip{"question-mark-with-tooltip" => "_",
"question-mark-with-tooltip-append-to-body" => "true",
"question-mark-with-tooltip-placement" => "top",
"question-mark-with-tooltip-animation" => true,
context: "'cart-sidebar'"}
.options-text
{{ line_item.variant.unit_price_price | localizeCurrency }} / {{ line_item.variant.unit_price_unit }}
.cart-empty{"ng-show" => "Cart.line_items.length == 0"}
%p

View File

@@ -18,6 +18,10 @@
%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
= line_item.single_display_amount_with_adjustments.to_html
- if feature? :unit_price, spree_current_user
%br
%span.unit-price
= line_item.unit_price_price_and_unit
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
- finalized_quantity = @order.completed? ? line_item.quantity : 0
= item_form.number_field :quantity,