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.

Update controller and routes.

Matthew Kennedyc1649284909a
diff --git a/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb b/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
index c6ff27ee03..dcb52fd25b 100644
--- a/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
+++ b/api/app/controllers/spree/api/v2/storefront/wishlists_controller.rb
@@ -59,14 +59,13 @@ module Spree
render_serialized_payload { serialize_resource(@default_wishlist) }
end
- def add_item
+ def add_wished_variant
spree_authorize! :create, Spree::WishedVariant
- @wished_variant = Spree::WishedVariant.new(params.permit(:quantity, :variant_id))
-
- if resource.include? params[:variant_id]
+ if resource.wished_variants.present? && resource.wished_variants.detect { |wv| wv.variant_id == params[:variant_id] }.present?
@wished_variant = resource.wished_variants.detect { |wv| wv.variant_id == params[:variant_id] }
else
+ @wished_variant = Spree::WishedVariant.new(params.permit(:quantity, :variant_id))
@wished_variant.wishlist = resource
@wished_variant.save
end
@@ -80,7 +79,7 @@ module Spree
end
end
- def update_item_quantity
+ def update_wished_variant_quantity
spree_authorize! :update, wished_variant
return render_error_item_quantity unless params[:quantity].to_i > 0
@@ -94,7 +93,7 @@ module Spree
end
end
- def remove_item
+ def remove_wished_variant
spree_authorize! :destroy, wished_variant
if wished_variant.destroy
diff --git a/api/config/routes.rb b/api/config/routes.rb
index 704eb15d8e..42bd8eabe9 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -173,9 +173,9 @@ Spree::Core::Engine.add_routes do
get :default, on: :collection
member do
- post :add_item
- patch 'update_item_quantity/:wished_variant_id', to: 'wishlists#update_item_quantity', as: :update_item_quantity
- delete 'remove_item/:wished_variant_id', to: 'wishlists#remove_item', as: :remove_item
+ post :add_wished_variant
+ patch 'update_wished_variant_quantity/:wished_variant_id', to: 'wishlists#update_wished_variant_quantity', as: :update_wished_variant_quantity
+ delete 'remove_wished_variant/:wished_variant_id', to: 'wishlists#remove_wished_variant', as: :remove_wished_variant
end
end
end
diff --git a/api/spec/serializers/spree/api/v2/storefront/wished_variant_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/wished_variant_serializer_spec.rb
similarity index 100%
rename from api/spec/serializers/spree/api/v2/storefront/wished_variant_serializer_spec.rb
rename to api/spec/serializers/spree/v2/storefront/wished_variant_serializer_spec.rb
diff --git a/api/spec/serializers/spree/api/v2/storefront/wishlist_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb
similarity index 100%
rename from api/spec/serializers/spree/api/v2/storefront/wishlist_serializer_spec.rb
rename to api/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb