1) 运行 bundle open spree ,导航到 core/app/spree/product/show.html.erb n
2)检查浏览器上的元素并找到按钮所在的位置。
3) 使用 deface 覆盖它。
这是一个例子:
我在div#cart-form 之前放了一个按钮(未经测试的相应修改)
Deface::Override.new(:virtual_path => "spree/product/show",
:insert_before => "div#cart-form",
:text => "<button name="button">Click me</button>",
:name => "button_product_show")
假设文件名为 button_product_show.rb
我会把这个文件放在app/overrides/spree/button_product_show.rb
spree/product/show.html.erb 如下所示(至少在我使用的版本上):
<div data-hook="product_show" itemscope itemtype="http://schema.org/Product">
<% @body_id = 'product-details' %>
<div class="columns six alpha" data-hook="product_left_part">
<div class="row" data-hook="product_left_part_wrap">
<div id="product-images" data-hook="product_images">
<div id="main-image" data-hook>
<%= render :partial => 'image' %>
</div>
<div id="thumbnails" data-hook>
<%= render :partial => 'thumbnails' %>
</div>
</div>
<div data-hook="product_properties">
<%= render :partial => 'properties' %>
</div>
</div>
</div>
<div class="columns ten omega" data-hook="product_right_part">
<div class="row" data-hook="product_right_part_wrap">
<div id="product-description" data-hook="product_description">
<h1 class="product-title" itemprop="name"><%= accurate_title %></h1>
<div itemprop="description" data-hook="description">
<%= product_description(@product) rescue t(:product_has_no_description) %>
</div>
<div id="cart-form" data-hook="cart_form">
<%= render :partial => 'cart_form' %>
</div>
</div>
<%= render :partial => 'taxons' %>
</div>
</div>
</div>
更多信息可以在这里找到:http://guides.spreecommerce.com/developer/view.html