Skip to content

armgit / spree

Public Imported from GitHub
0

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.

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.rb
similarity index 57%
rename from api/app/controllers/spree/api/v2/storefront/wished_products_controller.rb
rename to api/app/controllers/spree/api/v2/storefront/wished_variants_controller.rb
index 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 Spree
module Api
module V2
module Storefront
- class WishedProductsController < ::Spree::Api::V2::ResourceController
+ class WishedVariantsController < ::Spree::Api::V2::ResourceController
def create
- spree_authorize! :create, Spree::WishedProduct
+ spree_authorize! :create, Spree::WishedVariant
spree_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.save
end
wishlist.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)
end
end
def update
spree_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 Spree
private
def resource
- @resource ||= wishlist.wished_products.find(params[:id])
+ @resource ||= wishlist.wished_variants.find(params[:id])
end
def 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)
end
def resource_serializer
- ::Spree::V2::Storefront::WishedProductSerializer
+ ::Spree::V2::Storefront::WishedVariantSerializer
end
end
end
diff --git a/api/app/serializers/spree/v2/storefront/wished_product_serializer.rb b/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb
similarity index 89%
rename from api/app/serializers/spree/v2/storefront/wished_product_serializer.rb
rename to api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb
index 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 Spree
module V2
module Storefront
- class WishedProductSerializer < BaseSerializer
- set_type :wished_product
+ class WishedVariantSerializer < BaseSerializer
+ set_type :wished_variant
attributes :remark, :quantity
diff --git a/api/app/serializers/spree/v2/storefront/wishlist_serializer.rb b/api/app/serializers/spree/v2/storefront/wishlist_serializer.rb
index 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 Spree
attributes :token, :name, :is_private, :is_default
belongs_to :user
- has_many :wished_products
+ has_many :wished_variants
end
end
end
diff --git a/api/config/routes.rb b/api/config/routes.rb
index e0002e5313..85e8d48507 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -169,7 +169,7 @@ Spree::Core::Engine.add_routes do
resources :wishlists do
get 'default', on: :collection
- resources :wished_products, only: [:create, :update, :destroy]
+ resources :wished_variants, only: [:create, :update, :destroy]
end
end
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 672243ed9e..d80f6fdeea 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -42,7 +42,7 @@ module Spree
dependent: :destroy,
inverse_of: :variant
- has_many :wished_products, dependent: :destroy
+ has_many :wished_variants, dependent: :destroy
before_validation :set_cost_currency
diff --git a/core/app/models/spree/wished_product.rb b/core/app/models/spree/wished_variant.rb
similarity index 94%
rename from core/app/models/spree/wished_product.rb
rename to core/app/models/spree/wished_variant.rb
index 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::Base
extend DisplayMoney
money_methods :total, :price
diff --git a/core/app/models/spree/wishlist.rb b/core/app/models/spree/wishlist.rb
index d16430b965..30c718aef8 100644
--- a/core/app/models/spree/wishlist.rb
+++ b/core/app/models/spree/wishlist.rb
@@ -9,12 +9,12 @@ module Spree
after_commit :ensure_default_exists_and_is_unique
- has_many :wished_products, dependent: :destroy
+ has_many :wished_variants, dependent: :destroy
validates :name, :store, :user, presence: true
def include?(variant_id)
- wished_products.map(&:variant_id).include? variant_id.to_i
+ wished_variants.map(&:variant_id).include? variant_id.to_i
end
def to_param
diff --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.rb
new file mode 100644
index 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
+end
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 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]
end
end