Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying a product with attribute combinations results in incorrect StockQuantityHistory entry #7202

Closed
GordonBlahut opened this issue May 23, 2024 · 2 comments
Assignees
Labels

Comments

@GordonBlahut
Copy link

I believe there is a bug in the ProductCopyService.CopyAttributesMappingAsync method at the call to _productService.AddStockQuantityHistoryEntryAsync on lines 371-373.

The combinationId parameter receives combination.Id, but I believe that combinationCopy.Id would be more appropriate. Currently, the resulting entry in the StockQuantityHistory table references the product copy's id but the original comination's id and this causes issues when trying to reconcile inventory history for products with attribute combinations.

var combinationCopy = new ProductAttributeCombination
{
ProductId = productCopy.Id,
AttributesXml = newAttributesXml,
StockQuantity = combination.StockQuantity,
MinStockQuantity = combination.MinStockQuantity,
AllowOutOfStockOrders = combination.AllowOutOfStockOrders,
Sku = combination.Sku,
ManufacturerPartNumber = combination.ManufacturerPartNumber,
Gtin = combination.Gtin,
OverriddenPrice = combination.OverriddenPrice,
NotifyAdminForQuantityBelow = combination.NotifyAdminForQuantityBelow
};
await _productAttributeService.InsertProductAttributeCombinationAsync(combinationCopy);
//picture
var oldCombinationPictures = await _productAttributeService.GetProductAttributeCombinationPicturesAsync(combination.Id);
foreach (var oldCombinationPicture in oldCombinationPictures)
{
if (!originalNewPictureIdentifiers.TryGetValue(oldCombinationPicture.PictureId, out var combinationPictureId))
continue;
await _productAttributeService.InsertProductAttributeCombinationPictureAsync(new ProductAttributeCombinationPicture
{
ProductAttributeCombinationId = combinationCopy.Id,
PictureId = combinationPictureId
});
}
//quantity change history
await _productService.AddStockQuantityHistoryEntryAsync(productCopy, combination.StockQuantity,
combination.StockQuantity,
message: string.Format(await _localizationService.GetResourceAsync("Admin.StockQuantityHistory.Messages.CopyProduct"), product.Id), combinationId: combination.Id);

I would also argue there's a valid use case for wanting to copy a product and attribute combinations without copying any inventory information but that's a separate issue.

@parshan2
Copy link
Contributor

You are absolutely right. This issue also causes an exception error when copying products with attribute combinations. I have also fixed two other parameter issues in the AddStockQuantityHistoryEntryAsync method call. I have just created an equivalent pull request for this.

parshan2 added a commit to parshan2/nopCommerce that referenced this issue May 26, 2024
skoshelev pushed a commit that referenced this issue Jun 5, 2024
@skoshelev
Copy link
Contributor

Closed #7202

skoshelev pushed a commit that referenced this issue Jun 5, 2024
…en copy a product with combinations

(cherry picked from commit 6050d0c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants