Skip to content

Missing image not showing when using digital assets and the image file is missing #62

@ivaigor96

Description

@ivaigor96

For local Swift2 development on customer solutions that use digital assets for product images, not image patterns, when cloning the repisitory and running the project on a local machine, the product images are missing
This leads to the following front end behavior

The worst one is the product details page - this shows a stack trace because of the following code causing a null reference exception on assetValue

foreach (MediaViewModel asset in assetsList)
{
	var assetValue = asset.Value;

	foreach (string format in allSupportedFormats)
	{
		if (assetValue.IndexOf(format, StringComparison.OrdinalIgnoreCase) >= 0)
		{
			totalAssets++;
		}
	}
}

The fix is rather simple

var assetValue = asset?.Value; if (string.IsNullOrWhiteSpace(assetValue)) continue;

Product slider, product list - basically nothing is shown when the asset is missing. The missing image image is only shown when there are no assets selected on the product in the back end as seen on items 5 and 6 from the left in the example below

Image

Mini cart, potentially cart and express buy cart summary as well

Image

The image here is even worse, it is showing the chrome mising image icon and image name instead

The problem is with this code

string image = product?.DefaultImage?.Value ?? string.empty;

The DefaultImage should either return missing image if null or there should be another check
This workaround works, but it's not the cleanest

string image = product?.DefaultImage?.Value ?? Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/Ecom/Picture/NoPicture/Large_path");

I am pointing these issues out because it is very easy to fix, but causes a lot of problems (especially the exception) when developing in Swift1 and now these bugs have also been carried out to Swift2

I have made these adjustments on some templates, but I don't have permissions to make a PR here on github with my user, so it would be complicated to actually share the code without making my own Swift2 repo

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions