Skip to content

Commit

Permalink
Add new field - ShowOnCatalogPage on ProductAttributeMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Apr 28, 2020
1 parent 7da2881 commit 9a4c2c3
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 193 deletions.
5 changes: 5 additions & 0 deletions Grand.Core/Domain/Catalog/ProductAttributeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public ProductAttributeMapping()
/// </summary>
public bool IsRequired { get; set; }

/// <summary>
/// Gets or sets whether the attribute will be shown on the catalog page
/// </summary>
public bool ShowOnCatalogPage { get; set; }

/// <summary>
/// Gets or sets the attribute control type identifier
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Grand.Services/Catalog/ProductAttributeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public virtual async Task UpdateProductAttributeMapping(ProductAttributeMapping
.Set(x => x.ProductAttributeMappings.ElementAt(-1).ProductAttributeId, productAttributeMapping.ProductAttributeId)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).TextPrompt, productAttributeMapping.TextPrompt)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).IsRequired, productAttributeMapping.IsRequired)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).ShowOnCatalogPage, productAttributeMapping.ShowOnCatalogPage)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).AttributeControlTypeId, productAttributeMapping.AttributeControlTypeId)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).DisplayOrder, productAttributeMapping.DisplayOrder)
.Set(x => x.ProductAttributeMappings.ElementAt(-1).ValidationMinLength, productAttributeMapping.ValidationMinLength)
Expand Down
80 changes: 6 additions & 74 deletions Grand.Services/Catalog/ProductExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Grand.Core;
using Grand.Core.Domain.Catalog;
using Grand.Core.Domain.Customers;
using Grand.Services.Directory;
using Grand.Services.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Grand.Services.Catalog
{
Expand Down Expand Up @@ -39,7 +36,7 @@ public static TierPrice GetPreferredTierPrice(this Product product, Customer cus
var tierPrice = actualTierPrices.LastOrDefault(price => quantity >= price.Quantity);

return tierPrice;
}
}

