solidus_related_products 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.hound.yml +25 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +15 -0
- data/CONTRIBUTING.md +81 -0
- data/Gemfile +6 -0
- data/Guardfile +10 -0
- data/LICENSE.md +26 -0
- data/README.md +80 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/spree/backend/solidus_related_products.js +1 -0
- data/app/assets/javascripts/spree/frontend/solidus_related_products.js +1 -0
- data/app/assets/stylesheets/spree/backend/solidus_related_products.css +3 -0
- data/app/assets/stylesheets/spree/frontend/solidus_related_products.css +3 -0
- data/app/controllers/spree/admin/products_controller_decorator.rb +10 -0
- data/app/controllers/spree/admin/relation_types_controller.rb +6 -0
- data/app/controllers/spree/admin/relations_controller.rb +80 -0
- data/app/controllers/spree/api/relations_controller.rb +78 -0
- data/app/models/spree/calculator/related_product_discount.rb +50 -0
- data/app/models/spree/product_decorator.rb +106 -0
- data/app/models/spree/relation.rb +7 -0
- data/app/models/spree/relation_type.rb +6 -0
- data/app/overrides/add_product_relation_admin_sub_menu_tab.rb +6 -0
- data/app/overrides/add_related_product_admin_tabs.rb +6 -0
- data/app/views/spree/admin/products/_related_products.html.erb +3 -0
- data/app/views/spree/admin/products/_related_products_table.html.erb +42 -0
- data/app/views/spree/admin/products/related.html.erb +70 -0
- data/app/views/spree/admin/relation_types/_form.html.erb +19 -0
- data/app/views/spree/admin/relation_types/edit.html.erb +14 -0
- data/app/views/spree/admin/relation_types/index.html.erb +44 -0
- data/app/views/spree/admin/relation_types/new.html.erb +14 -0
- data/app/views/spree/admin/relations/create.js.erb +5 -0
- data/app/views/spree/admin/relations/destroy.js.erb +1 -0
- data/app/views/spree/api/relations/show.v1.rabl +2 -0
- data/bin/rails +7 -0
- data/config/locales/cs.yml +18 -0
- data/config/locales/de.yml +18 -0
- data/config/locales/en.yml +18 -0
- data/config/locales/es.yml +18 -0
- data/config/locales/fr.yml +18 -0
- data/config/locales/it.yml +18 -0
- data/config/locales/nl.yml +18 -0
- data/config/locales/pl.yml +18 -0
- data/config/locales/pt-BR.yml +18 -0
- data/config/locales/ru.yml +18 -0
- data/config/locales/sv.yml +18 -0
- data/config/routes.rb +24 -0
- data/db/migrate/20100308090631_create_relation_types.rb +14 -0
- data/db/migrate/20100308092101_create_relations.rb +14 -0
- data/db/migrate/20100324123835_add_discount_to_relation.rb +9 -0
- data/db/migrate/20111129044813_prefixing_tables_with_spree.rb +6 -0
- data/db/migrate/20120208144454_update_relation_types.rb +9 -0
- data/db/migrate/20120623014337_update_relations.rb +11 -0
- data/db/migrate/20130727004612_add_position_to_spree_relations.rb +5 -0
- data/lib/generators/solidus_related_products/install/install_generator.rb +20 -0
- data/lib/solidus_related_products.rb +7 -0
- data/lib/solidus_related_products/engine.rb +24 -0
- data/lib/solidus_related_products/version.rb +18 -0
- data/solidus_related_products.gemspec +45 -0
- data/spec/controllers/spree/admin/products_controller_decorator_spec.rb +20 -0
- data/spec/controllers/spree/admin/relations_controller_spec.rb +96 -0
- data/spec/controllers/spree/api/relations_controller_spec.rb +98 -0
- data/spec/factories/relation_factory.rb +7 -0
- data/spec/factories/relation_type_factory.rb +6 -0
- data/spec/features/spree/admin/product_relation_spec.rb +86 -0
- data/spec/features/spree/admin/relation_types_spec.rb +97 -0
- data/spec/models/spree/calculator/related_product_discount_spec.rb +48 -0
- data/spec/models/spree/product_spec.rb +129 -0
- data/spec/models/spree/relation_spec.rb +13 -0
- data/spec/models/spree/relation_type_spec.rb +18 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/capybara.rb +20 -0
- data/spec/support/database_cleaner.rb +23 -0
- data/spec/support/factory_girl.rb +7 -0
- data/spec/support/spree.rb +18 -0
- metadata +388 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
de:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Verwandte
|
7
|
+
other: Verhältnis
|
8
|
+
spree/relation_type:
|
9
|
+
one: Verwandschaftstyp
|
10
|
+
other: Verwandschaftstypen
|
11
|
+
spree:
|
12
|
+
new_relation_type: Neuer Verwandschaftstyp
|
13
|
+
related_product_discount: Skonto für verwandte Produkte
|
14
|
+
applies_to: Anwenden auf
|
15
|
+
related_products: Verwandte Produkte
|
16
|
+
add_related_product: Verwandtes Produkt hinzufügen
|
17
|
+
name_or_sku_short: Name oder Artikelnummer
|
18
|
+
no_relation_types: "Sie müssen Verwandschaftstypen konfigurieren, bevor Sie diese Funktion nutzen können."
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relation
|
7
|
+
other: Relations
|
8
|
+
spree/relation_type:
|
9
|
+
one: Relation Type
|
10
|
+
other: Relation Types
|
11
|
+
spree:
|
12
|
+
new_relation_type: New Relation Type
|
13
|
+
related_product_discount: Related Product Discount
|
14
|
+
applies_to: Applies To
|
15
|
+
related_products: Related Products
|
16
|
+
add_related_product: Add Related Product
|
17
|
+
name_or_sku_short: Name or SKU
|
18
|
+
no_relation_types: You need to configure Relation Types before you can use this feature.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
es:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relación
|
7
|
+
other: Relaciónes
|
8
|
+
spree/relation_type:
|
9
|
+
one: Tipo de relación
|
10
|
+
other: Tipos de relación
|
11
|
+
spree:
|
12
|
+
new_relation_type: Nuevo tipo de relación
|
13
|
+
related_product_discount: Descuento al producto relacionado
|
14
|
+
applies_to: Se aplica a
|
15
|
+
related_products: Productos relacionados
|
16
|
+
add_related_product: Añadir producto relacionado
|
17
|
+
name_or_sku_short: Nombre o SKU
|
18
|
+
no_relation_types: Debes configurar tipos de relación antes de poder usar esto.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
fr:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relation
|
7
|
+
other: Relations
|
8
|
+
spree/relation_type:
|
9
|
+
one: Type de relation
|
10
|
+
other: Types de relation
|
11
|
+
spree:
|
12
|
+
new_relation_type: Nouveau type de relation
|
13
|
+
related_product_discount: Rabais de produit connexe
|
14
|
+
applies_to: Appliquer à
|
15
|
+
related_products: Produits connexes
|
16
|
+
add_related_product: Ajouter un produit connexe
|
17
|
+
name_or_sku_short: Nom ou code barre
|
18
|
+
no_relation_types: Vous devez configurer des types de relation avant de pouvoir utiliser cette fonctionnalité.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
it:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relazione
|
7
|
+
other: Relazioni
|
8
|
+
spree/relation_type:
|
9
|
+
one: Tipo di Relazione
|
10
|
+
other: Tipi di Relazione
|
11
|
+
spree:
|
12
|
+
new_relation_type: Nuovo Tipo di Relazione
|
13
|
+
related_product_discount: Sconto prodotti correlati
|
14
|
+
applies_to: Si applica a
|
15
|
+
related_products: Prodotti Correlati
|
16
|
+
add_related_product: Aggiungi un Prodotto Correlato
|
17
|
+
name_or_sku_short: Nome o SKU
|
18
|
+
no_relation_types: Devi configurare i Tipi di Relazione prima di poter usare questa funzione.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
nl:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relatie
|
7
|
+
other: Relatie
|
8
|
+
spree/relation_type:
|
9
|
+
one: Relatie type
|
10
|
+
other: Relatie types
|
11
|
+
spree:
|
12
|
+
new_relation_type: Nieuw relatie type
|
13
|
+
related_product_discount: Korting gerelateerd product
|
14
|
+
applies_to: Toegepast op
|
15
|
+
related_products: Gerelateerde producten
|
16
|
+
add_related_product: Gerelateerd product toevoegen
|
17
|
+
name_or_sku_short: Naam of SKU
|
18
|
+
no_relation_types: Je moet relatie types instellen voordat je deze functie kan gebruiken.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
pl:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relacja
|
7
|
+
other: Relacje
|
8
|
+
spree/relation_type:
|
9
|
+
one: Typ relacja
|
10
|
+
other: Typy relacji
|
11
|
+
spree:
|
12
|
+
new_relation_type: Nowy typ relacji
|
13
|
+
related_product_discount: Zniżka na powiązany produkt
|
14
|
+
applies_to: Ma zastosowanie do
|
15
|
+
related_products: Produkty powiązane
|
16
|
+
add_related_product: Dodaj powiązany produkt
|
17
|
+
name_or_sku_short: Nazwa lub SKU
|
18
|
+
no_relation_types: Musisz najpierw skonfigurować typy relacji
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
pt-BR:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relação
|
7
|
+
other: Relaçãos
|
8
|
+
spree/relation_type:
|
9
|
+
one: Tipo de relação
|
10
|
+
other: Tipos de relação
|
11
|
+
spree:
|
12
|
+
new_relation_type: Novo tipo de relacionamento
|
13
|
+
related_product_discount: Desconto de produto relacionado
|
14
|
+
applies_to: Aplicado à
|
15
|
+
related_products: Produtos relacionados
|
16
|
+
add_related_product: Adicionar produto relacionado
|
17
|
+
name_or_sku_short: Nome ou SKU
|
18
|
+
no_relation_types: Você precisa configurar os tipos de relacionamento antes de utilizar esta funcionalidade.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
ru:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Oтношение
|
7
|
+
other: Oтношения
|
8
|
+
spree/relation_type:
|
9
|
+
one: Тип Oтношений
|
10
|
+
other: Типы Отношений
|
11
|
+
spree:
|
12
|
+
new_relation_type: Новый Тип Отношений
|
13
|
+
related_product_discount: Скидка На Относящийся Товар
|
14
|
+
applies_to: Применяется К
|
15
|
+
related_products: Относящиеся Товары
|
16
|
+
add_related_product: Добавить Относящийся Товар
|
17
|
+
name_or_sku_short: Название или Артикул
|
18
|
+
no_relation_types: Перед тем как поспользоваться этим функционалом настройте Типы Отношений.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
sv:
|
3
|
+
activerecord:
|
4
|
+
models:
|
5
|
+
spree/relation:
|
6
|
+
one: Relation
|
7
|
+
other: Relationer
|
8
|
+
spree/relation_type:
|
9
|
+
one: Relationstyp
|
10
|
+
other: Relationstyper
|
11
|
+
spree:
|
12
|
+
new_relation_type: Ny typ av relation
|
13
|
+
related_product_discount: Relaterad produkt rabatt
|
14
|
+
applies_to: Gäller
|
15
|
+
related_products: Relaterade produkter
|
16
|
+
add_related_product: Lägg till relaterad produkt
|
17
|
+
name_or_sku_short: Namn eller SKU
|
18
|
+
no_relation_types: Du måste konfigurera relationstyper innan du kan använda den här funktionen.
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Spree::Core::Engine.add_routes do
|
2
|
+
namespace :admin do
|
3
|
+
resources :relation_types
|
4
|
+
resources :products, only: [] do
|
5
|
+
get :related, on: :member
|
6
|
+
resources :relations do
|
7
|
+
collection do
|
8
|
+
post :update_positions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :api, defaults: { format: 'json' } do
|
15
|
+
resources :products, only: [] do
|
16
|
+
get :related, on: :member
|
17
|
+
resources :relations do
|
18
|
+
collection do
|
19
|
+
post :update_positions
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateRelationTypes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :relation_types do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :description
|
6
|
+
t.string :applies_to
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :relation_types
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateRelations < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :relations, force: true do |t|
|
4
|
+
t.references :relation_type
|
5
|
+
t.references :relatable, polymorphic: true
|
6
|
+
t.references :related_to, polymorphic: true
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :relations
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class UpdateRelationTypes < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
Spree::RelationType.where(applies_to: 'Product').update_all(applies_to: 'Spree::Product')
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
Spree::RelationType.where(applies_to: 'Spree::Product').update_all(applies_to: 'Product')
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class UpdateRelations < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
Spree::Relation.where(relatable_type: 'Product').update_all(relatable_type: 'Spree::Product')
|
4
|
+
Spree::Relation.where(related_to_type: 'Product').update_all(related_to_type: 'Spree::Product')
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
Spree::Relation.where(relatable_type: 'Spree::Product').update_all(relatable_type: 'Product')
|
9
|
+
Spree::Relation.where(related_to_type: 'Spree::Product').update_all(related_to_type: 'Product')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SolidusRelatedProducts
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=solidus_related_products'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
12
|
+
if run_migrations
|
13
|
+
run 'bundle exec rake db:migrate'
|
14
|
+
else
|
15
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SolidusRelatedProducts
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'solidus_related_products'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/models/spree/calculator)
|
8
|
+
|
9
|
+
initializer 'spree.promo.register.promotion.calculators' do |app|
|
10
|
+
app.config.spree.calculators.promotion_actions_create_adjustments << Spree::Calculator::RelatedProductDiscount
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def activate
|
15
|
+
cache_klasses = %W(#{config.root}/app/**/*_decorator*.rb)
|
16
|
+
Dir.glob(cache_klasses) do |klass|
|
17
|
+
Rails.configuration.cache_classes ? require(klass) : load(klass)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.to_prepare(&method(:activate).to_proc)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SolidusRelatedProducts
|
2
|
+
module_function
|
3
|
+
|
4
|
+
# Returns the version of the currently loaded SpreeRelatedProducts as a
|
5
|
+
# <tt>Gem::Version</tt>.
|
6
|
+
def version
|
7
|
+
Gem::Version.new VERSION::STRING
|
8
|
+
end
|
9
|
+
|
10
|
+
module VERSION
|
11
|
+
MAJOR = 1
|
12
|
+
MINOR = 0
|
13
|
+
TINY = 0
|
14
|
+
PRE = nil
|
15
|
+
|
16
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'solidus_related_products/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.name = 'solidus_related_products'
|
9
|
+
s.version = SolidusRelatedProducts.version
|
10
|
+
s.summary = 'Allows multiple types of relationships between products to be defined'
|
11
|
+
s.description = s.summary
|
12
|
+
s.required_ruby_version = '>= 2.1.0'
|
13
|
+
|
14
|
+
s.author = 'Brian Quinn'
|
15
|
+
s.email = 'brian@railsdog.com'
|
16
|
+
s.homepage = 'https://github.com/solidusio-contrib/solidus_related_products'
|
17
|
+
s.license = 'BSD-3'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.requirements << 'none'
|
23
|
+
|
24
|
+
s.has_rdoc = false
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'solidus_backend', '~> 1.0'
|
27
|
+
s.add_runtime_dependency 'deface'
|
28
|
+
|
29
|
+
s.add_development_dependency 'factory_girl', '~> 4.5'
|
30
|
+
s.add_development_dependency 'ffaker'
|
31
|
+
s.add_development_dependency 'rspec-rails', '~> 3.4'
|
32
|
+
s.add_development_dependency 'sqlite3'
|
33
|
+
s.add_development_dependency 'capybara', '~> 2.5'
|
34
|
+
s.add_development_dependency 'capybara-screenshot', '~> 1.0'
|
35
|
+
s.add_development_dependency 'poltergeist', '~> 1.9'
|
36
|
+
s.add_development_dependency 'shoulda-matchers', '~> 2.5'
|
37
|
+
s.add_development_dependency 'simplecov', '~> 0.9'
|
38
|
+
s.add_development_dependency 'database_cleaner', '~> 1.3'
|
39
|
+
s.add_development_dependency 'coffee-rails'
|
40
|
+
s.add_development_dependency 'sass-rails'
|
41
|
+
s.add_development_dependency 'guard-rspec'
|
42
|
+
s.add_development_dependency 'pry-rails'
|
43
|
+
s.add_development_dependency 'rubocop', '>= 0.24.1'
|
44
|
+
s.add_development_dependency 'rspec-activemodel-mocks'
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec.describe Spree::Admin::ProductsController, type: :controller do
|
2
|
+
stub_authorization!
|
3
|
+
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
let!(:product) { create(:product) }
|
6
|
+
|
7
|
+
before { stub_authentication! }
|
8
|
+
after { Spree::Admin::ProductsController.clear_overrides! }
|
9
|
+
|
10
|
+
context 'related' do
|
11
|
+
it 'is not routable' do
|
12
|
+
spree_get :related, id: product.id
|
13
|
+
expect(response.status).to be(200)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to model_class as Spree::Relation' do
|
17
|
+
expect(controller.send(:model_class)).to eq Spree::Product
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|