workarea-save_for_later 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +25 -0
- data/CHANGELOG.md +17 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +17 -0
- data/LICENSE +52 -0
- data/README.md +51 -0
- data/Rakefile +60 -0
- data/app/assets/stylesheets/workarea/storefront/save_for_later/components/_product_prices.scss +5 -0
- data/app/controllers/workarea/storefront/cart_items_controller.decorator +12 -0
- data/app/controllers/workarea/storefront/current_saved_list.rb +54 -0
- data/app/controllers/workarea/storefront/saved_list_items_controller.rb +55 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/workarea/storefront/saved_lists_helper.rb +13 -0
- data/app/models/workarea/saved_list.rb +27 -0
- data/app/models/workarea/saved_list/item.rb +14 -0
- data/app/view_models/workarea/storefront/saved_list_item_view_model.rb +45 -0
- data/app/view_models/workarea/storefront/saved_list_view_model.rb +19 -0
- data/app/views/workarea/storefront/carts/_save_for_later_button.html.haml +8 -0
- data/app/views/workarea/storefront/carts/_saved_for_later.html.haml +52 -0
- data/bin/rails +20 -0
- data/config/initializers/appends.rb +14 -0
- data/config/initializers/config.rb +3 -0
- data/config/locales/en.yml +14 -0
- data/config/routes.rb +5 -0
- data/lib/workarea/save_for_later.rb +11 -0
- data/lib/workarea/save_for_later/engine.rb +13 -0
- data/lib/workarea/save_for_later/version.rb +5 -0
- data/test/dummy/.ruby-version +1 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +36 -0
- data/test/dummy/bin/update +31 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +29 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +61 -0
- data/test/dummy/config/environments/production.rb +94 -0
- data/test/dummy/config/environments/test.rb +45 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/factories/workarea/saved_list.rb +13 -0
- data/test/integration/workarea/storefront/cart_items_save_for_later_integration_test.rb +46 -0
- data/test/integration/workarea/storefront/current_saved_list_integration_test.rb +62 -0
- data/test/integration/workarea/storefront/saved_list_items_integration_test.rb +107 -0
- data/test/models/workarea/saved_list_test.rb +40 -0
- data/test/system/workarea/storefront/save_for_later_system_test.rb +59 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/workarea-save_for_later.gemspec +23 -0
- metadata +146 -0
data/app/helpers/.keep
ADDED
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
class SavedList
|
|
3
|
+
include ApplicationDocument
|
|
4
|
+
|
|
5
|
+
# Will be either a object id for guests, or a user's id
|
|
6
|
+
field :_id, type: String, default: -> { BSON::ObjectId.new.to_s }
|
|
7
|
+
|
|
8
|
+
embeds_many :items, class_name: 'Workarea::SavedList::Item'
|
|
9
|
+
|
|
10
|
+
def add_item(item_attributes = {})
|
|
11
|
+
item_attributes = item_attributes.with_indifferent_access
|
|
12
|
+
existing = items.where(item_attributes.slice(:sku, :customizations)).first
|
|
13
|
+
|
|
14
|
+
if existing.present?
|
|
15
|
+
existing.quantity = existing.quantity + item_attributes[:quantity].to_i
|
|
16
|
+
else
|
|
17
|
+
items.build(item_attributes)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
save
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def remove_item(id)
|
|
24
|
+
items.find(id).destroy
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
class SavedList
|
|
3
|
+
class Item
|
|
4
|
+
include ApplicationDocument
|
|
5
|
+
|
|
6
|
+
field :product_id, type: String
|
|
7
|
+
field :sku, type: String
|
|
8
|
+
field :quantity, type: Integer, default: 1
|
|
9
|
+
field :customizations, type: Hash, default: {}
|
|
10
|
+
|
|
11
|
+
embedded_in :saved_list, class_name: 'Workarea::SavedList'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
module Storefront
|
|
3
|
+
class SavedListItemViewModel < ApplicationViewModel
|
|
4
|
+
delegate :name, :purchasable?, :sell_min_price, to: :product
|
|
5
|
+
|
|
6
|
+
def product
|
|
7
|
+
@product ||= ProductViewModel.wrap(
|
|
8
|
+
Catalog::Product.find(product_id),
|
|
9
|
+
options.merge(sku: sku, inventory: nil)
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def image
|
|
14
|
+
product.primary_image
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def variant
|
|
18
|
+
product.model.variants.where(sku: sku).first
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def inventory_status
|
|
22
|
+
InventoryStatusViewModel.new(inventory).message
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def details
|
|
26
|
+
@details ||= Hash[
|
|
27
|
+
variant.details.map do |k, v|
|
|
28
|
+
[k.to_s.titleize, [v].flatten.join(', ')]
|
|
29
|
+
end
|
|
30
|
+
]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def total_price
|
|
34
|
+
sell_min_price * quantity
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def inventory
|
|
40
|
+
@inventory ||=
|
|
41
|
+
options[:inventory] || Inventory::Sku.find_or_create_by(id: sku)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
module Storefront
|
|
3
|
+
class SavedListViewModel < ApplicationViewModel
|
|
4
|
+
def items
|
|
5
|
+
@items ||= model.items.map do |item|
|
|
6
|
+
SavedListItemViewModel.wrap(
|
|
7
|
+
item,
|
|
8
|
+
options.merge(inventory: inventory.for_sku(item.sku))
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def inventory
|
|
14
|
+
@inventory ||= Inventory::Collection.new(model.items.map(&:sku))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
.grid__cell
|
|
2
|
+
= form_tag saved_list_items_path, method: 'post', class: 'action-group__item', data: { analytics: save_for_later_analytics_data(item).to_json } do
|
|
3
|
+
= hidden_field_tag :product_id, item.product_id, id: nil
|
|
4
|
+
= hidden_field_tag :sku, item.sku, id: nil
|
|
5
|
+
= hidden_field_tag :quantity, item.quantity, id: nil
|
|
6
|
+
= hidden_field_tag :customizations, item.customizations.to_json, id: nil
|
|
7
|
+
= hidden_field_tag :cart_item_id, item.id, id: nil
|
|
8
|
+
%p= button_tag t('workarea.storefront.carts.save_for_later'), value: 'save_for_later', class: 'text-button'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
- if current_saved_list? && current_saved_list.items.any?
|
|
2
|
+
%h2= t('workarea.storefront.saved_lists.title')
|
|
3
|
+
|
|
4
|
+
%ul.product-list{ data: { analytics: product_list_analytics_data('Saved For Later').to_json } }
|
|
5
|
+
- current_saved_list.items.each_with_index do |item, index|
|
|
6
|
+
%li.product-list__item
|
|
7
|
+
.product-list__item-cell
|
|
8
|
+
.product-list__summary
|
|
9
|
+
%p.product-list__media= link_to image_tag(product_image_url(item.image, :small_thumb), alt: item.name, class: 'product-list__media-image'), product_url(item.product, sku: item.sku), class: 'product-list__media-link'
|
|
10
|
+
.product-list__info
|
|
11
|
+
%p.product-list__name= link_to item.name, product_path(item.product, sku: item.sku)
|
|
12
|
+
%p.product-list__id= item.variant.name
|
|
13
|
+
%p.product-list__inventory-status= item.inventory_status
|
|
14
|
+
- if item.details.present?
|
|
15
|
+
.product-list__option-group
|
|
16
|
+
- item.details.each do |name, value|
|
|
17
|
+
%p.product-list__option #{name.titleize}: #{value}
|
|
18
|
+
- item.customizations.each do |name, value|
|
|
19
|
+
%p.product-list__customization #{name.titleize}: #{value}
|
|
20
|
+
.grid.grid--auto
|
|
21
|
+
.grid__cell
|
|
22
|
+
= form_tag cart_items_path, class: 'action-group__item', data: { analytics: add_to_cart_analytics_data(item.product).to_json } do
|
|
23
|
+
= hidden_field_tag :product_id, item.product_id, id: nil
|
|
24
|
+
= hidden_field_tag :sku, item.sku, id: nil
|
|
25
|
+
= hidden_field_tag :quantity, item.quantity, id: nil
|
|
26
|
+
= hidden_field_tag :saved_list_item_id, item.id, id: nil
|
|
27
|
+
- if item.customizations.present?
|
|
28
|
+
- item.customizations.each do |key, value|
|
|
29
|
+
= hidden_field_tag key, value
|
|
30
|
+
- if item.purchasable?
|
|
31
|
+
%p= button_tag t('workarea.storefront.saved_lists.move_to_cart'), class: 'text-button'
|
|
32
|
+
- else
|
|
33
|
+
%p.unavailable= t('workarea.storefront.products.unavailable')
|
|
34
|
+
.grid__cell
|
|
35
|
+
= link_to t('workarea.storefront.saved_lists.remove'), saved_list_item_path(item), data: { method: 'delete', confirm: t('workarea.storefront.saved_lists.confirm_remove') }
|
|
36
|
+
|
|
37
|
+
.product-list__item-cell
|
|
38
|
+
%table.table
|
|
39
|
+
%thead
|
|
40
|
+
%tr
|
|
41
|
+
%th.table__prices= t('workarea.storefront.orders.price')
|
|
42
|
+
%th.table__quantity= t('workarea.storefront.orders.quantity')
|
|
43
|
+
%th.table__prices= t('workarea.storefront.orders.total')
|
|
44
|
+
%tbody
|
|
45
|
+
%tr
|
|
46
|
+
%td.table__prices
|
|
47
|
+
.product-prices.product-prices--saved-list
|
|
48
|
+
= render 'workarea/storefront/products/pricing', product: item.product
|
|
49
|
+
%td.table__quantity
|
|
50
|
+
%p= item.quantity
|
|
51
|
+
%td.table__prices
|
|
52
|
+
= number_to_currency(item.total_price)
|
data/bin/rails
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/workarea/save_for_later/engine', __dir__)
|
|
7
|
+
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
|
|
8
|
+
|
|
9
|
+
# Set up gems listed in the Gemfile.
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
12
|
+
|
|
13
|
+
require "action_controller/railtie"
|
|
14
|
+
require "action_view/railtie"
|
|
15
|
+
require "action_mailer/railtie"
|
|
16
|
+
require "rails/test_unit/railtie"
|
|
17
|
+
require "sprockets/railtie"
|
|
18
|
+
require 'teaspoon-mocha'
|
|
19
|
+
|
|
20
|
+
require 'rails/engine/commands'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Workarea.append_partials(
|
|
2
|
+
'storefront.cart_show',
|
|
3
|
+
'workarea/storefront/carts/saved_for_later'
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
Workarea.append_partials(
|
|
7
|
+
'storefront.cart_item_actions',
|
|
8
|
+
'workarea/storefront/carts/save_for_later_button'
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
Workarea.append_stylesheets(
|
|
12
|
+
'storefront.components',
|
|
13
|
+
'workarea/storefront/save_for_later/components/product_prices'
|
|
14
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
en:
|
|
2
|
+
workarea:
|
|
3
|
+
storefront:
|
|
4
|
+
carts:
|
|
5
|
+
save_for_later: Save for Later
|
|
6
|
+
saved_lists:
|
|
7
|
+
confirm_remove: Are you sure you want to remove this item from your saved list?
|
|
8
|
+
flash_messages:
|
|
9
|
+
created: Item has been saved for later
|
|
10
|
+
error: There was a problem saving this item for later
|
|
11
|
+
destroyed: Saved for later item has been removed
|
|
12
|
+
move_to_cart: Move to Cart
|
|
13
|
+
remove: Remove
|
|
14
|
+
title: Saved For Later
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
module SaveForLater
|
|
3
|
+
class Engine < ::Rails::Engine
|
|
4
|
+
include Workarea::Plugin
|
|
5
|
+
isolate_namespace Workarea::SaveForLater
|
|
6
|
+
|
|
7
|
+
config.to_prepare do
|
|
8
|
+
Storefront::ApplicationController.include(Storefront::CurrentSavedList)
|
|
9
|
+
Storefront::ApplicationController.send(:helper, Storefront::SavedListsHelper)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.4.4
|
data/test/dummy/Rakefile
ADDED
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require rails-ujs
|
|
14
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Dummy</title>
|
|
5
|
+
<%= csrf_meta_tags %>
|
|
6
|
+
<%= csp_meta_tag %>
|
|
7
|
+
|
|
8
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
|
9
|
+
<%= javascript_include_tag 'application' %>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<%= yield %>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= yield %>
|
data/test/dummy/bin/rake
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a starting point to setup your application.
|
|
14
|
+
# Add necessary setup steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
|
21
|
+
# system('bin/yarn')
|
|
22
|
+
|
|
23
|
+
# puts "\n== Copying sample files =="
|
|
24
|
+
# unless File.exist?('config/database.yml')
|
|
25
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
puts "\n== Preparing database =="
|
|
29
|
+
system! 'bin/rails db:setup'
|
|
30
|
+
|
|
31
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
32
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
33
|
+
|
|
34
|
+
puts "\n== Restarting application server =="
|
|
35
|
+
system! 'bin/rails restart'
|
|
36
|
+
end
|