mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Add default supplier view and relationship to address.
This commit is contained in:
5
app/models/spree/product_decorator.rb
Normal file
5
app/models/spree/product_decorator.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
Spree::Product.class_eval do
|
||||
attr_accessible :supplier_id
|
||||
|
||||
belongs_to :supplier
|
||||
end
|
||||
@@ -2,16 +2,8 @@ module Spree
|
||||
class Supplier < ActiveRecord::Base
|
||||
set_table_name 'suppliers'
|
||||
belongs_to :address
|
||||
# has_many :orders
|
||||
# belongs_to :country
|
||||
# belongs_to :state
|
||||
has_many :products
|
||||
|
||||
# validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
|
||||
|
||||
# after_initialize :initialize_country
|
||||
|
||||
# def initialize_country
|
||||
# self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
16
app/views/spree/admin/suppliers/_form.html.haml
Normal file
16
app/views/spree/admin/suppliers/_form.html.haml
Normal file
@@ -0,0 +1,16 @@
|
||||
%table{'data-hook' => "suppliers"}
|
||||
%tr{'data-hook' => "name"}
|
||||
%td Name:
|
||||
%td= f.text_field :name
|
||||
%tr{'data-hook' => "description"}
|
||||
%td Description:
|
||||
%td= f.text_field :description
|
||||
%tr{'data-hook' => "email"}
|
||||
%td Email:
|
||||
%td= f.text_field :email
|
||||
%tr{'data-hook' => "website"}
|
||||
%td Website:
|
||||
%td= f.text_field :website
|
||||
%tr{'data-hook' => "twitter"}
|
||||
%td Twitter:
|
||||
%td= f.text_field :twitter
|
||||
5
app/views/spree/admin/suppliers/edit.html.haml
Normal file
5
app/views/spree/admin/suppliers/edit.html.haml
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
= form_for [:admin, @supplier] do |f|
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/edit_resource_links'
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
<div class="toolbar" data-hook="toolbar">
|
||||
<ul class="actions">
|
||||
<li>
|
||||
<%= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link' %>
|
||||
</li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<table class="index" id='listing_suppliers'>
|
||||
<thead>
|
||||
<tr data-hook="suppliers_header">
|
||||
<th>Name</th>
|
||||
<th>
|
||||
Description
|
||||
</th>
|
||||
<th>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @suppliers.each do |supplier| %>
|
||||
<tr >
|
||||
<td><%= link_to supplier.name, spree.admin_supplier_path(supplier) %></td>
|
||||
<td><%=supplier.description %></td>
|
||||
<td data-hook="admin_supplier_index_row_actions">
|
||||
<%= link_to_edit supplier, :class => 'edit' %>
|
||||
<%= link_to_delete supplier %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if @suppliers.empty? %>
|
||||
<tr><td colspan="2"><%= t(:none) %></td></tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
22
app/views/spree/admin/suppliers/index.html.haml
Normal file
22
app/views/spree/admin/suppliers/index.html.haml
Normal file
@@ -0,0 +1,22 @@
|
||||
.toolbar{'data-hook' => "suppliers"}
|
||||
%ul.actions
|
||||
%li= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
|
||||
%br.clear
|
||||
%table#listing_suppliers.index
|
||||
%thead
|
||||
%tr{'data-hook' => "suppliers_header"}
|
||||
%th Name
|
||||
%th Description
|
||||
%th
|
||||
%tbody
|
||||
- @suppliers.each do |supplier|
|
||||
%tr
|
||||
%td= link_to supplier.name, spree.admin_supplier_path(supplier)
|
||||
%td= supplier.description
|
||||
%td{'data-hook' => "admin_supplier_index_row_actions"}
|
||||
= link_to_edit supplier, :class => 'edit'
|
||||
|
||||
= link_to_delete supplier
|
||||
- if @suppliers.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
6
app/views/spree/admin/suppliers/new.html.haml
Normal file
6
app/views/spree/admin/suppliers/new.html.haml
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
|
||||
= form_for [:admin, @supplier] do |f|
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/new_resource_links'
|
||||
21
app/views/spree/admin/suppliers/show.html.haml
Normal file
21
app/views/spree/admin/suppliers/show.html.haml
Normal file
@@ -0,0 +1,21 @@
|
||||
%h1 Supplier
|
||||
%table
|
||||
%tr
|
||||
%th Name
|
||||
%td= @supplier.name
|
||||
%tr
|
||||
%th Description
|
||||
%td= @supplier.description
|
||||
%tr
|
||||
%th Email
|
||||
%td= @supplier.email
|
||||
%tr
|
||||
%th Website
|
||||
%td= @supplier.website
|
||||
%tr
|
||||
%th Twitter
|
||||
%td= @supplier.twitter
|
||||
%p
|
||||
= link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
|
||||
= t(:or)
|
||||
= link_to t(:back), spree.admin_suppliers_path
|
||||
5
db/migrate/20120425065453_add_supplier_to_product.rb
Normal file
5
db/migrate/20120425065453_add_supplier_to_product.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddSupplierToProduct < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_products, :supplier_id, :integer
|
||||
end
|
||||
end
|
||||
9
spec/models/product_spec.rb
Normal file
9
spec/models/product_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Product do
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:supplier) }
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,8 +2,17 @@ require 'spec_helper'
|
||||
|
||||
describe Spree::Supplier do
|
||||
|
||||
describe "associations" do
|
||||
it { should have_many(:products) }
|
||||
it { should belong_to(:address) }
|
||||
end
|
||||
|
||||
it "should have an address"
|
||||
|
||||
it "should add an address on save"
|
||||
|
||||
describe 'validations' do
|
||||
# it{ should validate_presence_of(:comment) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user