I would like to Calculate Tax in one state only, how would i go about do it and which file i need to update? So when someone selects in state dropdown "Missouri" they will get extra 8.75% added to total price. i believe i have to update uCommerce/Preview.cshtml file?
I want to use "ShowOnHomepage" option on products but if the same product is included under multiple categories (I have products that can be displayed under multiple categories), it will be displayed that many times on homepage, i need to display the product only once. i believe i have to update HomepageCatalog.cshtml file.
I will try to go a bit more depth about "distinct" your products. Since you do not have posted your code for rendering the products I can only guess how you do and what you can do.
What you can do is using the Extension-method "Distinct" from LINQ (on your product array/list) to compare products and only get a product once. There is an example here how to create your own EqualityComparer which can be used with Distinct.
c:\webs\reedypress.com\MacroScripts\uCommerce\635601615825465546_HomepageCatalog.cshtml(9): error CS0246: The type or namespace name 'DistinctBySku' could not be found (are you missing a using directive or an assembly reference?)
It seems you're missing some namespace declaration in your HomePageCatalog.cshtml. Usually when I create classes for extensions/comparers etc. I create a new Visual Studio project inside my solution which contains all these classes to avoid bloating App_Code folder.
I have not tried to create a class the way you do it but I think it it is durable.
Instead of using an *.cshtml file try to create a new file called DistinctBySku.cs and copy the code into this file.
I dont know c#, for show on homepage we improvised and just created a category called "Featured" and had the products i wanted to be on that page checked under "Categories" tab. thanks for the help
ShowOnHomepage and Calculate Tax
Hello
I would like to Calculate Tax in one state only, how would i go about do it and which file i need to update?
So when someone selects in state dropdown "Missouri" they will get extra 8.75% added to total price.
i believe i have to update uCommerce/Preview.cshtml file?
I want to use "ShowOnHomepage" option on products but if the same product is included under multiple categories (I have products that can be displayed under multiple categories), it will be displayed that many times on homepage, i need to display the product only once.
i believe i have to update HomepageCatalog.cshtml file.
Hello,
For the tax calculation, the most correct way would be to implement a new ITaxService. You can override the current TaxService implementation and then register your own component. Please take a look here for how to register a custom component.
http://docs.ucommerce.net/ucommerce/v6/extending-ucommerce/register-a-component.html
For the duplicated products for "ShowOnHomePage": Yes, you can "distinct" the products in HomepageCatalog.cshtml.
Kind regards,
Jesper
Hello Jasper
would you by any chance have the code on how to:
"For the duplicated products for "ShowOnHomePage": Yes, you can "distinct" the products in HomepageCatalog.cshtml"
?
thanks, Arlan
Hi Arlan,
I will try to go a bit more depth about "distinct" your products. Since you do not have posted your code for rendering the products I can only guess how you do and what you can do.
What you can do is using the Extension-method "Distinct" from LINQ (on your product array/list) to compare products and only get a product once. There is an example here how to create your own EqualityComparer which can be used with Distinct.
http://www.codeproject.com/Articles/535374/DistinctBy-in-Linq-Find-Distinct-object-by-Propert
best regards Martin
Hi Martin
here is the
code all code in uCommerce/HomepageCatalog.cshtml file
@using UCommerce.Runtime
@{
var products = SiteContext.Current.CatalogContext.CurrentCatalog.Categories.SelectMany(c => c.Products.Where(p => p.ProductProperties.Any(pp => pp.ProductDefinitionField.Name == "ShowOnHomepage" && Convert.ToBoolean(pp.Value))));
}
@uCommerce.Helpers.Product.DisplayListProducts(products, null)
i could use some help since i am not that good with c#
Hi Arlan,
Sorry for a bit late answer. I have been quite busy. If you add this class to your solution:
Then you should be able to distinct like this
I haven't tested it but it should work. My equlitycomparer looks at the Sku so if you want it for VariantSku you have to make a minor adjustment.
Best regards Martin
Hi Martin
I believe here is the full code
%%%%%%%%%%%%%%%%%%%%%%%
Located:App_Code/uCommerce/Helpers.Product.cshtml
@using UCommerce
@using UCommerce.Api
@using UCommerce.Extensions
@using UCommerce.EntitiesV2
@using UCommerce.Runtime
@using UCommerce.Search
@using umbraco.MacroEngines
@* Distinct By SKU *@
@public class DistinctBySku : IEqualityComparer<product>
{
public bool Equals(Product x, Product y)
{
if (x == null || y == null)
return false;
return x.Sku == y.Sku;
}
public int GetHashCode(Product product)
{
return product.Sku.GetHashCode();
}
}
@* /Distinct By SKU *@
@helper DisplayListProducts(IEnumerable<UCommerce.EntitiesV2.Product> products, UCommerce.EntitiesV2.Category category)
{
var facetsForQuerying = Request.QueryString.ToFacets();
var filterProducts = category != null ? SearchLibrary.GetProductsFor(category, facetsForQuerying) : new List<UCommerce.Documents.Product>();
int i = 0;
if (filterProducts.Any())
{
foreach (var product in filterProducts.Where(x => x.DisplayOnSite))
{
var listProduct = products.First(x => x.Sku == product.Sku && x.VariantSku == product.VariantSku);
@DisplayListItemProduct(listProduct, category)
}
}
else
{
foreach (var product in products.Where(x => x.DisplayOnSite))
{
@DisplayListItemProduct(product, category);
}
}
}
@helper DisplayListItemProduct(UCommerce.EntitiesV2.Product product, UCommerce.EntitiesV2.Category category)
{
var url = CatalogLibrary.GetNiceUrlForProduct(product, category);
var price = CatalogLibrary.CalculatePrice(product);
<div class="product-display">
<div class="product-image">
@if (!string.IsNullOrEmpty(product.ThumbnailImageMediaId))
{
dynamic mediaItem = new DynamicMedia(product.ThumbnailImageMediaId);
<a href="@url"><img src="@mediaItem.umbracoFile" class="img-thumbnail" /></a>
}
@if (product.ProductReviews.Any())
{
@* View /App_Code/ReviewHelpers.cshtml for this helper *@
<p class="ratings">@uCommerce.Helpers.ProductReview.DisplayStars(product.Rating)</p>
}
</div>
<p class="view-details"><a href="@url">View more</a></p>
<p class="item-name"><a href="@url">@product.DisplayName()</a></p>
<p class="item-price">@(price.YourPrice != null ? price.YourPrice.Amount.ToString() : "")</p>
</div>
}
%%%%%%%%%%%%%%%%%%%%%%%
Located:MacroScripts/uCommerce/HomepageCatalog.cshtml
@using UCommerce.Runtime
@{
var products = SiteContext.Current
.CatalogContext
.CurrentCatalog
.Categories
.SelectMany(c => c.Products.Where(p => p.ProductProperties.Any(pp => pp.ProductDefinitionField.Name == "ShowOnHomepage" && Convert.ToBoolean(pp.Value))));
}
@uCommerce.Helpers.Product.DisplayListProducts(products, null)
%%%%%%%%%%%%%%%%%%%%%%%
i put this in product.cshtml
Error occured
c:\webs\reedypress.com\MacroScripts\uCommerce\635601615825465546_HomepageCatalog.cshtml(9): error CS0246: The type or namespace name 'DistinctBySku' could not be found (are you missing a using directive or an assembly reference?)
Hi Arlan,
It seems you're missing some namespace declaration in your HomePageCatalog.cshtml. Usually when I create classes for extensions/comparers etc. I create a new Visual Studio project inside my solution which contains all these classes to avoid bloating App_Code folder.
I have not tried to create a class the way you do it but I think it it is durable. Instead of using an *.cshtml file try to create a new file called DistinctBySku.cs and copy the code into this file.
Hi Martin
I dont know c#, for show on homepage we improvised and just created a category called "Featured" and had the products i wanted to be on that page checked under "Categories" tab. thanks for the help
Arlan
Hey Arlan
Would you be so kind and mark the post as solved?
Kind regards
Thomas Arvidsen
is working on a reply...