简体   繁体   中英

Spree gem without checkout

I am using Spree 2.0.4 on Rails 3.2.14. I want to build an ecommerce site, but it should not have checkout feature. An ecommerce site without checkout doesn't make a lot of sense but it's essentially a B2B model, so retail sales are not going to happen. I have read through documentation and it shows steps to customize the checkout process, but it's still not clear how to remove this functionality entirely. My requirement is to

  1. No Price display on froent end
  2. No Add to cart, or quantity option

I would like to use Spree because of it's inventory management and UX modules, which would help me get up and running fast.

There is no short way to do this, yet the easiest way would be to just get rid of any reference to check out and quantity in the front-end. You can do this overriding the views which refers to them, entirely or using deface (deface is more recommended but it also takes time to learn), and just removing any quantity field, price label, add-to-cart or checkout link.

However, having worked with Spree for quite a while now, my personal advice would be to fork the spree project from github and selectively remove the features you don't want, both in the frontend, the backend, and the core engine. That would take some extra effort though.

I haven't used 2.x versions, but I've looked at it and it should be enough to override show.html.erb for products with Deface:

app/overrides/products/show.rb:

 Deface::Override.new(
   virtual_path: 'spree/products/show',
   name: 'Remove cart',
   remove: '[data-hook="cart_form"]')

and same for products index.

app/overrides/shared/_products.rb:

 Deface::Override.new(
   virtual_path: 'spree/shared/_products',
   name: 'Remove price from products index',
   remove: "[erb-loud]:contains('display_price(product)')")

Beware, I've written above without testing based on my experience with 1.3 version, I don't have any Spree 2.x version installed and I can't do that now, I see they've splitted frontend and backend , so paths might be spree/frontend/app/views/spree/shared_products instead of above, but I doubt it.

That will of course remove it only visually, you may also try playing with Product class, eg overriding some base method like:

Spree::Product.class_eval do
  def on_sale?
    false
  end
end

but again, that's based on 1.3, I'm just pointing you where to look as it could've changed a lot since 1.3.

If you want to get rid of all traces of checkout options you should do as @Miotsu written, as you're going to remove one of basic functions of Spree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM