class TbCommerce::SampleData

Public Class Methods

add_sample_data() click to toggle source
# 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 => "test@westlakeinteractive.com",
    :address => "21 S Test Lane",
    :city => "Testville",
    :state => "IN",
    :postal => 46032,
    :country => "US"
  )
end
logger() click to toggle source
# File lib/modules/tb_commerce/sample_data.rb, line 4
def self.logger
  Rails.logger
end
rm_sample_data() click to toggle source
# File lib/modules/tb_commerce/sample_data.rb, line 95
def self.rm_sample_data
  logger.debug "Removing sample data.... \n\n"


end