页面刷新后,狂欢购物车是空的

时间:2016-03-13 06:24:06

标签: ruby-on-rails spree

我可以添加到购物车一次,但刷新页面后,购物车为空。我正在使用Spree 2.4。

点击“添加到购物车”后,我在订单控制器编辑中检查@order的值:

[1] pry(#<Spree::OrdersController>)> @order
=> #<Spree::Order id: 5, number: "R017142307", item_total: #<BigDecimal:89a8e10,'0.5E1',9(27)>, total: #<BigDecimal:89a8d20,'0.5E1',9(27)>, state: "cart", adjustment_total: #<BigDecimal:89a8bb8,'0.0',9(27)>, user_id: 1, completed_at: nil, bill_address_id: nil, ship_address_id: nil, payment_total: #<BigDecimal:89a8898,'0.0',9(27)>, shipping_method_id: nil, shipment_state: nil, payment_state: nil, email: "spree@example.com", special_instructions: nil, created_at: "2016-03-13 05:41:55", updated_at: "2016-03-13 06:18:01", currency: "USD", last_ip_address: "192.168.1.108", created_by_id: 1, shipment_total: #<BigDecimal:897bc80,'0.0',9(27)>, additional_tax_total: #<BigDecimal:897bb90,'0.0',9(27)>, promo_total: #<BigDecimal:897baa0,'0.0',9(27)>, channel: "spree", included_tax_total: #<BigDecimal:897b938,'0.0',9(27)>, item_count: 1, approver_id: nil, approved_at: nil, confirmation_delivered: false, considered_risky: false, guest_token: "kRau34G-dOY0Sh06Mk0_4g", canceled_at: nil, canceler_id: nil, store_id: 1, state_lock_version: 0>

还有line_items:

[3] pry(#<Spree::OrdersController>)> @order.line_items
=> [#<Spree::LineItem id: 21, variant_id: 7, order_id: 5, quantity: 1, price: #<BigDecimal:88e8480,'0.5E1',9(27)>, created_at: "2016-03-13 06:18:01", updated_at: "2016-03-13 06:18:01", currency: "USD", cost_price: #<BigDecimal:88e78a0,'0.17E2',9(27)>, tax_category_id: 1, adjustment_total: #<BigDecimal:88e7738,'0.0',9(27)>, additional_tax_total: #<BigDecimal:88e7648,'0.0',9(27)>, promo_total: #<BigDecimal:88e7558,'0.0',9(27)>, included_tax_total: #<BigDecimal:88e7468,'0.0',9(27)>, pre_tax_amount: #<BigDecimal:88e7378,'0.0',9(27)>>]

视图加载,购物车看起来很正常。但是,刷新后,它说购物车是空的..

@order仍然相同,但line_items已经消失:

[1] pry(#<Spree::OrdersController>)> @order
=> #<Spree::Order id: 5, number: "R017142307", item_total: #<BigDecimal:d3bfeb8,'0.5E1',9(27)>, total: #<BigDecimal:d3bfdc8,'0.5E1',9(27)>, state: "cart", adjustment_total: #<BigDecimal:d3bfc60,'0.0',9(27)>, user_id: 1, completed_at: nil, bill_address_id: nil, ship_address_id: nil, payment_total: #<BigDecimal:d3bf968,'0.0',9(27)>, shipping_method_id: nil, shipment_state: nil, payment_state: nil, email: "spree@example.com", special_instructions: nil, created_at: "2016-03-13 05:41:55", updated_at: "2016-03-13 06:18:01", currency: "USD", last_ip_address: "192.168.1.108", created_by_id: 1, shipment_total: #<BigDecimal:d3beb80,'0.0',9(27)>, additional_tax_total: #<BigDecimal:d3bea90,'0.0',9(27)>, promo_total: #<BigDecimal:d3be9a0,'0.0',9(27)>, channel: "spree", included_tax_total: #<BigDecimal:d3be838,'0.0',9(27)>, item_count: 1, approver_id: nil, approved_at: nil, confirmation_delivered: false, considered_risky: false, guest_token: "kRau34G-dOY0Sh06Mk0_4g", canceled_at: nil, canceler_id: nil, store_id: 1, state_lock_version: 0>

[2] pry(#<Spree::OrdersController>)> @order.line_items
=> []

我无法追踪line_items的填充位置。有人可以帮忙吗?感谢。

编辑:

我在POST后的日志中看到一个DELETE到/ orders / populate /在GET“/ cart”中:

Started GET "/cart" for 192.168.1.108 at 2016-03-13 19:01:17 -0400
Cannot render console from 192.168.1.108! Allowed networks: 192.168.2.0/192.168.2.255, 127.0.0.0/127.255.255.255, ::1
Processing by Spree::OrdersController#edit as HTML
  Spree::Preference Load (0.4ms)  SELECT  "spree_preferences".* FROM "spree_preferences"  WHERE "spree_preferences"."key" = 'spree/frontend_configuration/locale' LIMIT 1
  Spree::User Load (0.7ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = 1  ORDER BY "spree_users"."id" ASC LIMIT 1
  Spree::Store Load (0.5ms)  SELECT  "spree_stores".* FROM "spree_stores"  WHERE (url like '%192.168.1.108%')  ORDER BY "spree_stores"."id" ASC LIMIT 1
  Spree::Store Load (0.5ms)  SELECT  "spree_stores".* FROM "spree_stores"  WHERE "spree_stores"."default" = 't'  ORDER BY "spree_stores"."id" ASC LIMIT 1
  Spree::Order Load (1.5ms)  SELECT  "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."completed_at" IS NULL AND "spree_orders"."currency" = 'USD' AND "spree_orders"."guest_token" = 'kRau34G-dOY0Sh06Mk0_4g' AND "spree_orders"."store_id" = 1 AND "spree_orders"."user_id" = 1 LIMIT 1
  Spree::Adjustment Load (1.4ms)  SELECT "spree_adjustments".* FROM "spree_adjustments"  WHERE "spree_adjustments"."adjustable_type" = 'Spree::Order' AND "spree_adjustments"."adjustable_id" IN (5)  ORDER BY spree_adjustments.created_at ASC
  Spree::Order Load (0.2ms)  SELECT "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."user_id" = ? AND "spree_orders"."completed_at" IS NULL AND (id != 5)  [["user_id", 1]]
  Spree::Order Load (0.6ms)  SELECT  "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."number" IS NULL LIMIT 1
   (0.2ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = ? AND "spree_roles"."name" = 'admin'  [["user_id", 1]]
  Spree::LineItem Load (0.2ms)  SELECT "spree_line_items".* FROM "spree_line_items"  WHERE "spree_line_items"."order_id" = ?  ORDER BY spree_line_items.created_at ASC  [["order_id", 5]]
  Spree::Variant Load (0.5ms)  SELECT  "spree_variants".* FROM "spree_variants"  WHERE "spree_variants"."id" = ? LIMIT 1  [["id", 30]]
  Spree::Product Load (0.3ms)  SELECT  "spree_products".* FROM "spree_products"  WHERE "spree_products"."id" = ? LIMIT 1  [["id", 7]]
  Spree::SaleEvent Load (0.2ms)  SELECT "spree_sale_events".* FROM "spree_sale_events"  WHERE ((start_date <= '2016-03-13 23:01:17.395935' AND end_date >= '2016-03-13 23:01:17.396008') OR is_permanent = 't') AND "spree_sale_events"."is_active" = 't'
   (0.1ms)  begin transaction
  Spree::Adjustment Load (0.4ms)  SELECT "spree_adjustments".* FROM "spree_adjustments"  WHERE "spree_adjustments"."adjustable_id" = ? AND "spree_adjustments"."adjustable_type" = ?  [["adjustable_id", 36], ["adjustable_type", "Spree::LineItem"]]
  Spree::InventoryUnit Load (0.2ms)  SELECT "spree_inventory_units".* FROM "spree_inventory_units"  WHERE "spree_inventory_units"."line_item_id" = ?  [["line_item_id", 36]]
  SQL (1.2ms)  DELETE FROM "spree_line_items" WHERE "spree_line_items"."id" = ?  [["id", 36]]
  SQL (0.8ms)  UPDATE "spree_orders" SET "updated_at" = '2016-03-13 23:01:17.410798' WHERE "spree_orders"."id" = 5
   (12.6ms)  commit transaction
   (0.2ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = ? AND "spree_roles"."name" = 'admin'  [["user_id", 1]]
  Spree::User Load (1.0ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = ? LIMIT 1  [["id", 1]]
Deface: 1 overrides found for 'spree/orders/edit'
Deface: 'move_cart_buttons' matched 0 times with '[data-hook='form-table-foot']'
  Rendered /usr/local/rvm/gems/ruby-2.2.1@mystore20151008/bundler/gems/spree_bootstrap_frontend-d20c03352917/spree_bootstrap/frontend/app/views/spree/shared/_error_messages.html.erb (1.1ms)
  Spree::Image Load (0.7ms)  SELECT "spree_assets".* FROM "spree_assets"  WHERE "spree_assets"."type" IN ('Spree::Image') AND "spree_assets"."viewable_id" = ? AND "spree_assets"."viewable_type" = ?  ORDER BY "spree_assets"."position" ASC  [["viewable_id", 30], ["viewable_type", "Spree::Variant"]]
  Spree::Variant Load (0.9ms)  SELECT  "spree_variants".* FROM "spree_variants"  WHERE "spree_variants"."deleted_at" IS NULL AND "spree_variants"."product_id" = ? AND "spree_variants"."is_master" = 't' LIMIT 1  [["product_id", 7]]
  Spree::Image Exists (0.5ms)  SELECT  1 AS one FROM "spree_assets"  WHERE "spree_assets"."type" IN ('Spree::Image') AND "spree_assets"."viewable_id" = ? AND "spree_assets"."viewable_type" = ? LIMIT 1  [["viewable_id", 7], ["viewable_type", "Spree::Variant"]]
  Spree::Image Load (0.4ms)  SELECT  "spree_assets".* FROM "spree_assets"  WHERE "spree_assets"."type" IN ('Spree::Image') AND "spree_assets"."viewable_id" = ? AND "spree_assets"."viewable_type" = ?  ORDER BY "spree_assets"."position" ASC LIMIT 1  [["viewable_id", 7], ["viewable_type", "Spree::Variant"]]
  Spree::OptionValue Load (1.2ms)  SELECT "spree_option_values".* FROM "spree_option_values" INNER JOIN "spree_option_values_variants" ON "spree_option_values"."id" = "spree_option_values_variants"."option_value_id" WHERE "spree_option_values_variants"."variant_id" = ?  [["variant_id", 30]]
  Spree::OptionType Load (0.3ms)  SELECT  "spree_option_types".* FROM "spree_option_types"  WHERE "spree_option_types"."id" = ?  ORDER BY spree_option_types.position LIMIT 1  [["id", 1]]
  Spree::OptionType Load (0.2ms)  SELECT  "spree_option_types".* FROM "spree_option_types"  WHERE "spree_option_types"."id" = ?  ORDER BY spree_option_types.position LIMIT 1  [["id", 2]]
   (0.3ms)  SELECT SUM("spree_stock_items"."count_on_hand") AS sum_id FROM "spree_stock_items" INNER JOIN "spree_stock_locations" ON "spree_stock_locations"."id" = "spree_stock_items"."stock_location_id" WHERE "spree_stock_items"."deleted_at" IS NULL AND "spree_stock_items"."variant_id" = 30 AND "spree_stock_locations"."active" = 't'
  Rendered spree/orders/_line_item.html.erb (305.0ms)
  Rendered spree/orders/_form.html.erb (335.1ms)
  Spree::PaymentMethod Load (1.2ms)  SELECT "spree_payment_methods".* FROM "spree_payment_methods"  WHERE "spree_payment_methods"."deleted_at" IS NULL
  CACHE (0.0ms)  SELECT "spree_payment_methods".* FROM "spree_payment_methods"  WHERE "spree_payment_methods"."deleted_at" IS NULL
  Rendered spree/orders/edit.html.erb within spree/layouts/spree_application (463.7ms)
  Rendered spree/shared/_head.html.erb (8017.9ms)
Deface: 1 overrides found for 'spree/shared/_header'
Deface: 'move_link_to_cart_mobile' matched 1 times with 'div.navbar-brand-mobile'
Deface: [WARNING] No :original defined for 'move_link_to_cart_mobile', you should change its definition to include:
 :original => '1fe9fe305a7e977a4311678e40b0de8ac4fe953b' 
Deface: 4 overrides found for 'spree/shared/_nav_bar'
Deface: 'auth_shared_login_bar' matched 1 times with 'li#search-bar'
Deface: [ERROR] The original source for 'auth_shared_login_bar' has changed, this override should be reviewed to ensure it's still valid.
Deface: 'remove_search_bar' matched 1 times with 'li#search-bar'
Deface: [WARNING] No :original defined for 'remove_search_bar', you should change its definition to include:
 :original => 'c00d67dfc0496d21a351b48c41a728412cb5ed2c' 
Deface: 'move_link_to_cart' matched 1 times with 'ul#nav-bar'
Deface: [WARNING] No :original defined for 'move_link_to_cart', you should change its definition to include:
 :original => 'd32d3ed0d028db429111568a65baba0eeac8f4e0' 
Deface: 'add_country_flag_after_cart_link' matched 1 times with 'li#link-to-cart'
Deface: [WARNING] No :original defined for 'add_country_flag_after_cart_link', you should change its definition to include:
 :original => 'e9241f273349c0f080cef375ce5d2c26546eb870' 
  Rendered spree/shared/_nav_bar.html.erb (4.2ms)
  Rendered spree/shared/_header.html.erb (110.2ms)
  Rendered spree/shared/_footer_cart.html.erb (1712.9ms)
  Spree::Tracker Load (0.2ms)  SELECT  "spree_trackers".* FROM "spree_trackers"  WHERE "spree_trackers"."active" = 't' AND "spree_trackers"."environment" = 'development'  ORDER BY "spree_trackers"."id" ASC LIMIT 1
  Rendered /usr/local/rvm/gems/ruby-2.2.1@mystore20151008/bundler/gems/spree-dfd548b02fb3/frontend/app/views/spree/shared/_google_analytics.html.erb (11.8ms)
Completed 200 OK in 10696ms (Views: 10571.2ms | ActiveRecord: 35.1ms)


Started GET "/assets/spree/frontend/all.css" for 192.168.1.108 at 2016-03-13 19:01:28 -0400
Cannot render console from 192.168.1.108! Allowed networks: 192.168.2.0/192.168.2.255, 127.0.0.0/127.255.255.255, ::1


Started GET "/assets/spree/frontend/all.js" for 192.168.1.108 at 2016-03-13 19:01:28 -0400
Cannot render console from 192.168.1.108! Allowed networks: 192.168.2.0/192.168.2.255, 127.0.0.0/127.255.255.255, ::1


Started GET "/cart_link" for 192.168.1.108 at 2016-03-13 19:01:28 -0400
Cannot render console from 192.168.1.108! Allowed networks: 192.168.2.0/192.168.2.255, 127.0.0.0/127.255.255.255, ::1
Processing by Spree::StoreController#cart_link as */*
  Spree::Preference Load (0.5ms)  SELECT  "spree_preferences".* FROM "spree_preferences"  WHERE "spree_preferences"."key" = 'spree/frontend_configuration/locale' LIMIT 1
  Spree::User Load (2.1ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = 1  ORDER BY "spree_users"."id" ASC LIMIT 1
   (0.0ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = ? AND "spree_roles"."name" = 'admin'  [["user_id", 1]]
  Spree::Store Load (0.4ms)  SELECT  "spree_stores".* FROM "spree_stores"  WHERE (url like '%192.168.1.108%')  ORDER BY "spree_stores"."id" ASC LIMIT 1
  Spree::Store Load (0.8ms)  SELECT  "spree_stores".* FROM "spree_stores"  WHERE "spree_stores"."default" = 't'  ORDER BY "spree_stores"."id" ASC LIMIT 1
  Spree::Order Load (0.4ms)  SELECT  "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."completed_at" IS NULL AND "spree_orders"."currency" = 'USD' AND "spree_orders"."guest_token" = 'kRau34G-dOY0Sh06Mk0_4g' AND "spree_orders"."store_id" = 1 AND "spree_orders"."user_id" = 1 LIMIT 1
  Rendered /usr/local/rvm/gems/ruby-2.2.1@mystore20151008/bundler/gems/spree-dfd548b02fb3/frontend/app/views/spree/shared/_link_to_cart.html.erb (12.4ms)
Completed 200 OK in 969ms (Views: 939.1ms | ActiveRecord: 4.2ms)


Started GET "/assets/icons/delete.png" for 192.168.1.108 at 2016-03-13 19:01:29 -0400
Cannot render console from 192.168.1.108! Allowed networks: 192.168.2.0/192.168.2.255, 127.0.0.0/127.255.255.255, ::1

1 个答案:

答案 0 :(得分:0)

好像你正在使用gem 'spree_active_sale',这是这种行为的罪魁祸首。 它有一个before_filter,可以从订单中销毁非活动产品订单项。 请参阅https://github.com/suryart/spree_active_sale/blob/master/app/controllers/spree/orders_controller_decorator.rb#L3