2016-09-14 56 views

回答

1

我打算假設你使用Hotcakes 1.xx而不是2.xx版本,但代碼應該是對於兩者都是相同的。我只在01.10.04進行了測試。

我已經建立了一個基於您可以在視圖中找到的購物車視圖來完成此操作的示例。

原來的願望列表視圖看起來是這樣的:

@model IEnumerable<Hotcakes.Modules.Core.Areas.Account.Models.SavedItemViewModel> 

<h2>@Localization.GetString("SavedItems")</h2> 
@Html.Raw((string)TempData["messages"]) 
<div class="hc-record-list hc-wishlist clearfix"> 
    @foreach (var item in Model) 
    { 
     <div class="hc-record"> 
      <div class="hc-recimage"> 
       <a href="@item.FullProduct.ProductLink"> 
        <img src="@item.FullProduct.ImageUrls.SmallUrl" border="0" alt="@item.FullProduct.ImageUrls.SmallAltText" /> 
       </a> 
      </div> 
      <div class="hc-recname"> 
       <h2>@item.FullProduct.Item.ProductName</h2> 
       <div class="hc-recdescription"> 
        @Html.Raw(item.FullProduct.Item.LongDescription) 
       </div> 
      </div> 
      <div class="hc-reccontrols"> 
       <table class="dnnFormItem"> 
        <tr> 
         <td class="hc-recprice"> 
          @Html.Raw(item.FullProduct.UserPrice.DisplayPrice(true)) 
         </td> 
         <td> 
          @if(!item.FullProduct.Item.IsGiftCard && !item.FullProduct.Item.IsUserSuppliedPrice) 
          { 
           using (Html.BeginHccRouteForm(HccRoute.WishList, new { action = "addtocart" }, FormMethod.Post)) 
           { 
            <input type="hidden" name="itemid" value="@item.SavedItem.Id" /> 
            <input class="dnnPrimaryAction" type="submit" value="@Localization.GetString("AddToCart")" /> 
           } 
          } 
         </td> 
         <td> 
          @using (Html.BeginHccRouteForm(HccRouteNames.WishList, new { action = "delete" }, FormMethod.Post)) 
          { 
           <input type="hidden" name="itemid" value="@item.SavedItem.Id" /> 
           <input type="submit" class="hc-delete" value="@Localization.GetString("RemoveSavedItem")" /> 
          } 
         </td> 
        </tr> 
       </table> 
      </div> 
     </div> 
    } 
</div> 

以下產品的描述中,我添加了下面的代碼片段:

@using Hotcakes.Commerce.Catalog 
@if (item.SavedItem.SelectionData != null && item.SavedItem.SelectionData.OptionSelectionList != null && item.SavedItem.SelectionData.OptionSelectionList.Count > 0) 
{ 
    <div class="clearfix"> 
     @Html.Raw(item.FullProduct.Item.Options.CartDescription(item.SavedItem.SelectionData.OptionSelectionList)) 
    </div> 
} 

這使得整個觀點是這樣的:

@using Hotcakes.Commerce.Catalog 
@model IEnumerable<Hotcakes.Modules.Core.Areas.Account.Models.SavedItemViewModel> 

<h2>@Localization.GetString("SavedItems")</h2> 
@Html.Raw((string)TempData["messages"]) 
<div class="hc-record-list hc-wishlist clearfix"> 
    @foreach (var item in Model) 
    { 
     <div class="hc-record"> 
      <div class="hc-recimage"> 
       <a href="@item.FullProduct.ProductLink"> 
        <img src="@item.FullProduct.ImageUrls.SmallUrl" border="0" alt="@item.FullProduct.ImageUrls.SmallAltText" /> 
       </a> 
      </div> 
      <div class="hc-recname"> 
       <h2>@item.FullProduct.Item.ProductName</h2> 
       <div class="hc-recdescription"> 
        @Html.Raw(item.FullProduct.Item.LongDescription) 
       </div> 
       @if (item.SavedItem.SelectionData != null && item.SavedItem.SelectionData.OptionSelectionList != null && item.SavedItem.SelectionData.OptionSelectionList.Count > 0) 
       { 
        <div class="clearfix"> 
         @Html.Raw(item.FullProduct.Item.Options.CartDescription(item.SavedItem.SelectionData.OptionSelectionList)) 
        </div> 
       } 
      </div> 
      <div class="hc-reccontrols"> 
       <table class="dnnFormItem"> 
        <tr> 
         <td class="hc-recprice"> 
          @Html.Raw(item.FullProduct.UserPrice.DisplayPrice(true)) 
         </td> 
         <td> 
          @if(!item.FullProduct.Item.IsGiftCard && !item.FullProduct.Item.IsUserSuppliedPrice) 
          { 
           using (Html.BeginHccRouteForm(HccRoute.WishList, new { action = "addtocart" }, FormMethod.Post)) 
           { 
            <input type="hidden" name="itemid" value="@item.SavedItem.Id" /> 
            <input class="dnnPrimaryAction" type="submit" value="@Localization.GetString("AddToCart")" /> 
           } 
          } 
         </td> 
         <td> 
          @using (Html.BeginHccRouteForm(HccRouteNames.WishList, new { action = "delete" }, FormMethod.Post)) 
          { 
           <input type="hidden" name="itemid" value="@item.SavedItem.Id" /> 
           <input type="submit" class="hc-delete" value="@Localization.GetString("RemoveSavedItem")" /> 
          } 
         </td> 
        </tr> 
       </table> 
      </div> 
     </div> 
    } 
</div> 
+0

不錯!這工作完美。謝謝,威爾,你很神奇! –

相關問題