From f610a709e1f32d3da2fa867a2ba983cd583841b5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 12:51:00 +1000 Subject: [PATCH] Adding inherits_properties to BPE --- .../admin/bulk_product_update.js.coffee | 18 +++++++++++------- app/models/spree/product_decorator.rb | 6 ++++-- .../api/admin/product_serializer.rb | 2 +- .../bulk_edit/_products_head.html.haml | 2 ++ .../bulk_edit/_products_product.html.haml | 2 ++ .../features/admin/bulk_product_update_spec.rb | 4 ++++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index e8e14413ae..97c19cdd26 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -4,13 +4,14 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $scope.StatusMessage = StatusMessage $scope.columns = - producer: {name: "Producer", visible: true} - name: {name: "Name", visible: true} - unit: {name: "Unit", visible: true} - price: {name: "Price", visible: true} - on_hand: {name: "On Hand", visible: true} - category: {name: "Category", visible: false} - available_on: {name: "Available On", visible: false} + producer: {name: "Producer", visible: true} + name: {name: "Name", visible: true} + unit: {name: "Unit", visible: true} + price: {name: "Price", visible: true} + on_hand: {name: "On Hand", visible: true} + category: {name: "Category", visible: false} + inherits_properties: {name: "Inherits Properties?", visible: false} + available_on: {name: "Available On", visible: false} $scope.variant_unit_options = VariantUnitManager.variantUnitOptions() @@ -307,6 +308,9 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("category_id") filteredProduct.primary_taxon_id = product.category_id hasUpdatableProperty = true + if product.hasOwnProperty("inherits_properties") + filteredProduct.inherits_properties = product.inherits_properties + hasUpdatableProperty = true if product.hasOwnProperty("available_on") filteredProduct.available_on = product.available_on hasUpdatableProperty = true diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index fbd882dfd4..c127977823 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -18,8 +18,10 @@ Spree::Product.class_eval do delegate_belongs_to :master, :unit_value, :unit_description delegate :images_attributes=, :display_as=, to: :master - attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size - attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes, :images_attributes, :display_as + attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes + attr_accessible :group_buy, :group_buy_unit_size, :unit_description, :notes, :images_attributes, :display_as + attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value + attr_accessible :inherits_properties validates_associated :master, message: "^Price and On Hand must be valid" validates_presence_of :supplier diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index d980013674..31b2db8ffd 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -1,5 +1,5 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer - attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand + attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand, :inherits_properties attributes :on_hand, :price, :available_on, :permalink_live diff --git a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml index d6be2a88e0..69cdc465ef 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml @@ -7,6 +7,7 @@ %col.price{ ng: { show: 'columns.price.visible'} } %col.on_hand{ ng: { show: 'columns.on_hand.visible' } } %col.category{ ng: { show: 'columns.category.visible' } } + %col.inherits_properties{ ng: { show: 'columns.inherits_properties.visible' } } %col.available_on{ ng: { show: 'columns.available_on.visible' } } %col.actions %col.actions @@ -22,6 +23,7 @@ %th.price{ 'ng-show' => 'columns.price.visible' } Price %th.on_hand{ 'ng-show' => 'columns.on_hand.visible' } On Hand %th.category{ 'ng-show' => 'columns.category.visible' } Category + %th.inherits_properties{ 'ng-show' => 'columns.inherits_properties.visible' } Inherits Properties? %th.available_on{ 'ng-show' => 'columns.available_on.visible' } Av. On %th.actions %th.actions diff --git a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml index bf527ba507..c850dc849c 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml @@ -20,6 +20,8 @@ %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } %td.category{ 'ng-if' => 'columns.category.visible' } %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category_id", 'ng-model' => 'product.category_id', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category_id', 'multiple-selection' => 'false', placeholder: 'Category' } + %td.inherits_properties{ 'ng-show' => 'columns.inherits_properties.visible' } + %input{ 'ng-model' => 'product.inherits_properties', :name => 'inherits_properties', 'ofn-track-product' => 'inherits_properties', type: "checkbox" } %td.available_on{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index debb234284..bb84edb33f 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -299,6 +299,7 @@ feature %q{ first("div#columns_dropdown", :text => "COLUMNS").click first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click first("div#columns_dropdown div.menu div.menu_item", text: "Category").click + first("div#columns_dropdown div.menu div.menu_item", text: "Inherits Properties?").click within "tr#p_#{p.id}" do expect(page).to have_field "product_name", with: p.name @@ -308,6 +309,7 @@ feature %q{ expect(page).to have_selector "div#s2id_p#{p.id}_category_id a.select2-choice" expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" expect(page).to have_field "on_hand", with: "6" + expect(page).to have_checked_field "inherits_properties" fill_in "product_name", with: "Big Bag Of Potatoes" select s2.name, :from => 'producer_id' @@ -317,6 +319,7 @@ feature %q{ select2_select t1.name, from: "p#{p.id}_category_id" fill_in "on_hand", with: "18" fill_in "display_as", with: "Big Bag" + uncheck "inherits_properties" end click_button 'Save Changes' @@ -332,6 +335,7 @@ feature %q{ expect(p.price).to eq 20.0 expect(p.on_hand).to eq 18 expect(p.primary_taxon).to eq t1 + expect(p.inherits_properties).to be false end scenario "updating a product with a variant unit of 'items'" do