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
rename wished_product to wished_variant
Matthew Kennedy7348b331d694
diff --git a/api/app/controllers/spree/api/v2/storefront/wished_products_controller.rb b/api/app/controllers/spree/api/v2/storefront/wished_variants_controller.rbsimilarity index 57%rename from api/app/controllers/spree/api/v2/storefront/wished_products_controller.rbrename to api/app/controllers/spree/api/v2/storefront/wished_variants_controller.rbindex 133ffdfe1e..df27ea8f9b 100644--- a/api/app/controllers/spree/api/v2/storefront/wished_products_controller.rb+++ b/api/app/controllers/spree/api/v2/storefront/wished_variants_controller.rb@@ -2,31 +2,31 @@ module Spreemodule Apimodule V2module Storefront- class WishedProductsController < ::Spree::Api::V2::ResourceController+ class WishedVariantsController < ::Spree::Api::V2::ResourceControllerdef create- spree_authorize! :create, Spree::WishedProduct+ spree_authorize! :create, Spree::WishedVariantspree_authorize! :update, wishlist- wished_product = Spree::WishedProduct.new(wished_product_attributes)+ wished_variant = Spree::WishedVariant.new(wished_variant_attributes)- if wishlist.include? params[:wished_product][:variant_id]- wished_product = wishlist.wished_products.detect { |wp| wp.variant_id == params[:wished_product][:variant_id].to_i }+ if wishlist.include? params[:wished_variant][:variant_id]+ wished_variant = wishlist.wished_variants.detect { |wp| wp.variant_id == params[:wished_variant][:variant_id].to_i }else- wished_product.wishlist = wishlist- wished_product.save+ wished_variant.wishlist = wishlist+ wished_variant.saveendwishlist.reload- if wished_product.persisted?- render_serialized_payload { serialize_resource(wished_product) }+ if wished_variant.persisted?+ render_serialized_payload { serialize_resource(wished_variant) }else- render_error_payload(wished_product.errors.full_messages.to_sentence)+ render_error_payload(wished_variant.errors.full_messages.to_sentence)endenddef updatespree_authorize! :update, resource- resource.update(wished_product_attributes)+ resource.update(wished_variant_attributes)if resource.errors.empty?render_serialized_payload { serialize_resource(resource) }@@ -47,19 +47,19 @@ module Spreeprivatedef resource- @resource ||= wishlist.wished_products.find(params[:id])+ @resource ||= wishlist.wished_variants.find(params[:id])enddef wishlist@wishlist ||= current_store.wishlists.find_by!(token: params[:wishlist_id])end- def wished_product_attributes- params.require(:wished_product).permit(permitted_wished_product_attributes)+ def wished_variant_attributes+ params.require(:wished_variant).permit(permitted_wished_variant_attributes)enddef resource_serializer- ::Spree::V2::Storefront::WishedProductSerializer+ ::Spree::V2::Storefront::WishedVariantSerializerendendenddiff --git a/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb b/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rbsimilarity index 89%rename from api/app/serializers/spree/v2/storefront/wished_product_serializer.rbrename to api/app/serializers/spree/v2/storefront/wished_variant_serializer.rbindex 978ce45278..5e2bf67810 100644--- a/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb@@ -1,8 +1,8 @@module Spreemodule V2module Storefront- class WishedProductSerializer < BaseSerializer- set_type :wished_product+ class WishedVariantSerializer < BaseSerializer+ set_type :wished_variantattributes :remark, :quantitydiff --git a/api/app/serializers/spree/v2/storefront/wishlist_serializer.rb b/api/app/serializers/spree/v2/storefront/wishlist_serializer.rbindex 31b90e03d1..d3398d4730 100644--- a/api/app/serializers/spree/v2/storefront/wishlist_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/wishlist_serializer.rb@@ -7,7 +7,7 @@ module Spreeattributes :token, :name, :is_private, :is_defaultbelongs_to :user- has_many :wished_products+ has_many :wished_variantsendendenddiff --git a/api/config/routes.rb b/api/config/routes.rbindex e0002e5313..85e8d48507 100644--- a/api/config/routes.rb+++ b/api/config/routes.rb@@ -169,7 +169,7 @@ Spree::Core::Engine.add_routes doresources :wishlists doget 'default', on: :collection- resources :wished_products, only: [:create, :update, :destroy]+ resources :wished_variants, only: [:create, :update, :destroy]endenddiff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 672243ed9e..d80f6fdeea 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -42,7 +42,7 @@ module Spreedependent: :destroy,inverse_of: :variant- has_many :wished_products, dependent: :destroy+ has_many :wished_variants, dependent: :destroybefore_validation :set_cost_currencydiff --git a/core/app/models/spree/wished_product.rb b/core/app/models/spree/wished_variant.rbsimilarity index 94%rename from core/app/models/spree/wished_product.rbrename to core/app/models/spree/wished_variant.rbindex f3b23fc6ef..103fae87f8 100644--- a/core/app/models/spree/wished_product.rb+++ b/core/app/models/spree/wished_variant.rb@@ -1,5 +1,5 @@module Spree- class WishedProduct < Spree::Base+ class WishedVariant < Spree::Baseextend DisplayMoneymoney_methods :total, :pricediff --git a/core/app/models/spree/wishlist.rb b/core/app/models/spree/wishlist.rbindex d16430b965..30c718aef8 100644--- a/core/app/models/spree/wishlist.rb+++ b/core/app/models/spree/wishlist.rb@@ -9,12 +9,12 @@ module Spreeafter_commit :ensure_default_exists_and_is_unique- has_many :wished_products, dependent: :destroy+ has_many :wished_variants, dependent: :destroyvalidates :name, :store, :user, presence: truedef include?(variant_id)- wished_products.map(&:variant_id).include? variant_id.to_i+ wished_variants.map(&:variant_id).include? variant_id.to_ienddef to_paramdiff --git a/core/db/migrate/20210906180746_rename_spree_wished_products_to_spree_wished_variants.rb b/core/db/migrate/20210906180746_rename_spree_wished_products_to_spree_wished_variants.rbnew file mode 100644index 0000000000..cc2aa97d4e--- /dev/null+++ b/core/db/migrate/20210906180746_rename_spree_wished_products_to_spree_wished_variants.rb@@ -0,0 +1,5 @@+class RenameSpreeWishedProductsToSpreeWishedVariants < ActiveRecord::Migration[5.2]+ def change+ rename_table :spree_wished_products, :spree_wished_variants+ end+enddiff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rbindex 995f693181..3cfff20888 100644--- a/core/lib/spree/permitted_attributes.rb+++ b/core/lib/spree/permitted_attributes.rb@@ -31,7 +31,7 @@ module Spree:cms_page_attributes,:cms_section_attributes,:wishlist_attributes,- :wished_product_attributes+ :wished_variant_attributes]mattr_reader *ATTRIBUTES@@ -145,6 +145,6 @@ module Spree@@wishlist_attributes = [:name, :is_default, :is_private]- @@wished_product_attributes = [:variant_id, :remark, :quantity]+ @@wished_variant_attributes = [:variant_id, :remark, :quantity]endend