3

我正在尝试向 Spree admin 添加几行代码。

我想覆盖的文件:

backend/app/views/spree/admin/orders/_shipment.html.erb

我想在这里添加它:

<tr class="show-tracking total">
        <td colspan="5" class="tracking-value">
          <% if shipment.tracking.present? %>
            <strong><%= Spree.t(:tracking) %>:</strong> <%= shipment.tracking %>
          <% else %>
            <%= Spree.t(:no_tracking_present) %>
          <% end %>
        </td>
      </tr>

我的覆盖是:

<!-- insert_after '.tracking-value' -->
</br>
<strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
  <% if shipment.date_delivered? %>
    <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
  <% end %>

位于app/overrides/spree/admin/orders/shipment/add_tracking_info.html.erb.deface

内容:

</br>
<strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
  <% if shipment.date_delivered? %>
    <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
  <% end %>

我想渲染:

<tr class="show-tracking total">
        <td colspan="5" class="tracking-value">
          <% if shipment.tracking.present? %>
            <strong><%= Spree.t(:tracking) %>:</strong> <%= shipment.tracking %>
            </br>
           <strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %</br>
          <% if shipment.date_delivered? %>
            <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
          <% end %>
          <% else %>
            <%= Spree.t(:no_tracking_present) %>
          <% end %>
        </td>
      </tr>

任何有关此问题的帮助将不胜感激,非常感谢!

4

1 回答 1

2

你少了一步。您需要以一种非常抽象的方式告诉 spree 您需要插入的位置和内容。

Deface::Override.new(
  virtual_path: 'spree/admin/shared/_order_summary',    
  name:         'admin_order_custom_details',
  insert_after: 'header#order_tab_summary > dl.additional-info',
  partial:      'spree/admin/shared/admin_order_custom_details'
)

以下是从我工作到昨天的项目中复制的。它指示Deface添加部分“spree/admin/shared/admin_order_custom_details just after the dom element identified byheader#order_tab_summary > dl.additional-info”的作用是什么。

所以我看到你需要做的是

  1. 更改html.erb.deface为 justhtml.erb并将其移动到某个位置,这样它就会像app/views/spree/admin/orders/add_order_detials_to_shipment.html.erb
  2. 在中创建一个新文件app/overides/(剧透警报,使其成为有意义的警报或稍后后悔)
  3. 找到标识符(只是看着它,我认为它类似于erb[silent]:contains('if shipment.tracking.present?')
  4. 使用insert_bottom而不是insert_after

我没有运行这个,但我相信这就是你要找的。

Deface::Override.new(
  virtual_path:  'app/views/spree/admin/orders/_shipment',    
  name:          'add_order_detials_to_shipment', # Or a fancy unique name
  insert_bottom: "erb[silent]:contains('if shipment.tracking.present?')",
  partial:       'app/views/spree/admin/orders/add_order_detials_to_shipment'
)

附言

在阅读了文档的那部分之后,我不知道有一个用于 Deface 的 DSL,我认为您需要更新 DSL,以便

<!-- insert_bottom "erb[silent]:contains('if shipment.tracking.present?')" -->
</br>
<strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
<% if shipment.date_delivered? %>
  <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
<% end %>
于 2014-12-06T15:28:19.757 回答