From ee4402f751474b17534b5f6c12aee6c7db30f9cd Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 21 May 2023 19:16:47 +0100 Subject: [PATCH] Stop using master variant for storing :display_as value (cherry picked from commit 8c0b8dad8561db21c5c9294a649fb441da3ab1e6) --- app/models/spree/product.rb | 9 +++++---- app/views/spree/admin/products/_display_as.html.haml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 3d858a1272..51c52d451f 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -76,11 +76,11 @@ module Spree } delegate_belongs_to :master, :images, :sku, :unit_value, :unit_description - delegate :images_attributes=, :display_as=, to: :master + delegate :images_attributes=, to: :master - # Transient attribute used temporarily when creating a new product, - # this value is persisted on the product's variant - attr_accessor :price + # Transient attributes used temporarily when creating a new product, + # these values are persisted on the product's variant + attr_accessor :price, :display_as after_create :set_master_variant_defaults after_save :save_master @@ -395,6 +395,7 @@ module Spree variant.product = self variant.is_master = false variant.price = price + variant.display_as = display_as variants << variant end diff --git a/app/views/spree/admin/products/_display_as.html.haml b/app/views/spree/admin/products/_display_as.html.haml index 9a98e660c4..c0719e97f8 100644 --- a/app/views/spree/admin/products/_display_as.html.haml +++ b/app/views/spree/admin/products/_display_as.html.haml @@ -1,4 +1,4 @@ .six.columns.omega{ "ng-if" => "product.variant_unit_with_scale != 'items'" } = f.field_container :display_as do = f.label :product_display_as, t('.display_as') - %input#product_display_as.fullwidth{name: "product[display_as]", placeholder: "{{ placeholder_text }}", type: "text", value: @product.master.display_as} + %input#product_display_as.fullwidth{name: "product[display_as]", placeholder: "{{ placeholder_text }}", type: "text", value: @product.display_as}