Giter VIP home page Giter VIP logo

spree_related_products's Introduction

Related Products

Build Status Code Climate

Related Products is a Spree Commerce extension that 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.

Possible uses

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

Relation Types

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_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).


Installation

  1. Add this extension to your Gemfile with this line:

Spree >= 3.1

gem 'spree_related_products', github: 'spree-contrib/spree_related_products'

Spree 3.0 and Spree 2.x

gem 'spree_related_products', github: 'spree-contrib/spree_related_products', branch: 'X-X-stable'

The branch option is important: it must match the version of Spree you're using. For example, use 3-0-stable if you're using Spree 3-0-stable or any 3.0.x version.

  1. Install the gem using Bundler:
bundle install
  1. Copy & run migrations
bundle exec rails g spree_related_products:install
  1. Restart your server

If your server was running, restart it so that it can find the assets properly.


Contributing

See corresponding guidelines


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

spree_related_products's People

Contributors

ajjahn avatar alepore avatar aplegatt avatar bbonislawski avatar bdq avatar citrus avatar damianlegawiec avatar futhr avatar geekoncoffee avatar gudata avatar jdutil avatar jsqu99 avatar krzysiek1507 avatar lani13 avatar lbrapid avatar maokomioko avatar mauazua avatar nishant-cyro avatar patrickmcelwee avatar przemosk avatar pszyszkaspark avatar qoobaa avatar radar avatar reinaris avatar rhlrjv avatar romul avatar schof avatar szymoniwacz avatar tiagoamaro avatar vygovskysergey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spree_related_products's Issues

Promotion error because routing bug

I found a problem in routing during creating a new promotion.

I correct it in my fork

namespace :products do
    get '/products/related', :to => "products#related"
    resources :relations
end

spree_related_products: Product.to_ary

Pulled over from spree/spree issues #370

Imported from lighthouse. Original ticket at: http://railsdog.lighthouseapp.com/projects/31096/tickets/1848 - Created by Robert Wünsch -
Wed Feb 09 16:47:15 UTC 2011

After installing the gem spree_related_products, I opened the /admin/products page in Spree to see this:

@@@
NameError in Admin/products#index

Showing /spree_core-0.40.0/app/views/admin/products/index.html.erb where line #37 raised:

undefined local variable or method `to_ary' for #Product:0x00000104755e68
Extracted source (around line #37):

34: <% end %>
35:

36: <%= hook :admin_products_index_row_actions, locals do %>
37: <%= link_to_edit product unless product.deleted? %>
38:
39: <%= link_to_clone product %>
40:
Full Trace:
activemodel (3.0.3) lib/active_model/attribute_methods.rb:364:in method_missing'
activerecord (3.0.3) lib/active_record/attribute_methods.rb:46:inmethod_missing'
spree_related_products/lib/spree_related_products.rb:22:in method_missing'
rd_resource_controller (1.0.0) lib/urligence.rb:36:inflatten'
rd_resource_controller (1.0.0) lib/urligence.rb:36:in urligence'
rd_resource_controller (1.0.0) lib/urligence.rb:4:insmart_url'
rd_resource_controller (1.0.0) lib/resource_controller/helpers/urls.rb:48:in block (2 levels) in module:Urls'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:55:inedit_object_url'
spree_core (0.40.0) app/helpers/admin/navigation_helper.rb:43:in `link_to_edit'
@@@

