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.

  • Marianne Hildesheim Bertelsen 26 posts 169 karma points
    Oct 29, 2014 @ 10:02
    Marianne Hildesheim Bertelsen
    0

    Problem with using a custom IPricingService

    Hi

    I'm trying to add a custom IPricingService to my uCommerce project. I've added the custom class and registered it, but the site doesn't seem to use my custom class. 

    Here's what I've done so far:

    In custom.config I've added the line 

    <component id="PriceService" service="UCommerce.Catalog.IPricingService, UCommerce" type="MyProject.UcommerceExtensions.MyPricingService, MyProject"/>

    which should override the default uCommerce PricingService.

    My PricingService class looks like this (it's pretty bare so far):

    using UCommerce;
    using UCommerce.Catalog;
    using UCommerce.EntitiesV2;
    
    namespace MyProject.UcommerceExtensions
    {
        public class MyPricingService : IPricingService
    { private readonly IPricingService _base; public MyPricingService()
    { _base = new PricingService(); } public Money GetProductPrice(Product product, PriceGroup priceGroup) { return _base.GetProductPrice(product, priceGroup); } } }

    When I debug the project (breakpoint in the GetProductPrice method) while running the site it never enters the GetProductPrice method in my custom service.

    I wonder if we have to explicitly call the method when showing the price in the view, or if it should happen automagially when I've registered my custom PricingService in custom.config.

    I've tried both:

    var pricingService = ObjectFactory.Instance.Resolve<IPricingService>();
    var priceGroup = PriceGroup.Get(7);
    var price = pricingService.GetProductPrice(variant, priceGroup);
    

    Price is null and the MyPricingService.GetProductPrice is not called.

    and

    var price = CatalogLibrary.CalculatePrice(variant)

    price is correct, but MyPricingService.GetProductPrice is still not called.

    I've also tried recycling the application pool but that didn't seem to make a difference.

    The products we're getting prices for are all variants -- but I'm thinking that shouldn't make a difference?

    What am I missing?

    PS: uCommerce 6 and Umbraco 7.

  • Marianne Hildesheim Bertelsen 26 posts 169 karma points
    Oct 29, 2014 @ 12:09
    Marianne Hildesheim Bertelsen
    0

    I should describe the purpose of the custom IPricingService:

    I want to show different prices in the website when a user is logged in (dependent on the user type) -- not just adjust the prices when an order is created (if case those two things require two different setups).

  • Morten Skjoldager 440 posts 1499 karma points
    Oct 29, 2014 @ 12:40
    Morten Skjoldager
    0

    Can you verify that you only have one components.config located in your website structure. Sometimes another set of configuration files are hit because we scan for the file. The one set you should be located under /umbraco/ucommerce/configuration/components.config

    All other components.config should be deleted :) 

    Another thing is that i believe you should override the PricingServiceClass and just call base.calculatePrice to let that handle the actual pricegroup you want to use. 

  • Marianne Hildesheim Bertelsen 26 posts 169 karma points
    Oct 29, 2014 @ 12:51
    Marianne Hildesheim Bertelsen
    0

    I do have another set of configuration files but that's in another (test) project (in the same solution). Can that mess things up?

    Sorry, I'm not sure what you mean by overriding the PricingServiceClass -- isn't that what I'm already doing? You don't mean that I should extend the PricingServiceClass rather than implement the IPricingService interface, right?

  • Marianne Hildesheim Bertelsen 26 posts 169 karma points
    Oct 29, 2014 @ 14:01
    Marianne Hildesheim Bertelsen
    100

    Figured out the problem (finally).

    I was, as Morten suggested, a problem with another set of uCommerce configuration files: I had been deploying the project to our test server using msbuild/deploy. This creates a Package folder in the project's obj folder, which is (naturally) not deleted when you clean solution in Visual Studio. In the Package folder another set of uCommerce configuration files was present, and apparantly uCommerce found these files before finding the ones from my website. 

    Thus I was making changes in the configuration files in my website, but uCommerce was using the configuration files from an old deployment package folder.

    @Morten: I'd still like to know if it's better to do something else than I'm currently doing in my custom PricingService in regards to overriding the default PricingService class.

  • Marianne Hildesheim Bertelsen 26 posts 169 karma points
    Dec 01, 2014 @ 20:08
    Marianne Hildesheim Bertelsen
    0

    This is also a problem with custom.config in regards to creating custom pipeline tasks -- make sure that the only copy of custom.config present in your code (sub)folder(s) is the one you're actually editing.

Please Sign in or register to post replies

Write your reply to:

Draft