Product/table configuration (first-time user)

32 views
Skip to first unread message

jameson...@gmail.com

unread,
Feb 27, 2013, 5:01:32 PM2/27/13
to ror_ec...@googlegroups.com
Hello,

This is my first time using ror ecommerce and I had a couple questions as I'm trying to set up the tables. If this has already been covered in detail I apologize and feel free to direct me to that source. Anyway, I'm building an ecommerce site that sells men's, women's, and kid's clothes. 

The navigation consists of Men's, Women's, Kid's.

When you click one of these it takes you to the main page for that category with a listing of subcategories.

For example, click on Men's, and it will take you to a page that has options for pants, short sleeve shirts, long sleeve shirts, shoes, and outerwear.

After you choose one of these subcategories it takes you to a page displaying all of the products for the selected subcategory. Ex. click pants, and will take you to a page displaying all the Men's pants in the database.

My question is how do 'Properties', 'Product Type', 'Prototype', and 'Product' fit the above architecture. Which table will Men's, Women's, etc. go on? Does every single product, regardless of type or whether its mens or womens, go in the Product table?

I've read through all the documentation and I can't seem to find a clear answer.

Thank you so much for your help. I very much appreciate it and I'll try and return the favor.

Jameson

David Henner

unread,
Feb 28, 2013, 1:49:45 AM2/28/13
to ror_ec...@googlegroups.com
Jameson,

If you prefer I might be able to answer on Google Hangout.

I have 2 possibilities for you.  

The first is what comes out of the box.

