Skip to content

Commit

Permalink
Merged PR 12604: #18562 - ProductReplacement: Add to cart disabled st…
Browse files Browse the repository at this point in the history
…ate fix

#18562 - ProductReplacement: Add to cart disabled state fix

Related work items: #18562
  • Loading branch information
smnDW committed Apr 3, 2024
2 parents 7c0703c + 2d706bb commit 6e6e3f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@inherits ViewModelTemplate<ProductListViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Ecommerce.ProductCatalog
@using Dynamicweb.Ecommerce.Products

@{
string orderId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("OrderID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("OrderID") : "";
Expand Down Expand Up @@ -60,10 +61,9 @@
}
}
}

var products = order == null ? Model.Products : orderProducts;
bool hasDiscontinuedProducts = products.Any(p => p.Discontinued && !string.IsNullOrEmpty(p.ReplacementProduct.ProductId) && p.ReplacementProduct.GetProduct() != null
&& p.ReplacementProduct.GetProduct().Active && (p.ReplacementProduct.GetProduct().StockLevel > 0 || p.ReplacementProduct.GetProduct().NeverOutOfstock));
&& p.ReplacementProduct.GetProduct().Active && (p.ReplacementProduct.GetProduct().ProductType != ProductType.Stock || p.ReplacementProduct.GetProduct().StockLevel >= 0 || p.ReplacementProduct.GetProduct().NeverOutOfstock));
}

@if (products.Any())
Expand Down Expand Up @@ -93,9 +93,11 @@
productCounter += 1;

ProductViewModel replacementProduct = product.Discontinued && product.ReplacementProduct != null && !string.IsNullOrEmpty(product.ReplacementProduct.ProductId) ? product.ReplacementProduct.GetProduct() : null;
bool showReplacementProduct = product.Discontinued && replacementProduct != null && replacementProduct.Active && (replacementProduct.StockLevel > 0 || replacementProduct.NeverOutOfstock);

if ((product.StockLevel < 1 && !product.NeverOutOfstock) || product.Discontinued)
bool showReplacementProduct = product.Discontinued && replacementProduct != null && replacementProduct.Active && (replacementProduct.ProductType != ProductType.Stock || replacementProduct.StockLevel > 0 || replacementProduct.NeverOutOfstock);


if ((product.StockLevel <= 0 && !product.NeverOutOfstock) || product.Discontinued)
{
<tr>
<td class="align-middle">
Expand Down Expand Up @@ -233,9 +235,8 @@
}

ProductViewModel replacementProduct = product.Discontinued && product.ReplacementProduct != null && !string.IsNullOrEmpty(product.ReplacementProduct.ProductId) ? product.ReplacementProduct.GetProduct() : null;
bool showReplacementProduct = product.Discontinued && replacementProduct != null && replacementProduct.Active && (replacementProduct.StockLevel > 0 || replacementProduct.NeverOutOfstock);
bool showReplacementProduct = product.Discontinued && replacementProduct != null && replacementProduct.Active && (replacementProduct.ProductType != ProductType.Stock || (replacementProduct.StockLevel > 0 || replacementProduct.NeverOutOfstock));
string replacementProductFeed = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl("Default.aspx?ID=" + GetPageIdByNavigationTag("ReorderReplacement") + "&ProductId=" + product.Id + "&productCounter=" + productCounter + "&quantity=" + quantity + "&getproductinfo=true");

<article class="grid grid-10 grid-lg-12 gap-2 g-col-12 align-items-center align-items-lg-center product js-replacement-product @disableOrderline" data-product-counter="@productCounter" data-replacement-feed="@replacementProductFeed">

<div class="d-none d-lg-block g-col-12 border-top"></div>
Expand Down Expand Up @@ -300,7 +301,6 @@
</div>

</article>

if (product.Discontinued && showReplacementProduct)
{
<div class="position-relative start-50 translate-middle d-flex g-start-8 js-product-replacements-button" data-product-counter="@productCounter" data-replacing-message="@($"{Translate("Replacing")} {product.Name}")" data-replace-refused-message="@Translate("Replacement Refused")">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
string replacementProductLink = replacementProduct.GetProductLink(GetPageIdByNavigationTag("Shop"), false);
string replacementProductStockState = replacementProduct.NeverOutOfstock ? Translate("In stock") : $"{replacementProduct.StockLevel} {Translate("In stock")}";
string replacementProductPrice = showPricesWithVat == "false" && !neverShowVat ? replacementProduct.PriceBeforeDiscount.PriceWithoutVatFormatted : replacementProduct.PriceBeforeDiscount.PriceFormatted;


string disableQuantityField = null;
double? stepQty = replacementProduct.PurchaseQuantityStep > 0 ? replacementProduct.PurchaseQuantityStep : 1;
double? minQty = replacementProduct.PurchaseMinimumQuantity > 0 ? replacementProduct.PurchaseMinimumQuantity : 1;
double? valueQty = minQty > stepQty ? minQty : stepQty;
bool isStockType = replacementProduct.ProductType == ProductType.Stock;
bool setMaxQty = isStockType && !replacementProduct.NeverOutOfstock;
double? maxQty = setMaxQty ? replacementProduct.StockLevel : null;
double? maxQty = null;
bool isStockType = replacementProduct.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock;

if (isStockType && !replacementProduct.NeverOutOfstock)
{
disableQuantityField = (replacementProduct.StockLevel <= 0) || replacementProduct.Discontinued ? "disabled" : disableQuantityField;
maxQty = replacementProduct.StockLevel;
}

string disableQuantityField = (replacementProduct.StockLevel < 1 && !replacementProduct.NeverOutOfstock) || replacementProduct.Discontinued ? "disabled" : "";
int productCounter = Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("productCounter"));
double? quantity = Converter.ToDouble(Dynamicweb.Context.Current.Request.QueryString.Get("quantity"));

Expand Down Expand Up @@ -144,10 +148,10 @@
{
<div class="fs-8 fs-lg-6 text-end text-lg-start text-danger productStockState">@Translate("Discontinued")</div>
}
else if (replacementProduct.NeverOutOfstock)
else if (!isStockType || replacementProduct.NeverOutOfstock)
{
<div class="fs-8 fs-lg-6 text-end text-lg-start text-success">@Translate("In stock")</div>
} else if (replacementProduct.StockLevel > 0)
} else if (isStockType && replacementProduct.StockLevel > 0)
{
<div class="fs-8 fs-lg-6 text-end text-lg-start text-success">@replacementProduct.StockLevel @Translate("In stock")</div>
}
Expand Down

0 comments on commit 6e6e3f3

Please sign in to comment.