Inhalte aufrufen

Profilbild
- - - - -

BundleItemModel get Product from ProductService ?


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
1 Antwort zu diesem Thema

#1 FabianO

FabianO

    Newbie

  • Members
  • Punkt
  • 6 Beiträge

Geschrieben: 01 March 2019 - 14:46

Moin,

Ich suche nach einer Möglichkeit über eine ModelExtension des BundleItemModel an das Product aus dem ProductService zu kommen.

Ich muss realisieren, das in den Bestelldetails zu den Positionen eines Bundles auch die die Bilder der bundleItems angezeigt werden.

Im Warenkorb ist das ja Standard.

 

Hier mein Code mit dem ich es Probieren habe.

using SmartStore.Core.Infrastructure;
using SmartStore.Services.Catalog;
using static abc.Web.Models.Order.OrderDetailsModel;

namespace abc.Extensions.SmartstoreExtensions
{
	public static class BundleItemModelExtension
	{
		public static string GetBundleItemImage(this BundleItemModel bundleItemModel)
		{
			var productService = EngineContext.Current.Resolve<IProductService>();
			// var fileName = productService.GetProductBySystemName(orderItemModel.ProductSeName);
			//productService.GetProductById
			var url = bundleItemModel.ProductUrl;
			// var test = productService.GetBundleItems(orderItemModel.ProductId)[0].Item.Product.ProductPictures;
			return "";
		}
	}
}

Wie komme ich an die Bilder ?

Über die ProductId des Bundles würde das vlt. gehen, aber wie kann ich das dann den einzelnen Positionen in der View zuordnen ? 

@helper BundleProducts(OrderDetailsModel.OrderItemModel parentItem)
{
	if (parentItem.BundleItems != null)
	{
		foreach (var item in parentItem.BundleItems.OrderBy(x => x.DisplayOrder))
		{
			<div class="cart-row cart-row-child">
				<div class="cart-col cart-col-main">
					<div class="row sm-gutters">
						<div class="col cart-item-img">
							<!-- Spacer -->
						</div>
						<div class="col">
							<div class="mr-3" style="@("width: {0}px;".FormatInvariant(Math.Min(60, 60)))">
								@if (string.IsNullOrEmpty(item.GetBundleItemImage())) // Kommt von mir
								{
									<img class="img-fluid" src="@parentItem.Picture.ImageUrl" alt="@parentItem.Picture.AlternateText" title="@parentItem.Picture.Title" />
								}
							</div>
							@if (item.Quantity > 1 && parentItem.BundlePerItemShoppingCart)
							{
								<span class="font-weight-medium">@(item.Quantity)&nbsp;&#215;</span>
							}
							@if (item.VisibleIndividually)
							{
								<a class="cart-item-link" href="@item.ProductUrl" title="@T("Products.Details")" dir="auto">@item.ProductName</a>
							}
							else
							{
								<span class="cart-item-link" dir="auto">@item.ProductName</span>
							}
							@if (item.AttributeInfo.HasValue())
							{
								<div class="cart-item-attrs">
									@Html.Raw(item.AttributeInfo)
								</div>
							}
						</div>
					</div>
				</div>
				<div class="cart-col cart-col-price">
					@if (item.PriceWithDiscount.HasValue())
					{			
						<span class="price">@Html.Raw(item.PriceWithDiscount)</span>
					}
					else
					{
						<text>&nbsp;</text>
					}
				</div>
				<div class="cart-col">&nbsp;</div>
				<div class="cart-col">&nbsp;</div>
			</div>
		}
	}
}

Angehängte Bilder


  • RidgeOi und Brantot gefällt das

#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 01 March 2019 - 20:28

Ein wenig Pseudo-Code:
var product = productService.GetProductBySku(BundleItemModel.Sku);
var picture = pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
var pictureUrl = pictureService.GetUrl(picture, 32, false);
Besser BundleItemModel.ProductId hinzufügen und mit GetProductById laden.
 
Noch besser: ähnlich nachbauen wie es im ShoppingCartController gemacht wurde. BundleItemModel also ähnlich wie ShoppingCartItemModel erweitern, sprich PictureModel hinzufügen und ähnlich wie hier aufbauen.

  • RidgeOi gefällt das

Marcus Gesing

Smartstore AG