3

我想在产品页面显示从布局上传的尺寸,因为我有很多产品,每个 SKU 都有不同的尺寸,所以我会浪费很多时间添加每个度量作为产品规格。

我找到了 1.9 版的扩展,但我正在开发 3.0。

4

1 回答 1

3
  1. 将这些属性添加到 Models\Catalog\ ProductDetailsModel:

    public decimal Weight { get; set; }
    public decimal Length { get; set; }
    public decimal Width { get; set; }
    public decimal Height { get; set; }
    
  2. 在 CatalogController 的 PrepareProductDetailsPageModel 方法中为这些参数赋值。为此,您应该找到字符串“var model = new ProductDetailsModel()”并在“IsCurrentCustomerRegistered = _workContext.CurrentCustomer.IsRegistered()”之后添加以下行:

    Weight = product.Weight,
    Length = product.Length,
    Width = product.Width,
    Height = product.Height
    
  3. 将新属性添加到 ProductTemplate.Simple.cshtml 和 ProductTemplate.Grouped.cshtml 视图:

    <div>
       <span class="label">Weight:</span>
       <span class="value">@Model.Weight</span>
    </div>
    <div>
       <span class="label">Width:</span>
       <span class="value">@Model.Width</span>
    </div>
    <div>
       <span class="label">Length:</span>
       <span class="value">@Model.Length</span>
    </div>
    <div>
       <span class="label">Height:</span>
       <span class="value">@Model.Height</span>
    </div>
    

例如,在 "@Html.Partial("_SKU_Man_Stock", Model)" 行之后。

于 2013-09-03T13:56:44.837 回答