From b42e3eb2c976377cf3b9ea5fc97d22ef590e9c0f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Sat, 3 Feb 2018 19:29:31 +0000 Subject: [PATCH] Product Import Guide WIP --- .../controllers/import_options_form.js.coffee | 7 +- .../stylesheets/admin/product_import.css.scss | 35 +++++++ .../admin/product_import_controller.rb | 8 +- app/models/spree/ability_decorator.rb | 2 +- .../admin/product_import/guide.html.haml | 69 ++++++++++++++ .../product_import/guide/_columns.html.haml | 93 +++++++++++++++++++ .../product_import/guide/_units.html.haml | 54 +++++++++++ .../product_import/guide/_variants.html.haml | 54 +++++++++++ .../admin/product_import/index.html.haml | 6 ++ config/routes.rb | 1 + 10 files changed, 325 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/product_import/guide.html.haml create mode 100644 app/views/admin/product_import/guide/_columns.html.haml create mode 100644 app/views/admin/product_import/guide/_units.html.haml create mode 100644 app/views/admin/product_import/guide/_variants.html.haml diff --git a/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee b/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee index 25a8cc7470..2198b830dc 100644 --- a/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee +++ b/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee @@ -26,12 +26,15 @@ angular.module("admin.productImport").controller "ImportOptionsFormCtrl", ($scop , true $scope.toggleResetAbsent = (id) -> - resetAbsent = $scope.settings[id]['reset_all_absent'] + checked = $scope.settings[id]['reset_all_absent'] confirmed = confirm t('js.product_import.confirmation') if resetAbsent - if confirmed or !resetAbsent + if confirmed or !checked ProductImportService.updateResetAbsent($scope.supplierId, $scope.reset_counts[$scope.supplierId], resetAbsent) + if !confirmed and checked + $scope.settings[id]['reset_all_absent'] = false + $scope.resetTotal = ProductImportService.resetTotal $rootScope.$watch 'resetTotal', (newValue) -> diff --git a/app/assets/stylesheets/admin/product_import.css.scss b/app/assets/stylesheets/admin/product_import.css.scss index ebd58fc468..eecd46b2b1 100644 --- a/app/assets/stylesheets/admin/product_import.css.scss +++ b/app/assets/stylesheets/admin/product_import.css.scss @@ -1,3 +1,38 @@ +.product-import-introduction { + + h1, h2, h3, h4, h5, h6 { + margin: 1.5em 0 1em; + } + + h6 { + font-size: 1em; + } + + p { + margin-bottom: 1em; + } + + span.category { + display: inline-block; + background-color: #f3f3f3; + padding: 0.4em 0.8em; + margin: 0 0.4em 0.5em 0; + } + + table { + + &.product-import-columns tr:hover td { + background-color: transparent; + } + + thead th { + text-transform: none; + font-size: 100%; + text-align: left; + } + } +} + div.panel-section { .neutral { diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index 3b5e9638e2..b8c760a9fc 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -2,7 +2,13 @@ require 'roo' module Admin class ProductImportController < Spree::Admin::BaseController - before_filter :validate_upload_presence, except: %i[index validate_data] + before_filter :validate_upload_presence, except: %i[index guide validate_data] + + def guide + @product_categories = Spree::Taxon.order('name ASC').pluck(:name) + @tax_categories = Spree::TaxCategory.order('name ASC').pluck(:name) + @shipping_categories = Spree::ShippingCategory.order('name ASC').pluck(:name) + end def import # Save uploaded file to tmp directory diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index ed8d15fb47..d9a99bce7f 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -177,7 +177,7 @@ class AbilityDecorator can [:admin, :index, :read, :search], Spree::Taxon can [:admin, :index, :read, :create, :edit], Spree::Classification - can [:admin, :index, :import, :save, :save_data, :validate_data, :reset_absent_products], ProductImport::ProductImporter + can [:admin, :index, :guide, :import, :save, :save_data, :validate_data, :reset_absent_products], ProductImport::ProductImporter # Reports page can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :packing], :report diff --git a/app/views/admin/product_import/guide.html.haml b/app/views/admin/product_import/guide.html.haml new file mode 100644 index 0000000000..aab0350606 --- /dev/null +++ b/app/views/admin/product_import/guide.html.haml @@ -0,0 +1,69 @@ +- content_for :page_title do + Product Import Guide + +- content_for :page_actions do + %div.toolbar{ 'data-hook' => "toolbar" } + %ul.actions.header-action-links.inline-menu + %li + = button_link_to 'Back to Import', main_app.admin_product_import_path + += render partial: 'spree/admin/shared/product_sub_menu' + +.product-import-introduction + + %h5 Spreadsheet Columns + + = render 'admin/product_import/guide/columns' + + %h5 Weight, volume, or single items + + %p + When creating a product you can specify a number of options. If the product is measured + by weight, unit_value should be set to a number and unit_type should be set to either + g for grams, Kg for kilograms, or T for tonnes. + + %p + For items such as liquids, the unit_type can be ml for millilitres, L for litres or + Kl for kilolitres. + + %p + For other items that are sold in different units such as "a bunch of carrots", you can + enter 1 for units, leave unit_type blank, and enter a name in the variant_unit_name + column such as "loaf" or "bunch". + + %h6 Example spreadsheet data: + + = render 'admin/product_import/guide/units' + + + %h5 Product Variants + + %p + Variants are distinguished by the units and display_name fields and grouped by product name. + The example below shows a salad that comes in 500g and 750g variants, and a cake that comes in + multiple flavours. + + %h6 Example spreadsheet data: + + = render 'admin/product_import/guide/variants' + + + %h5 Category Values + + %p + Listed below are the available Product categories, as well as Tax and Shipping categories. + + %h6 Product Categories + + - @product_categories.each do |pc| + %span.category= pc + + %h6 Tax Categories + + - @tax_categories.each do |tc| + %span.category= tc + + %h6 Shipping Categories + + - @shipping_categories.each do |sc| + %span.category= sc diff --git a/app/views/admin/product_import/guide/_columns.html.haml b/app/views/admin/product_import/guide/_columns.html.haml new file mode 100644 index 0000000000..d5aa454670 --- /dev/null +++ b/app/views/admin/product_import/guide/_columns.html.haml @@ -0,0 +1,93 @@ +%table.product-import-columns + %thead + %tr + %th Column Title + %th Required + %th Examples + %th Description + %th Notes + %tbody + %tr + %td + %strong name + %td Yes + %td Potatoes + %td The name of the product + %td + %tr + %td + %strong supplier + %td Yes + %td Pennylane Farm + %td The name of the product's supplier + %td + %tr + %td + %strong category + %td Yes + %td Vegetables + %td The product category + %td See below for a list of available categories + %tr + %td + %strong on_hand + %td Yes + %td 15 + %td The amount currently in stock + %td + %tr + %td + %strong price + %td Yes + %td 2.50 + %td The price of the product + %td + %tr + %td + %strong units + %td Yes + %td 750 + %td The weight or volume value. + %td + %tr + %td + %strong unit_type + %td Yes + %td g + %td The unit type, i.e. g for grams, Kg for Kilograms, ml for millilitres. Can be blank (see notes). + %td If unit_type is left blank, a variant_unit_name must be given. + %tr + %td + %strong variant_unit_name + %td Maybe + %td bunch + %td If the product is sold as an item such as "bunch", "loaf" or "case", that goes here. + %td Used for products that don't use a unit_type for weight or volume. + %tr + %td + %strong display_name + %td No + %td Orange + %td Used to name product variants, if they have a distinct name. + %td + %tr + %td + %strong on_demand + %td No + %td 1 + %td Flag the product as "made on demand". The product will not use stock levels. + %td 1 for active, 0 for disabled, or leave blank to ignore. + %tr + %td + %strong tax_category + %td No + %td (Various, see notes) + %td Sets the product tax category + %td See below for a list of available categories + %tr + %td + %strong shipping_category + %td No + %td (Various, see notes) + %td Sets the product shipping category + %td See below for a list of available categories diff --git a/app/views/admin/product_import/guide/_units.html.haml b/app/views/admin/product_import/guide/_units.html.haml new file mode 100644 index 0000000000..07161bdb1c --- /dev/null +++ b/app/views/admin/product_import/guide/_units.html.haml @@ -0,0 +1,54 @@ +%table + %thead + %tr + %th + %th name + %th category + %th supplier + %th on_hand + %th price + %th units + %th unit_type + %th variant_unit_name + %tbody + %tr + %td 1 + %td Salad Bag + %td Salads + %td Sue's Salads + %td 26 + %td 3.50 + %td 500 + %td g + %td + %tr + %td 2 + %td Fruit Juice + %td Drinks + %td Country Juices + %td 12 + %td 3.50 + %td 300 + %td ml + %td + %tr + %td 3 + %td Potatoes + %td Vegetables + %td Fernwell Farm + %td 67 + %td 4.20 + %td 1 + %td kg + %td + + %tr + %td 3 + %td Wholemeal Bread + %td Baked goods + %td Tim's Bakery + %td 66 + %td 3.00 + %td 1 + %td + %td loaf diff --git a/app/views/admin/product_import/guide/_variants.html.haml b/app/views/admin/product_import/guide/_variants.html.haml new file mode 100644 index 0000000000..dfd95879c1 --- /dev/null +++ b/app/views/admin/product_import/guide/_variants.html.haml @@ -0,0 +1,54 @@ +%table + %thead + %tr + %th + %th name + %th category + %th supplier + %th on_hand + %th price + %th units + %th unit_type + %th display_name + %tbody + %tr + %td 1 + %td Salad Bag + %td Salads + %td Sue's Salads + %td 26 + %td 3.50 + %td 500 + %td g + %td + %tr + %td 2 + %td Salad Bag + %td Salads + %td Sue's Salads + %td 44 + %td 5.50 + %td 750 + %td g + %td + %tr + %td 3 + %td Cake + %td Baked goods + %td Tim's Cakes + %td 10 + %td 4 + %td 500 + %td g + %td Banana and Walnut + %tr + %td 4 + %td Cake + %td Baked goods + %td Tim's Cakes + %td 18 + %td 4 + %td 500 + %td g + %td Carrot + diff --git a/app/views/admin/product_import/index.html.haml b/app/views/admin/product_import/index.html.haml index fd17684ef0..f2e8e5208b 100644 --- a/app/views/admin/product_import/index.html.haml +++ b/app/views/admin/product_import/index.html.haml @@ -1,6 +1,12 @@ - content_for :page_title do #{t('admin.product_import.title')} +- content_for :page_actions do + %div.toolbar{ 'data-hook' => "toolbar" } + %ul.actions.header-action-links.inline-menu + %li + = button_link_to 'View Guide', main_app.admin_product_import_guide_path + = render partial: 'spree/admin/shared/product_sub_menu' = render 'upload_form' diff --git a/config/routes.rb b/config/routes.rb index fe62513e2a..8a00086f4f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -134,6 +134,7 @@ Openfoodnetwork::Application.routes.draw do get '/inventory', to: 'variant_overrides#index' get '/product_import', to: 'product_import#index' + get '/product_import/guide', to: 'product_import#guide', as: 'product_import_guide' post '/product_import', to: 'product_import#import' post '/product_import/validate_data', to: 'product_import#validate_data', as: 'product_import_process_async' post '/product_import/save_data', to: 'product_import#save_data', as: 'product_import_save_async'