This problem seems to be initiated here:
spree_related_products/lib/spree_related_products.rb:22:in `method_missing'

Doesn't create method if name has spaces and isn't plural

Somewhere it should mention this.

1.9.1 :045 > Spree::RelationType.create name: "Something Something", applies_to: "Spree::Product"
  SQL (0.9ms)  INSERT INTO "spree_relation_types" ("applies_to", "created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?, ?)  [["applies_to", "Spree::Product"], ["created_at", Fri, 13 Apr 2012 17:40:59 UTC +00:00], ["description", nil], ["name", "Something Something"], ["updated_at", Fri, 13 Apr 2012 17:40:59 UTC +00:00]]
 => #<Spree::RelationType id: 7, name: "Something Something", description: nil, applies_to: "Spree::Product", created_at: "2012-04-13 17:40:59", updated_at: "2012-04-13 17:40:59"> 
1.9.1 :046 > Spree::RelationType.create name: "Something Somethings", applies_to: "Spree::Product"
  SQL (0.5ms)  INSERT INTO "spree_relation_types" ("applies_to", "created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?, ?)  [["applies_to", "Spree::Product"], ["created_at", Fri, 13 Apr 2012 17:41:22 UTC +00:00], ["description", nil], ["name", "Something Somethings"], ["updated_at", Fri, 13 Apr 2012 17:41:22 UTC +00:00]]
 => #<Spree::RelationType id: 8, name: "Something Somethings", description: nil, applies_to: "Spree::Product", created_at: "2012-04-13 17:41:22", updated_at: "2012-04-13 17:41:22"> 
1.9.1 :047 > Spree::Product.last
  Spree::Product Load (0.3ms)  SELECT "spree_products".* FROM "spree_products" ORDER BY "spree_products"."id" DESC LIMIT 1
 => #<Spree::Product id: 101, name: "Product #100 - 2084", description: "Voluptas deserunt asperiores est. Ea nisi atque aut...", available_on: "2011-04-13 15:10:40", deleted_at: nil, permalink: "product-number-100-2084", meta_description: nil, meta_keywords: nil, tax_category_id: 1, shipping_category_id: 1, created_at: "2012-04-13 15:10:43", updated_at: "2012-04-13 15:10:43", count_on_hand: 0> 
1.9.1 :048 > Spree::Product.last.something_something
  Spree::Product Load (0.2ms)  SELECT "spree_products".* FROM "spree_products" ORDER BY "spree_products"."id" DESC LIMIT 1
  Spree::RelationType Load (0.4ms)  SELECT "spree_relation_types".* FROM "spree_relation_types" WHERE "spree_relation_types"."applies_to" = 'Spree::Product' ORDER BY name
NoMethodError: undefined method `something_something' for #<Spree::Product:0x007f87e0df7810>
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/gems/activemodel-3.1.4/lib/active_model/attribute_methods.rb:385:in `method_missing'
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/gems/activerecord-3.1.4/lib/active_record/attribute_methods.rb:60:in `method_missing'
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/bundler/gems/spree_related_products-dcac3c3aff2b/app/models/spree/product_decorator.rb:48:in `method_missing'
    from (irb):48
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/gems/railties-3.1.4/lib/rails/commands/console.rb:45:in `start'
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/gems/railties-3.1.4/lib/rails/commands/console.rb:8:in `start'
    from /Users/krainboltgreene/Code/mignon-faget/vendor/ruby/1.9.1/gems/railties-3.1.4/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
1.9.1 :049 > Spree::Product.last.something_somethings
  Spree::Product Load (0.3ms)  SELECT "spree_products".* FROM "spree_products" ORDER BY "spree_products"."id" DESC LIMIT 1
  Spree::RelationType Load (0.4ms)  SELECT "spree_relation_types".* FROM "spree_relation_types" WHERE "spree_relation_types"."applies_to" = 'Spree::Product' ORDER BY name
  Spree::Relation Load (0.2ms)  SELECT related_to_id FROM "spree_relations" WHERE "spree_relations"."relatable_id" = 101 AND "spree_relations"."relatable_type" = 'Spree::Product' AND "spree_relations"."relation_type_id" = 7
  Spree::Product Load (0.3ms)  SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."id" IN (NULL) AND "spree_products"."deleted_at" IS NULL AND (spree_products.available_on IS NOT NULL) AND (spree_products.available_on <= '2012-04-13 17:41:35.980064')
 => []
1.9.1 :050 > 1.9.1 :RelationType.create name: "Something Otherthings", applies_to: "Spree::Product"
  SQL (0.6ms)  INSERT INTO "spree_relation_types" ("applies_to", "created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?, ?)  [["applies_to", "Spree::Product"], ["created_at", Fri, 13 Apr 2012 17:44:05 UTC +00:00], ["description", nil], ["name", "Something Otherthings"], ["updated_at", Fri, 13 Apr 2012 17:44:05 UTC +00:00]]
 => #<Spree::RelationType id: 9, name: "Something Otherthings", description: nil, applies_to: "Spree::Product", created_at: "2012-04-13 17:44:05", updated_at: "2012-04-13 17:44:05"> 
1.9.1 :051 > Spree::Product.last.something_otherthings
  Spree::Product Load (0.3ms)  SELECT "spree_products".* FROM "spree_products" ORDER BY "spree_products"."id" DESC LIMIT 1
  Spree::RelationType Load (0.4ms)  SELECT "spree_relation_types".* FROM "spree_relation_types" WHERE "spree_relation_types"."applies_to" = 'Spree::Product' ORDER BY name
  Spree::Relation Load (0.2ms)  SELECT related_to_id FROM "spree_relations" WHERE "spree_relations"."relatable_id" = 101 AND "spree_relations"."relatable_type" = 'Spree::Product' AND "spree_relations"."relation_type_id" = 9
  Spree::Product Load (0.2ms)  SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."id" IN (NULL) AND "spree_products"."deleted_at" IS NULL AND (spree_products.available_on IS NOT NULL) AND (spree_products.available_on <= '2012-04-13 17:44:10.139542')
 => [] 

Can't create related product via admin on spree 1.3.1 / rails 3.2.10

I'm using related_products gem 1-3-stable from github.

gem 'spree_related_products', :branch => '1-3-stable', :git => 'git://github.com/spree/spree_related_products.git'

The product name field seems to be hidden, but if I click on field label I get this JS error: "Uncaught RangeError: Maximum call stack size exceeded"

Any ideas?
Screen Shot 2013-03-01 at 12 25 18 AM

Deleted products are still showing up in related products list

I notice that if I delete a product, it still shows up in "related products" lists that had included that product. I would expect that either (a) deleting a product would trigger deletion of its inbound recommendations, and/or (b) viewing of a recommendation for a deleted product would be suppressed.

Feature Request: Related Product Options

I like the idea of related products, but I am missing a possibility to set some options for related product (or rather relation type).

E.g. if I have a relation type 'Product Addons' I would like to set an option 'individual_sale' to false, meaning that the related products could not be sold by their own, and even not listed in the main catalog
This/these options should be stored in the database table for the relation_type

Unprocessable entity from API when assigning products

The API call when searching for a variant in the related products form returns a 422 Unprocessable entity error. Expecting a list of matching variants.

AJAX exception is:

"exception":"Mysql2::Error: Column 'id' in field list is ambiguous: SELECT COUNT(DISTINCT count_column) FROM (SELECT  id AS count_column FROM `spree_variants` LEFT OUTER JOIN `spree_products` ON `spree_products`.`id` = `spree_variants`.`product_id` AND `spree_products`.`deleted_at` IS NULL WHERE `spree_variants`.`deleted_at` IS NULL AND ((`spree_products`.`name` LIKE '%Goo%' OR `spree_variants`.`sku` LIKE '%Goo%')) LIMIT 25 OFFSET 0) subquery_for_count"}

Gist of Gemfile.lock:
https://gist.github.com/Migweld/039aecad059d68278bd7

Any help appreciated.

Cannot create promotion for discounts in version 1-1-stable

Hello,
i am using version 1-1-stable of this gem, i cant follow the instructions in order for the coupon to be automatically applied, because i cant create blank codes. And even if a create one with a code, the Action of type : RelatedProductDiscount is not listed.

discount_issue

Unable to add a Related Product if one of the related products in the search is deleted

I'm running Rails 3.2.3, MySQL, Spree 1.1.0 and spree_related_products, :git => 'git://github.com/spree/spree_related_products.git'.

The related product dropdown never loads (loading gif stays up and no product show up in autocomplete dropdown) when I type in a product that has been deleted through the admin screen.

To reproduce create 2 products with very simliar names. For example, Hand Held Remote and Hand Held Remote 2. Delete Hand Held Remote. Go to another product and start typing in Hand Held in the Add a Related Product text box. You would expect to see Hand Held Remote 2 in the autocomplete dropdown, but that product never loads and the loading gif stays spinning. Go to Rails console and delete Hand Held Remote via the console so that it's no longer in the database. Go back related products and type Hand Held. You will now see Hand Held Remote 2 show up in the autcomplete.

1-0-stable branch?

I'm running spree on the '1-0-stable' branch. According to the version file here, there should be a branch to make this version work. Unfortunately, there isn't any branch that works with 1-0-stable. So I guess I have to fork.

I feel this is an issue with many spree extensions. Many forks just have one commit and that is setting the dependency to a spree version that works for them.

See for example:
https://github.com/yangjindong/spree_related_products/commit/155bfe0a44d21098ebcab27487582df38ca6bea5

I love spree, but errors like:

Bundler could not find compatible versions for gem "spree_promo":
  In Gemfile:
    spree_related_products (>= 0) ruby depends on
      spree_promo (~> 1.1.0) ruby

    spree (>= 0) ruby depends on
      spree_promo (1.0.4.beta)

drive me nuts because they seem so unnecessary.

undefined method `empty?' for nil:NilClass

