Skip to content

Add UpdateProductInViewModel#71

Open
DWDBE wants to merge 1 commit into
mainfrom
dbe/28599-Add-UpdateProductInViewModel-method-for-Swift
Open

Add UpdateProductInViewModel#71
DWDBE wants to merge 1 commit into
mainfrom
dbe/28599-Add-UpdateProductInViewModel-method-for-Swift

Conversation

@DWDBE

@DWDBE DWDBE commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@DWDBE DWDBE requested review from a team as code owners June 26, 2026 10:33
@DWDBE DWDBE requested a review from MatthiasSort June 26, 2026 10:34
string unitId = settings.UseUnitPrices ? productForRequest.DefaultUnitId : null;
var productSelection = productForRequest.GetPriceProductSelection(1, unitId);

var productInfo = ProductManager.GetProductInfo(productForRequest, settings, user);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: cache lookup/fetch is not currency-aware. GetProductInfo(productForRequest, settings, user) ignores the current currency, and FetchProductInfos(..., false, ...) can reuse another currency's cached ProductInfo. Pass the context/unit to GetProductInfo and enable currency checking on fetch.

if (productInfo == null)
return;

ProductManager.ProductProvider.FillProductValues(productInfo, loadedProduct, settings, productSelection.Quantity, context);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: this mutates loadedProduct, not the ProductViewModel passed in. If ProductFields or price lazy properties were already evaluated, the caller still sees stale values. Rebuild/assign the affected view-model properties or return a refreshed ProductViewModel.

var logger = new Logging.Logger(settings);
bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault");
var productForRequest = showVariantDefault ? ProductManager.ProductProvider.GetProductFromVariantComboId(loadedProduct, logger) : loadedProduct;
var context = new LiveContext(Helpers.GetCurrentCurrency(), user, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: new LiveContext(GetCurrentCurrency(), user, null) leaves both Shop and PriceContext null. Because PriceContext is null, FillProductValues (line 165) writes the price into a throwaway new PriceContext(...) (see ProductProviderBase.FillProductValues/GetPriceInfoCore) that is then discarded — so the price computation here has no lasting effect, independent of the view-model issue noted on line 165. The live-price hook does the opposite: ProductPriceProvider.PreparePrices builds new LiveContext(context) so the request's real PriceContext (and shop) is used. Thread the caller's PriceContext/shop in here too. Also note settings/shopId come from Global.CurrentShopId, but the context shop is null, so the fetch runs shop-less while the settings are shop-scoped.


var logger = new Logging.Logger(settings);
bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault");
var productForRequest = showVariantDefault ? ProductManager.ProductProvider.GetProductFromVariantComboId(loadedProduct, logger) : loadedProduct;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: with ShowVariantDefault on, productForRequest is the variant-combo product and drives GetProductInfo, FetchProductInfos, and productSelection (lines 148-159), but FillProductValues is then applied to loadedProduct (the base product), not productForRequest (line 165). ProductPriceProvider.PreparePrices/FindPriceInfo use the same product throughout. Please confirm this cross-apply is intended — otherwise the base product is filled from the combo product's info (or from none, if the identifiers differ).


// Update Product Custom Fields
if (settings.AddProductFieldsToRequest && product.ProductFieldValues.Count > 0)
if (settings.AddProductFieldsToRequest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: dropping && product.ProductFieldValues.Count > 0 has no functional effect here — FillProductFieldValues only foreaches over product.ProductFieldValues, so an empty collection is already a no-op. If the intent was to populate/send fields when the in-memory collection is empty, this change doesn't achieve it; if it's just simplification, it's harmless but doesn't change behaviour.

AddChildXmlNode(itemNode, "Quantity", productWithQuantity.Quantity.ToIntegrationString(currentSettings, logger));

if (settings.AddProductFieldsToRequest && product.ProductFieldValues.Count > 0)
if (settings.AddProductFieldsToRequest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: same as the ProductProviderBase change — AppendProductFields only iterates product.ProductFieldValues, so dropping the Count > 0 guard produces identical XML (no custom-field nodes when the collection is empty). No-op unless the goal was to emit something for the empty case, which this doesn't do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants