Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Arlan 58 posts 184 karma points
    Nov 23, 2014 @ 23:26
    Arlan
    0

    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.

     

     

  • Jesper Nielsen 141 posts 498 karma points
    Nov 25, 2014 @ 13:16
    Jesper Nielsen
    1

    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

  • Arlan 58 posts 184 karma points
    Feb 13, 2015 @ 00:02
    Arlan
    0

    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

  • Martin 181 posts 740 karma points
    Feb 13, 2015 @ 18:33
    Martin
    0

    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

  • Arlan 58 posts 184 karma points
    Feb 18, 2015 @ 05:02
    Arlan
    0

    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# 

     

     

     

  • Martin 181 posts 740 karma points
    Feb 20, 2015 @ 17:56
    Martin
    0

    Hi Arlan,

    Sorry for a bit late answer. I have been quite busy. If you add this class to your solution:

    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();
        }
    }
    

    Then you should be able to distinct like this

                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))))
                .Distinct(new DistinctBySku());
    

    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

  • Arlan 58 posts 184 karma points
    Feb 22, 2015 @ 06:27
    Arlan
    0

    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

    publicclassDistinctBySku:IEqualityComparer<Product>
    {
       
    publicboolEquals(Product x,Product y)
       
    {
           
    if(x ==null|| y ==null)
               
    returnfalse;

           
    return x.Sku== y.Sku;
       
    }

       
    publicintGetHashCode(Product product)
       
    {
           
    return product.Sku.GetHashCode();
       
    }
    }
    and below in HomepageCatalog.cshtml
    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))))
               
    .Distinct(newDistinctBySku());
    i get error

    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?)

  • Martin 181 posts 740 karma points
    Feb 22, 2015 @ 19:42
    Martin
    0

    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.

  • Arlan 58 posts 184 karma points
    Mar 03, 2015 @ 05:18
    Arlan
    1

    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

     

  • Thomas 30 posts 163 karma points
    Mar 24, 2015 @ 16:34
    Thomas
    100

    Hey Arlan

    Would you be so kind and mark the post as solved?

    Kind regards

    Thomas Arvidsen

Please Sign in or register to post replies

Write your reply to:

Draft