Using spree-3.0.8 and using the branch 3-0-stable of spree_related_products, when you visit the administration panel and you try to go to the related products for a specific product you will get the next error:

ActionView::Template::Error (undefined method `empty?' for nil:NilClass):
3:
4: <%= csrf_meta_tag %>
5:
6: <% if @relation_types.empty? %>
7:


8: <%= Spree.t(:no_relation_types) %>
9:

I was taking a look at the previous version and the error seems to be next:

module Spree
  module Admin
    ProductsController.class_eval do
      def related
        load_resource
        @relation_types = Spree::Product.relation_types
      end
    end
  end
end

instead of using

Spree::Admin::ProductsController.class_eval do
 def related
        load_resource
        @relation_types = Spree::Product.relation_types
      end
end

Related products are not shown

Is it just here or this gem stopped to show related products in the product's page in branch 2-2-stable?

For the product with title "Spree Baseball Jersey" I added the related product with title "Ruby on Rails Jr. Spaghetti" but the information shown to the user is unchanged. The relation type has name "Foo" and applies to "Spree::Product".

I find it hard to deduce how it works based on the documentation, please explain me more if I'm missing something. Specially regarding the "applies to", what are the possible values and how does it affect the behavior?

Dev notes for master branch.

After some refactor on master branch I noticed some things that can be improved or need to be fixed:

  • Need to look into issue #82 and add better specs for the calculator so it proper test discounts.
  • The delete related record need to be rebuilt, it doesn't work and the JS inject the list after delete totally wrong. This is related to issue #95
  • Need to look into issue #88 concerning has_related_products?
  • Need :ru :pl :nl :cs :it check for new active_model translations.

These are dev memory notes, you welcome to help out with PR.

No longer compatible with 1.1.2?

I've been using the related products extension in Spree 1.1.2 for a couple of weeks now without any problems. I updated my bundle today, and bundler is now complaining that spree_related_products requires spree_core 1.2.0:

In Gemfile:
spree_related_products (>= 0) ruby depends on
spree_core (~> 1.2.0) ruby

Is there a specific version that I can use that still works with 1.1.2? I'm reticent to upgrade to 1.2.0 because there are several other extensions I'm using that haven't yet been updated to work with it.

Can not add related product at admin.

Hi,
I'm using rails '3.2.3', spree 1-1-stable, spree_related_products master branch.
I couldn't add related product via Related Products tab on the edit product UI.
It seems js is not loading the products.

Please advice..
Thanks

How to add related products for product without variants?

I have a hard time understanding how this should work.
The "Related products" tab under product edit allows to search only for variants.

How to add related products for a Product that has no variants? It does not show up in the autocomplete of course, because it hits the variants index.

Thanks
Wojtek

PS I'm on spree 3-0-stable branch for both spree and spree_related_products

find_by_permalink does not work with 2.2-stable

in relations_controller.rb, the find_by_permalink method doesn't work because the new release uses a slug instead.

From the release note:
Switched to using friendly_id for permalink generation. This meant that we needed to rename Spree::Product's permalink field to slug.

Changing this line:
@Product = Spree::Product.find_by_permalink(params[:product_id])
to
@Product = Spree::Product. friendly.find(params[:product_id]) worked for me.

Could not find gem 'spree_promo (~> 2.0.0.beta)

I get this error when running bundle install.
Could not find gem 'spree_promo (~> 2.0.0.beta) x86-mingw32', which is required by gem 'spree_related_products (>= 0) x8
6-mingw32', in any of the sources.

I have this in my Gemfile:
gem 'spree', :git => 'git://github.com/spree/spree.git', :branch =>'master'
gem 'spree_related_products', :git => 'git://github.com/spree/spree_related_products.git', :branch => 'master'

I know that spree_related_products is causing the issue because it works when I remove it from my Gemfile.

Find product relation types from all relations

@product.relations will return all relations associated with a product, but how can I get them sorted by relation type?

Instead of calling @product.accessories to get all accessories some products have multiple relations so I wanted to call @product.relations to get all the related products, but I need to have them sorted on my view. For instance I am using bootstrap tabs and each relation type has a tab with the related products below.

How do I sort @product.relations by type?

Unable to Add A Related Product v.1-3-stable spree v.1.3.2

I might be missing something obvious here.
I just installed the gem, ran the migrations, went into the admin section, created a new Relation Type, then I go to edit a product, click 'related products' and I see this (screenshot attached) .
I feel like I should see a text input where I can write in the names or sku's of the related products, somewhere near the 'NAME OR SKU' label, or I'm not understanding how this works.

Screen Shot 2013-04-09 at 2 07 37 PM

Admin sort not working after related product add

2-3-stable admin js sortable functionality does not work after adding a related product-- requires a page refresh to instantiate properly. no console js errors, rows become selected on drag/sort attempt.

screen shot 2014-08-26 at 11 17 15 am

comparison of NilClass with BigDecimal failed

in an installation from scratch, when I delete a cart item and that item is in a promotion RelatedProductDiscount, there is an error "comparison of NilClass With BigDecimal failed"

"Cross Sells" not working

I'm trying to use "Cross Sells" option with discount, but I do not see any calculation at the order summary.

My stuff:
gem 'spree', github: 'spree/spree', branch: '2-1-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
gem 'spree_related_products', github: 'spree/spree_related_products', branch: '2-1-stable'

Please, someone confirm this issue.

Admin related product delete issue

2-3-stable when in the admin and deleting a related product the page glitches out and in the js console this error Uncaught TypeError: undefined is not a function that refers to this script but it is seemingly unrelated:

jQuery(function($) {
  // Make select beautiful
  $('select.select2').select2({
    allowClear: true,
    dropdownAutoWidth: true
  });

  function format_taxons(taxon) {
    new_taxon = taxon.text.replace('->', '<i class="fa fa-arrow-right">')
    return new_taxon;
  }

  $("#product_taxon_ids").on({
    change: function(e){
      $('.select2-search-choice .with-tip').powerTip({
        smartPlacement: true,
        fadeInTime: 50,
        fadeOutTime: 50
      })
    }
  })
})
;

appears that the response is being injected into the wrong element.

screen shot 2014-08-26 at 8 40 32 am

Error installing on 1.1.1

bundle exec rails g spree_related_products:install
run rake railties:install:migrations FROM=spree_related_products from "."
NOTE: Migration 20111129044813_prefix_tables_with_spree.rb from spree_related_products has been skipped. Migration with the same name already exists.
Would you like to run the migrations now? [Y/n] y
run rake db:migrate from "."
== UpdateRelationTypes: migrating ============================================
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: Table 'spree_development.spree_relation_types' doesn't exist: UPDATE spree_relation_types SET applies_to = 'Spree::Product' WHERE spree_relation_types.applies_to = 'Product'

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Here is the trace:

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
== UpdateRelationTypes: migrating ============================================
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: Table 'spree_development.spree_relation_types' doesn't exist: UPDATE spree_relation_types SET applies_to = 'Spree::Product' WHERE spree_relation_types.applies_to = 'Product'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in query' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:inblock in execute'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:280:in block in log' /var/lib/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:275:in log' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:inexecute'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in execute' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb:238:inexec_delete'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in update' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/query_cache.rb:14:inupdate'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/relation.rb:294:in update_all' /home/linux/Workspaces/dandyhat/db/migrate/20120517145161_update_relation_types.spree_related_products.rb:4:inup'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:410:in block (2 levels) in migrate' /usr/lib/ruby/1.9.1/benchmark.rb:280:inmeasure'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:410:in block in migrate' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:119:inwith_connection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:389:in migrate' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:528:inmigrate'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:777:incall'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:777:in ddl_transaction' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:719:inblock in migrate'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:700:in each' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:700:inmigrate'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:570:in up' /var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/migration.rb:551:inmigrate'
/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/railties/databases.rake:153:in block (2 levels) in <top (required)>' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:incall'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in block in execute' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:ineach'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in execute' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:inblock in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:ininvoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in invoke' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:ininvoke_task'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block (2 levels) in top_level' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:ineach'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block in top_level' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in top_level' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:inblock in run'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling' /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:inrun'
/var/lib/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in <top (required)>' /usr/local/bin/rake:19:inload'
/usr/local/bin/rake:19:in `

'
Tasks: TOP => db:migrate

Calculating total price with multi currency

I installed spree_related_products for my website (spree 3.0). I found that there is only one discount input for related product but I have 2 currencies in my system. So I want to ask about this situation. Thank you.

Update for spree 2.4

Is there going to be a stable branch update for spree 2.4? Looking to upgrade, but not sure if 2.3 or master should be used for spree 2.4.

Special UTF Characters in format_name and Method Missing

Hello!

I've been using this gem for a long time, since Spree 1.1. But only now I've encountered a problem with the approach used by the gem using method_missing for establishing the relation between the item (in my case, Spree::Product) and its related items.

The name field is being used in the front-end for dynamic exhibition for relation types, as the following code demonstrates:

<% @relation_types.each do |relation_type| %>
  <% products = @product.send(relation_type.name.parameterize('_')) %>
  <% next if products.empty? %>
  <%= content_tag :h3, relation_type.name %>
  [iteration over each product...]
<% end %>

The problem is that the name have accents, because the current locale is pt-BR.

I thought that this could be solved in two different ways and I would like the opinion of the community:

One of them would be adding an extra field to identify internally the relation, or keeping the name and adding a field like presentation to appear in the front end.

The other way would be changing the format_name method using parameterize instead of downcase, to avoid problems with accents.

Old code

def format_name(name)
  name.to_s.downcase.gsub(' ', '_').pluralize
end

New code

def format_name(name)
  name.to_s.parameterize('_').pluralize
end

I'm not having errors, at least not in development environment, but I guess a method name with accents isn't a good thing...

What you guys think about it?
If you have other solution, I would be glad to read it!

Thanks!

product.{{relation_type}} returns nil in the array

The version that i work with is 2.1.

to reproduce the bug , associate to a product 2 products, first product is not available("AVAILABLE ON" is empty) and the second will be available
the relation type name is "color"
in the console in goes likes that :

[96] pry(main)> product = Spree::Product.find  7
  Spree::Product Load (4.0ms)  SELECT "spree_products".* FROM "spree_products" WHERE ("spree_products".deleted_at IS NULL) AND "spree_products"."id" = $1 LIMIT 1  [["id", 7]]
=> #<Spree::Product id: 7, name: "אלקטרה בר אדום רימון-24חו", description: "", available_on: nil, deleted_at: nil, permalink: "lqtrh-br-dvm-rymvn-24khv", meta_description: "", meta_keywords: "", tax_category_id: nil, shipping_category_id: 1, created_at: "2013-11-21 17:38:13", updated_at: "2013-11-24 14:17:28", bullet1: "", bullet2: "", bullet3: "">

[98] pry(main)> product.relations
=> [#<Spree::Relation id: 1, relation_type_id: 1, relatable_id: 7, relatable_type: "Spree::Product", related_to_id: 4, related_to_type: "Spree::Product", created_at: "2013-11-24 16:20:18", updated_at: "2013-11-24 16:28:47", discount_amount: #<BigDecimal:c7f3bfc,'0.11E2',9(18)>, position: nil>,
 #<Spree::Relation id: 2, relation_type_id: 1, relatable_id: 7, relatable_type: "Spree::Product", related_to_id: 5, related_to_type: "Spree::Product", created_at: "2013-11-24 16:20:28", updated_at: "2013-11-24 16:28:47", discount_amount: #<BigDecimal:c7f2e3c,'0.11E2',9(18)>, position: nil>]

[101] pry(main)> product.colors
DEPRECATION WARNING: This dynamic method is deprecated. Please use e.g. Post.where(...).all instead. (called from relation_types at /home/yaron/.rvm/gems/ruby-2.0.0-p247@payngo/bundler/gems/spree_related_products-0d84c715cca8/app/models/spree/product_decorator.rb:6)
  Spree::RelationType Load (0.5ms)  SELECT "spree_relation_types".* FROM "spree_relation_types" WHERE "spree_relation_types"."applies_to" = 'Spree::Product' ORDER BY "spree_relation_types"."name" ASC
   (0.2ms)  SELECT "spree_relations"."related_to_id" FROM "spree_relations" WHERE "spree_relations"."relatable_id" = $1 AND "spree_relations"."relatable_type" = $2 AND "spree_relations"."relation_type_id" = 1 ORDER BY "spree_relations"."position" ASC  [["relatable_id", 7], ["relatable_type", "Spree::Product"]]
DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from relations_for_relation_type at /home/yaron/.rvm/gems/ruby-2.0.0-p247@payngo/bundler/gems/spree_related_products-0d84c715cca8/app/models/spree/product_decorator.rb:75)
  Spree::Product Load (0.5ms)  SELECT "spree_products".* FROM "spree_products" WHERE ("spree_products".deleted_at IS NULL) AND "spree_products"."id" IN (4, 5) AND "spree_products"."deleted_at" IS NULL AND (spree_products.available_on IS NOT NULL) AND (spree_products.available_on <= '2013-11-24 16:53:29.930488')
=> [#<Spree::Product id: 4, name: "אלקטרה בר קרם שמנת-24חודש", description: "", available_on: "2013-11-18 00:00:00", deleted_at: nil, permalink: "lqtrh-br-qrm-shmnt-24khvdsh", meta_description: "", meta_keywords: "", tax_category_id: nil, shipping_category_id: 1, created_at: "2013-11-21 17:35:55", updated_at: "2013-11-24 16:39:37", bullet1: "", bullet2: "", bullet3: "">,
 nil]

product.colors return nil in the array and it shouldn't.

Not working with edge spree

Trying to add related product returns

Unknown action
The action 'index' could not be found for Admin::RelationsController

Cache invalidation

Thoughts on having relations touch the relatable when they are updated?

I can submit a PR.

Update README.md to include installation info

Even though "This will be obsolete with Rails 3.1," until then, it might save people some time to put the simple installation instructions in the README.md:

gem 'spree_related_products', :git => 'https://github.com/spree/spree_related_products.git'

$bundle install

$ rake spree_related_products:instal
$ rake db:migrate

. . . or whatever is the preferred method.

NOTE: I did not seem to get the rake task when I just did
gem 'spree_related_products'
only when I did:
gem 'spree_related_products', :git => 'https://github.com/spree/spree_related_products.git'

Not published to rubygems

I would like to include this gem as a dependency in another gem. The easiest way to do that would be for you to publish this to rubygems. Is there a reason not to publish this?

discount Calculator problem

With spree 2.4.6 and spree_related_products 2-4-stable, the Calculator doesn't work.
This small change in 'app/models/spree/calculator/related_product_discount.rb' fixed it:

    order.line_items.each do |li|
      mastervariant = li.variant.product.master
      if discount_applies_to.include? mastervariant
        discount = relations.detect {|rel| rel.related_to.master == mastervariant}.discount_amount
        ...

Maybe there is a better way to fix the problem, but it works.

undefined method `empty?' for nil:NilClass

Hello everyone,

I got this error 'undefined method `empty?' for nil:NilClass' when I install spree related products 3-0-stable to spree 3.0.4. Can you please help me to resolve the error? Thank you.

Showing /home/phuong3030/.rvm/gems/ruby-2.2.3@eshop/bundler/gems/spree_related_products-a265c6ee7418/app/views/spree/admin/products/related.html.erb where line #6 raised:

undefined method `empty?' for nil:NilClass
Extracted source (around line #6):


<%= csrf_meta_tag %>

<% if @relation_types.empty? %>
  <div class="alert alert-warning no-objects-found">
  <%= Spree.t(:no_relation_types) %>
</div>

new branch added - requesting review

I pushed an update to the 0.70 branch that removes the 'if false' statements wrapping the 'discount' logic and succesfully hooked in with spree_promo. I also changed the readme to remove the references to the automatic coupons extension.

I have just created a new branch off of master that should mirror these changes verbatim (w/ namespace considersations).

I did not push to master b/c I have not tested it yet.

Does anyone have 10 minutes to verify correctness? I will eventually get to it and wanted to provide this as-is branch for now, just to make it available in the interim.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.