Our client works with a food product that can be packaged and sold in different weights. One product mixes other products on the site together and is sold by weight at a fixed price. Up to 8 different products from the website can be mixed of 50 or more different items.
I configured this on nopCommerce 4.40.4 by:
1. Creating a simple item for the mixed product
2. Adding Attributes to the mixed product as dropdown boxes
2. Creating simple products for each product that can be added to the mix, items that are published, not visible individually, in an unpublished category, and have the same names as the stand-alone product.
4. Adding Attribute Values Associated to Product and attached to each of these products
Issue:
Because the client has so many products that can be added to the mix, she would like any unpublished or deleted products that are attached to this mixed product to no longer display. I tested and determined that current behavior is to continue to display the values and, if selected as a product to add to the mix, Add to Cart then displays an error message indicated that the product is unpublished or deleted. We need them to not display at all.
I see some potential solutions in the forum that involve tracking inventory, but our client does not want to do that. Instead, I've located code that displays the dropdown box in _ProductAttributes.cshtml in the /Views/Products/ folder and am trying to add code to only add the <option> line if:
Attribute value is "Simple" OR
(Attribute value is "Associated to Product" AND
Associated product is published AND
Associated product is not deleted)
I would like to modify Lines 39-46 like this (pseudo code):
@foreach (var attributeValue in attribute.Values)
{
If (attribute is "Simple" OR (attribute is "Associated to Product" AND AssociatedProduct is Published AND AssociatedProduct is not Deleted))
{
var attributeName = string.IsNullOrEmpty(attributeValue.PriceAdjustment) ?
attributeValue.Name :
T("Products.ProductAttributes.PriceAdjustment", attributeValue.Name, attributeValue.PriceAdjustment,
attributeValue.CustomerEntersQty ? T("Products.ProductAttributes.PriceAdjustment.PerItem").Text : string.Empty).Text;
<option data-attr-value="@attributeValue.Id" selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">@attributeName</option>
}
}
where
var attribute in Model.ProductAttributes; and
var attributeValue in attribute.Values
Per documentation, it seems I need to reference AttributeValueTypeId and AssociatedProductId to do this, but my understanding of nopCommerce coding is weak and I could not see how to reference those. Does someone know how to implement the IF statement?