在心愿单模块中显示产品选项 - DNN Hotcakes

Display product options in Wishlist module - DNN Hotcakes

愿望清单模块的当前默认视图显示产品,但不显示已选择的选项。

如何更改此选项以便同时显示选项标签和所选值?

我假设您使用的是 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>