Skip to content

Commit

Permalink
Resolves #791 Preselected attributes or attribute combinations should…
Browse files Browse the repository at this point in the history
… always be appended as querystring to product page links (part 1)

Perf: Flyout shopping cart must not round-trip the database for bundle item data, OrganizedShoppingCart already provides it
Flyout shopping cart should consider ShoppingCartSettings.ShowProductBundleImagesOnShoppingCart
  • Loading branch information
mgesing committed Oct 22, 2015
1 parent c31f25b commit 0f8ddbf
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 39 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* #778 Web-API: Increase MaxExpansionDepth for using expand pathes
* #767 Remove assignments to a grouped product if the grouped product is deleted
* #773 Reduce number of guest records created by search engine requests
* #791 Preselected attributes or attribute combinations should always be appended as querystring to product page links

### Bugfixes
* #523 Redirecting to payment provider performed by core instead of plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,7 @@ public ActionResult ProductVariantAttributeCombinationList(GridCommand command,

var productUrlTitle = _localizationService.GetResource("Common.OpenInShop");
var productUrl = Url.RouteUrl("Product", new { SeName = product.GetSeName() });
productUrl = "{0}{1}attributes=".FormatWith(productUrl, productUrl.Contains("?") ? "&" : "?");
productUrl = "{0}{1}attributes=".FormatInvariant(productUrl, productUrl.Contains("?") ? "&" : "?");

