Migrate product image from master variant to product

This commit is contained in:
Matt-Yorkley
2023-05-22 11:39:38 +01:00
parent d8649fc9fb
commit 7dc1091bc2
37 changed files with 73 additions and 89 deletions

View File

@@ -9,9 +9,9 @@ module Api
product = Spree::Product.find(params[:product_id])
authorize! :update, product
image = product.images.first || Spree::Image.new(
viewable_id: product.master.id,
viewable_type: 'Spree::Variant'
image = product.image || Spree::Image.new(
viewable_id: product.id,
viewable_type: 'Spree::Product'
)
success_status = image.persisted? ? :ok : :created

View File

@@ -116,7 +116,7 @@ module Api
def product_query_includes
[
master: { images: { attachment_attachment: :blob } },
image: { attachment_attachment: :blob },
variants: [:default_price, :stock_locations, :stock_items, :variant_overrides]
]
end