/solidus_related_products

:fork_and_knife: Related products extension for Solidus

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Related Products

CircleCI Gem License

This extension provides a generic way for you to define different types of relationships between your products, by defining a RelationType for each type of relationship you'd like to maintain.

You can manage RelationTypes via the admin configuration menu, and you can maintain product relationships via Related Products tab on the edit product UI or via Related Products section on the edit variant UI.

Installation

Add to Gemfile:

gem 'solidus_related_products'

Run:

$ bundle install
$ bundle exec rails g solidus_related_products:install

Possible uses

  • Accessories
  • Cross Sells
  • Up Sells
  • Compatible Products
  • Replacement Products
  • Warranty & Support Products

Relation Types

You can create four different RelationTypes:

Applies From Applies To
Spree::Product Spree::Product
Spree::Product Spree::Variant
Spree::Variant Spree::Product
Spree::Variant Spree::Variant

The following examples use a Spree::Product -> Spree::Product relation type.

When you create a RelationType you can access that set of related products by referencing the relation_type name, see below for an example:

rt = Spree::RelationType.create(name: 'Accessories', applies_from: 'Spree::Product', applies_to: 'Spree::Product')
 => #<Spree::RelationType id: 4, name: "Accessories" ...>
product = Spree::Product.last
 => #<Spree::Product id: 1060500592 ...>
product.accessories
 => []

Since respond_to? will not work in this case, you can test whether a relation_type method exists with has_related_products?(method):

product.has_related_products?('accessories')
# => true

if product.has_related_products?('accessories')
  # Display an accessories box..
end

You can access all related products regardless of RelationType by:

product.relations
 => []

Discounts You can optionally specify a discount amount to be applied if a customer purchases both products.

Note: In order for the coupon to be automatically applied, you must create a promotion leaving the code value empty, and adding an Action of type : RelatedProductDiscount (blank codes are required for coupons to be automatically applied).

Contributing

See corresponding guidelines


Copyright (c) 2010-2015 Brian Quinn and contributors, released under the New BSD License