Frage

Currently, I'm trying to add a cart link into a dropdown menu on my page. The code is below:

   <ul>
    <a href="<%= cart_path %>">
      <li id="link-to-cart" data-hook>
        <%= link_to_cart %>
      </li>
    </a>
    <a href="<%= checkout_path %>">
      <li>
        Check Out
      </li>
    </a>
  </ul>

This works properly for the checkout path, but not for the cart. The idea is to make the whole <li> the link to the proper location so that users have an easier time and don't have to specifically click on the text. What's rendered is shown in a screenshot below:

inspect element view

My current assumption is that an anchor tag cannot be encapsulated by another anchor tag, which results in what is shown. However, that does not explain why there are three anchor tags to /cart in the resulting HTML. How can I fix this behavior? Or alternatively, can I retrieve cart information, such as number of items and subtotal through a different means other than link_to_cart?

War es hilfreich?

Lösung

To change how the cart is rendered you can overwrite the link_to_cart method into spree base_helper.rb. You can find instructions about how to extend that helper here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top