本文整理汇总了C#中Nop.Core.Domain.Catalog.Product.ToModel方法的典型用法代码示例。如果您正苦于以下问题:C# Product.ToModel方法的具体用法?C# Product.ToModel怎么用?C# Product.ToModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Core.Domain.Catalog.Product
的用法示例。
在下文中一共展示了Product.ToModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareProductDetailsPageModel
protected ProductModel PrepareProductDetailsPageModel(Product product)
{
if (product == null)
throw new ArgumentNullException("product");
var model = product.ToModel();
//template
var templateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY, product.ProductTemplateId);
model.ProductTemplateViewPath = _cacheManager.Get(templateCacheKey, () =>
{
var template = _productTemplateService.GetProductTemplateById(product.ProductTemplateId);
if (template == null)
template = _productTemplateService.GetAllProductTemplates().FirstOrDefault();
return template.ViewPath;
});
//pictures
model.DefaultPictureZoomEnabled = _mediaSetting.DefaultPictureZoomEnabled;
var pictures = _pictureService.GetPicturesByProductId(product.Id);
if (pictures.Count > 0)
{
//default picture
model.DefaultPictureModel = new PictureModel()
{
ImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault(), _mediaSetting.ProductDetailsPictureSize),
FullSizeImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault()),
Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
};
//all pictures
foreach (var picture in pictures)
{
model.PictureModels.Add(new PictureModel()
{
ImageUrl = _pictureService.GetPictureUrl(picture, _mediaSetting.ProductThumbPictureSizeOnProductDetailsPage),
FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
});
}
}
else
{
//no images. set the default one
model.DefaultPictureModel = new PictureModel()
{
ImageUrl = _pictureService.GetDefaultPictureUrl(_mediaSetting.ProductDetailsPictureSize),
FullSizeImageUrl = _pictureService.GetDefaultPictureUrl(),
Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name),
};
}
//product variants
foreach (var variant in _productService.GetProductVariantsByProductId(product.Id))
model.ProductVariantModels.Add(PrepareProductVariantModel(new ProductModel.ProductVariantModel(), variant));
return model;
}
示例2: PrepareProductOverviewModel
protected ProductModel PrepareProductOverviewModel(Product product, bool preparePriceModel = true, bool preparePictureModel = true, int? productThumbPictureSize = null)
{
if (product == null)
throw new ArgumentNullException("product");
var model = product.ToModel();
//price
if (preparePriceModel)
{
model.ProductPrice = PrepareProductPriceModel(product);
}
//picture
if (preparePictureModel)
{
//If a size has been set in the view, we use it in priority
int pictureSize = productThumbPictureSize.HasValue ? productThumbPictureSize.Value : _mediaSetting.ProductThumbPictureSize;
//prepare picture model
var defaultProductPictureCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_DEFAULTPICTURE_MODEL_KEY, product.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured());
model.DefaultPictureModel = _cacheManager.Get(defaultProductPictureCacheKey, () =>
{
var picture = product.GetDefaultProductPicture(_pictureService);
var pictureModel = new PictureModel()
{
ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize),
FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name)
};
return pictureModel;
});
}
return model;
}
示例3: PrepareProductOverviewModel
protected ProductModel PrepareProductOverviewModel(Product product, bool preparePriceModel = true, bool preparePictureModel = true, int? productThumbPictureSize = null)
{
if (product == null)
throw new ArgumentNullException("product");
var model = product.ToModel();
//price
if (preparePriceModel)
{
model.ProductPrice = PrepareProductPriceModel(product);
}
//picture
if (preparePictureModel)
{
//If a size has been set in the view, we use it in priority
int pictureSize = productThumbPictureSize.HasValue ? productThumbPictureSize.Value : _mediaSetting.ProductThumbPictureSize;
var picture = product.GetDefaultProductPicture(_pictureService);
if (picture != null)
{
model.DefaultPictureModel.ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize, true);
model.DefaultPictureModel.FullSizeImageUrl = _pictureService.GetPictureUrl(picture);
}
else
{
model.DefaultPictureModel.ImageUrl = _pictureService.GetDefaultPictureUrl(pictureSize);
model.DefaultPictureModel.FullSizeImageUrl = _pictureService.GetDefaultPictureUrl();
}
model.DefaultPictureModel.Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name);
model.DefaultPictureModel.AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name);
}
return model;
}