/// <summary>
/// Formats the stock availability/quantity message
Expand Down Expand Up @@ -140,7 +137,7 @@ public static string FormatStockMessage(this Product product, string warehouseId
default:
break;
}
if(!combination.AllowOutOfStockOrders)
if (!combination.AllowOutOfStockOrders)
stockMessage = localizationService.GetResource("Products.Availability.Attributes.OutOfStock");
}
}
Expand Down Expand Up @@ -199,7 +196,7 @@ public static int[] ParseAllowedQuantities(this Product product)
if (!String.IsNullOrWhiteSpace(product.AllowedQuantities))
{
product.AllowedQuantities
.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.ToList()
.ForEach(qtyStr =>
{
Expand Down Expand Up @@ -227,7 +224,7 @@ public static int[] ParseAllowedQuantities(this Product product)
/// Used only with "multiple warehouses" enabled.
/// </param>
/// <returns>Result</returns>
public static int GetTotalStockQuantity(this Product product,
public static int GetTotalStockQuantity(this Product product,
bool useReservedQuantity = true, string warehouseId = "")
{
if (product == null)
Expand Down Expand Up @@ -320,7 +317,7 @@ public static int GetTotalStockQuantityForCombination(this Product product, Prod

}



/// <summary>
/// Gets SKU, Manufacturer part number and GTIN
Expand All @@ -341,7 +338,7 @@ private static void GetSkuMpnGtin(this Product product, string attributesXml, IP
manufacturerPartNumber = null;
gtin = null;

if (!String.IsNullOrEmpty(attributesXml) &&
if (!String.IsNullOrEmpty(attributesXml) &&
product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes)
{
//manage stock by attribute combinations
Expand Down Expand Up @@ -431,70 +428,5 @@ public static string FormatGtin(this Product product, string attributesXml = nul

return gtin;
}


/// <summary>
/// Format base price (PAngV)
/// </summary>
/// <param name="product">Product</param>
/// <param name="productPrice">Product price (in primary currency). Pass null if you want to use a default produce price</param>
/// <param name="localizationService">Localization service</param>
/// <param name="measureService">Measure service</param>
/// <param name="currencyService">Currency service</param>
/// <param name="workContext">Work context</param>
/// <param name="priceFormatter">Price formatter</param>
/// <returns>Base price</returns>
public static async Task<string> FormatBasePrice(this Product product, decimal? productPrice, ILocalizationService localizationService,
IMeasureService measureService, ICurrencyService currencyService,
IWorkContext workContext, IPriceFormatter priceFormatter)
{
if (product == null)
throw new ArgumentNullException("product");

if (localizationService == null)
throw new ArgumentNullException("localizationService");

if (measureService == null)
throw new ArgumentNullException("measureService");

if (currencyService == null)
throw new ArgumentNullException("currencyService");

if (workContext == null)
throw new ArgumentNullException("workContext");

if (priceFormatter == null)
throw new ArgumentNullException("priceFormatter");

if (!product.BasepriceEnabled)
return null;

var productAmount = product.BasepriceAmount;
//Amount in product cannot be 0
if (productAmount == 0)
return null;
var referenceAmount = product.BasepriceBaseAmount;
var productUnit = await measureService.GetMeasureWeightById(product.BasepriceUnitId);
//measure weight cannot be loaded
if (productUnit == null)
return null;
var referenceUnit = await measureService.GetMeasureWeightById(product.BasepriceBaseUnitId);
//measure weight cannot be loaded
if (referenceUnit == null)
return null;

productPrice = productPrice.HasValue ? productPrice.Value : product.Price;

decimal basePrice = productPrice.Value /
//do not round. otherwise, it can cause issues
await measureService.ConvertWeight(productAmount, productUnit, referenceUnit, false) *
referenceAmount;
decimal basePriceInCurrentCurrency = await currencyService.ConvertFromPrimaryStoreCurrency(basePrice, workContext.WorkingCurrency);
string basePriceStr = priceFormatter.FormatPrice(basePriceInCurrentCurrency, true, false);

var result = string.Format(localizationService.GetResource("Products.BasePrice"),
basePriceStr, referenceAmount.ToString("G29"), referenceUnit.Name);
return result;
}
}
}
6 changes: 6 additions & 0 deletions Grand.Web/App_Data/Localization/Upgrade/EN_460_470.nopres.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,11 @@
<LocaleResource Name="Admin.Catalog.Attributes.ProductAttributes.Fields.SeName.Hint">
<Value>Set a search engine friendly name. Leave empty to generate it automatically based on the name of the attribute.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.Fields.ShowOnCatalogPage">
<Value>Show attribute on product catalog pages</Value>
</LocaleResource>
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.Fields.ShowOnCatalogPage.hint">
<Value>Check to show in public store on catalog pages.</Value>
</LocaleResource>
</Language>

6 changes: 6 additions & 0 deletions Grand.Web/App_Data/Localization/defaultResources.grandres.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4315,6 +4315,12 @@
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.Fields.TextPrompt">
<Value>Text prompt</Value>
</LocaleResource>
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.Fields.ShowOnCatalogPage">
<Value>Show attribute on product catalog pages</Value>
</LocaleResource>
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.Fields.ShowOnCatalogPage.hint">
<Value>Check to show in public store on catalog pages.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules">
<Value>Validation rules</Value>
</LocaleResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ public ProductAttributeModel()
}

public string ProductAttributeId { get; set; }

public string Name { get; set; }

public string TextPrompt { get; set; }

public bool IsRequired { get; set; }

public AttributeControlType AttributeControlType { get; set; }

public IList<ProductAttributeValueModel> Values { get; set; }
}

Expand Down
4 changes: 2 additions & 2 deletions Grand.Web/Areas/Admin/Models/Catalog/ProductModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -965,12 +965,12 @@ public ProductAttributeMappingModel()
public IList<SelectListItem> AvailableProductAttribute { get; set; }

[GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.TextPrompt")]

public string TextPrompt { get; set; }

[GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.IsRequired")]
public bool IsRequired { get; set; }

[GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.ShowOnCatalogPage")]
public bool ShowOnCatalogPage { get; set; }
public int AttributeControlTypeId { get; set; }
[GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.AttributeControlType")]
public string AttributeControlType { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Grand.Web/Areas/Admin/Services/ProductViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,7 @@ public virtual async Task DeleteBulkEdit(IList<BulkEditProductModel> products)
ProductAttributeId = x.ProductAttributeId,
TextPrompt = x.TextPrompt,
IsRequired = x.IsRequired,
ShowOnCatalogPage = x.ShowOnCatalogPage,
AttributeControlType = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext),
AttributeControlTypeId = x.AttributeControlTypeId,
DisplayOrder = x.DisplayOrder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@
<div class="col-md-9 col-sm-9">
<label class="mt-checkbox mt-checkbox-outline control control-checkbox">
<admin-input asp-for="IsRequired" />
<div class="control__indicator"></div>
<div class="control__indicator"></div>
</label>
<span asp-validation-for="IsRequired"></span>
</div>
</div>
<div class="form-group">
<admin-label asp-for="ShowOnCatalogPage" class="col-sm-3 control-label" />
<div class="col-md-9 col-sm-9">
<label class="mt-checkbox mt-checkbox-outline control control-checkbox">
<admin-input asp-for="ShowOnCatalogPage" />
<div class="control__indicator"></div>
</label>
<span asp-validation-for="ShowOnCatalogPage"></span>
</div>
</div>
<div class="form-group">
<admin-label asp-for="AttributeControlType" />
<div class="col-md-9 col-sm-9">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
</div>
</div>
<div class="form-group" @(attributeControlType != AttributeControlType.FileUpload ? Html.Raw("style='display: none;'") : null)>
<admin-label asp-for="ValidationFileAllowedExtensions" class="col-sm-3 control-label" />)
<admin-label asp-for="ValidationFileAllowedExtensions" class="col-sm-3 control-label" />
<div class="col-md-9 col-sm-9">
<admin-input asp-for="ValidationFileAllowedExtensions" />
<span asp-validation-for="ValidationFileAllowedExtensions"></span>
</div>
</div>
<div class="form-group" @(attributeControlType != AttributeControlType.FileUpload ? Html.Raw("style='display: none;'") : null)>
<admin-label asp-for="ValidationFileMaximumSize" class="col-sm-3 control-label" />)
<admin-label asp-for="ValidationFileMaximumSize" class="col-sm-3 control-label" />
<div class="col-md-9 col-sm-9">
<admin-input asp-for="ValidationFileMaximumSize" />
<span asp-validation-for="ValidationFileMaximumSize"></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@model ProductModel
@using Grand.Core.Domain.Catalog

<div class="panel panel-default">
<vc:admin-widget widget-zone="product_details_product_attributes_top" additional-data="Model" />
Expand Down Expand Up @@ -111,28 +110,14 @@
field: "AttributeControlTypeId",
title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.AttributeControlType")",
width: 140,
editor: attributeControlTypeDropDownEditor,
template: "#:AttributeControlType#"
template: "#:AttributeControlType# <br> # if(ValidationRulesAllowed) {# <a href='javascript:OpenWindow(\"@Url.Content("~/Admin/Product/ProductAttributeValidationRulesPopup/")#=Id#?&productId=@(Model.Id)&btnId=btnRefreshProductAttributes&formId=product-form\", 800, 300, true);'>@T("Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules.ViewLink")</a><br />#=ValidationRulesString# #} #"
},
{
field: "DisplayOrder",
title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Fields.DisplayOrder")",
width: 70,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" },
//integer format
format: "{0:0}"
}, {
field: "ShouldHaveValues",
title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values")",
width: 60,
template: '# if(ShouldHaveValues) {# <a href="@Url.Content("~/Admin/Product/EditAttributeValues/")?productAttributeMappingId=#=Id#&productId=@(Model.Id)">@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.ViewLink")</a><br />@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.TotalValues") #=TotalValues# #} #'
},
{
field: "ValidationRulesAllowed",
title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules")",
width: 80,
template: "# if(ValidationRulesAllowed) {# <a href='javascript:OpenWindow(\"@Url.Content("~/Admin/Product/ProductAttributeValidationRulesPopup/")#=Id#?&productId=@(Model.Id)&btnId=btnRefreshProductAttributes&formId=product-form\", 800, 300, true);'>@T("Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules.ViewLink")</a><br />#=ValidationRulesString# #} #"},
{
field: "ConditionAllowed",
title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Condition")",
Expand All @@ -152,62 +137,7 @@
});
});
//local datasource
var allProductAttributes = [
@for (int i = 0; i < Model.AvailableProductAttributes.Count; i++)
{
var productAttributeItem = Model.AvailableProductAttributes[i];
<text>
{
Id: '@(productAttributeItem.Value)',
Name: "@(Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode(productAttributeItem.Text)))"
}
</text>
if (i != Model.AvailableProductAttributes.Count - 1)
{
<text>,</text>
}
}
];
var allAttributeControlTypes = [
@{
var allAttributeControlTypes = (from act in AttributeControlType.DropdownList.ToSelectList(Context)
select new {Id = act.Value, Name = act.Text}).ToList();
}
@for (int i = 0; i < allAttributeControlTypes.Count; i++)
{
var attributeControlType = allAttributeControlTypes[i];
<text>
{
Id: '@(attributeControlType.Id)',
Name: "@(Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode(attributeControlType.Name)))"
}
</text>
if (i != allAttributeControlTypes.Count - 1)
{
<text>,</text>
}
}
];
function productAttributeDropDownEditor(container, options) {
$('<input required data-text-field="Name" data-value-field="Id" data-bind="value:ProductAttributeId"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: allProductAttributes
});
}
function attributeControlTypeDropDownEditor(container, options) {
$('<input required data-text-field="Name" data-value-field="Id" data-bind="value:AttributeControlTypeId"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: allAttributeControlTypes
});
}
</script>
<input type="submit" id="btnRefreshProductAttributes" style="display: none" />
<script type="text/javascript">
Expand Down
Loading

0 comments on commit 9a4c2c3

Please sign in to comment.