var productVariantAttributesModel = allCombinations.Select(x =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private ShoppingCartModel.ShoppingCartItemModel PrepareShoppingCartItemModel(Org

product.MergeWithCombination(item.AttributesXml);

var model = new ShoppingCartModel.ShoppingCartItemModel()
var model = new ShoppingCartModel.ShoppingCartItemModel
{
Id = item.Id,
Sku = product.Sku,
Expand All @@ -235,10 +235,12 @@ private ShoppingCartModel.ShoppingCartItemModel PrepareShoppingCartItemModel(Org
IsShipEnabled = product.IsShipEnabled,
ShortDesc = product.GetLocalized(x => x.ShortDescription),
ProductType = product.ProductType,
BasePrice = product.GetBasePriceInfo(_localizationService, _priceFormatter, _currencyService, _taxService, _priceCalculationService, _workContext.WorkingCurrency),
Weight = product.Weight
BasePrice = product.GetBasePriceInfo(_localizationService, _priceFormatter, _currencyService, _taxService, _priceCalculationService, _workContext.WorkingCurrency),
Weight = product.Weight
};

model.ProductUrl = GetProductUrl(item, model.ProductSeName);

if (item.BundleItem != null)
{
model.BundlePerItemPricing = item.BundleItem.BundleProduct.BundlePerItemPricing;
Expand Down Expand Up @@ -419,7 +421,7 @@ private WishlistModel.ShoppingCartItemModel PrepareWishlistCartItemModel(Organiz

product.MergeWithCombination(item.AttributesXml);

var model = new WishlistModel.ShoppingCartItemModel()
var model = new WishlistModel.ShoppingCartItemModel
{
Id = item.Id,
Sku = product.Sku,
Expand All @@ -432,6 +434,8 @@ private WishlistModel.ShoppingCartItemModel PrepareWishlistCartItemModel(Organiz
VisibleIndividually = product.VisibleIndividually
};

model.ProductUrl = GetProductUrl(item, model.ProductSeName);

if (item.BundleItem != null)
{
model.BundlePerItemPricing = item.BundleItem.BundleProduct.BundlePerItemPricing;
Expand Down Expand Up @@ -587,6 +591,20 @@ private void PrepareButtonPaymentMethodModel(ButtonPaymentMethodModel model, ILi
}
}

private string GetProductUrl(ShoppingCartItem cartItem, string productSeName)
{
var url = Url.RouteUrl("Product", new { SeName = productSeName });

var queryString = _productAttributeParser.SerializeQueryData(cartItem.ProductId, cartItem.AttributesXml);

if (queryString.HasValue())
{
url = string.Concat(url, url.Contains("?") ? "&" : "?", "attributes=", queryString);
}

return url;
}

/// <summary>
/// Prepare shopping cart model
/// </summary>
Expand Down Expand Up @@ -960,7 +978,7 @@ protected MiniShoppingCartModel PrepareMiniShoppingCartModel()
.Take(_shoppingCartSettings.MiniShoppingCartProductNumber)
.ToList())
{
var cartItemModel = new MiniShoppingCartModel.ShoppingCartItemModel()
var cartItemModel = new MiniShoppingCartModel.ShoppingCartItemModel
{
Id = sci.Item.Id,
ProductId = sci.Item.Product.Id,
Expand All @@ -977,23 +995,27 @@ protected MiniShoppingCartModel PrepareMiniShoppingCartModel()
allowHyperlinks: false)
};

if (sci.Item.Product.ProductType == ProductType.BundledProduct)
{
var bundleItems = _productService.GetBundleItems(sci.Item.Product.Id);
foreach (var bundleItem in bundleItems)
{
var bundleItemModel = new MiniShoppingCartModel.ShoppingCartItemBundleItem();
bundleItemModel.ProductName = bundleItem.Item.Product.GetLocalized(x => x.Name);
var bundlePic = _pictureService.GetPicturesByProductId(bundleItem.Item.ProductId).FirstOrDefault();
if(bundlePic != null)
bundleItemModel.PictureUrl = _pictureService.GetPictureUrl(bundlePic.Id, 32);
cartItemModel.ProductUrl = GetProductUrl(sci.Item, cartItemModel.ProductSeName);

bundleItemModel.ProductSeName = bundleItem.Item.Product.GetSeName();
if (sci.ChildItems != null && _shoppingCartSettings.ShowProductBundleImagesOnShoppingCart)
{
foreach (var childItem in sci.ChildItems.Where(x => x.Item.Id != sci.Item.Id && x.Item.BundleItem != null && !x.Item.BundleItem.HideThumbnail))
{
var bundleItemModel = new MiniShoppingCartModel.ShoppingCartItemBundleItem
{
ProductName = childItem.Item.Product.GetLocalized(x => x.Name),
ProductSeName = childItem.Item.Product.GetSeName(),
};

if (!bundleItem.Item.HideThumbnail)
cartItemModel.BundleItems.Add(bundleItemModel);
}
}
bundleItemModel.ProductUrl = GetProductUrl(childItem.Item, bundleItemModel.ProductSeName);

var itemPicture = _pictureService.GetPicturesByProductId(childItem.Item.ProductId, 1).FirstOrDefault();
if (itemPicture != null)
bundleItemModel.PictureUrl = _pictureService.GetPictureUrl(itemPicture.Id, 32);

cartItemModel.BundleItems.Add(bundleItemModel);
}
}

//unit prices
if (sci.Item.Product.CallForPrice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public ShoppingCartItemModel()

public string ProductSeName { get; set; }

public string ProductUrl { get; set; }

public int Quantity { get; set; }

public string UnitPrice { get; set; }
Expand All @@ -57,6 +59,7 @@ public partial class ShoppingCartItemBundleItem : ModelBase
public string PictureUrl { get; set; }
public string ProductName { get; set; }
public string ProductSeName { get; set; }
public string ProductUrl { get; set; }
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public ShoppingCartItemModel()

public string ProductSeName { get; set; }

public string ProductUrl { get; set; }

public bool VisibleIndividually { get; set; }

public ProductType ProductType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public ShoppingCartItemModel()
ChildItems = new List<ShoppingCartItemModel>();
BundleItem = new BundleItemModel();
}

public string Sku { get; set; }

public PictureModel Picture {get;set;}
Expand All @@ -61,6 +62,8 @@ public ShoppingCartItemModel()

public string ProductSeName { get; set; }

public string ProductUrl { get; set; }

public bool VisibleIndividually { get; set; }

public ProductType ProductType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@if (Model.ShowProductImages)
{
<figure class="picture pull-left">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@item.Picture.Title">
<a href="@item.ProductUrl" title="@item.Picture.Title">
<img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
</a>
</figure>
Expand All @@ -41,7 +41,7 @@
@(item.Quantity)<span class="times">x</span>
</div>
<div class="data pull-left">
<a class="name" href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@item.ProductName">@item.ProductName</a>
<a class="name" href="@item.ProductUrl" title="@item.ProductName">@item.ProductName</a>
@if (item.AttributeInfo.HasValue())
{
<br />
Expand Down Expand Up @@ -71,19 +71,16 @@
{
var bundleItem = item.BundleItems[j];

<a href="@Url.RouteUrl("Product", new { SeName = bundleItem.ProductSeName })" title="@bundleItem.ProductName">
<img alt="@bundleItem.ProductName" src="@bundleItem.PictureUrl" title="@bundleItem.ProductName" />
</a>
<a href="@bundleItem.ProductUrl" title="@bundleItem.ProductName">
<img alt="@bundleItem.ProductName" src="@bundleItem.PictureUrl" title="@bundleItem.ProductName" /></a>

if (bundlelength != (j + 1))
{
<i class="fa fa-plus"></i>
}

}
</div>
}

</li>
}
@if (Model.IgnoredProductsCount > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@if (Model.ShowProductImages)
{
<figure class="picture pull-left">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@item.Picture.Title">
<a href="@item.ProductUrl" title="@item.Picture.Title">
<img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
</a>
</figure>
Expand All @@ -37,7 +37,7 @@
@(item.Quantity)<span class="times">x</span>
</div>
<div class="data pull-left">
<a class="name" href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@item.ProductName">@item.ProductName</a>
<a class="name" href="@item.ProductUrl" title="@item.ProductName">@item.ProductName</a>
@if (item.AttributeInfo.HasValue())
{
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="bundle-item-name">
@if (item.VisibleIndividually)
{
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@T("Products.Details")">@item.ProductName</a>
<a href="@item.ProductUrl" title="@T("Products.Details")">@item.ProductName</a>
}
else
{
Expand Down Expand Up @@ -81,7 +81,7 @@
<li>
<div class="cart-item-row">
<div class="product">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
<a href="@item.ProductUrl" title="View details">@item.ProductName</a>
@if (!String.IsNullOrEmpty(item.AttributeInfo))
{
<div class="attributes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</td>
}
<td class="product">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@T("Products.Details")">@item.ProductName</a>
<a href="@item.ProductUrl" title="@T("Products.Details")">@item.ProductName</a>

@if (Model.DisplayShortDesc && !String.IsNullOrEmpty(item.ShortDesc))
{
Expand Down Expand Up @@ -151,7 +151,7 @@
<div class="bundle-item">
@if (Model.ShowProductBundleImages)
{
<div class="bundle-item-image" style="@("min-width: {0}px; min-height: {0}px;".FormatWith(Model.BundleThumbSize + 10))">
<div class="bundle-item-image" style="@("min-width: {0}px; min-height: {0}px;".FormatInvariant(Model.BundleThumbSize + 10))">
@if (!item.BundleItem.HideThumbnail)
{
<img class="img-polaroid" src="@item.Picture.ImageUrl" alt="@item.Picture.AlternateText" title="@item.Picture.Title" />
Expand All @@ -162,7 +162,7 @@
<div class="bundle-item-name">
@if (item.VisibleIndividually)
{
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@T("Products.Details")">@item.ProductName</a>
<a href="@item.ProductUrl" title="@T("Products.Details")">@item.ProductName</a>
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="bundle-item-name">
@if (item.VisibleIndividually)
{
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@T("Products.Details")">@item.ProductName</a>
<a href="@item.ProductUrl" title="@T("Products.Details")">@item.ProductName</a>
}
else
{
Expand Down Expand Up @@ -99,7 +99,7 @@
<li>
<div class="cart-item-row">
<div class="product">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
<a href="@item.ProductUrl" title="View details">@item.ProductName</a>
@if (!String.IsNullOrEmpty(item.AttributeInfo))
{
<div class="attributes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</td>
}
<td class="product">
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
<a href="@item.ProductUrl" title="View details">@item.ProductName</a>

@if (Model.DisplayShortDesc && !String.IsNullOrEmpty(item.ShortDesc))
{
Expand Down Expand Up @@ -144,7 +144,7 @@
<div class="bundle-item-name">
@if (item.VisibleIndividually)
{
<a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@T("Products.Details")">@item.ProductName</a>
<a href="@item.ProductUrl" title="@T("Products.Details")">@item.ProductName</a>
}
else
{
Expand Down

0 comments on commit 0f8ddbf

Please sign in to comment.