本文整理汇总了C#中SmartStore.Core.Domain.Catalog.Product.GetLocalized方法的典型用法代码示例。如果您正苦于以下问题:C# Product.GetLocalized方法的具体用法?C# Product.GetLocalized怎么用?C# Product.GetLocalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmartStore.Core.Domain.Catalog.Product
的用法示例。
在下文中一共展示了Product.GetLocalized方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteProductToXml
//.........这里部分代码省略.........
writer.Write("CallForPrice", product.CallForPrice.ToString());
writer.Write("Price", product.Price.ToString(culture));
writer.Write("OldPrice", product.OldPrice.ToString(culture));
writer.Write("ProductCost", product.ProductCost.ToString(culture));
writer.Write("SpecialPrice", product.SpecialPrice.HasValue ? product.SpecialPrice.Value.ToString(culture) : "");
writer.Write("SpecialPriceStartDateTimeUtc", product.SpecialPriceStartDateTimeUtc.HasValue ? product.SpecialPriceStartDateTimeUtc.Value.ToString(culture) : "");
writer.Write("SpecialPriceEndDateTimeUtc", product.SpecialPriceEndDateTimeUtc.HasValue ? product.SpecialPriceEndDateTimeUtc.Value.ToString(culture) : "");
writer.Write("CustomerEntersPrice", product.CustomerEntersPrice.ToString());
writer.Write("MinimumCustomerEnteredPrice", product.MinimumCustomerEnteredPrice.ToString(culture));
writer.Write("MaximumCustomerEnteredPrice", product.MaximumCustomerEnteredPrice.ToString(culture));
writer.Write("HasTierPrices", product.HasTierPrices.ToString());
writer.Write("HasDiscountsApplied", product.HasDiscountsApplied.ToString());
writer.Write("Weight", product.Weight.ToString(culture));
writer.Write("Length", product.Length.ToString(culture));
writer.Write("Width", product.Width.ToString(culture));
writer.Write("Height", product.Height.ToString(culture));
writer.Write("AvailableStartDateTimeUtc", product.AvailableStartDateTimeUtc.HasValue ? product.AvailableStartDateTimeUtc.Value.ToString(culture) : "");
writer.Write("AvailableEndDateTimeUtc", product.AvailableEndDateTimeUtc.HasValue ? product.AvailableEndDateTimeUtc.Value.ToString(culture) : "");
writer.Write("BasePriceEnabled", product.BasePriceEnabled.ToString());
writer.Write("BasePriceMeasureUnit", product.BasePriceMeasureUnit);
writer.Write("BasePriceAmount", product.BasePriceAmount.HasValue ? product.BasePriceAmount.Value.ToString(culture) : "");
writer.Write("BasePriceBaseAmount", product.BasePriceBaseAmount.HasValue ? product.BasePriceBaseAmount.Value.ToString() : "");
writer.Write("VisibleIndividually", product.VisibleIndividually.ToString());
writer.Write("DisplayOrder", product.DisplayOrder.ToString());
writer.Write("BundleTitleText", product.BundleTitleText);
writer.Write("BundlePerItemPricing", product.BundlePerItemPricing.ToString());
writer.Write("BundlePerItemShipping", product.BundlePerItemShipping.ToString());
writer.Write("BundlePerItemShoppingCart", product.BundlePerItemShoppingCart.ToString());
writer.Write("LowestAttributeCombinationPrice", product.LowestAttributeCombinationPrice.HasValue ? product.LowestAttributeCombinationPrice.Value.ToString(culture) : "");
writer.Write("IsEsd", product.IsEsd.ToString());
WriteLocalized(writer, context, lang =>
{
writer.Write("Name", product.GetLocalized(x => x.Name, lang.Id, false, false), lang);
writer.Write("SeName", product.GetSeName(lang.Id, false, false), lang);
writer.Write("ShortDescription", product.GetLocalized(x => x.ShortDescription, lang.Id, false, false), lang, true);
writer.Write("FullDescription", product.GetLocalized(x => x.FullDescription, lang.Id, false, false), lang, true);
writer.Write("MetaKeywords", product.GetLocalized(x => x.MetaKeywords, lang.Id, false, false), lang);
writer.Write("MetaDescription", product.GetLocalized(x => x.MetaDescription, lang.Id, false, false), lang);
writer.Write("MetaTitle", product.GetLocalized(x => x.MetaTitle, lang.Id, false, false), lang);
writer.Write("BundleTitleText", product.GetLocalized(x => x.BundleTitleText, lang.Id, false, false), lang);
});
if (product.DeliveryTime != null)
{
writer.WriteStartElement("DeliveryTime");
writer.Write("Id", product.DeliveryTime.Id.ToString());
writer.Write("Name", product.DeliveryTime.Name);
writer.Write("DisplayLocale", product.DeliveryTime.DisplayLocale);
writer.Write("ColorHexValue", product.DeliveryTime.ColorHexValue);
writer.Write("DisplayOrder", product.DeliveryTime.DisplayOrder.ToString());
WriteLocalized(writer, context, lang =>
{
writer.Write("Name", product.DeliveryTime.GetLocalized(x => x.Name, lang.Id, false, false), lang);
});
writer.WriteEndElement();
}
WriteQuantityUnit(writer, context, product.QuantityUnit);
writer.WriteStartElement("ProductTags");
foreach (var tag in product.ProductTags)
{
writer.WriteStartElement("ProductTag");
writer.Write("Id", tag.Id.ToString());
writer.Write("Name", tag.Name);
示例2: AddProductTokens
public virtual void AddProductTokens(IList<Token> tokens, Product product, int languageId)
{
tokens.Add(new Token("Product.ID", product.Id.ToString()));
tokens.Add(new Token("Product.Sku", product.Sku));
tokens.Add(new Token("Product.Name", product.GetLocalized(x => x.Name, languageId)));
tokens.Add(new Token("Product.ShortDescription", product.GetLocalized(x => x.ShortDescription, languageId), true));
tokens.Add(new Token("Product.StockQuantity", product.StockQuantity.ToString()));
// TODO: add a method for getting URL (use routing because it handles all SEO friendly URLs)
var productUrl = string.Format("{0}{1}", _webHelper.GetStoreLocation(false), product.GetSeName());
tokens.Add(new Token("Product.ProductURLForCustomer", productUrl, true));
//event notification
_eventPublisher.EntityTokensAdded(product, tokens);
}
示例3: PrepareProductDetailModel
/// <param name="selectedAttributes">Attributes explicitly selected by user or by query string.</param>
public ProductDetailsModel PrepareProductDetailModel(
ProductDetailsModel model,
Product product,
bool isAssociatedProduct = false,
ProductBundleItemData productBundleItem = null,
IList<ProductBundleItemData> productBundleItems = null,
NameValueCollection selectedAttributes = null,
int selectedQuantity = 1)
{
if (product == null)
throw new ArgumentNullException("product");
if (model == null)
throw new ArgumentNullException("model");
if (selectedAttributes == null)
selectedAttributes = new NameValueCollection();
var store = _services.StoreContext.CurrentStore;
var customer = _services.WorkContext.CurrentCustomer;
var currency = _services.WorkContext.WorkingCurrency;
decimal preSelectedPriceAdjustmentBase = decimal.Zero;
decimal preSelectedWeightAdjustment = decimal.Zero;
bool displayPrices = _services.Permissions.Authorize(StandardPermissionProvider.DisplayPrices);
bool isBundle = (product.ProductType == ProductType.BundledProduct);
bool isBundleItemPricing = (productBundleItem != null && productBundleItem.Item.BundleProduct.BundlePerItemPricing);
bool isBundlePricing = (productBundleItem != null && !productBundleItem.Item.BundleProduct.BundlePerItemPricing);
int bundleItemId = (productBundleItem == null ? 0 : productBundleItem.Item.Id);
bool hasSelectedAttributesValues = false;
bool hasSelectedAttributes = (selectedAttributes.Count > 0);
List<ProductVariantAttributeValue> selectedAttributeValues = null;
var variantAttributes = (isBundle ? new List<ProductVariantAttribute>() : _productAttributeService.GetProductVariantAttributesByProductId(product.Id));
model.ProductPrice.DynamicPriceUpdate = _catalogSettings.EnableDynamicPriceUpdate;
model.ProductPrice.BundleItemShowBasePrice = _catalogSettings.BundleItemShowBasePrice;
if (!model.ProductPrice.DynamicPriceUpdate)
selectedQuantity = 1;
#region Product attributes
if (!isBundle) // bundles doesn't have attributes
{
foreach (var attribute in variantAttributes)
{
var pvaModel = new ProductDetailsModel.ProductVariantAttributeModel
{
Id = attribute.Id,
ProductId = attribute.ProductId,
BundleItemId = bundleItemId,
ProductAttributeId = attribute.ProductAttributeId,
Alias = attribute.ProductAttribute.Alias,
Name = attribute.ProductAttribute.GetLocalized(x => x.Name),
Description = attribute.ProductAttribute.GetLocalized(x => x.Description),
TextPrompt = attribute.TextPrompt,
IsRequired = attribute.IsRequired,
AttributeControlType = attribute.AttributeControlType,
AllowedFileExtensions = _catalogSettings.FileUploadAllowedExtensions
};
if (attribute.AttributeControlType == AttributeControlType.Datepicker)
{
if (pvaModel.Alias.HasValue() && RegularExpressions.IsYearRange.IsMatch(pvaModel.Alias))
{
var match = RegularExpressions.IsYearRange.Match(pvaModel.Alias);
pvaModel.BeginYear = match.Groups[1].Value.ToInt();
pvaModel.EndYear = match.Groups[2].Value.ToInt();
}
if (hasSelectedAttributes)
{
var attributeKey = "product_attribute_{0}_{1}_{2}_{3}".FormatInvariant(product.Id, bundleItemId, attribute.ProductAttributeId, attribute.Id);
var day = selectedAttributes[attributeKey + "_day"].ToInt();
var month = selectedAttributes[attributeKey + "_month"].ToInt();
var year = selectedAttributes[attributeKey + "_year"].ToInt();
if (day > 0 && month > 0 && year > 0)
{
pvaModel.SelectedDay = day;
pvaModel.SelectedMonth = month;
pvaModel.SelectedYear = year;
}
}
}
else if (attribute.AttributeControlType == AttributeControlType.TextBox || attribute.AttributeControlType == AttributeControlType.MultilineTextbox)
{
if (hasSelectedAttributes)
{
var attributeKey = "product_attribute_{0}_{1}_{2}_{3}".FormatInvariant(product.Id, bundleItemId, attribute.ProductAttributeId, attribute.Id);
pvaModel.TextValue = selectedAttributes[attributeKey];
}
}
var preSelectedValueId = 0;
var pvaValues = (attribute.ShouldHaveValues() ? _productAttributeService.GetProductVariantAttributeValues(attribute.Id) : new List<ProductVariantAttributeValue>());
foreach (var pvaValue in pvaValues)
//.........这里部分代码省略.........
示例4: WriteItem
private void WriteItem(FeedFileCreationContext fileCreation, XmlWriter writer, Product product, Currency currency, string measureWeightSystemKey)
{
GoogleProductRecord googleProduct = null;
try
{
googleProduct = GetGoogleProductRecord(product.Id);
if (googleProduct != null && !googleProduct.Export)
return;
}
catch (Exception exc)
{
fileCreation.Logger.Error(exc.Message, exc);
}
writer.WriteStartElement("item");
try
{
var manu = _manufacturerService.GetProductManufacturersByProductId(product.Id).FirstOrDefault();
var mainImageUrl = Helper.GetMainProductImageUrl(fileCreation.Store, product);
var category = ProductCategory(googleProduct);
if (category.IsEmpty())
fileCreation.ErrorMessage = Helper.GetResource("MissingDefaultCategory");
string manuName = (manu != null ? manu.Manufacturer.GetLocalized(x => x.Name, Settings.LanguageId, true, false) : null);
string productName = product.GetLocalized(x => x.Name, Settings.LanguageId, true, false);
string shortDescription = product.GetLocalized(x => x.ShortDescription, Settings.LanguageId, true, false);
string fullDescription = product.GetLocalized(x => x.FullDescription, Settings.LanguageId, true, false);
var brand = (manuName ?? Settings.Brand);
var mpn = Helper.GetManufacturerPartNumber(product);
bool identifierExists = product.Gtin.HasValue() || brand.HasValue() || mpn.HasValue();
writer.WriteElementString("g", "id", _googleNamespace, product.Id.ToString());
writer.WriteStartElement("title");
writer.WriteCData(productName.Truncate(70));
writer.WriteEndElement();
var description = Helper.BuildProductDescription(productName, shortDescription, fullDescription, manuName, d =>
{
if (fullDescription.IsEmpty() && shortDescription.IsEmpty())
{
var rnd = new Random();
switch (rnd.Next(1, 5))
{
case 1: return d.Grow(Settings.AppendDescriptionText1, " ");
case 2: return d.Grow(Settings.AppendDescriptionText2, " ");
case 3: return d.Grow(Settings.AppendDescriptionText3, " ");
case 4: return d.Grow(Settings.AppendDescriptionText4, " ");
case 5: return d.Grow(Settings.AppendDescriptionText5, " ");
}
}
return d;
});
writer.WriteStartElement("description");
writer.WriteCData(description.RemoveInvalidXmlChars());
writer.WriteEndElement();
writer.WriteStartElement("g", "google_product_category", _googleNamespace);
writer.WriteCData(category);
writer.WriteFullEndElement();
string productType = Helper.GetCategoryPath(product);
if (productType.HasValue())
{
writer.WriteStartElement("g", "product_type", _googleNamespace);
writer.WriteCData(productType);
writer.WriteFullEndElement();
}
writer.WriteElementString("link", Helper.GetProductDetailUrl(fileCreation.Store, product));
writer.WriteElementString("g", "image_link", _googleNamespace, mainImageUrl);
foreach (string additionalImageUrl in Helper.GetAdditionalProductImages(fileCreation.Store, product, mainImageUrl))
{
writer.WriteElementString("g", "additional_image_link", _googleNamespace, additionalImageUrl);
}
writer.WriteElementString("g", "condition", _googleNamespace, Condition());
writer.WriteElementString("g", "availability", _googleNamespace, Availability(product));
decimal price = Helper.GetProductPrice(product, currency, fileCreation.Store);
string specialPriceDate;
if (SpecialPrice(product, out specialPriceDate))
{
writer.WriteElementString("g", "sale_price", _googleNamespace, price.FormatInvariant() + " " + currency.CurrencyCode);
writer.WriteElementString("g", "sale_price_effective_date", _googleNamespace, specialPriceDate);
// get regular price ignoring any special price
decimal specialPrice = product.SpecialPrice.Value;
product.SpecialPrice = null;
price = Helper.GetProductPrice(product, currency, fileCreation.Store);
//.........这里部分代码省略.........
示例5: PrepareProductReviewsModel
public void PrepareProductReviewsModel(ProductReviewsModel model, Product product)
{
if (product == null)
throw new ArgumentNullException("product");
if (model == null)
throw new ArgumentNullException("model");
model.ProductId = product.Id;
model.ProductName = product.GetLocalized(x => x.Name);
model.ProductSeName = product.GetSeName();
var productReviews = product.ProductReviews.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
foreach (var pr in productReviews)
{
model.Items.Add(new ProductReviewModel()
{
Id = pr.Id,
CustomerId = pr.CustomerId,
CustomerName = pr.Customer.FormatUserName(),
AllowViewingProfiles = _customerSettings.AllowViewingProfiles && pr.Customer != null && !pr.Customer.IsGuest(),
Title = pr.Title,
ReviewText = pr.ReviewText,
Rating = pr.Rating,
Helpfulness = new ProductReviewHelpfulnessModel()
{
ProductReviewId = pr.Id,
HelpfulYesTotal = pr.HelpfulYesTotal,
HelpfulNoTotal = pr.HelpfulNoTotal,
},
WrittenOnStr = _dateTimeHelper.ConvertToUserTime(pr.CreatedOnUtc, DateTimeKind.Utc).ToString("g"),
});
}
model.AddProductReview.CanCurrentCustomerLeaveReview = _catalogSettings.AllowAnonymousUsersToReviewProduct || !_services.WorkContext.CurrentCustomer.IsGuest();
model.AddProductReview.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage;
}
示例6: PrepareProductDetailsPageModel
public ProductDetailsModel PrepareProductDetailsPageModel(
Product product,
bool isAssociatedProduct = false,
ProductBundleItemData productBundleItem = null,
IList<ProductBundleItemData> productBundleItems = null,
NameValueCollection selectedAttributes = null,
NameValueCollection queryData = null)
{
if (product == null)
throw new ArgumentNullException("product");
var model = new ProductDetailsModel
{
Id = product.Id,
Name = product.GetLocalized(x => x.Name),
ShortDescription = product.GetLocalized(x => x.ShortDescription),
FullDescription = product.GetLocalized(x => x.FullDescription),
MetaKeywords = product.GetLocalized(x => x.MetaKeywords),
MetaDescription = product.GetLocalized(x => x.MetaDescription),
MetaTitle = product.GetLocalized(x => x.MetaTitle),
SeName = product.GetSeName(),
ProductType = product.ProductType,
VisibleIndividually = product.VisibleIndividually,
//Manufacturers = _manufacturerService.GetProductManufacturersByProductId(product.Id),
Manufacturers = PrepareManufacturersOverviewModel(_manufacturerService.GetProductManufacturersByProductId(product.Id), null, true),
ReviewCount = product.ApprovedTotalReviews,
DisplayAdminLink = _services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel),
//EnableHtmlTextCollapser = Convert.ToBoolean(_settingService.GetSettingByKey<string>("CatalogSettings.EnableHtmlTextCollapser")),
//HtmlTextCollapsedHeight = Convert.ToString(_settingService.GetSettingByKey<string>("CatalogSettings.HtmlTextCollapsedHeight")),
ShowSku = _catalogSettings.ShowProductSku,
Sku = product.Sku,
ShowManufacturerPartNumber = _catalogSettings.ShowManufacturerPartNumber,
DisplayProductReviews = _catalogSettings.ShowProductReviewsInProductDetail,
ManufacturerPartNumber = product.ManufacturerPartNumber,
ShowGtin = _catalogSettings.ShowGtin,
Gtin = product.Gtin,
StockAvailability = product.FormatStockMessage(_localizationService),
HasSampleDownload = product.IsDownload && product.HasSampleDownload,
IsCurrentCustomerRegistered = _services.WorkContext.CurrentCustomer.IsRegistered()
};
// get gift card values from query string
if (queryData != null && queryData.Count > 0)
{
var giftCardItems = queryData.AllKeys
.Where(x => x.EmptyNull().StartsWith("giftcard_"))
.SelectMany(queryData.GetValues, (k, v) => new { key = k, value = v.TrimSafe() });
foreach (var item in giftCardItems)
{
var key = item.key.EmptyNull().ToLower();
if (key.EndsWith("recipientname"))
model.GiftCard.RecipientName = item.value;
else if (key.EndsWith("recipientemail"))
model.GiftCard.RecipientEmail = item.value;
else if (key.EndsWith("sendername"))
model.GiftCard.SenderName = item.value;
else if (key.EndsWith("senderemail"))
model.GiftCard.SenderEmail = item.value;
else if (key.EndsWith("message"))
model.GiftCard.Message = item.value;
}
}
// Back in stock subscriptions
if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
product.BackorderMode == BackorderMode.NoBackorders &&
product.AllowBackInStockSubscriptions &&
product.StockQuantity <= 0)
{
//out of stock
model.DisplayBackInStockSubscription = true;
model.BackInStockAlreadySubscribed = _backInStockSubscriptionService
.FindSubscription(_services.WorkContext.CurrentCustomer.Id, product.Id, _services.StoreContext.CurrentStore.Id) != null;
}
//template
var templateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY, product.ProductTemplateId);
model.ProductTemplateViewPath = _services.Cache.Get(templateCacheKey, () =>
{
var template = _productTemplateService.GetProductTemplateById(product.ProductTemplateId);
if (template == null)
template = _productTemplateService.GetAllProductTemplates().FirstOrDefault();
return template.ViewPath;
});
IList<ProductBundleItemData> bundleItems = null;
ProductVariantAttributeCombination combination = null;
if (product.ProductType == ProductType.GroupedProduct && !isAssociatedProduct) // associated products
{
var searchContext = new ProductSearchContext
{
OrderBy = ProductSortingEnum.Position,
StoreId = _services.StoreContext.CurrentStore.Id,
ParentGroupedProductId = product.Id,
PageSize = int.MaxValue,
VisibleIndividuallyOnly = false
};
//.........这里部分代码省略.........
示例7: CopyProduct
//.........这里部分代码省略.........
Weight = product.Weight,
Length = product.Length,
Width = product.Width,
Height = product.Height,
AvailableStartDateTimeUtc = product.AvailableStartDateTimeUtc,
AvailableEndDateTimeUtc = product.AvailableEndDateTimeUtc,
DisplayOrder = product.DisplayOrder,
Published = isPublished,
Deleted = product.Deleted,
CreatedOnUtc = utcNow,
UpdatedOnUtc = utcNow,
DeliveryTimeId = product.DeliveryTimeId,
QuantityUnitId = product.QuantityUnitId,
BasePriceEnabled = product.BasePriceEnabled,
BasePriceMeasureUnit = product.BasePriceMeasureUnit,
BasePriceAmount = product.BasePriceAmount,
BasePriceBaseAmount = product.BasePriceBaseAmount,
BundleTitleText = product.BundleTitleText,
BundlePerItemShipping = product.BundlePerItemShipping,
BundlePerItemPricing = product.BundlePerItemPricing,
BundlePerItemShoppingCart = product.BundlePerItemShoppingCart
};
_productService.InsertProduct(productCopy);
//search engine name
_urlRecordService.SaveSlug(productCopy, productCopy.ValidateSeName("", productCopy.Name, true), 0);
var languages = _languageService.GetAllLanguages(true);
//localization
foreach (var lang in languages)
{
var name = product.GetLocalized(x => x.Name, lang.Id, false, false);
if (!String.IsNullOrEmpty(name))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.Name, name, lang.Id);
var shortDescription = product.GetLocalized(x => x.ShortDescription, lang.Id, false, false);
if (!String.IsNullOrEmpty(shortDescription))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.ShortDescription, shortDescription, lang.Id);
var fullDescription = product.GetLocalized(x => x.FullDescription, lang.Id, false, false);
if (!String.IsNullOrEmpty(fullDescription))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.FullDescription, fullDescription, lang.Id);
var metaKeywords = product.GetLocalized(x => x.MetaKeywords, lang.Id, false, false);
if (!String.IsNullOrEmpty(metaKeywords))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.MetaKeywords, metaKeywords, lang.Id);
var metaDescription = product.GetLocalized(x => x.MetaDescription, lang.Id, false, false);
if (!String.IsNullOrEmpty(metaDescription))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.MetaDescription, metaDescription, lang.Id);
var metaTitle = product.GetLocalized(x => x.MetaTitle, lang.Id, false, false);
if (!String.IsNullOrEmpty(metaTitle))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.MetaTitle, metaTitle, lang.Id);
var bundleTitleText = product.GetLocalized(x => x.BundleTitleText, lang.Id, false, false);
if (!String.IsNullOrEmpty(bundleTitleText))
_localizedEntityService.SaveLocalizedValue(productCopy, x => x.BundleTitleText, bundleTitleText, lang.Id);
//search engine name
_urlRecordService.SaveSlug(productCopy, productCopy.ValidateSeName("", name, false), lang.Id);
}
示例8: PrepareProductDetailsPageModel
protected ProductDetailsModel PrepareProductDetailsPageModel(Product product, bool isAssociatedProduct = false,
ProductBundleItemData productBundleItem = null, IList<ProductBundleItemData> productBundleItems = null, FormCollection selectedAttributes = null)
{
if (product == null)
throw new ArgumentNullException("product");
var model = new ProductDetailsModel()
{
Id = product.Id,
Name = product.GetLocalized(x => x.Name),
ShortDescription = product.GetLocalized(x => x.ShortDescription),
FullDescription = product.GetLocalized(x => x.FullDescription),
MetaKeywords = product.GetLocalized(x => x.MetaKeywords),
MetaDescription = product.GetLocalized(x => x.MetaDescription),
MetaTitle = product.GetLocalized(x => x.MetaTitle),
SeName = product.GetSeName(),
ProductType = product.ProductType,
VisibleIndividually = product.VisibleIndividually,
//Manufacturers = _manufacturerService.GetProductManufacturersByProductId(product.Id), /* codehint: sm-edit */
Manufacturers = PrepareManufacturersOverviewModel(_manufacturerService.GetProductManufacturersByProductId(product.Id)),
ReviewCount = product.ApprovedTotalReviews, /* codehint: sm-add */
DisplayAdminLink = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel),
EnableHtmlTextCollapser = Convert.ToBoolean(_settingService.GetSettingByKey<string>("CatalogSettings.EnableHtmlTextCollapser")),
HtmlTextCollapsedHeight = Convert.ToString(_settingService.GetSettingByKey<string>("CatalogSettings.HtmlTextCollapsedHeight")),
ShowSku = _catalogSettings.ShowProductSku,
Sku = product.Sku,
ShowManufacturerPartNumber = _catalogSettings.ShowManufacturerPartNumber,
ManufacturerPartNumber = product.ManufacturerPartNumber,
ShowGtin = _catalogSettings.ShowGtin,
Gtin = product.Gtin,
StockAvailability = product.FormatStockMessage(_localizationService),
HasSampleDownload = product.IsDownload && product.HasSampleDownload,
IsCurrentCustomerRegistered = _workContext.CurrentCustomer.IsRegistered()
};
// Back in stock subscriptions
if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
product.BackorderMode == BackorderMode.NoBackorders &&
product.AllowBackInStockSubscriptions &&
product.StockQuantity <= 0)
{
//out of stock
model.DisplayBackInStockSubscription = true;
model.BackInStockAlreadySubscribed = _backInStockSubscriptionService
.FindSubscription(_workContext.CurrentCustomer.Id, product.Id, _storeContext.CurrentStore.Id) != null;
}
//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;
});
IList<ProductBundleItemData> bundleItems = null;
ProductVariantAttributeCombination combination = null;
var combinationImageIds = new List<int>();
if (product.ProductType == ProductType.GroupedProduct && !isAssociatedProduct) // associated products
{
var searchContext = new ProductSearchContext()
{
StoreId = _storeContext.CurrentStore.Id,
ParentGroupedProductId = product.Id,
VisibleIndividuallyOnly = false
};
var associatedProducts = _productService.SearchProducts(searchContext);
foreach (var associatedProduct in associatedProducts)
model.AssociatedProducts.Add(PrepareProductDetailsPageModel(associatedProduct, true));
}
else if (product.ProductType == ProductType.BundledProduct && productBundleItem == null) // bundled items
{
bundleItems = _productService.GetBundleItems(product.Id);
foreach (var itemData in bundleItems.Where(x => x.Item.Product.CanBeBundleItem()))
{
var item = itemData.Item;
var bundledProductModel = PrepareProductDetailsPageModel(item.Product, false, itemData);
bundledProductModel.BundleItem.Id = item.Id;
bundledProductModel.BundleItem.Quantity = item.Quantity;
bundledProductModel.BundleItem.HideThumbnail = item.HideThumbnail;
bundledProductModel.BundleItem.Visible = item.Visible;
bundledProductModel.BundleItem.IsBundleItemPricing = item.BundleProduct.BundlePerItemPricing;
string bundleItemName = item.GetLocalized(x => x.Name);
if (bundleItemName.HasValue())
bundledProductModel.Name = bundleItemName;
string bundleItemShortDescription = item.GetLocalized(x => x.ShortDescription);
if (bundleItemShortDescription.HasValue())
bundledProductModel.ShortDescription = bundleItemShortDescription;
model.BundledItems.Add(bundledProductModel);
}
//.........这里部分代码省略.........
示例9: AddProductTokens
public virtual void AddProductTokens(IList<Token> tokens, Product product, Language language)
{
// TODO: add a method for getting URL (use routing because it handles all SEO friendly URLs)
var storeLocation = _webHelper.GetStoreLocation(false);
var productUrl = storeLocation + product.GetSeName();
var productName = product.GetLocalized(x => x.Name, language.Id);
tokens.Add(new Token("Product.ID", product.Id.ToString()));
tokens.Add(new Token("Product.Sku", product.Sku));
tokens.Add(new Token("Product.Name", productName));
tokens.Add(new Token("Product.ShortDescription", product.GetLocalized(x => x.ShortDescription, language.Id), true));
tokens.Add(new Token("Product.StockQuantity", product.StockQuantity.ToString()));
tokens.Add(new Token("Product.ProductURLForCustomer", productUrl, true));
var currency = _workContext.WorkingCurrency;
var additionalShippingCharge = _currencyService.ConvertFromPrimaryStoreCurrency(product.AdditionalShippingCharge, currency);
var additionalShippingChargeFormatted = _priceFormatter.FormatPrice(additionalShippingCharge, false, currency.CurrencyCode, false, language);
tokens.Add(new Token("Product.AdditionalShippingCharge", additionalShippingChargeFormatted));
if (_mediaSettings.MessageProductThumbPictureSize > 0)
{
var pictureHtml = ProductPictureToHtml(GetPictureFor(product, null), language, productName, productUrl, storeLocation);
tokens.Add(new Token("Product.Thumbnail", pictureHtml, true));
}
//event notification
_eventPublisher.EntityTokensAdded(product, tokens);
}