The second is something I did to allow a product to be completely flexible on a contract I was on last year (unfortunately I have yetto donate that code back to the platform.

FIRST:

I think what you need is covered by product types.  I would setup product types as follows:

"Men's" >> pants
"Men's" >> short sleeve shirts
"Men's" >> long sleeve shirts
"Men's" >> shoes
"Men's" >> outerwear

"Women's" >> pants
"Women's" >> short sleeve shirts
"Women's" >> long sleeve shirts
"Women's" >> shoes
"Women's" >> outerwear

"Girls" >> pants
"Girls" >> short sleeve shirts
"Girls" >> long sleeve shirts
"Girls" >> shoes
"Girls" >> outerwear

"Boys" >> pants
"Boys" >> short sleeve shirts
"Boys" >> long sleeve shirts
"Boys" >> shoes
"Boys" >> outerwear

Now if you look at the code in the product's controller you will see a filter based on the product_type_id.  Basically if the product_type is Men's you will get all men's shirts/pants...  but if the product type is Men's>>shirts you get just men's shirts.

class ProductsController < ApplicationController

  def index
    products = Product.active.includes(:variants)

    product_types = nil
    if params[:product_type_id].present? && product_type = ProductType.find_by_id(params[:product_type_id])
      product_types = product_type.self_and_descendants.map(&:id)
    end
    if product_types
      @products = products.where('product_type_id IN (?)', product_types)
    else
      @products = products.all
    end
  end
end

______________________________________


As for the other solution you will need to write some code:

First you can create two models:
Category and Categorizations.

class Categorization < ActiveRecord::Base
  attr_accessible :categorizable_id, :categorizable_type, :category_id

  belongs_to :category
  belongs_to :categorizable , :polymorphic => true
end

class Category < ActiveRecord::Base
  attr_accessible :active, :lft, :name, :parent_id, :rgt
  acts_as_nested_set
  extend FriendlyId
  friendly_id :name, :use => :slugged

  has_many :categorizations
  has_many :products
end

and 

class Product
  has_many :categorizations, :as => :categorizable
  has_many :categories, :through => :categorizations
###......  much more

  def self.within_category(category)
    category__ids = category.self_and_descendants.map(&:id)
    includes(:categorizations).where('categorizations.category_id IN (?)', category__ids)
  end

end


Finally

    category = Category.find_by_id(params[:category_id])
    products = Product.active.within_category(category) 

That will allow you to "categorize" your product as men's >>  Jeans  or just "jeans"  mixed with mens and women's

 
Hope that helps



--
You received this message because you are subscribed to the Google Groups "ror_ecommerce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ror_ecommerc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jameson Trinker

unread,
Feb 28, 2013, 9:47:08 AM2/28/13
to ror_ec...@googlegroups.com
Thank you Dave! I appreciate that so much. That cleared a lot up for me. I'll start playing with it and maybe I'll contact you later, if you don't mind, if I run into any issues.

You've been a huge help.

Jameson Trinker

unread,
Feb 28, 2013, 11:52:29 AM2/28/13
to ror_ec...@googlegroups.com
Hi Dave,

Would you mind explaining this bit of code a little more:

product_types = nil
    if params[:product_type_id].present? && product_type = ProductType.find_by_id(params[:product_type_id])
      product_types = product_type.self_and_descendants.map(&:id)
    end
    if product_types
      @products = products.where('product_type_id IN (?)', product_types)
    else
      @products = products.all
    end
  end
end

If I wanted to only display men's pants in a view, how would I translate that?

Thanks again!

Jameson

On Thursday, February 28, 2013 12:49:45 AM UTC-6, Dave wrote:

David Henner

unread,
Feb 28, 2013, 2:52:50 PM2/28/13
to ror_ec...@googlegroups.com
Here goes....

________________________________
Lets say the DB looks like this

  • ID   ,     name,       parent_id
  • 1     ,    Mens ,      null
  • 2     ,    pants ,      1
  • 3     ,    shirts ,       1
  • 4     , womens,       null
if params[:product_type_id] is null the code will set 

@products = products.all

if params[:product_type_id] is '1' the code will set

@products = products.where('product_type_id IN (?)', product_types)

So in the case of params[:product_type_id] == 2

This line of code:
 if params[:product_type_id].present? && product_type = ProductType.find_by_id(params[:product_type_id])
Will return an object 
This line of code:
product_type.self_and_descendants.map(&:id)
Will return an array
[2]
Then " if product_types "  will evaluate to true. and
@products = products.where('product_type_id IN (?)', product_types)
will return all products that are pants

__________________________________________
One more example

So in the case of params[:product_type_id] == 1

This line of code:
 if params[:product_type_id].present? && product_type = ProductType.find_by_id(params[:product_type_id])
Will return an object 
This line of code:
product_type.self_and_descendants.map(&:id)
Will return an array
[1, 2, 3]  #  not 4
Then " if product_types "  will evaluate to true. and
@products = products.where('product_type_id IN (?)', product_types)
will return all products that are Mens or Men's pant or Mens shirts BUT NOT Womens...

________________________

product_types = nil
    if params[:product_type_id].present? && product_type = ProductType.find_by_id(params[:product_type_id])
      product_types = product_type.self_and_descendants.map(&:id)
    end
    if product_types
      @products = products.where('product_type_id IN (?)', product_types)
    else
      @products = products.all
    end
  end
end


Hope that helps

Jameson Trinker

unread,
Feb 28, 2013, 4:48:05 PM2/28/13
to ror_ec...@googlegroups.com
Dave,

You've out done yourself again. Thank you so much. That makes perfect sense.

Now I'm making some headway.

Jameson

Jameson Trinker

unread,
Mar 8, 2013, 9:38:34 AM3/8/13
to ror_ec...@googlegroups.com
Hey Dave!

I was wondering if you know any solutions out there for social media type functionality. For example, I would like to create the option to share a product or purchase on facebook and then the customer receives 10% off their purchase? Also, anyway to make a ror-e store on facebook, such as this http://spreecommerce.com/extensions/224-f-connect-online-store-and-widgets-on-facebook ?

Thanks again for all your help!

Jameson

David Henner

unread,
Mar 8, 2013, 1:34:06 PM3/8/13
to ror_ec...@googlegroups.com
Jameson,

    • share a product or purchase on facebook and then the customer receives 10% off their purchase
      • Yes,  Log this event then automatically give the user a coupon in the checkout flow
    • make a ror-e store on facebook
      • It is just code so the answer is yes but I have not looked into a facebook store.  I'm sorta an anti-facebook person.  I guess I should explore this more so I can understand this better.
    Sorry for such little detail.  I'm knee deep in code right now.

    =)

    Dave
    Reply all
    Reply to author
    Forward
    0 new messages