Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Product taxonomy mapping controller, model. Add product image.

  • Loading branch information...
commit 6f4cdf0d66bdae992835f1049f1d6242135aaea4 1 parent 8515eef
Stephanie Powell authored
View
26 app/controllers/admin/taxon_mapper_controller.rb
@@ -0,0 +1,26 @@
+class Admin::TaxonMapperController < Admin::BaseController
+ resource_controller
+ layout 'admin'
+ require_role :admin
+
+ def index
+ @taxons = Taxon.find(:all)
+ @taxons.each do |taxon|
+ if !taxon.taxon_map
+ taxon_map = TaxonMap.new(:product_type => '', :taxon_id => taxon.id, :priority => 0)
+ taxon_map.save
+ taxon.taxon_map = taxon_map
+ end
+ end
+@products = Product.find(:all)
+ end
+
+ def update
+ TaxonMap.delete(TaxonMap.find(:all))
+ params[:tax_id].each do |k, v|
+ taxon_map = TaxonMap.new(:product_type => v, :taxon_id => k, :priority => params[:priority][k].to_i || 0)
+ taxon_map.save
+ end
+ redirect_to admin_taxon_mapper_index_url
+ end
+end
View
2  app/helpers/admin/taxon_mapper_helper.rb
@@ -0,0 +1,2 @@
+module Admin::TaxonMapperHelper
+end
View
3  app/models/taxon_map.rb
@@ -0,0 +1,3 @@
+class TaxonMap < ActiveRecord::Base
+ belongs_to :taxons
+end
View
13 app/views/admin/taxon_mapper/index.html.erb
@@ -0,0 +1,13 @@
+<h1>Google Base</h1>
+<% form_for :taxon_map, :url => { :controller => :taxon_mapper, :action => "update" } do |f| %>
+<% @taxons.each do |taxon| -%>
+ <p>
+ <%= taxon.name %>:
+ <%= text_field(:tax_id, taxon.id, :value => taxon.taxon_map.product_type) %>
+ <%= text_field(:priority, taxon.id, :value => taxon.taxon_map.priority.to_s) %>
+ </p>
+<% end -%>
+<%= submit_tag 'Update' %>
+<% end %>
+
+<%= debug(@products) %>
View
8 config/routes.rb
@@ -1,5 +1,3 @@
-# Put your extension routes here.
-
-# map.namespace :admin do |admin|
-# admin.resources :whatever
-# end
+map.namespace :admin do |admin|
+ admin.resources :taxon_mapper
+end
View
14 db/migrate/20090224211256_create_taxon_maps.rb
@@ -0,0 +1,14 @@
+class CreateTaxonMaps < ActiveRecord::Migration
+ def self.up
+ create_table :taxon_maps do |t|
+ t.integer :taxon_id
+ t.string :product_type
+ t.integer :priority
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :taxon_maps
+ end
+end
View
23 google_base_extension.rb
@@ -3,16 +3,19 @@
class GoogleBaseExtension < Spree::Extension
version "1.0"
- description "Describe your extension here"
- url "http://yourwebsite.com/google_base"
+ description "Google Base Extension"
+ url "http://spreehq.org"
- # Please use google_base/config/routes.rb instead for extension routes.
-
- # def self.require_gems(config)
- # config.gem "gemname-goes-here", :version => '1.2.3'
- # end
-
def activate
- # admin.tabs.add "Google Base", "/admin/google_base", :after => "Layouts", :visibility => [:all]
+ Admin::ConfigurationsController.class_eval do
+ before_filter :add_taxon_map_link, :only => :index
+ def add_taxon_map_link
+ @extension_links << {:link => admin_taxon_mapper_index_url, :link_text => 'Google Base', :description => 'Google Base'}
+ end
+ end
+
+ Taxon.class_eval do
+ has_one :taxon_map
+ end
end
-end
+end
View
48 lib/tasks/google_base.rake
@@ -1,48 +0,0 @@
-namespace :spree do
- namespace :google_base do
- task :generate => :environment do
- blah = _build_xml
- puts blah
- end
- end
-end
-
-def _build_xml
- returning '' do |output|
- xml = Builder::XmlMarkup.new(:target => output, :indent => 2)
- xml.instruct! :xml, :version => "1.0", :encoding => "UTF-9"
- xml.urlset( :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" ) {
- Product.find(:all).each do |product|
- xml.item {
- xml.id product.sku.to_s
- xml.link ''+product.permalink #add root
- xml.title product.name
- xml.description product.description
- xml.price product.master_price
- xml.condition 'New'
- #Recommended
- #xml.brand 'brand'
- #xml.image_link 'image_link'
- #xml.isbn 'isbn'
- #xml.mpn 'mpn'
- #xml.upc 'upc'
- #xml.weight 'weight'
- #Optional
- #xml.color 'color'
- #xml.expiration_date 'expiration_date'
- #xml.height 'height'
- #xml.length 'length'
- #xml.model_number 'model_number'
- #xml.payment_accepted 'payment_accepted'
- #xml.payment_notes 'payment_notes'
- #xml.price_type 'price_type'
- #xml.product_type 'product_type' #map to category
- #xml.quantity 'quantity'
- #xml.shipping 'shipping'
- #xml.size 'size'
- #xml.tax 'tax'
- }
- end
- }
- end
-end
View
51 lib/tasks/google_base_extension_tasks.rake
@@ -1,3 +1,5 @@
+require 'net/ftp'
+
namespace :db do
desc "Bootstrap your database for Spree."
task :bootstrap => :environment do
@@ -25,10 +27,30 @@ namespace :spree do
end
task :generate => :environment do
results = _build_xml
- puts results
+ File.open("#{SPREE_ROOT}/public/google_base.xml", "w") do |io|
+ io.puts(results)
+ end
end
+ task :transfer => :environment do
+ ftp = Net::FTP.new('uploads.google.com')
+ ftp.login(user = "*", passwd = "*")
+ ftp.putfile("{SPREE_ROOT}/public/google_base.xml", 'test.xml')
+ ftp.quit()
+ end
+ end
+ end
+end
+
+def _get_product_type(product)
+ product_type = ''
+ priority = 1000
+ product.taxons.each do |taxon|
+ if taxon.taxon_map.priority
+ priority = taxon.taxon_map.priority
+ product_type = taxon.taxon_map.product_type
end
end
+ product_type
end
def _build_xml
@@ -39,32 +61,15 @@ def _build_xml
Product.find(:all).each do |product|
xml.item {
xml.id product.sku.to_s
- xml.link ''+product.permalink #add root
+ xml.link 'public_root' + product.permalink
xml.title product.name
xml.description product.description
xml.price product.master_price
xml.condition 'New'
- #Recommended
- #xml.brand 'brand'
- #xml.image_link 'image_link'
- #xml.isbn 'isbn'
- #xml.mpn 'mpn'
- #xml.upc 'upc'
- #xml.weight 'weight'
- #Optional
- #xml.color 'color'
- #xml.expiration_date 'expiration_date'
- #xml.height 'height'
- #xml.length 'length'
- #xml.model_number 'model_number'
- #xml.payment_accepted 'payment_accepted'
- #xml.payment_notes 'payment_notes'
- #xml.price_type 'price_type'
- #xml.product_type 'product_type' #map to category
- #xml.quantity 'quantity'
- #xml.shipping 'shipping'
- #xml.size 'size'
- #xml.tax 'tax'
+ xml.product_type _get_product_type(product)
+ xml.image 'public_root' + product.images.first.attachment.url(:product)
+ #others: xml.brand, xml.isbn, xml.mpn, xml.upc, xml.weight, xml.color, xml.height, xml.length,
+ #xml.payment_accepted, xml.payment_notes, xml.price_type, xml.quantity, xml.shipping, xml.size, xml.tax
}
end
}
View
10 spec/controllers/admin/taxon_mapper_controller_spec.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::TaxonMapperController do
+
+ #Delete this example and add some real ones
+ it "should use Admin::TaxonMapperController" do
+ controller.should be_an_instance_of(Admin::TaxonMapperController)
+ end
+
+end
View
11 spec/helpers/admin/taxon_mapper_helper_spec.rb
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::TaxonMapperHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should include the Admin::TaxonMapperHelper" do
+ included_modules = self.metaclass.send :included_modules
+ included_modules.should include(Admin::TaxonMapperHelper)
+ end
+
+end
View
11 spec/models/taxon_map_spec.rb
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe TaxonMap do
+ before(:each) do
+ @taxon_map = TaxonMap.new
+ end
+
+ it "should be valid" do
+ @taxon_map.should be_valid
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.