Class: TbCommerce::SampleData

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/tb_commerce/sample_data.rb

Class Method Summary collapse

Class Method Details

.add_sample_dataObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/modules/tb_commerce/sample_data.rb', line 8

def self.add_sample_data
  # This sample script helps explain how the various models in TbCommerce are connected
  # Run this code in your rails console to see the results
  logger.debug "Creating sample data.... \n\n"

  # Create a category
  #
  category = TbCommerce::Category.create({:title => 'Automated Test'})

  # Create a product
  #
  product = TbCommerce::Product.create({
    :title => 'Shirt',
    :description => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
    :price => 9.99,
    :category => category
  })

  # Create an OptionSet for sizes
  #
  sizes = TbCommerce::OptionSet.create({
    :name => 'Size',
    :description => 'Sizes for Shirts'
  })
  small = sizes.options.create(:value => 'Small')
  medium = sizes.options.create(:value => 'Medium')
  large = sizes.options.create(:value => 'Large')

  # Create an OptionSet for colors
  #
  colors = TbCommerce::OptionSet.create({
    :name => 'Colors'
  })
  red = colors.options.create(:value => 'Red')
  blue = colors.options.create(:value => 'Blue')
  yellow = colors.options.create(:value => 'Yellow')

  # Assign our OptionSets to the Product
  #
  product.option_sets = [sizes, colors]

  # Now, create some SKUs with options
  #
  sku_a = product.product_skus.create(:sku => 'PRODUCT_A')
  sku_a.options = [small, red]

  sku_b = product.product_skus.create(:sku => 'PRODUCT_B', :add_price => 1.50)
  sku_b.options = [medium, blue]

  sku_c = product.product_skus.create(:sku => 'PRODUCT_C', :add_price => 2.50)
  sku_c.options = [large, yellow]

  # Done! You now have a Shirt product with configured options
  #

  [sku_a, sku_b, sku_c].each do |sku|
    logger.debug "== #{sku.sku}: #{sku.product.title} =="
    logger.debug "Price: #{sku.price}"
    logger.debug "Options:"
    sku.options.each do |option|
      logger.debug " * #{option.label}: #{option.value}"
    end
    logger.debug "\n"
  end

  # Start ordering some of the created products to create transactions
  logger.debug "Ordering some products.... \n\n"

  cart = TbCommerce::Cart.create(:session_id => 'ubipsjg8zr5cv4dhmotna69xwe072kyl', :is_completed => true)
  cart.cart_items.create({
    :product_sku => sku_a
  })

  #logger.debug cart.id.to_s

  order = TbCommerce::Order.create(
    :cart => cart,
    :name => "Ima Tester",
    :email => "[email protected]",
    :address => "21 S Test Lane",
    :city => "Testville",
    :state => "IN",
    :postal => 46032,
    :country => "US"
  )
end

.loggerObject



4
5
6
# File 'lib/modules/tb_commerce/sample_data.rb', line 4

def self.logger
  Rails.logger
end

.rm_sample_dataObject



95
96
97
98
99
# File 'lib/modules/tb_commerce/sample_data.rb', line 95

def self.rm_sample_data
  logger.debug "Removing sample data.... \n\n"


end