diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
index 6663ac4..984db20 100644
--- a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
+++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
@@ -1,49 +1,48 @@
require 'base64'
-class ShoppingCartPluginController < PublicController
+class ShoppingCartPluginController < OrdersPluginController
include ShoppingCartPlugin::CartHelper
helper ShoppingCartPlugin::CartHelper
- append_view_path File.join(File.dirname(__FILE__) + '/../views')
- before_filter :login_required, :only => []
-
- before_filter :login_required, :only => []
-
def get
config =
if cart.nil?
- { :profile_id => nil,
+ { :profile_id => params[:profile_id],
:has_products => false,
:visible => false,
:products => []}
else
- { :profile_id => cart[:profile_id],
+ {
+ :profile_id => cart[:profile_id],
+ :profile_short_name => cart_profile.short_name,
:has_products => (cart[:items].keys.size > 0),
:visible => visible?,
- :products => products}
+ :products => products,
+ }
end
+ config[:has_previous_orders] = if cart_profile then previous_orders.first.present? else false end
render :text => config.to_json
end
def add
product = find_product(params[:id])
- if product && profile = validate_same_profile(product)
- self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil?
- self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil?
- self.cart[:items][product.id] += 1
- render :text => {
- :ok => true,
- :error => {:code => 0},
- :products => [{
- :id => product.id,
- :name => product.name,
- :price => get_price(product, profile.environment),
- :description => product.description,
- :picture => product.default_image(:minor),
- :quantity => self.cart[:items][product.id]
- }]
- }.to_json
+ if product && (profile = validate_same_profile(product))
+ self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil?
+ self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil?
+ self.cart[:items][product.id] += 1
+ render :text => {
+ :ok => true,
+ :error => {:code => 0},
+ :products => [{
+ :id => product.id,
+ :name => product.name,
+ :price => get_price(product, profile.environment),
+ :description => product.description,
+ :picture => product.default_image(:minor),
+ :quantity => self.cart[:items][product.id]
+ }]
+ }.to_json
end
end
@@ -93,36 +92,56 @@ class ShoppingCartPluginController < PublicController
}.to_json
end
+ # override from OrdersPluginController
+ def repeat
+ unless params[:id].present?
+ @orders = previous_orders.last(5).reverse
+ @orders.each{ |o| o.enable_product_diff }
+ else
+ @order = cart_profile.orders.find params[:id]
+ self.cart = { profile_id: cart_profile.id, items: {} }
+ @order.items.each do |item|
+ next unless item.repeat_product and item.repeat_product.available
+ self.cart[:items][item.repeat_product.id] = item.quantity_consumer_ordered.to_i
+ end
+ self.cart[:repeat_order_id] = @order.id
+
+ render json: {
+ products: products,
+ }
+ end
+ end
+
def buy
+ @no_design_blocks = true
@customer = user || Person.new
- if validate_cart_presence
- @cart = cart
- @profile = environment.profiles.find(cart[:profile_id])
- @settings = Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin)
- render :layout => false
+ return redirect_to request.referer || environment.top_url if self.cart.nil?
+ @settings = cart_profile.shopping_cart_settings
+ @cart = cart
+ @profile = cart_profile
+ @order = profile.sales.build consumer: user
+
+ @order.supplier_delivery = profile.delivery_methods.find session[:cart][:last_delivery_option_id] rescue nil
+ if repeat_order_id = self.cart[:repeat_order_id]
+ repeat_order = cart_profile.orders.where(id: repeat_order_id).first
+ @order.consumer_delivery_data = repeat_order.consumer_delivery_data if repeat_order
end
end
def send_request
- register_order(params[:customer], self.cart[:items])
+ order = register_order(params[:customer], self.cart[:items])
begin
- profile = environment.profiles.find(cart[:profile_id])
- ShoppingCartPlugin::Mailer.customer_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]).deliver
- ShoppingCartPlugin::Mailer.supplier_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]).deliver
+ ShoppingCartPlugin::Mailer.customer_notification(order, self.cart[:items]).deliver
+ ShoppingCartPlugin::Mailer.supplier_notification(order, self.cart[:items]).deliver
+ session[:notice] = _('Your order has been sent successfully! You will receive a confirmation e-mail shortly.')
+ @success = true
+ @profile = cart_profile
+ session[:cart] ||= {}
+ session[:cart][:last_delivery_option_id] = order.supplier_delivery_id
self.cart = nil
- render :text => {
- :ok => true,
- :message => _('Request sent successfully. Check your email.'),
- :error => {:code => 0}
- }.to_json
- rescue ActiveRecord::ActiveRecordError
- render :text => {
- :ok => false,
- :error => {
- :code => 6,
- :message => exception.message
- }
- }.to_json
+ rescue ActiveRecord::ActiveRecordError => exception
+ @success = false
+ @error = exception.message
end
end
@@ -168,35 +187,35 @@ class ShoppingCartPluginController < PublicController
end
end
- def update_delivery_option
- profile = environment.profiles.find(cart[:profile_id])
- settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin)
- delivery_price = settings.delivery_options[params[:delivery_option]]
- delivery = Product.new(:name => params[:delivery_option], :price => delivery_price)
- delivery.save(false)
- items = self.cart[:items].clone
- items[delivery.id] = 1
- total_price = get_total_on_currency(items, environment)
- delivery.destroy
- render :text => {
- :ok => true,
- :delivery_price => float_to_currency_cart(delivery_price, environment),
- :total_price => total_price,
- :message => _('Delivery option updated.'),
- :error => {:code => 0}
- }.to_json
+ def update_supplier_delivery
+ @profile = cart_profile
+ supplier_delivery = @profile.delivery_methods.find params[:order][:supplier_delivery_id]
+ order = build_order self.cart[:items], supplier_delivery
+ total_price = order.total_price
+ render json: {
+ ok: true,
+ delivery_price: float_to_currency_cart(supplier_delivery.cost(total_price), environment, unit: ''),
+ total_price: float_to_currency_cart(total_price, environment, unit: ''),
+ message: _('Delivery option updated.'),
+ error: {code: 0}
+ }
end
- private
+ # must be public
+ def profile
+ cart_profile
+ end
+
+ protected
def validate_same_profile(product)
if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id]
render :text => {
:ok => false,
:error => {
- :code => 1,
- :message => _("Can't join items from different enterprises.")
- }
+ :code => 1,
+ :message => _("Your basket contains items from '%{profile_name}'. Please empty the basket or checkout before adding items from here.") % {profile_name: cart_profile.short_name}
+ }
}.to_json
return nil
end
@@ -262,40 +281,48 @@ class ShoppingCartPluginController < PublicController
end
def register_order(custumer, items)
- new_items = {}
- items.each do |id, quantity|
+ products_list = {}; items.each do |id, quantity|
product = Product.find(id)
price = product.price || 0
- new_items[id] = {:quantity => quantity, :price => price, :name => product.name}
+ products_list[id] = {:quantity => quantity, :price => price, :name => product.name}
end
- purchase_order = ShoppingCartPlugin::PurchaseOrder.new
- purchase_order.seller = environment.profiles.find(cart[:profile_id])
- purchase_order.customer = user
- purchase_order.status = ShoppingCartPlugin::PurchaseOrder::Status::OPENED
- purchase_order.products_list = new_items
- purchase_order.customer_delivery_option = params[:delivery_option]
- purchase_order.customer_payment = params[:customer][:payment]
- purchase_order.customer_change = params[:customer][:change]
- purchase_order.customer_name = params[:customer][:name]
- purchase_order.customer_email = params[:customer][:email]
- purchase_order.customer_contact_phone = params[:customer][:contact_phone]
- purchase_order.customer_address = params[:customer][:address]
- purchase_order.customer_district = params[:customer][:district]
- purchase_order.customer_city = params[:customer][:city]
- purchase_order.customer_zip_code = params[:customer][:zip_code]
- purchase_order.save!
- end
- protected
+ order = OrdersPlugin::Sale.new
+ order.profile = environment.profiles.find(cart[:profile_id])
+ order.supplier_delivery = profile.delivery_methods.find params[:order][:supplier_delivery_id]
+ order.session_id = session_id unless user
+ order.consumer = user
+ order.source = 'shopping_cart_plugin'
+ order.status = 'ordered'
+ order.products_list = products_list
+ order.consumer_data = params[:order][:consumer_data]
+ order.payment_data = params[:order][:payment_data]
+ order.consumer_delivery_data = params[:order][:consumer_delivery_data]
+ order.save!
+
+ order
+ end
def cart
@cart ||=
begin
cookies[cookie_key] && YAML.load(Base64.decode64(cookies[cookie_key])) || nil
end
+ # migrate from old attribute
+ @cart[:profile_id] ||= @cart.delete(:enterprise_id) if @cart and @cart[:enterprise_id].present?
@cart
end
+ def cart_profile
+ profile_id = if params[:profile_id].present? then params[:profile_id] elsif cart then cart[:profile_id] end
+ @cart_profile ||= environment.profiles.find profile_id rescue nil
+ end
+
+ # from OrdersPluginController
+ def supplier
+ cart_profile
+ end
+
def cart=(data)
@cart = data
end
diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
index ed7c5fd..4ba4e5a 100644
--- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
+++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
@@ -1,70 +1,26 @@
class ShoppingCartPluginMyprofileController < MyProfileController
- def edit
- params[:settings] = treat_cart_options(params[:settings])
-
- @settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin, params[:settings])
- if request.post?
- begin
- @settings.save!
- session[:notice] = _('Option updated successfully.')
- rescue Exception => exception
- session[:notice] = _('Option wasn\'t updated successfully.')
- end
- redirect_to :action => 'edit'
- end
- end
-
- def reports
- utc_string = ' 00:00:00 UTC'
- @from = params[:from] ? Time.parse(params[:from] + utc_string) : Time.now.utc.at_beginning_of_month
- @to = params[:to] ? Time.parse(params[:to] + utc_string) : Time.now.utc
- @status = !params[:filter_status].blank? ? params[:filter_status].to_i : nil
-
- condition = 'created_at >= ? AND created_at <= ?'
- condition_parameters = [@from, @to+1.day]
- if @status
- condition += ' AND status = ?'
- condition_parameters << @status
- end
- conditions = [condition] + condition_parameters
- @orders = profile.orders.find(:all, :conditions => conditions)
+ helper DeliveryPlugin::DisplayHelper
- @products = {}
- @orders.each do |order|
- order.products_list.each do |id, qp|
- @products[id] ||= ShoppingCartPlugin::LineItem.new(id, qp[:name])
- @products[id].quantity += qp[:quantity]
+ def edit
+ params[:settings] = treat_cart_options(params[:settings])
+ @settings = profile.shopping_cart_settings params[:settings] || {}
+ respond_to do |format|
+ format.js do
+ if request.post?
+ @success = @settings.save!
+ end
end
+ format.html
end
end
- def update_order_status
- order = ShoppingCartPlugin::PurchaseOrder.find(params[:order_id].to_i)
- order.status = params[:order_status].to_i
- order.save!
- redirect_to :action => 'reports', :from => params[:context_from], :to => params[:context_to], :filter_status => params[:context_status]
- end
-
- private
+ protected
def treat_cart_options(settings)
return if settings.blank?
settings[:enabled] = settings[:enabled] == '1'
- settings[:delivery] = settings[:delivery] == '1'
- settings[:free_delivery_price] = settings[:free_delivery_price].blank? ? nil : settings[:free_delivery_price].to_d
- settings[:delivery_options] = treat_delivery_options(settings[:delivery_options])
settings
end
- def treat_delivery_options(params)
- result = {}
- return result if params.nil? || params[:options].nil?
- params[:options].size.times do |counter|
- if params[:options][counter].present? && params[:prices][counter].present?
- result[params[:options][counter]] = params[:prices][counter]
- end
- end
- result
- end
end
diff --git a/plugins/shopping_cart/db/migrate/20121022190819_move_fields_included_on_profiles_table_to_settings.rb b/plugins/shopping_cart/db/migrate/20121022190819_move_fields_included_on_profiles_table_to_settings.rb
index b071aec..a32a1ec 100644
--- a/plugins/shopping_cart/db/migrate/20121022190819_move_fields_included_on_profiles_table_to_settings.rb
+++ b/plugins/shopping_cart/db/migrate/20121022190819_move_fields_included_on_profiles_table_to_settings.rb
@@ -1,7 +1,7 @@
class MoveFieldsIncludedOnProfilesTableToSettings < ActiveRecord::Migration
def self.up
Profile.find_each do |profile|
- settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin)
+ settings = profile.shopping_cart_settings
settings.enabled = profile.shopping_cart
settings.delivery = profile.shopping_cart_delivery
settings.delivery_price = profile.shopping_cart_delivery_price
diff --git a/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb b/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
new file mode 100644
index 0000000..a8a5090
--- /dev/null
+++ b/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
@@ -0,0 +1,86 @@
+OrdersPlugin.send :remove_const, :Item if defined? OrdersPlugin::Item
+OrdersPlugin.send :remove_const, :Order if defined? OrdersPlugin::Order
+
+class ShoppingCartPlugin::PurchaseOrder < Noosfero::Plugin::ActiveRecord
+ acts_as_having_settings :field => :data
+
+ module Status
+ OPENED = 0
+ CANCELED = 1
+ CONFIRMED = 2
+ SHIPPED = 3
+ end
+end
+
+class Profile
+ has_many :orders, :class_name => 'OrdersPlugin::Order'
+end
+
+class OrdersPlugin::Item < Noosfero::Plugin::ActiveRecord
+ belongs_to :order, :class_name => 'OrdersPlugin::Order'
+end
+class OrdersPlugin::Order < Noosfero::Plugin::ActiveRecord
+ has_many :items, :class_name => 'OrdersPlugin::Item', :foreign_key => :order_id
+
+ extend CodeNumbering::ClassMethods
+ code_numbering :code, :scope => proc{ self.profile.orders }
+end
+
+StatusTransform = {
+ ShoppingCartPlugin::PurchaseOrder::Status::OPENED => 'ordered',
+ ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED => 'accepted',
+ ShoppingCartPlugin::PurchaseOrder::Status::CANCELED => 'cancelled',
+ ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED => 'delivered',
+}
+
+class MoveShoppingCartPurchaseOrderToOrdersPluginOrder < ActiveRecord::Migration
+ def self.up
+ OrdersPlugin::Order.record_timestamps = false
+
+ ShoppingCartPlugin::PurchaseOrder.all(:order => 'created_at ASC').each do |purchase_order|
+ data = purchase_order.data
+
+ order = OrdersPlugin::Order.new :profile_id => purchase_order.seller_id, :consumer_id => purchase_order.customer_id
+
+ order.consumer_data = {}
+ ['contact_phone','name','email'].each do |prop|
+ order.consumer_data[prop.to_sym] = data[('customer_'+prop).to_sym]
+ end
+
+ order.consumer_delivery_data = {
+ :name => data[:customer_delivery_option],
+ :address_line1 => data[:customer_address],
+ :address_line2 => data[:customer_district],
+ :postal_code => data[:customer_zip_code],
+ :state => data[:customer_state],
+ :country => 'Brasil'
+ }
+ order.supplier_delivery_data = {}
+
+ data[:products_list].each do |id, data|
+ item = order.items.build :product_id => id, :name => data[:name], :quantity_consumer_ordered => data[:quantity], :price => data[:price]
+ item.order = order
+ end
+
+ order.payment_data = {
+ :method => data[:customer_payment],
+ :change => data[:customer_change]
+ }
+
+ order.status = StatusTransform[purchase_order.status]
+
+ order.updated_at = purchase_order.updated_at
+ order.created_at = purchase_order.created_at
+
+ order.save!
+ end
+
+ # Leave table for registry
+ #drop_table :shopping_cart_plugin_purchase_orders
+
+ OrdersPlugin::Order.record_timestamps = true
+ end
+
+ def self.down
+ end
+end
diff --git a/plugins/shopping_cart/db/migrate/20150202122535_move_shopping_delivery_options_to_delivery_plugin.rb b/plugins/shopping_cart/db/migrate/20150202122535_move_shopping_delivery_options_to_delivery_plugin.rb
new file mode 100644
index 0000000..749c9ec
--- /dev/null
+++ b/plugins/shopping_cart/db/migrate/20150202122535_move_shopping_delivery_options_to_delivery_plugin.rb
@@ -0,0 +1,21 @@
+class MoveShoppingDeliveryOptionsToDeliveryPlugin < ActiveRecord::Migration
+ def up
+ Enterprise.find_each batch_size: 20 do |enterprise|
+ settings = enterprise.shopping_cart_settings
+ next if settings.delivery_options.blank?
+
+ free_over_price = settings.free_delivery_price
+ settings.delivery_options.each do |name, price|
+ enterprise.delivery_methods.create! name: name, fixed_cost: price.to_f, delivery_type: 'deliver', free_over_price: free_over_price
+ end
+
+ settings.free_delivery_price = nil
+ settings.delivery_options = nil
+ enterprise.save!
+ end
+ end
+
+ def down
+ say "this migration can't be reverted"
+ end
+end
diff --git a/plugins/shopping_cart/lib/ext/enterprise.rb b/plugins/shopping_cart/lib/ext/enterprise.rb
deleted file mode 100644
index 139a9a5..0000000
--- a/plugins/shopping_cart/lib/ext/enterprise.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require_dependency 'enterprise'
-
-class Enterprise
- has_many :orders, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'seller_id'
-end
diff --git a/plugins/shopping_cart/lib/ext/person.rb b/plugins/shopping_cart/lib/ext/person.rb
deleted file mode 100644
index e01e85b..0000000
--- a/plugins/shopping_cart/lib/ext/person.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require_dependency 'person'
-
-class Person
- has_many :purchases, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'customer_id'
-end
diff --git a/plugins/shopping_cart/lib/ext/profile.rb b/plugins/shopping_cart/lib/ext/profile.rb
new file mode 100644
index 0000000..ef4ea74
--- /dev/null
+++ b/plugins/shopping_cart/lib/ext/profile.rb
@@ -0,0 +1,24 @@
+require_dependency 'profile'
+
+class Profile
+
+ def shopping_cart_settings attrs = {}
+ @shopping_cart_settings ||= Noosfero::Plugin::Settings.new self, ShoppingCartPlugin, attrs
+ attrs.each{ |a, v| @shopping_cart_settings.send "#{a}=", v }
+ @shopping_cart_settings
+ end
+
+ def shopping_cart_enabled
+ self.shopping_cart_settings.enabled
+ end
+
+ # may be customized by other profiles
+ def cart_order_supplier_notification_recipients
+ if self.contact_email.present?
+ [self.contact_email]
+ else
+ self.admins.collect(&:contact_email).select{ |email| email.present? }
+ end
+ end
+
+end
diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin.rb b/plugins/shopping_cart/lib/shopping_cart_plugin.rb
index c2acfaf..50059dc 100644
--- a/plugins/shopping_cart/lib/shopping_cart_plugin.rb
+++ b/plugins/shopping_cart/lib/shopping_cart_plugin.rb
@@ -1,44 +1,13 @@
class ShoppingCartPlugin < Noosfero::Plugin
- class << self
- def plugin_name
+ def self.plugin_name
"Shopping Basket"
- end
-
- def plugin_description
- _("A shopping basket feature for enterprises")
- end
-
- def delivery_default_setting
- false
- end
-
- def delivery_price_default_setting
- 0
- end
-
- def delivery_options_default_setting
- {}
- end
end
- def add_to_cart_button(item)
- profile = item.profile
- settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin)
- if settings.enabled && item.available
- lambda {
- link_to(_('Add to basket'), "add:#{item.name}",
- :class => 'cart-add-item',
- :onclick => "Cart.addItem(#{item.id}, this); return false"
- )
- }
- end
+ def self.plugin_description
+ _("A shopping basket feature for enterprises")
end
- alias :product_info_extras :add_to_cart_button
- alias :catalog_item_extras :add_to_cart_button
- alias :asset_product_extras :add_to_cart_button
-
def stylesheet?
true
end
@@ -48,19 +17,45 @@ class ShoppingCartPlugin < Noosfero::Plugin
end
def body_beginning
- expanded_template('cart.html.erb')
+ lambda do
+ extend ShoppingCartPlugin::CartHelper
+ render 'public/cart' unless cart_minimized
+ end
end
def control_panel_buttons
- settings = Noosfero::Plugin::Settings.new(context.profile, ShoppingCartPlugin)
buttons = []
if context.profile.enterprise?
buttons << { :title => _('Shopping basket'), :icon => 'shopping-cart-icon', :url => {:controller => 'shopping_cart_plugin_myprofile', :action => 'edit'} }
end
- if context.profile.enterprise? && settings.enabled
- buttons << { :title => _('Purchase reports'), :icon => 'shopping-cart-purchase-report', :url => {:controller => 'shopping_cart_plugin_myprofile', :action => 'reports'} }
- end
buttons
end
+
+ def add_to_cart_button item, options = {}
+ profile = item.profile
+ return unless profile.shopping_cart_enabled and item.available
+ lambda do
+ extend ShoppingCartPlugin::CartHelper
+ add_to_cart_button item, options
+ end
+ end
+
+ alias :product_info_extras :add_to_cart_button
+ alias :catalog_item_extras :add_to_cart_button
+ alias :asset_product_extras :add_to_cart_button
+
+ # We now think that it's not a good idea to have the basket in the same time.
+ #def catalog_autocomplete_item_extras product
+ # add_to_cart_button product, with_text: false
+ #end
+
+ def catalog_search_extras_begin
+ return unless profile.shopping_cart_enabled
+ lambda do
+ extend ShoppingCartPlugin::CartHelper
+ content_tag 'li', render('public/cart'), :class => 'catalog-cart'
+ end
+ end
+
end
diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
index 8b4981f..df3e5ed 100644
--- a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
+++ b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
@@ -1,15 +1,40 @@
+require_dependency 'delivery_plugin/display_helper'
+
module ShoppingCartPlugin::CartHelper
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TagHelper
+ include DeliveryPlugin::DisplayHelper
+
+ def add_to_cart_button item, options = {}
+ label = if options[:with_text].nil? or options[:with_text] then _('Add to basket') else '' end
+ button_to_function 'cart', label, "Cart.addItem(#{item.id}, this)", class: 'cart-add-item', type: 'primary'
+ end
+
+ def cart_applet
+ button_to_function 'cart', ' ', "cart.toggle()", class: 'cart-applet-indicator', type: 'primary'
+ end
+
+ def cart_minimized
+ @catalog_bar
+ end
+
+ def repeat_checkout_order_button order
+ button_to_function :check, t('views.public.repeat.checkout'), 'cart.repeatCheckout(event, this)', 'data-order-id' => order.id, class: 'repeat-checkout-order'
+ end
+
+ def repeat_choose_order_button order
+ button_to_function :edit, t('views.public.repeat.choose'), 'cart.repeatChoose(event, this)', 'data-order-id' => order.id, class: 'repeat-choose-order'
+ end
+
def sell_price(product)
return 0 if product.price.nil?
product.discount ? product.price_with_discount : product.price
end
- def get_price(product, environment, quantity=1)
- float_to_currency_cart(price_with_quantity(product,quantity), environment)
+ def get_price product, environment, quantity=1, options = {}
+ float_to_currency_cart price_with_quantity(product,quantity), environment, options
end
def price_with_quantity(product, quantity=1)
@@ -25,68 +50,28 @@ module ShoppingCartPlugin::CartHelper
float_to_currency_cart(get_total(items), environment)
end
- def items_table(items, profile, delivery_option = nil, by_mail = false)
- environment = profile.environment
- settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin)
- items = items.to_a
-
- quantity_opts = { :class => 'cart-table-quantity' }
- quantity_opts.merge!({:align => 'center'}) if by_mail
- price_opts = {:class => 'cart-table-price'}
- price_opts.merge!({:align => 'right'}) if by_mail
- items.sort! {|a, b| Product.find(a.first).name <=> Product.find(b.first).name}
-
- if settings.delivery
- if settings.free_delivery_price && get_total(items) >= settings.free_delivery_price
- delivery = Product.new(:name => _('Free delivery'), :price => 0)
- else
- delivery = Product.new(:name => delivery_option || _('Delivery'), :price => settings.delivery_options[delivery_option])
- end
- delivery.save(false)
- items << [delivery.id, '']
+ def build_order items, delivery_method = nil
+ @order = @profile.sales.build
+ items.each do |product_id, quantity|
+ @order.items.build product_id: product_id, quantity_consumer_ordered: quantity
end
+ @order.supplier_delivery = delivery_method
+ @order
+ end
- table = '
' +
- content_tag('tr',
- content_tag('th', _('Item name')) +
- content_tag('th', by_mail ? ' # ' : '#') +
- content_tag('th', c_('Price'))
- ) +
- items.map do |id, quantity|
- product = Product.find(id)
- name_opts = {}
- is_delivery = quantity.kind_of?(String)
- if is_delivery
- price_opts.merge!({:id => 'delivery-price'})
- name_opts.merge!({:id => 'delivery-name'})
- end
- content_tag('tr',
- content_tag('td', product.name, name_opts) +
- content_tag('td', quantity, quantity_opts ) +
- content_tag('td', get_price(product, environment, quantity), price_opts)
- )
- end.join("\n")
-
- total = get_total_on_currency(items, environment)
- delivery.destroy if settings.delivery
-
- table +
- content_tag('th', _('Total:'), :colspan => 2, :class => 'cart-table-total-label') +
- content_tag('th', total, :class => 'cart-table-total-value') +
- '
'
+ def items_table(items, profile, delivery_method = nil, by_mail = false)
+ # partial key needed in mailer context
+ render partial: 'shopping_cart_plugin/items', locals: {order: build_order(items, delivery_method), by_mail: by_mail}
end
- def float_to_currency_cart(value, environment)
- number_to_currency(value, :unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :precision => 2, :format => "%u%n")
+ def float_to_currency_cart value, environment, _options = {}
+ options = {:unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :precision => 2, :format => "%u%n"}
+ options.merge! _options
+ number_to_currency value, options
end
- def select_delivery_options(options, environment)
- result = options.map do |option, price|
- ["#{option} (#{float_to_currency_cart(price, environment)})", option]
- end
- result << ["#{_('Delivery')} (#{float_to_currency_cart(0, environment)})", 'delivery'] if result.empty?
- result
+ def options_for_payment
+ options_for_select OrdersPlugin::Order::PaymentMethods.map{ |key, text| [text.call, key] }
end
+
end
diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb b/plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb
index a37e38b..62952a3 100644
--- a/plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb
+++ b/plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb
@@ -2,38 +2,38 @@ class ShoppingCartPlugin::Mailer < Noosfero::Plugin::MailerBase
include ShoppingCartPlugin::CartHelper
- def customer_notification(customer, supplier, items, delivery_option)
- domain = supplier.hostname || supplier.environment.default_hostname
- @customer = customer
- @supplier = supplier
+ helper ShoppingCartPlugin::CartHelper
+
+ attr_accessor :environment, :profile
+
+ def customer_notification order, items
+ domain = order.profile.hostname || order.profile.environment.default_hostname
+ self.profile = order.profile
+ self.environment = order.profile.environment
+ @order = order
@items = items
- @environment = supplier.environment
- @helper = self
- @delivery_option = delivery_option
mail(
- to: customer[:email],
+ to: @order.consumer_data[:email],
from: 'no-reply@' + domain,
- reply_to: supplier.contact_email,
- subject: _("[%s] Your buy request was performed successfully.") % supplier[:name],
+ reply_to: @order.profile.cart_order_supplier_notification_recipients,
+ subject: _("[%s] Your buy request was performed successfully.") % @order.profile.short_name(nil),
content_type: 'text/html'
)
end
- def supplier_notification(customer, supplier, items, delivery_option)
- domain = supplier.environment.default_hostname
- @customer = customer
- @supplier = supplier
+ def supplier_notification order, items
+ domain = order.profile.environment.default_hostname
+ self.profile = order.profile
+ self.environment = order.profile.environment
+ @order = order
@items = items
- @environment = supplier.environment
- @helper = self
- @delivery_option = delivery_option
mail(
- to: supplier.contact_email,
+ to: @order.profile.cart_order_supplier_notification_recipients,
from: 'no-reply@' + domain,
- reply_to: customer[:email],
- subject: _("[%s] You have a new buy request from %s.") % [supplier.environment.name, customer[:name]],
+ reply_to: @order.consumer_data[:email],
+ subject: _("[%s] You have a new buy request from %s.") % [order.profile.environment.name, @order.consumer_data[:name]],
content_type: 'text/html'
)
end
diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin/purchase_order.rb b/plugins/shopping_cart/lib/shopping_cart_plugin/purchase_order.rb
deleted file mode 100644
index e201b74..0000000
--- a/plugins/shopping_cart/lib/shopping_cart_plugin/purchase_order.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-class ShoppingCartPlugin::PurchaseOrder < Noosfero::Plugin::ActiveRecord
-
- belongs_to :customer, :class_name => "Profile"
- belongs_to :seller, :class_name => "Profile"
-
- validates_presence_of :status, :seller
-
- attr_accessible :seller, :status, :products_list
-
- acts_as_having_settings :field => :data
-
- settings_items :products_list, :type => Array, :default => {}
- settings_items :customer_name, :type => String
- settings_items :customer_email, :type => String
- settings_items :customer_contact_phone, :type => String
- settings_items :customer_address, :type => String
- settings_items :customer_district, :type => String
- settings_items :customer_city, :type => String
- settings_items :customer_zip_code, :type => String
- settings_items :customer_delivery_option, :type => String
- settings_items :customer_payment, :type => String
- settings_items :customer_change, :type => String
-
- before_create do |order|
- order.created_at = Time.now.utc
- order.updated_at = Time.now.utc
- end
-
- before_update do |order|
- order.updated_at = Time.now.utc
- end
-
- module Status
- OPENED = 0
- CANCELED = 1
- CONFIRMED = 2
- SHIPPED = 3
-
- def self.name
- [_('Opened'), _('Canceled'), _('Confirmed'), _('Shipped')]
- end
- end
-end
diff --git a/plugins/shopping_cart/plugin.yml b/plugins/shopping_cart/plugin.yml
new file mode 100644
index 0000000..33ee6d0
--- /dev/null
+++ b/plugins/shopping_cart/plugin.yml
@@ -0,0 +1,3 @@
+name: shopping_cart
+dependencies:
+ - orders
diff --git a/plugins/shopping_cart/po/de/shopping_cart.po b/plugins/shopping_cart/po/de/shopping_cart.po
index f226407..38b9db4 100644
--- a/plugins/shopping_cart/po/de/shopping_cart.po
+++ b/plugins/shopping_cart/po/de/shopping_cart.po
@@ -6,8 +6,8 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: 1.1-166-gaf47713\n"
-"POT-Creation-Date: 2015-06-01 17:26-0300\n"
+"Project-Id-Version: 1.0-690-gcb6e853\n"
+"POT-Creation-Date: 2015-03-05 12:09-0300\n"
"PO-Revision-Date: 2015-02-23 11:36+0200\n"
"Last-Translator: Michal Čihař \n"
"Language-Team: German \n"
"Language-Team: Spanish \n"
"Language-Team: French \n"
"Language-Team: Armenian \n"
-"Language-Team: Portuguese \n"
+"Language-Team: Portuguese \n"
"Language: pt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -65,6 +65,18 @@ msgstr "Frete grátis"
msgid "Delivery"
msgstr "Entrega"
+#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb:7
+msgid "Delivery or pickup"
+msgstr "Forma de retirada ou entrega"
+
+#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb:7
+msgid "Deliveries or pickups"
+msgstr "Formas de retirada ou entrega"
+
+#: plugins/delivery/views/delivery_plugin/_order_select.html.slim
+msgid "Instructions"
+msgstr "Instruções"
+
#: plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb:53
msgid "Item name"
msgstr "Nome do item"
@@ -86,6 +98,10 @@ msgstr "[%s] Você tem um novo pedido de compra de %s."
msgid "Request sent successfully. Check your email."
msgstr "Requisição enviada com sucesso. Cheque seu email."
+#: plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb:115
+msgid "Your order has been sent successfully! You will receive a confirmation e-mail shortly."
+msgstr "Seu pedido foi enviado com sucesso! Você receberá uma confirmação em breve."
+
#: plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb:138
msgid "Basket displayed."
msgstr "Cesto exibido."
@@ -134,18 +150,15 @@ msgstr "Opção foi atualizada com sucesso."
msgid "Option wasn't updated successfully."
msgstr "Opção não foi atualizada com sucesso."
-#: plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb:6
#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_orders_list.html.erb:35
#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:5
msgid "Name"
msgstr "Nome"
-#: plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb:10
#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:13
-msgid "Delivery Address"
-msgstr "Endereço de Entrega"
+msgid "Delivery or pickup method"
+msgstr "Forma de entrega ou retirada"
-#: plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb:16
#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:22
msgid "Send buy request"
msgstr "Enviar pedido de compra"
@@ -176,10 +189,9 @@ msgstr "Estado"
msgid "E-mail"
msgstr "E-mail"
-#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_orders_list.html.erb:35
-#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:8
-msgid "Delivery option"
-msgstr "Opção de entrega"
+#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:9
+msgid "Personal identification"
+msgstr "Identificação pessoal"
#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_orders_list.html.erb:35
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:20
@@ -188,12 +200,20 @@ msgstr "Opção de entrega"
msgid "Payment"
msgstr "Pagamento"
+#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:9
+msgid "Payment's method"
+msgstr "Forma de pagamento"
+
#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_orders_list.html.erb:35
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:22
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb:20
#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:10
msgid "shopping_cart|Change"
-msgstr "Troco"
+msgstr "Troco para"
+
+#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:10
+msgid "Your Order"
+msgstr "Seu Pedido"
#: plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_products_list.html.erb:7
msgid "Quantity"
@@ -303,42 +323,30 @@ msgid "Hi %s!"
msgstr "Olá %s!"
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:10
-msgid "This is a notification e-mail about your buy request on %s."
-msgstr "Esse é um email de notificação sobre o seu pedido de compra em %s."
+msgid "This is a notification e-mail about your buy request on the enterprise %s."
+msgstr "Esse é um email de notificação sobre o seu pedido de compra no empreendimento %s."
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:11
msgid ""
-"The supplier already received your buy request and may contact you for "
+"The enterprise already received your buy request and will contact you for "
"confirmation."
msgstr ""
-"O fornecedor já recebeu o seu pedido de compra e deve te contactar para "
+"O empreendimento já recebeu o seu pedido de compra e entrará em contato para "
"confirmação."
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:12
-msgid "If you have any doubts, contact us at: %s"
-msgstr "Se você tem alguma dúvida, nos contacte em: %s"
+msgid "If you have any doubts about your order, write to us at: %s."
+msgstr "Se você tem alguma dúvida sobre o seu pedido, nos escreva: %s."
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:13
-msgid "Please check if your information below is correct:"
-msgstr "Por favor cheque se suas informações abaixo estão corretas:"
+msgid "Review below the informations of your order:"
+msgstr "Abaixo, revise as informações do seu pedido:"
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:19
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb:17
msgid "Phone number"
msgstr "Telefone"
-#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:20
-#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb:18
-#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:9
-msgid "Money"
-msgstr "Dinheiro"
-
-#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:20
-#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb:18
-#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:9
-msgid "shopping_cart|Check"
-msgstr "Cheque"
-
#: plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb:47
msgid "Here are the products you bought:"
msgstr "Aqui estão os produtos que você pediu:"
@@ -368,3 +376,17 @@ msgstr "E aqui estão os itens pedidos por esse consumidor:"
msgid "If there are any problems with this email contact the admin of %s."
msgstr ""
"Se houver algum problema com esse email contacte o administrador de %s."
+
+#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:15
+msgid "Address completion"
+msgstr "Complemento (p.ex. apto)"
+
+#:
+msgid "repeat order"
+msgstr "repetir pedido"
+
+#: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
+msgid "haven't finished yet: back to shopping"
+msgstr "ainda não concluí: voltar às compras"
+
+
diff --git a/plugins/shopping_cart/po/ru/shopping_cart.po b/plugins/shopping_cart/po/ru/shopping_cart.po
index a8468b7..1b883e3 100644
--- a/plugins/shopping_cart/po/ru/shopping_cart.po
+++ b/plugins/shopping_cart/po/ru/shopping_cart.po
@@ -5,8 +5,8 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: 1.1-166-gaf47713\n"
-"POT-Creation-Date: 2015-06-01 17:26-0300\n"
+"Project-Id-Version: 1.0-690-gcb6e853\n"
+"POT-Creation-Date: 2015-03-05 12:09-0300\n"
"PO-Revision-Date: 2015-02-23 11:36+0200\n"
"Last-Translator: Michal Čihař \n"
"Language-Team: Russian =2 && n"
-"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
+"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<="
+"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 2.3-dev\n"
#: plugins/shopping_cart/lib/shopping_cart_plugin.rb:9
diff --git a/plugins/shopping_cart/public/buy.js b/plugins/shopping_cart/public/buy.js
index 4da3197..c8e3442 100644
--- a/plugins/shopping_cart/public/buy.js
+++ b/plugins/shopping_cart/public/buy.js
@@ -1,34 +1,48 @@
-jQuery(document).ready(function(){
- jQuery("#cart-request-form").validate({
- submitHandler: function(form) {
- jQuery(form).find('input.submit').attr('disabled', true);
- jQuery('#cboxLoadingOverlay').show().addClass('loading');
- jQuery('#cboxLoadingGraphic').show().addClass('loading');
- }
- });
-});
+shopping_cart.buy = {
-jQuery('#delivery_option').change(function(){
- jQuery('#cboxLoadingGraphic').show();
- me = this;
- profile = jQuery(me).attr('data-profile-identifier');
- option = jQuery(me).val();
- jQuery.ajax({
- url: '/plugin/shopping_cart/update_delivery_option',
- dataType: "json",
- data: 'delivery_option='+option,
- success: function(data, st, ajax) {
- jQuery('#delivery-price').text(data.delivery_price);
- jQuery('.cart-table-total-value').text(data.total_price);
- jQuery('#delivery-name').text(option);
- jQuery('#cboxLoadingGraphic').hide();
- },
- error: function(ajax, st, errorThrown) {
- alert('Update delivery option - HTTP '+st+': '+errorThrown);
- },
- });
-});
+ validate: function() {
+ $("#cart-request-form").validate({
+ submitHandler: function(form) {
+ $(form).find('input.submit').attr('disabled', true);
+ $('#cboxLoadingOverlay').show().addClass('loading');
+ $('#cboxLoadingGraphic').show().addClass('loading');
+ }
+ });
+ },
+
+ update_delivery: function () {
+ $('#cboxLoadingGraphic').show();
+ var me = $(this);
+ var profile = me.attr('data-profile-identifier');
+ var id = me.val();
+ var name = me.find('option:selected').attr('data-label');
+ $.ajax({
+ url: '/plugin/shopping_cart/update_supplier_delivery',
+ dataType: "json",
+ data: 'order[supplier_delivery_id]='+id,
+ success: function(data, st, ajax) {
+ $('#delivery-price').text(data.delivery_price);
+ $('.cart-table-total-value').text(data.total_price);
+ $('#delivery-name').text(name);
+ $('#cboxLoadingGraphic').hide();
+ display_notice(data.message)
+ },
+ error: function(ajax, st, errorThrown) {
+ alert('Update delivery option - HTTP '+st+': '+errorThrown);
+ },
+ });
+ },
+
+ update_payment: function() {
+ var payment = $(this)
+ var form = $(payment.get(0).form)
+ var changeField = form.find('#order_payment_data_change').parents('.form-group');
+ var method = payment.val() == 'money' ? 'slideDown' : 'slideUp';
+ changeField[method]('fast');
+ },
+}
+
+$(document).ready(shopping_cart.buy.validate)
+$('#order_supplier_delivery_id').on('change keyup', shopping_cart.buy.update_delivery)
+$('#order_payment_data_method').on('change keyup', shopping_cart.buy.update_payment)
-jQuery('#customer_payment').change(function(){
- jQuery(this).closest('.formfieldline').next().slideToggle('fast');
-});
diff --git a/plugins/shopping_cart/public/cart.js b/plugins/shopping_cart/public/cart.js
index 6043975..07b0048 100644
--- a/plugins/shopping_cart/public/cart.js
+++ b/plugins/shopping_cart/public/cart.js
@@ -1,25 +1,30 @@
+shopping_cart = {
+}
+
function Cart(config) {
var $ = jQuery;
+ config.minimized = Cart.minimized;
Cart.instance = this; // this may be a list on the future;
- this.cartElem = $("#cart1")[0];
+ this.cartElem = $("#cart1");
this.cartElem.cartObj = this;
- this.contentBox = $("#cart1 .cart-content");
+ this.contentBox = (config.minimized) ? $("#cart1 .cart-inner") : $("#cart1 .cart-inner .cart-content");
this.itemsBox = $("#cart1 .cart-items");
+ this.profileId = config.profile_id;
this.items = {};
+ this.products = config.products;
this.empty = !config.has_products;
+ this.minimized = config.minimized;
+ this.hasPreviousOrders = config.has_previous_orders;
this.visible = false;
+ this.itemTemplate = _.template(jQuery('#cart-item-template').html());
+ $("#cart-profile-name").text(config.profile_short_name);
$(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} });
- if (!this.empty) {
- $(this.cartElem).show();
- this.visible = config.visible;
- this.addToList(config.products, true)
- }
+ this.load()
}
(function($){
-
// Forbidding the user to request more the one action on the cart
- // simultaneously because the cart in the cookie doesn't supports it.
+ // simultaneously because the cart in the cookie doesn't support it.
Cart.prototype.ajax = function(config){
var me = this;
this.disabled = true;
@@ -31,6 +36,17 @@ function Cart(config) {
$.ajax(config);
}
+ Cart.prototype.load = function(){
+ if (!this.empty) {
+ if (!this.minimized) {
+ $(this.cartElem).show();
+ }
+ this.addToList(this.products, true)
+ } else if (this.minimized) {
+ this.setQuantity(0)
+ }
+ }
+
Cart.prototype.addToList = function(products, clear) {
if( clear ) this.itemsBox.empty();
var me = this;
@@ -38,17 +54,12 @@ function Cart(config) {
for( var item,i=0; item=products[i]; i++ ) {
this.items[item.id] = { price:item.price, quantity:item.quantity };
this.updateTotal();
- var liId = "cart-item-"+item.id;
- var li = $("#"+liId);
- if( !li[0] ) li = $('\n').appendTo(this.itemsBox);
- li.empty();
- $('' +
- ''+ item.name +'' +
- '' +
- ''+ (item.price ? '× '+ item.price : '') +'
' +
- ' remove'
- ).appendTo(li);
+ item.priceTxt = (item.price) ? '×' + item.price : '';
+
+ jQuery('#cart-item-'+item.id).remove()
+ var li = jQuery(this.itemTemplate({item: item}))
+ li.appendTo(this.itemsBox);
+
var input = $("input", li)[0];
input.lastValue = input.value;
input.productId = item.id;
@@ -67,16 +78,24 @@ function Cart(config) {
li.animate({ backgroundColor: liBg }, 1000);
}
- if (!clear && this.empty) $(this.cartElem).show();
- if((!clear && this.empty) || (this.visible && clear)) {
- this.contentBox.hide();
- this.show(!clear);
+ if (!Cart.minimized) {
+ if (!clear && this.empty) $(this.cartElem).show();
+ if((!clear && this.empty) || (this.visible && clear)) {
+ this.contentBox.hide();
+ }
+ } else {
+ if (!clear) {
+ $( ".cart-applet .cart-applet-indicator" ).addClass( 'cart-highlight' );
+ $( ".cart-applet" ).effect('bounce', 300, function(){
+ $( ".cart-applet .cart-applet-indicator" ).removeClass( 'cart-highlight' );
+ });
+ }
}
this.empty = false;
}
Cart.prototype.updateQuantity = function(input, itemId, quantity) {
- if(this.disabled) return alert(shoppingCartPluginL10n.waitLastRequest);
+ if(this.disabled) return alert(Cart.l10n.waitLastRequest);
quantity = parseInt(quantity);
input.disabled = true;
var originalBg = input.style.backgroundImage;
@@ -117,24 +136,16 @@ function Cart(config) {
}
Cart.addItem = function(itemId, link) {
- if(this.instance.disabled) return alert(shoppingCartPluginL10n.waitLastRequest);
+ if(this.instance.disabled) return alert(Cart.l10n.waitLastRequest);
if ( this.productsLength > 100 ) {
// This limit protect the user from losing data on cookie limit.
// This is NOT limiting to 100 products, is limiting to 100 kinds of products.
- alert(shoppingCartPluginL10n.maxNumberOfItens);
+ alert(Cart.l10n.maxNumberOfItens);
return false;
}
- link.intervalId = setInterval(function() {
- $(link).addClass('loading');
- steps = ['w', 'n', 'e', 's'];
- if( !link.step || link.step==3 ) link.step = 0;
- link.step++;
- $(link).button({ icons: { primary: 'ui-icon-arrowrefresh-1-'+steps[link.step]}})
- }, 100);
+ $(link).addClass('small-loading');
var stopBtLoading = function() {
- clearInterval(link.intervalId);
- $(link).removeClass('loading');
- $(link).button({ icons: { primary: 'ui-icon-cart'}});
+ $(link).removeClass('small-loading');
};
this.instance.addItem(itemId, stopBtLoading);
}
@@ -145,7 +156,12 @@ function Cart(config) {
url: '/plugin/shopping_cart/add/'+ itemId,
dataType: 'json',
success: function(data, status, ajax){
- if ( !data.ok ) log.error('Shopping cart data failure', data.error);
+ if ( !data.ok ) {
+ if (typeof data.error.message != "undefined")
+ alert(data.error.message)
+ else
+ log.error('Shopping cart data failure', data.error);
+ }
else me.addToList(data.products);
},
cache: false,
@@ -157,8 +173,8 @@ function Cart(config) {
}
Cart.removeItem = function(itemId) {
- if(this.instance.disabled) return alert(shoppingCartPluginL10n.waitLastRequest);
- if( confirm(shoppingCartPluginL10n.removeItem) ) this.instance.removeItem(itemId);
+ if(this.instance.disabled) return alert(Cart.l10n.waitLastRequest);
+ if( confirm(Cart.l10n.removeItem) ) this.instance.removeItem(itemId);
}
Cart.prototype.removeItem = function(itemId) {
@@ -179,11 +195,51 @@ function Cart(config) {
}
Cart.toggle = function(link) {
- if(this.instance.disabled) return alert(shoppingCartPluginL10n.waitLastRequest);
+ if(this.instance.disabled) return alert(Cart.l10n.waitLastRequest);
link.parentNode.parentNode.cartObj.toggle();
}
Cart.prototype.toggle = function() {
- this.visible ? this.hide(true) : this.show(true);
+ if (this.empty && this.hasPreviousOrders)
+ noosfero.modal.url('/plugin/shopping_cart/repeat?profile_id='+cart.profileId)
+ else
+ this.visible ? this.hide(true) : this.show(true)
+ }
+
+ Cart.prototype.repeat = function(order_id, callback) {
+ this.ajax({
+ url: '/plugin/shopping_cart/repeat/'+order_id+'?profile_id='+cart.profileId,
+ success: function(data) {
+ cart.addToList(data.products, true)
+ callback(data)
+ },
+ // can't do POST because of firefox cookie reset bug
+ type: 'GET', dataType: 'json', cache: false
+ })
+ }
+
+ Cart.prototype.repeatCheckout = function(event, button) {
+ var order_id = jQuery(button).attr('data-order-id')
+ this.repeat(order_id, function(data) {
+ window.location.href = '/plugin/shopping_cart/buy'
+ })
+ event.stopPropagation()
+ return false;
+ }
+
+ Cart.prototype.repeatChoose = function(event, button) {
+ var order_id = jQuery(button).attr('data-order-id')
+ this.repeat(order_id, function(data) {
+ noosfero.modal.close()
+ cart.show(true);
+ })
+ event.stopPropagation()
+ return false;
+ }
+
+ Cart.prototype.clearOrdersSession = function() {
+ noosfero.modal.close()
+ cart.hasPreviousOrders = false;
+ cart.setQuantity(0)
}
Cart.prototype.show = function(register) {
@@ -221,7 +277,7 @@ function Cart(config) {
}
Cart.prototype.updateTotal = function() {
- var total = 0;
+ var total = qtty = 0;
var currency, sep = "";
for( var itemId in this.items ) {
var item = this.items[itemId];
@@ -230,15 +286,27 @@ function Cart(config) {
sep = item.price.charAt(item.price.length-3);
var price = item.price.replace(/[^0-9]/g,"");
total += item.quantity * parseFloat(price);
+ qtty += item.quantity;
}
}
total = Math.round(total).toString().replace(/(..)$/, sep+"$1")
$(".cart-total b", this.cartElem).text( ( (total!=0) ? currency+" "+total : "---" ) );
+ this.setQuantity(qtty)
+ }
+
+ Cart.prototype.setQuantity = function(qtty) {
+ this.cartElem.find('.cart-applet-checkout').toggle(qtty > 0)
+ this.cartElem.find('.cart-applet-checkout-disabled').toggle(qtty === 0)
+
+ if (qtty === 0 && this.hasPreviousOrders)
+ $(".cart-qtty", this.cartElem).text( Cart.l10n.repeatOrder )
+ else
+ $(".cart-qtty", this.cartElem).text( qtty )
}
Cart.clean = function(link) {
- if(this.instance.disabled) return alert(shoppingCartPluginL10n.waitLastRequest);
- if( confirm(shoppingCartPluginL10n.cleanCart) ) link.parentNode.parentNode.parentNode.cartObj.clean();
+ if(this.instance.disabled) return alert(Cart.l10n.waitLastRequest);
+ if( confirm(Cart.l10n.cleanCart) ) link.parentNode.parentNode.parentNode.cartObj.clean();
}
Cart.prototype.clean = function() {
@@ -250,9 +318,9 @@ function Cart(config) {
if ( !data.ok ) log.error(data.error);
else{
me.items = {};
- $(me.cartElem).slideUp(500, function() {
+ $(me.contentBox).slideUp(500, function() {
$(me.itemsBox).empty();
- me.hide();
+ //me.hide();
me.updateTotal();
me.empty = true;
});
@@ -277,21 +345,8 @@ function Cart(config) {
type: 'POST',
url: '/plugin/shopping_cart/send_request',
data: params,
- dataType: 'json',
- success: function(data, status, ajax){
- if ( !data.ok ) display_notice(data.error.message);
- else {
- me.clean();
- display_notice(data.message);
- }
- },
+ dataType: 'script',
cache: false,
- error: function(ajax, status, errorThrown) {
- log.error('Send request - HTTP '+status, errorThrown);
- },
- complete: function() {
- noosfero.modal.close();
- }
});
}
@@ -301,31 +356,4 @@ function Cart(config) {
Cart.unloadingPage = true;
});
- $(function(){
-
- $.ajax({
- url: "/plugin/shopping_cart/get",
- dataType: 'json',
- success: function(data) {
- new Cart(data);
- $('.cart-add-item').button({ icons: { primary: 'ui-icon-cart'} })
- },
- cache: false,
- error: function(ajax, status, errorThrown) {
- // Give some time to register page unload.
- setTimeout(function() {
- // page unload is not our problem.
- if (Cart.unloadingPage) {
- log('Page unload before cart load.');
- } else {
- log.error('Error getting shopping cart - HTTP '+status, errorThrown);
- if ( confirm(shoppingCartPluginL10n.getProblemConfirmReload) ) {
- document.location.reload();
- }
- }
- }, 100);
- }
- });
- });
-
})(jQuery);
diff --git a/plugins/shopping_cart/public/edit.js b/plugins/shopping_cart/public/edit.js
index 2d051ad..373d74c 100644
--- a/plugins/shopping_cart/public/edit.js
+++ b/plugins/shopping_cart/public/edit.js
@@ -1,16 +1,18 @@
-jQuery('#settings_delivery').click(function(){
- jQuery('#delivery_settings').toggle('fast');
+$('#settings_enabled').click(function(){
+ $('#delivery-settings').toggle('fast');
});
+$('#delivery-settings').toggle($('#settings_enabled').prop('checked'))
-jQuery('#add-new-option').click(function(){
- new_option = jQuery('#empty-option').clone();
+$('#add-new-option').click(function(){
+ new_option = $('#empty-option').clone();
new_option.removeAttr('id');
- jQuery('#add-new-option-row').before(new_option);
+ $('#add-new-option-row').before(new_option);
new_option.show();
return false;
});
-jQuery('.remove-option').live('click', function(){
- jQuery(this).closest('tr').remove();
+$('.remove-option').live('click', function(){
+ $(this).closest('tr').remove();
return false;
});
+
diff --git a/plugins/shopping_cart/public/images/control-panel/purchase-report.gif b/plugins/shopping_cart/public/images/control-panel/purchase-report.gif
deleted file mode 100644
index cc2ea7d..0000000
Binary files a/plugins/shopping_cart/public/images/control-panel/purchase-report.gif and /dev/null differ
diff --git a/plugins/shopping_cart/public/images/control-panel/purchase-report.png b/plugins/shopping_cart/public/images/control-panel/purchase-report.png
deleted file mode 100644
index f8d4148..0000000
Binary files a/plugins/shopping_cart/public/images/control-panel/purchase-report.png and /dev/null differ
diff --git a/plugins/shopping_cart/public/images/control-panel/purchase-report.svg b/plugins/shopping_cart/public/images/control-panel/purchase-report.svg
deleted file mode 100644
index f7197b1..0000000
--- a/plugins/shopping_cart/public/images/control-panel/purchase-report.svg
+++ /dev/null
@@ -1,742 +0,0 @@
-
-
-
-
diff --git a/plugins/shopping_cart/public/style.css b/plugins/shopping_cart/public/style.css
deleted file mode 100644
index dc5fb9e..0000000
--- a/plugins/shopping_cart/public/style.css
+++ /dev/null
@@ -1,226 +0,0 @@
-.cart-add-item .ui-icon-cart {
- background: url("/plugins/shopping_cart/images/button-icon.png") no-repeat scroll left center transparent;
- width: 22px;
-}
-.cart-buy .ui-icon-cart {
- background: url("/plugins/shopping_cart/images/button-icon.png") no-repeat scroll left center transparent;
- width: 22px;
-}
-.cart-add-item .ui-button-text {
- padding-left: 2.6em;
-}
-
-.product-item .cart-add-item {
- top: 0px;
-}
-
-.cart {
- position: fixed;
- right: 20px;
- top: 0px;
- width: 200px;
- z-index: 1000;
- border: 1px solid #777;
- background: rgba(100,100,100,0.8);
-}
-
-.cart h3 {
- color: #000;
- margin: 0px 0px 0px 5px;
-}
-
-.cart-clean {
- color: #AAA;
- position: absolute;
- top: 1px;
- right: 5px;
- text-decoration: none;
-}
-.cart-clean:hover {
- color: #888;
-}
-
-.cart-content {
- display: none;
-}
-
-.cart-items {
- margin: 0px;
- padding: 0px;
- max-height: 328px;
- overflow: auto;
-}
-
-.cart-items li {
- height: 50px;
- padding: 5px;
- margin: 3px;
- border: 1px solid #999;
- list-style: none;
- background: #FFF;
- position: relative;
-}
-
-.cart-items .picture {
- float: left;
- width: 50px;
- height: 50px;
- margin-right: 10px;
- background-repeat: no-repeat;
- background-position: 50% 50%;
-}
-
-.cart .item-name {
- margin-right: 20px;
-}
-
-.cart .button {
- position: absolute;
- top: 2px;
- right: 2px;
-}
-
-.cart input {
- border: 1px solid transparent;
- background: transparent 50% 50% no-repeat;
- text-align: center;
- padding: 0px;
- font-family: monospace;
- width: 2em;
-}
-.cart:hover input, .cart input:focus {
- border: 1px solid #CCC;
-}
-
-.cart-buy {
- display: block;
- margin: 2px 4px;
-}
-
-.cart-total {
- position: absolute;
- left: 5px;
- bottom: 0px;
-}
-
-.cart-toggle {
- display: block;
- color: #AAA;
- text-decoration: none;
- float: right;
- padding: 0px 5px;
-}
-.cart-toggle:hover {
- color: #fff;
-}
-
-#cart-request-box {
- width: 690px;
-}
-
-#cart-request-form {
- width: 274px;
- float: left;
-}
-
-#cart-request-box .cart-box-close {
- position: absolute;
- right: 10px;
- bottom: 10px;
- width: 16px;
- height: 16px;
- background-repeat: no-repeat;
-}
-
-#cart-form-main {
- border: 2px solid #FFF;
- padding: 0px 10px;
-}
-
-#cart-request-form fieldset {
- clear: left;
- color: #999;
- border: 1px solid #BBB;
- margin-top: 5px;
-}
-
-#cart-request-form input,
-#cart-request-form select {
- width: 250px;
-}
-
-#cart-form-actions {
- clear: both;
- padding-top: 15px;
- text-align: center;
-}
-
-#cart-form-actions .submit {
- cursor: pointer;
-}
-
-#cart-items-table {
- margin-left: 285px;
- width: 400px
-}
-
-.cart-table-quantity {
- text-align: center;
-}
-
-.cart-table-price,
-.cart-table-total-label,
-.cart-table-total-value {
- text-align: right;
-}
-
-label.error {
- float: none;
- color: red;
- padding-left: .5em;
- vertical-align: top;
-}
-
-.controller-profile_editor a.control-panel-shopping-cart-purchase-report {background-image: url("/plugins/shopping_cart/images/control-panel/purchase-report.png")}
-.controller-profile_editor .msie6 a.control-panel-shopping-cart-purchase-report {background-image: url("/plugins/shopping_cart/images/control-panel/purchase-report.gif")}
-.controller-profile_editor a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.png")}
-.controller-profile_editor .msie6 a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.gif")}
-
-.action-shopping_cart_plugin_myprofile-reports td.order-info {
- padding: 0px;
- height: auto;
-}
-
-.action-shopping_cart_plugin_myprofile-reports .customer-details,
-.action-shopping_cart_plugin_myprofile-reports .order-products {
- list-style-position: inside;
- float: left;
- width: 49%;
- margin: 0px;
- padding: 10px 0px;
-}
-
-.action-shopping_cart_plugin_myprofile-reports .order-products {
- float: right;
-}
-
-.action-shopping_cart_plugin_myprofile-reports .customer-details li,
-.action-shopping_cart_plugin_myprofile-reports .order-products li {
- padding-left: 5px;
-}
-
-#cart-order-filter {
- background-color: #ccc;
- border: 1px solid #aaa;
- border-radius: 5px;
- padding: 3px 8px;
- margin-bottom: 10px;
-}
-
-th {
- text-align: center;
-}
-
-td {
- text-align: left;
-}
diff --git a/plugins/shopping_cart/public/style.scss b/plugins/shopping_cart/public/style.scss
new file mode 100644
index 0000000..9229f0f
--- /dev/null
+++ b/plugins/shopping_cart/public/style.scss
@@ -0,0 +1,289 @@
+.cart-add-item .ui-icon-cart,
+.cart-buy .ui-icon-cart,
+.icon-cart, .btn.icon-cart {
+ background-image: url("/plugins/shopping_cart/images/button-icon.png");
+ background-repeat: no-repeat;
+ background-position: 5px center;
+}
+.cart-add-item.small-loading {
+ background-image: url(/images/loading-small.gif);
+}
+
+a.button.with-text.icon-cart,
+a.button.with-text.icon-cart:visited,
+body.noosfero a.button.with-text.icon-cart,
+body.noosfero a.button.with-text.icon-cart:visited,
+input.button.with-text.icon-cart,
+.icon-cart, .btn.icon-cart {
+ padding-left: 30px;
+}
+.catalog-autocomplete .cart-add-item {
+ display: block;
+ float: right;
+}
+.cart-add-item .ui-button-text {
+ padding-left: 2.6em;
+}
+.product-item .cart-add-item {
+ top: 0px;
+}
+
+
+.action-shopping_cart_plugin-buy .cart {
+ display: none !important;
+}
+.cart {
+ display: none;
+ position: fixed;
+ right: 20px;
+ top: 0px;
+ z-index: 100;
+}
+.cart-minimized {
+ float: right;
+ position: relative;
+}
+#catalog-options ul .catalog-cart {
+ float: right;
+ margin: 0;
+}
+#cart1 .cart-inner {
+ width: 200px;
+ z-index: 1000;
+ border: 1px solid #777;
+ border-radius: 10px;
+ box-shadow: #000 2px 2px 8px;
+ background: rgba(130,130,130,0.9);
+}
+.cart .cart-inner {
+ position: relative;
+ top: 2px;
+ padding-bottom: 20px;
+}
+.cart .cart-inner .cart-content {
+ display: none;
+}
+.cart-minimized .cart-inner {
+ display: none;
+ position: absolute;
+ top: 24px;
+ left: -150px;
+}
+.cart-minimized .cart-applet {
+ float: right;
+ text-align: center;
+}
+#content .cart-minimized .cart-applet .cart-highlight {
+ background-color: yellow;
+}
+.cart-minimized .cart-applet-checkout, .cart-minimized .cart-applet-checkout-disabled {
+ display: block;
+ font-size: 80%;
+ margin-top: 3px;
+}
+.cart-minimized .cart-applet-checkout-disabled {
+ pointer-events: none;
+ cursor: default;
+ color: #CCC;
+ text-decoration: none;
+}
+.cart-qtty {
+ font-weight: bold;
+}
+#cart1 h3 {
+ color: #036276;
+ margin: 0px 0px 0px 5px;
+ font-weight: lighter;
+}
+#cart-profile-name {
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ margin: 0px 5px;
+ color: #000;
+}
+.cart-clean {
+ color: #AAA;
+ position: absolute;
+ top: 1px;
+ right: 5px;
+ text-decoration: none;
+}
+.cart-clean:hover {
+ color: #888;
+}
+.cart-items {
+ margin: 0px;
+ padding: 0px;
+ max-height: 328px;
+ overflow-y: auto;
+ overflow-x: hidden;
+}
+#catalog-options .cart-items {
+ padding: 0;
+ margin: 0;
+}
+#catalog-options .cart-items li {
+ margin-right: 0;
+}
+.cart-items li {
+ padding: 0;
+ border: 2px solid #999;
+ width: 98%;
+ list-style: none;
+ background: #FFF;
+ position: relative;
+ border-radius: 5px;
+ font-size: 85%;
+ min-height: 50px;
+}
+.cart-items .picture {
+ float: left;
+ width: 50px;
+ height: 50px;
+ margin-right: 10px;
+ background-repeat: no-repeat;
+ background-position: 50% 50%;
+}
+#cart1 .item-name {
+ margin-right: 0;
+}
+.cart-items .cart-remove-item {
+ float: right;
+}
+
+#cart1 input {
+ border: 1px solid transparent;
+ background: transparent 50% 50% no-repeat;
+ text-align: center;
+ padding: 0px;
+ font-family: monospace;
+ width: 2em;
+}
+#cart1:hover input, #cart1 input:focus {
+ border: 1px solid #CCC;
+}
+.cart-buy {
+ display: block;
+ margin: 2px 4px;
+}
+.cart-total {
+ float: left;
+}
+.cart-toggle, .cart-toggle:visited {
+ display: block;
+ color: #036276;
+ text-decoration: none;
+ float: right;
+ padding: 0px 5px;
+}
+.cart-toggle:hover {
+ color: #fff;
+}
+.str-hide {
+ display: none;
+}
+
+#cart-request-box {
+ overflow: hidden;
+}
+#cart-request-box a {
+ font-size: smaller;
+}
+#cart-request-form {
+}
+#cart-request-box .cart-box-close {
+ position: absolute;
+ right: 10px;
+ bottom: 10px;
+ width: 16px;
+ height: 16px;
+ background-repeat: no-repeat;
+}
+#cart-request-box .cart-go-back {
+ float: right;
+ text-transform: none;
+ font-variant: normal;
+}
+
+#cart-request-form fieldset {
+ clear: left;
+ color: #999;
+ margin-top: 5px;
+}
+
+#cart-request-form input,
+#cart-request-form select {
+}
+
+#cart-form-actions {
+ clear: both;
+ padding-top: 15px;
+ text-align: center;
+}
+
+#cart-form-actions .submit {
+ cursor: pointer;
+}
+
+#cart-items-table {
+}
+
+.cart-table-quantity {
+ text-align: center;
+}
+
+.cart-table-price,
+.cart-table-total-label,
+.cart-table-total-value {
+ text-align: right;
+}
+label.error {
+ float: none;
+ color: red;
+ padding-left: .5em;
+ vertical-align: top;
+}
+
+.controller-profile_editor a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.png")}
+.controller-profile_editor .msie6 a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.gif")}
+
+.action-shopping_cart_plugin_myprofile-reports td.order-info {
+ padding: 0px;
+ height: auto;
+}
+.action-shopping_cart_plugin_myprofile-reports .customer-details,
+.action-shopping_cart_plugin_myprofile-reports .order-products {
+ list-style-position: inside;
+ float: left;
+ width: 49%;
+ margin: 0px;
+ padding: 10px 0px;
+}
+.action-shopping_cart_plugin_myprofile-reports .order-products {
+ float: right;
+}
+.action-shopping_cart_plugin_myprofile-reports .customer-details li,
+.action-shopping_cart_plugin_myprofile-reports .order-products li {
+ padding-left: 5px;
+}
+#cart-order-filter {
+ background-color: #ccc;
+ border: 1px solid #aaa;
+ border-radius: 5px;
+ padding: 3px 8px;
+ margin-bottom: 10px;
+}
+th {
+ text-align: center;
+}
+td {
+ text-align: left;
+}
+/* Repeat orders */
+a.button.repeat-checkout-order, a.button.repeat-choose-order {
+ display: block;
+ margin: 0 5px 5px 40px;
+ font-size: 80%;
+ background-color: #ffc64c;
+}
diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
index 0d465cd..ef56320 100644
--- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
+++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -154,29 +154,29 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase
product1 = fast_create(Product, :profile_id => profile.id, :price => 1.99)
product2 = fast_create(Product, :profile_id => profile.id, :price => 2.23)
@controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1, product2.id => 2}})
- assert_difference 'ShoppingCartPlugin::PurchaseOrder.count', 1 do
+ assert_difference 'OrdersPlugin::Order.count', 1 do
post :send_request,
:customer => {:name => "Manuel", :email => "manuel@ceu.com"}
end
- order = ShoppingCartPlugin::PurchaseOrder.last
+ order = OrdersPlugin::Order.last
assert_equal 1.99, order.products_list[product1.id][:price]
assert_equal 1, order.products_list[product1.id][:quantity]
assert_equal 2.23, order.products_list[product2.id][:price]
assert_equal 2, order.products_list[product2.id][:quantity]
- assert_equal ShoppingCartPlugin::PurchaseOrder::Status::OPENED, order.status
+ assert_equal 'confirmed', order.status
end
should 'register order on send request and not crash if product is not defined' do
product1 = fast_create(Product, :profile_id => profile.id)
@controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1}})
- assert_difference 'ShoppingCartPlugin::PurchaseOrder.count', 1 do
+ assert_difference 'OrdersPlugin::Order.count', 1 do
post :send_request,
:customer => {:name => "Manuel", :email => "manuel@ceu.com"}
end
- order = ShoppingCartPlugin::PurchaseOrder.last
+ order = OrdersPlugin::Order.last
assert_equal 0, order.products_list[product1.id][:price]
end
diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
index 27661d5..0d5a6e3 100644
--- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
+++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
@@ -51,6 +51,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase
assert settings.delivery_price == price.to_s
end
+ # FIXME
should 'be able to choose delivery_options' do
delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']}
post :edit, :profile => profile.identifier, :settings => {:delivery_options => delivery_options}
@@ -61,18 +62,18 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase
should 'filter the reports correctly' do
another_profile = fast_create(Enterprise)
- po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
- po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED)
- po3 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
+ po1 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed'
+ po2 = OrdersPlugin::Sale.create! :profile => profile, :status => 'shipped'
+ po3 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed'
po3.created_at = 1.year.ago
po3.save!
- po4 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => another_profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
+ po4 = OrdersPlugin::Sale.create! :profile => another_profile, :status => 'confirmed'
post :reports,
:profile => profile.identifier,
:from => (Time.now - 1.day).strftime(TIME_FORMAT),
:to => (Time.now + 1.day).strftime(TIME_FORMAT),
- :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED
+ :filter_status => 'confirmed'
assert_includes assigns(:orders), po1
assert_not_includes assigns(:orders), po2
@@ -86,14 +87,14 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase
p3 = fast_create(Product, :profile_id => profile.id, :price => 3)
po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }}
po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}}
- po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
- po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
+ po1 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po1_products, :status => 'confirmed'
+ po2 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po2_products, :status => 'confirmed'
post :reports,
:profile => profile.identifier,
:from => (Time.now - 1.day).strftime(TIME_FORMAT),
:to => (Time.now + 1.day).strftime(TIME_FORMAT),
- :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED
+ :filter_status => 'confirmed'
lineitem1 = ShoppingCartPlugin::LineItem.new(p1.id, p1.name)
lineitem1.quantity = 1
@@ -107,20 +108,20 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase
end
should 'be able to update the order status' do
- po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
+ po = OrdersPlugin::Sale.create!(:profile => profile, :status => 'confirmed')
post :update_order_status,
:profile => profile.identifier,
:order_id => po.id,
- :order_status => ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED
+ :order_status => 'confirmed'
po.reload
- assert_equal ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED, po.status
+ assert_equal 'confirmed', po.status
end
private
def settings
@profile.reload
- Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin)
+ profile.shopping_cart_settings
end
end
diff --git a/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb b/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
index a2d8312..f9d8890 100644
--- a/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
+++ b/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
@@ -28,7 +28,7 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase
should 'be disabled by default on the enterprise' do
profile = fast_create(Enterprise)
- settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin)
+ settings = profile.shopping_cart_settings
assert !settings.enabled
end
end
diff --git a/plugins/shopping_cart/views/cart.html.erb b/plugins/shopping_cart/views/cart.html.erb
deleted file mode 100644
index dac4baf..0000000
--- a/plugins/shopping_cart/views/cart.html.erb
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
diff --git a/plugins/shopping_cart/views/public/_cart.html.erb b/plugins/shopping_cart/views/public/_cart.html.erb
new file mode 100644
index 0000000..11728c8
--- /dev/null
+++ b/plugins/shopping_cart/views/public/_cart.html.erb
@@ -0,0 +1,82 @@
+
+ <% if cart_minimized %>
+
+ <%= cart_applet %>
+
+ <%= link_to _('Shopping checkout'), "/plugin/shopping_cart/buy", class: 'cart-applet-checkout' %>
+
+ <%= _('Basket is empty') %>
+
+
+ <% end %>
+
+
+
+
+
+
diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/_items.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/_items.html.erb
new file mode 100644
index 0000000..ebc5cec
--- /dev/null
+++ b/plugins/shopping_cart/views/shopping_cart_plugin/_items.html.erb
@@ -0,0 +1,47 @@
+
+
+
+
+ <%= _('Item name') %>
+ |
+
+ <%= if by_mail then ' # ' else '#' end %>
+ |
+
+ <%= _('Price') + " (#{@environment.currency_unit})" %>
+ |
+
+
+ <% order.items.each do |item| %>
+
+
+ <%= item.name %>
+ |
+
+ <%= item.quantity_consumer_ordered %>
+ |
+
+ <%= get_price item.product, @environment, item.quantity_consumer_ordered, unit: '' %>
+ |
+
+
+ <% end %>
+
+
+
+ <%= order.supplier_delivery.name if order.supplier_delivery %>
+ |
+
+ <%= float_to_currency_cart order.supplier_delivery.cost(order.total_price), @environment, unit: '' if order.supplier_delivery %>
+ |
+
+
+
+ <%= _('Total:') %>
+ |
+
+ <%= float_to_currency_cart order.total, @environment %>
+ |
+
diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
index 25ff05c..6383e5c 100644
--- a/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
+++ b/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
@@ -1,30 +1,53 @@
-
- <%= form_for(:customer, :url => {:action => 'send_request'},
- :html => {:onsubmit => "return Cart.send_request(this)", :id => 'cart-request-form'}) do |f| %>
-
- <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %>
- <%= labelled_form_field('* ' + c_("Email"), f.text_field(:email, :class => 'required email') ) %>
- <%= labelled_form_field('* ' + c_("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %>
- <%= labelled_form_field(_('Delivery option'), select_tag(:delivery_option, options_for_select(select_delivery_options(@settings.delivery_options, environment)), 'data-profile-identifier' => @profile.identifier)) unless !@settings.delivery || (@settings.free_delivery_price && get_total(@cart[:items]) >= @settings.free_delivery_price) %>
- <%= labelled_form_field(_('Payment'), select_tag('customer[payment]', options_for_select([[_("Money"), :money],[_('shopping_cart|Check'), :check]]))) %>
- <%= labelled_form_field(s_('shopping_cart|Change'), text_field_tag('customer[change]')) %>
+
+
+ <%= _('Shopping checkout') %>
+ <%= button :back, _("haven't finished yet: back to shopping"), 'javascript:history.back()', class: 'cart-go-back' %>
+
+
+ <%= form_for :order, url: {action: :send_request},
+ html: {onsubmit: "return Cart.send_request(this)", id: 'cart-request-form'} do |f| %>
+
+
+
+
+
+
+ <% if profile.delivery_methods.size > 0 %>
+
+ <% end %>
- <% if @settings.delivery %>
-