Permalink
Browse files

significant work on clearing out data from shop extensions (discounts…

…, packages, variants). Seed data being fixed up
  • Loading branch information...
1 parent c53496b commit 890525d40b98d90a31f4543e79e31e5206ce1b37 Dirk Kelly committed Oct 23, 2010
@@ -147,6 +147,7 @@ def config_global
@meta << 'handle'
@meta << 'layouts'
@meta << 'page'
+ @meta << 'status'
@parts << 'description'
end
@@ -158,6 +158,7 @@ def config_global
@meta << 'page'
@meta << 'category'
@meta << 'layout'
+ @meta << 'status'
@parts << 'description'
end
@@ -11,7 +11,7 @@ class ShopCategory < ActiveRecord::Base
has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discounted_id
has_many :discounts, :class_name => 'ShopDiscount', :through => :discountables
- before_validation :assign_slug, :assign_breadcrumb
+ before_validation :assign_slug, :assign_breadcrumb, :assign_page_class_name
accepts_nested_attributes_for :page
@@ -24,7 +24,13 @@ def name; page.title; end
def handle; ShopProduct.to_sku(page.url); end
# Returns the content of the product's page's description part
- def description; page.parts.find_by_name('description').content; rescue ''; end
+ def description
+ begin
+ page.parts.find_by_name('description').content
+ rescue
+ ''
+ end
+ end
# Returns products through the pages children
def products; page.children.map(&:shop_product); end
@@ -81,5 +87,10 @@ def assign_breadcrumb
self.page.breadcrumb = ShopProduct.to_sku(page.breadcrumb.present? ? page.breadcrumb : page.slug)
end
end
+
+ # Assigns a page class if its nil
+ def assign_page_class_name
+ self.page.class_name = page.class_name || 'ShopCategoryPage'
+ end
end
View
@@ -12,16 +12,14 @@ class ShopProduct < ActiveRecord::Base
has_many :images, :class_name => 'Image', :through => :attachments, :uniq => true
has_many :variants, :class_name => 'ShopProductVariant', :foreign_key => :product_id, :dependent => :destroy
- before_validation :assign_slug, :assign_breadcrumb
+ before_validation :assign_slug, :assign_breadcrumb, :assign_page_class_name
validates_presence_of :page
validates_numericality_of :price, :greater_than => 0.00, :allow_nil => true, :precisions => 2
accepts_nested_attributes_for :page
accepts_nested_attributes_for :variants
- after_create :assign_discounts
-
# Returns the title of the product's page
def name; page.title; end
@@ -35,7 +33,13 @@ def category; page.parent.shop_category; end
def category_id; category.id; end
# Returns the content of the product's page's description part
- def description; page.parts.find_by_name('description').content rescue ''; end
+ def description
+ begin
+ page.parts.find_by_name('description').content
+ rescue
+ ''
+ end
+ end
# Returns the url of the page
def url; page.url; end
@@ -121,11 +125,9 @@ def assign_breadcrumb
end
end
- # Assigns discounts based off categories discounts
- def assign_discounts
- category.discounts.each do |discount|
- ShopDiscountable.create(:discount => discount, :discounted => self)
- end
+ # Assigns a page class if its nil
+ def assign_page_class_name
+ self.page.class_name = page.class_name || 'ShopProductPage'
end
end
@@ -0,0 +1,2 @@
+- f.fields_for :page do |pf|
+ = pf.hidden_field :status_id,:value => Status[Radiant::Config['defaults.page.status']].id
@@ -0,0 +1,2 @@
+- f.fields_for :page do |pf|
+ = pf.hidden_field :status_id,:value => Status[Radiant::Config['defaults.page.status']].id
@@ -13,27 +13,26 @@ def self.up
t.integer "page_id"
end
+ create_table "shop_categories", :force => true do |t|
+ t.integer "product_layout_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "created_by_id"
+ t.integer "updated_by_id"
+ t.integer "page_id"
+ end
+
create_table "shop_product_attachments", :force => true do |t|
t.integer "position", :default => 1
t.integer "image_id"
t.integer "product_id"
t.integer "created_by_id"
t.integer "updated_by_id"
end
-
add_index "shop_product_attachments", ["image_id"], :name => "index_shop_product_attachments_on_image_id"
add_index "shop_product_attachments", ["position"], :name => "index_shop_product_attachments_on_position"
add_index "shop_product_attachments", ["product_id"], :name => "index_shop_product_attachments_on_product_id"
- create_table "shop_categories", :force => true do |t|
- t.integer "product_layout_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.integer "created_by_id"
- t.integer "updated_by_id"
- t.integer "page_id"
- end
-
create_table "shop_orders", :force => true do |t|
t.text "notes"
t.string "status", :default => "new"
@@ -45,7 +44,6 @@ def self.up
t.integer "created_by_id"
t.integer "updated_by_id"
end
-
add_index "shop_orders", ["customer_id"], :name => "index_shop_orders_on_customer_id"
add_index "shop_orders", ["status"], :name => "index_shop_orders_on_status"
@@ -59,7 +57,6 @@ def self.up
t.integer "created_by_id"
t.integer "updated_by_id"
end
-
add_index "shop_line_items", ["item_id"], :name => "index_shop_line_items_on_item_id"
add_index "shop_line_items", ["order_id"], :name => "index_shop_line_items_on_order_id"
View
@@ -1,11 +1,9 @@
-puts "Seed Shop Forms";
-
+#---------------------------------------------------#
# Add Cart Item
-
-Form.create({
- :title => 'CartAddProduct',
- :action => '/shop/cart', # Redirects to the cart listing
- :body => <<-BODY
+#---------------------------------------------------#
+add = Form.new
+add.title = 'CartAddProduct'
+add.body = <<-BODY
<r:shop:product>
<input type="hidden" name="line_item[item_id]" value="<r:id />" />
<input type="hidden" name="line_item[item_type]" value="ShopProduct" />
@@ -14,99 +12,101 @@
<input type="submit" name="add_to_cart" id="add_to_cart_<r:id />" value="Buy Now" />
</r:shop:product>
BODY
-})
+add.config = <<-CONFIG
+add_product:
+ extension: line_item
+ process: add
+CONFIG
-Form.create({
- :title => 'CartAddProductVariant',
- :action => '/shop/cart', # Redirects to the cart listing
- :body => <<-BODY
-<r:shop:product>
- <input type="hidden" name="line_item[item_id]" value="<r:id />" />
- <input type="hidden" name="line_item[item_type]" value="ShopProduct" />
-
- <input type="hidden" name="line_item[quantity]" value="1" />
- <input type="submit" name="add_to_cart" id="add_to_cart_<r:id />" value="Buy Now" />
-</r:shop:product>
-BODY
-})
+add.save
+#---------------------------------------------------#
# Update Cart Item
-
-Form.create({
- :title => 'CartUpdateItem',
- :action => '',
- :body => <<-BODY
+#---------------------------------------------------#
+update = Form.new
+update.title = 'CartUpdateItem'
+update.body = <<-BODY
<r:shop:cart>
- <r:item>
- <input type="hidden" name="_method" value="put" />
- <input type="hidden" name="line_item[id]" value="<r:item:id />" />
-
- <input type="text" name="line_item[quantity]" value="<r:quantity />" />
- <input type="submit" name="add_to_cart" id="update_<r:id />" value="Update" />
- </r:item>
+<r:item>
+ <input type="hidden" name="_method" value="put" />
+ <input type="hidden" name="line_item[id]" value="<r:item:id />" />
+
+ <input type="text" name="line_item[quantity]" value="<r:quantity />" />
+ <input type="submit" name="add_to_cart" id="update_<r:id />" value="Update" />
+</r:item>
</r:shop:cart>
BODY
-})
+update.config = <<-CONFIG
+add_product:
+ extension: line_item
+ process: modify
+CONFIG
-# Checkout Addresses
+update.save
-addresses_body = <<-BODY
+#---------------------------------------------------#
+# Checkout Addresses
+#---------------------------------------------------#
+addresses = Form.new
+addresses.title = 'CheckoutAddresses'
+addresses.redirect_to = '/shop/checkout/payment'
+addresses.body = <<-BODY
<r:shop:cart>
<div class="addresses">
<div id="billing" class="address">
<h4>Billing</h4>
<ol class="address">
<r:address type='billing'>
<r:if_address><input type="hidden" name="billing[id]" value="<r:id />" /></r:if_address>
- <li>
+ <li class="billing_name_input">
<r:label for='billing[name]'>Full Name</r:label>
<input type="text" name="billing[name]" value="<r:name/>" />
</li>
- <li>
+ <li class="billing_email_input">
<r:label for='billing[email]'>Email</r:label>
<input type="text" name="billing[email]" value="<r:email/>" />
</li>
- <li>
+ <li class="billing_street_input">
<r:label for='billing[street]'>Street</r:label>
<input type="text" name="billing[street]" value="<r:street/>" />
</li>
- <li>
+ <li class="billing_city_input">
<r:label for='billing[city]'>Suburb and Postcode</r:label>
<input type="text" name="billing[city]" value="<r:city/>" />
<input type="text" name="billing[postcode]" value="<r:postcode/>" />
</li>
- <li>
+ <li class="billing_state_input">
<r:label for='billing[state]'>State and Country</r:label>
<input type="text" name="billing[state]" value="<r:state/>" />
<input type="text" name="billing[country]" value="<r:country/>" />
</li>
</r:address>
</ol>
</div>
-
+
<div id="shipping" class="address">
<h4>Shipping</h4>
<ol class="address">
<r:address type='shipping'>
<r:if_address><input type="hidden" name="shipping[id]" value="<r:id />" /></r:if_address>
- <li>
+ <li class="shipping_name_input">
<r:label for='shipping[name]'>Full Name</r:label>
<input type="text" name="shipping[name]" value="<r:name/>" />
</li>
- <li>
+ <li class="shipping_email_input">
<r:label for='shipping[email]'>Email</r:label>
<input type="text" name="shipping[email]" value="<r:email/>" />
</li>
- <li>
+ <li class="shipping_street_input">
<r:label for='shipping[street]'>Street</r:label>
<input type="text" name="shipping[street]" value="<r:street/>" />
</li>
- <li>
+ <li class="shipping_city_input">
<r:label for='shipping[city]'>Suburb and Postcode</r:label>
<input type="text" name="shipping[city]" value="<r:city/>" />
<input type="text" name="shipping[postcode]" value="<r:postcode/>" />
</li>
- <li>
+ <li class="shipping_state_input">
<r:label for='shipping[state]'>State and Country</r:label>
<input type="text" name="shipping[state]" value="<r:state/>" />
<input type="text" name="shipping[country]" value="<r:country/>" />
@@ -119,72 +119,11 @@
<r:submit value="Save Addresses" />
BODY
-
-addresses_config = <<-CONFIG
-checkout:
- address:
- billing: true
- shipping: true
+addresses.config = <<-CONFIG
+checkout_addresses:
+ extension: address
+ billing: true
+ shipping: true
CONFIG
-Forms.create({
- :title => 'CheckoutAddresses',
- :redirect_to => '/shop',
- :body => addresses_body,
- :config => addresses_config
-})
-
-eway_body = <<-BODY
-<r:shop:cart>
- <ol class="card">
- <li>
- <r:label for='card[type]'>Type of Card</r:label>
- <r:select name='card[type]'>
- <r:option value='visa'>Visa</r:option>
- <r:option value='mastercard'>Master Card</r:option>
- <r:option value='diners'>Diners Club</r:option>
- <r:option vlaue='amex'>AMEX</r:option>
- </r:select>
- </li>
- <li>
- <r:label for='card[name]'>Name on Card</r:label>
- <r:text name='card[name]' />
- </li>
- <li>
- <r:label for='card[number]'>Card Number</r:label>
- <r:text name='card[number]' />
- </li>
- <li>
- <r:label for='card[verification]'>Verification Code</r:label>
- <r:text name='card[verification]' length='4' />
- </li>
- <li>
- <r:label for='card[month]'>Date on Card</r:label>
- <r:select:card:month />
- <r:select:card:year />
- </li>
- </ol>
-</r:shop:cart>
-
-<h3>Special Instructions</h3>
-
-<p><textarea name="order[message]"></textarea></p>
-
-<r:shop:cart:address type='billing'>
- <input type="hidden" name="options[address][address1]" value="<r:street />" />
- <input type="hidden" name="options[address][city]" value="<r:city />" />
- <input type="hidden" name="options[address][state]" value="<r:state />" />
- <input type="hidden" name="options[address][country]" value="<r:country />" />
- <input type="hidden" name="options[address][zip]" value="<r:postcode />" />
- <input type="hidden" name="options[email]" value="<r:email />" />
- <input type="hidden" name="options[description]" value="<r:config:setting key='site.url' /> order #<r:shop:cart:id />" />
-</r:shop:cart:address>
-
-<r:submit value="Place Order" />
-
-<r:snippet name='PaymentResponse' />
-BODY
-
-eway_config = <<-CONFIG
-
-CONFIG
+addresses.save
Oops, something went wrong.

0 comments on commit 890525d

Please sign in to comment.