Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add display price, in currency and validations.
Matthew Kennedye67efa9e11fe
diff --git a/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb b/api/app/serializers/spree/v2/storefront/wished_product_serializer.rbindex 7487054fd8..978ce45278 100644--- a/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb@@ -4,7 +4,23 @@ module Spreeclass WishedProductSerializer < BaseSerializerset_type :wished_product- attributes :remark, :quantity, :total, :display_total+ attributes :remark, :quantity++ attribute :price do |wished_variant, params|+ wished_variant.price(currency: params[:currency])+ end++ attribute :total do |wished_variant, params|+ wished_variant.total(currency: params[:currency])+ end++ attribute :display_price do |wished_variant, params|+ wished_variant.display_price(currency: params[:currency])+ end++ attribute :display_total do |wished_variant, params|+ wished_variant.display_total(currency: params[:currency])+ endbelongs_to :variantbelongs_to :wishlist, serializer: ::Spree::V2::Storefront::WishlistSerializerdiff --git a/core/app/models/spree/wished_product.rb b/core/app/models/spree/wished_product.rbindex 425395a571..ff331d028a 100644--- a/core/app/models/spree/wished_product.rb+++ b/core/app/models/spree/wished_product.rb@@ -1,16 +1,21 @@module Spreeclass WishedProduct < Spree::Base+ extend DisplayMoney+ money_methods :total, :price+belongs_to :variantbelongs_to :wishlisthas_one :product, through: :variant- def total- quantity * (variant.price || 0)+ validates :variant, :wishlist, presence: true++ def price(currency)+ variant.price_in(currency[:currency]).amount.to_iend- def display_total- Spree::Money.new(total)+ def total(currency)+ quantity * variant.price_in(currency[:currency]).amount.to_iendendenddiff --git a/core/app/models/spree/wishlist.rb b/core/app/models/spree/wishlist.rbindex 89eff3d80c..931a961835 100644--- a/core/app/models/spree/wishlist.rb+++ b/core/app/models/spree/wishlist.rb@@ -10,6 +10,7 @@ module Spreehas_many :wished_products, dependent: :destroyvalidates :name, presence: true+ validates :is_default, uniqueness: { scope: [:store] }def include?(variant_id)wished_products.map(&:variant_id).include? variant_id.to_i