mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Merge pull request #2539 from luisramos0/delete_dead_cart
removed Cart route, controller, model and specs: dead code
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
module OpenFoodNetwork
|
||||
class CartController < ApplicationController
|
||||
respond_to :json
|
||||
|
||||
# before_filter :authorize_read!, :except => [:index, :search, :create]
|
||||
|
||||
def new
|
||||
@cart = Cart.new(current_api_user)
|
||||
if @cart.save
|
||||
respond_with(@cart, :status => 201)
|
||||
else
|
||||
invalid_resource!(@cart)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@cart = Cart.find(params[:id])
|
||||
respond_with(@cart)
|
||||
end
|
||||
|
||||
def add_variant
|
||||
@cart = Cart.find(params[:cart_id])
|
||||
distributor = Enterprise.find_by_permalink(params[:distributor_id])
|
||||
order_cycle = OrderCycle.find(params[:order_cycle_id]) if params[:order_cycle_id]
|
||||
|
||||
if @cart.add_variant params[:variant_id], params[:quantity], distributor, order_cycle, current_currency
|
||||
respond_with(@cart)
|
||||
else
|
||||
respond_with(@cart.populate_errors)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_currency
|
||||
Spree::Config[:currency]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -202,20 +202,6 @@ Spree::OrdersController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def populate_cart hash
|
||||
if spree_current_user
|
||||
unless spree_current_user.cart
|
||||
spree_current_user.build_cart
|
||||
cart = Cart.create(user: spree_current_user)
|
||||
spree_current_user.cart = cart
|
||||
spree_current_user.save
|
||||
end
|
||||
distributor = Enterprise.find(hash[:distributor_id])
|
||||
order_cycle = OrderCycle.find(hash[:order_cycle_id]) if hash[:order_cycle_id]
|
||||
spree_current_user.cart.add_variant hash[:variants].keys.first, hash[:variants].values.first, distributor, order_cycle, current_currency
|
||||
end
|
||||
end
|
||||
|
||||
# Rails to_json encodes Float::INFINITY as Infinity, which is not valid JSON
|
||||
# Return it as a large integer (max 32 bit signed int)
|
||||
def wrap_json_infinity(n)
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
class Cart < ActiveRecord::Base
|
||||
has_many :orders, :class_name => 'Spree::Order'
|
||||
belongs_to :user, :class_name => Spree.user_class
|
||||
|
||||
def add_variant variant_id, quantity, distributor, order_cycle, currency
|
||||
order = create_or_find_order_for_distributor distributor, order_cycle, currency
|
||||
|
||||
@populator = Spree::OrderPopulator.new(order, currency)
|
||||
@populator.populate({ :variants => { variant_id => quantity } })
|
||||
end
|
||||
|
||||
def create_or_find_order_for_distributor distributor, order_cycle, currency
|
||||
order_for_distributor = orders.find { |order| order.distributor == distributor && order.order_cycle == order_cycle }
|
||||
unless order_for_distributor
|
||||
order_for_distributor = Spree::Order.create(:currency => currency, :distributor => distributor)
|
||||
order_for_distributor.distributor = distributor
|
||||
order_for_distributor.order_cycle = order_cycle
|
||||
order_for_distributor.save!
|
||||
orders << order_for_distributor
|
||||
end
|
||||
|
||||
order_for_distributor
|
||||
end
|
||||
|
||||
def populate_errors
|
||||
@populator.errors
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,6 @@ end
|
||||
Spree::Order.class_eval do
|
||||
belongs_to :order_cycle
|
||||
belongs_to :distributor, class_name: 'Enterprise'
|
||||
belongs_to :cart
|
||||
belongs_to :customer
|
||||
has_one :proxy_order
|
||||
has_one :subscription, through: :proxy_order
|
||||
|
||||
@@ -9,7 +9,6 @@ Spree.user_class.class_eval do
|
||||
has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :account_invoices
|
||||
has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner
|
||||
has_one :cart
|
||||
has_many :customers
|
||||
has_many :credit_cards
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
object @cart
|
||||
attributes :id
|
||||
|
||||
node( :orders ) do |p|
|
||||
partial '/open_food_network/orders/index', object: p.orders
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
collection @line_items
|
||||
|
||||
extends "open_food_network/line_items/show"
|
||||
@@ -1,4 +0,0 @@
|
||||
object @line_item
|
||||
attributes :id, :quantity
|
||||
|
||||
node(:name) { |p| p.variant.name }
|
||||
@@ -1,3 +0,0 @@
|
||||
collection @orders
|
||||
|
||||
extends "open_food_network/orders/show"
|
||||
@@ -1,7 +0,0 @@
|
||||
object @order
|
||||
attributes :id
|
||||
|
||||
node( :distributor ) { |p| p.distributor.blank? ? "" : p.distributor.name }
|
||||
node( :line_items ) do |p|
|
||||
partial '/open_food_network/line_items/index', object: p.line_items
|
||||
end
|
||||
Reference in New Issue
Block a user