Skip to content

Commit 40cda6f

Browse files
committed
A product cannot be linked to itself through linkage attribute
1 parent 707e4d8 commit 40cda6f

File tree

8 files changed

+21
-9
lines changed

8 files changed

+21
-9
lines changed

src/Presentation/SmartStore.Web/Administration/Controllers/ProductController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,16 +3029,17 @@ public ActionResult ProductAttributeValueCreatePopup(int productAttributeAttribu
30293029
if (pva == null)
30303030
throw new ArgumentException(T("Products.Variants.NotFound", productAttributeAttributeId));
30313031

3032-
var model = new ProductModel.ProductVariantAttributeValueModel()
3032+
var model = new ProductModel.ProductVariantAttributeValueModel
30333033
{
3034+
ProductId = pva.ProductId,
30343035
ProductVariantAttributeId = productAttributeAttributeId,
30353036
DisplayColorSquaresRgb = pva.AttributeControlType == AttributeControlType.ColorSquares,
30363037
ColorSquaresRgb = "#000000",
30373038
Quantity = 1
30383039
};
30393040

3040-
//locales
30413041
AddLocales(_languageService, model.Locales);
3042+
30423043
return View(model);
30433044
}
30443045

@@ -3069,7 +3070,7 @@ public ActionResult ProductAttributeValueCreatePopup(string btnId, string formId
30693070

30703071
if (ModelState.IsValid)
30713072
{
3072-
var pvav = new ProductVariantAttributeValue()
3073+
var pvav = new ProductVariantAttributeValue
30733074
{
30743075
ProductVariantAttributeId = model.ProductVariantAttributeId,
30753076
Name = model.Name,
@@ -3108,8 +3109,9 @@ public ActionResult ProductAttributeValueEditPopup(int id)
31083109

31093110
var linkedProduct = _productService.GetProductById(pvav.LinkedProductId);
31103111

3111-
var model = new ProductModel.ProductVariantAttributeValueModel()
3112+
var model = new ProductModel.ProductVariantAttributeValueModel
31123113
{
3114+
ProductId = pvav.ProductVariantAttribute.ProductId,
31133115
ProductVariantAttributeId = pvav.ProductVariantAttributeId,
31143116
Name = pvav.Name,
31153117
Alias = pvav.Alias,
@@ -3136,7 +3138,6 @@ public ActionResult ProductAttributeValueEditPopup(int id)
31363138
model.QuantityInfo = " × {0}".FormatWith(model.Quantity);
31373139
}
31383140

3139-
//locales
31403141
AddLocales(_languageService, model.Locales, (locale, languageId) =>
31413142
{
31423143
locale.Name = pvav.GetLocalized(x => x.Name, languageId, false, false);

src/Presentation/SmartStore.Web/Administration/Models/Catalog/ProductModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ public ProductVariantAttributeValueModel()
628628
Locales = new List<ProductVariantAttributeValueLocalizedModel>();
629629
}
630630

631+
public int ProductId { get; set; }
631632
public int ProductVariantAttributeId { get; set; }
632633

633634
[SmartResourceDisplayName("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.Fields.Alias")]

src/Presentation/SmartStore.Web/Administration/Views/Product/_CreateOrUpdateProductAttributeValue.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
url: '@Url.Action("EntityPicker", "Common", new { area = "" })',
5151
caption: '@T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.Fields.LinkedProduct.AddNew")',
5252
maxReturnValues: 1,
53+
disableIds: '@Model.ProductId',
5354
onLoadDialogBefore: function () {
5455
$('#AddProductLinkageButton').button('loading').prop('disabled', true);
5556
},

src/Presentation/SmartStore.Web/Content/smartstore.entitypicker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
margin: 5px 0;
2727
border-radius: 3px;
2828
}
29-
.entity-picker-list .item:hover {
29+
.entity-picker-list .item:not(.disable):hover {
3030
cursor: pointer;
3131
}
3232
.entity-picker-list .item:not(.selected):hover {

src/Presentation/SmartStore.Web/Controllers/CommonController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,11 @@ public ActionResult EntityPicker(EntityPickerModel model, FormCollection form)
10551055
model.PublishedString = T("Common.Published");
10561056
model.UnpublishedString = T("Common.Unpublished");
10571057

1058-
var disableIf = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
1059-
10601058
try
10611059
{
1060+
var disableIf = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
1061+
var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
1062+
10621063
using (var scope = new DbContextScope(_services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true))
10631064
{
10641065
if (model.Entity.IsCaseInsensitiveEqual("product"))
@@ -1118,6 +1119,10 @@ orderby grp.Key
11181119
{
11191120
item.Disable = (x.ProductTypeId != (int)ProductType.SimpleProduct);
11201121
}
1122+
else
1123+
{
1124+
item.Disable = disableIds.Contains(x.Id);
1125+
}
11211126

11221127
if (x.ProductTypeId == (int)ProductType.GroupedProduct)
11231128
{

src/Presentation/SmartStore.Web/Models/Common/EntityPickerModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class EntityPickerModel : ModelBase
1414
public string Entity { get; set; }
1515
public bool HighligtSearchTerm { get; set; }
1616
public string DisableIf { get; set; }
17+
public string DisableIds { get; set; }
1718
public string SearchTerm { get; set; }
1819
public string ReturnField { get; set; }
1920
public int MaxReturnValues { get; set; }

src/Presentation/SmartStore.Web/Scripts/smartstore.entityPicker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
entity: 'product',
6363
caption: '&nbsp;',
6464
disableIf: '',
65+
disableIds: '',
6566
thumbZoomer: false,
6667
highligtSearchTerm: true,
6768
returnField: 'id',
@@ -133,7 +134,8 @@
133134
"HighligtSearchTerm": opt.highligtSearchTerm,
134135
"ReturnField": opt.returnField,
135136
"MaxReturnValues": opt.maxReturnValues,
136-
"DisableIf": opt.disableIf
137+
"DisableIf": opt.disableIf,
138+
"DisableIds": opt.disableIds
137139
},
138140
url: opt.url,
139141
beforeSend: function () {

src/Presentation/SmartStore.Web/Views/Common/EntityPicker.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<input type="hidden" name="ReturnField" value="@Model.ReturnField" />
1414
<input type="hidden" name="MaxReturnValues" value="@Model.MaxReturnValues" />
1515
<input type="hidden" name="DisableIf" value="@Model.DisableIf" />
16+
<input type="hidden" name="DisableIds" value="@Model.DisableIds" />
1617
<input type="hidden" name="PageIndex" value="@Model.PageIndex" />
1718

1819
@if (Model.Entity.IsCaseInsensitiveEqual("product"))

0 commit comments

Comments
 (0)