How to refer to types declared in other plugins

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I have been following Akshay's video tutorials about SXC, the last one about creating a minion: https://www.konabos.com/blog/creating-a-minion-for-sitecore-commerce-xc-9/. In this tutorial he creates a Plugin with a minion that calculates loyalty points for customers based on previous orders by that customer. In the plugin he refers to multiple types that are found in other plugins, e.g. Order, Customer, LoyaltyComponent (the latter type was created in another custom plugin in a previous tutorial).



How do I set up the dependencies to these types from my new minion plugin?



Or in general:



How do I refer to types that are declared in other commerce engine plugins (features)?



First thought was simply to refer to the other plugins directly, e.g. Sitecore.Commerce.Plugin.Orders, Sitecore.Commerce.Plugin.Customers, Plugin.Xxxx.Loyalty but as the plugins are found in the feature-layer, I guess this is the wrong way to go, otherwise I would have features referencing each other.



Second thought was to refer to the Sitecore.Commerce.ServiceProxy foundation project that is part of the commerce SDK. This proxy contains the types, deferred from the Commerce Engine API. The problem here is that the types of the ServiceProxy-project do not inherit from the base types found in Sitecore.Commerce.Core so they are not directly usable with core functionality.



An example: In this method in my pipeline block I am trying to convert the order entities from a list to an object of type Order, but it is not possible because Order from the ServiceProxy project does not inherit from Sitecore.Commerce.Core.CommerceEntity.



public override async Task<Customer> Run(Customer customer, CommercePipelineExecutionContext context)

var listName = $"Orders.ByCustomer-customer.Id";
var result = await _findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Order), listName, 0,int.MaxValue), context);

var customerOrderPoints = 0;
if (result?.List != null && result.List.Items.Any())

foreach (CommerceEntity entity in result.List.Items)

var order = (Order)entity; // <-- This is not possible because 'Order' is from ServiceProxy and inherits from another 'CommerceEntity' than the one found in Sitecore.Commerce.Core

if (order != null)

customerOrderPoints += order.HasComponent<LoyaltyComponent>()
? order.GetComponent<LoyaltyComponent>().PointsEarned
: 0;


var loyaltyComponent = customer.GetComponent<LoyaltyComponent>();
loyaltyComponent.PointsEarned = customerOrderPoints;

await _persistEntityPipeline.Run(new PersistEntityArgument(customer), context);


return customer;



So I can only make it work with the first approach but I don't want to go that way. Akshay's code is not on Github yet, so I can't see exactly how he has done.



EDIT: I noticed that the developer's guide for SXC 9 says




A plugin can also take a dependency on another plugin to extend its functionality.




This implies that it is okay to make direct references. But the Helix principles says that one feature module must never depend on another feature module, so perhaps the plugins should not be placed in the feature-layer like they are in this tutorial(?)







share|improve this question


























    up vote
    5
    down vote

    favorite
    1












    I have been following Akshay's video tutorials about SXC, the last one about creating a minion: https://www.konabos.com/blog/creating-a-minion-for-sitecore-commerce-xc-9/. In this tutorial he creates a Plugin with a minion that calculates loyalty points for customers based on previous orders by that customer. In the plugin he refers to multiple types that are found in other plugins, e.g. Order, Customer, LoyaltyComponent (the latter type was created in another custom plugin in a previous tutorial).



    How do I set up the dependencies to these types from my new minion plugin?



    Or in general:



    How do I refer to types that are declared in other commerce engine plugins (features)?



    First thought was simply to refer to the other plugins directly, e.g. Sitecore.Commerce.Plugin.Orders, Sitecore.Commerce.Plugin.Customers, Plugin.Xxxx.Loyalty but as the plugins are found in the feature-layer, I guess this is the wrong way to go, otherwise I would have features referencing each other.



    Second thought was to refer to the Sitecore.Commerce.ServiceProxy foundation project that is part of the commerce SDK. This proxy contains the types, deferred from the Commerce Engine API. The problem here is that the types of the ServiceProxy-project do not inherit from the base types found in Sitecore.Commerce.Core so they are not directly usable with core functionality.



    An example: In this method in my pipeline block I am trying to convert the order entities from a list to an object of type Order, but it is not possible because Order from the ServiceProxy project does not inherit from Sitecore.Commerce.Core.CommerceEntity.



    public override async Task<Customer> Run(Customer customer, CommercePipelineExecutionContext context)

    var listName = $"Orders.ByCustomer-customer.Id";
    var result = await _findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Order), listName, 0,int.MaxValue), context);

    var customerOrderPoints = 0;
    if (result?.List != null && result.List.Items.Any())

    foreach (CommerceEntity entity in result.List.Items)

    var order = (Order)entity; // <-- This is not possible because 'Order' is from ServiceProxy and inherits from another 'CommerceEntity' than the one found in Sitecore.Commerce.Core

    if (order != null)

    customerOrderPoints += order.HasComponent<LoyaltyComponent>()
    ? order.GetComponent<LoyaltyComponent>().PointsEarned
    : 0;


    var loyaltyComponent = customer.GetComponent<LoyaltyComponent>();
    loyaltyComponent.PointsEarned = customerOrderPoints;

    await _persistEntityPipeline.Run(new PersistEntityArgument(customer), context);


    return customer;



    So I can only make it work with the first approach but I don't want to go that way. Akshay's code is not on Github yet, so I can't see exactly how he has done.



    EDIT: I noticed that the developer's guide for SXC 9 says




    A plugin can also take a dependency on another plugin to extend its functionality.




    This implies that it is okay to make direct references. But the Helix principles says that one feature module must never depend on another feature module, so perhaps the plugins should not be placed in the feature-layer like they are in this tutorial(?)







    share|improve this question
























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I have been following Akshay's video tutorials about SXC, the last one about creating a minion: https://www.konabos.com/blog/creating-a-minion-for-sitecore-commerce-xc-9/. In this tutorial he creates a Plugin with a minion that calculates loyalty points for customers based on previous orders by that customer. In the plugin he refers to multiple types that are found in other plugins, e.g. Order, Customer, LoyaltyComponent (the latter type was created in another custom plugin in a previous tutorial).



      How do I set up the dependencies to these types from my new minion plugin?



      Or in general:



      How do I refer to types that are declared in other commerce engine plugins (features)?



      First thought was simply to refer to the other plugins directly, e.g. Sitecore.Commerce.Plugin.Orders, Sitecore.Commerce.Plugin.Customers, Plugin.Xxxx.Loyalty but as the plugins are found in the feature-layer, I guess this is the wrong way to go, otherwise I would have features referencing each other.



      Second thought was to refer to the Sitecore.Commerce.ServiceProxy foundation project that is part of the commerce SDK. This proxy contains the types, deferred from the Commerce Engine API. The problem here is that the types of the ServiceProxy-project do not inherit from the base types found in Sitecore.Commerce.Core so they are not directly usable with core functionality.



      An example: In this method in my pipeline block I am trying to convert the order entities from a list to an object of type Order, but it is not possible because Order from the ServiceProxy project does not inherit from Sitecore.Commerce.Core.CommerceEntity.



      public override async Task<Customer> Run(Customer customer, CommercePipelineExecutionContext context)

      var listName = $"Orders.ByCustomer-customer.Id";
      var result = await _findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Order), listName, 0,int.MaxValue), context);

      var customerOrderPoints = 0;
      if (result?.List != null && result.List.Items.Any())

      foreach (CommerceEntity entity in result.List.Items)

      var order = (Order)entity; // <-- This is not possible because 'Order' is from ServiceProxy and inherits from another 'CommerceEntity' than the one found in Sitecore.Commerce.Core

      if (order != null)

      customerOrderPoints += order.HasComponent<LoyaltyComponent>()
      ? order.GetComponent<LoyaltyComponent>().PointsEarned
      : 0;


      var loyaltyComponent = customer.GetComponent<LoyaltyComponent>();
      loyaltyComponent.PointsEarned = customerOrderPoints;

      await _persistEntityPipeline.Run(new PersistEntityArgument(customer), context);


      return customer;



      So I can only make it work with the first approach but I don't want to go that way. Akshay's code is not on Github yet, so I can't see exactly how he has done.



      EDIT: I noticed that the developer's guide for SXC 9 says




      A plugin can also take a dependency on another plugin to extend its functionality.




      This implies that it is okay to make direct references. But the Helix principles says that one feature module must never depend on another feature module, so perhaps the plugins should not be placed in the feature-layer like they are in this tutorial(?)







      share|improve this question














      I have been following Akshay's video tutorials about SXC, the last one about creating a minion: https://www.konabos.com/blog/creating-a-minion-for-sitecore-commerce-xc-9/. In this tutorial he creates a Plugin with a minion that calculates loyalty points for customers based on previous orders by that customer. In the plugin he refers to multiple types that are found in other plugins, e.g. Order, Customer, LoyaltyComponent (the latter type was created in another custom plugin in a previous tutorial).



      How do I set up the dependencies to these types from my new minion plugin?



      Or in general:



      How do I refer to types that are declared in other commerce engine plugins (features)?



      First thought was simply to refer to the other plugins directly, e.g. Sitecore.Commerce.Plugin.Orders, Sitecore.Commerce.Plugin.Customers, Plugin.Xxxx.Loyalty but as the plugins are found in the feature-layer, I guess this is the wrong way to go, otherwise I would have features referencing each other.



      Second thought was to refer to the Sitecore.Commerce.ServiceProxy foundation project that is part of the commerce SDK. This proxy contains the types, deferred from the Commerce Engine API. The problem here is that the types of the ServiceProxy-project do not inherit from the base types found in Sitecore.Commerce.Core so they are not directly usable with core functionality.



      An example: In this method in my pipeline block I am trying to convert the order entities from a list to an object of type Order, but it is not possible because Order from the ServiceProxy project does not inherit from Sitecore.Commerce.Core.CommerceEntity.



      public override async Task<Customer> Run(Customer customer, CommercePipelineExecutionContext context)

      var listName = $"Orders.ByCustomer-customer.Id";
      var result = await _findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Order), listName, 0,int.MaxValue), context);

      var customerOrderPoints = 0;
      if (result?.List != null && result.List.Items.Any())

      foreach (CommerceEntity entity in result.List.Items)

      var order = (Order)entity; // <-- This is not possible because 'Order' is from ServiceProxy and inherits from another 'CommerceEntity' than the one found in Sitecore.Commerce.Core

      if (order != null)

      customerOrderPoints += order.HasComponent<LoyaltyComponent>()
      ? order.GetComponent<LoyaltyComponent>().PointsEarned
      : 0;


      var loyaltyComponent = customer.GetComponent<LoyaltyComponent>();
      loyaltyComponent.PointsEarned = customerOrderPoints;

      await _persistEntityPipeline.Run(new PersistEntityArgument(customer), context);


      return customer;



      So I can only make it work with the first approach but I don't want to go that way. Akshay's code is not on Github yet, so I can't see exactly how he has done.



      EDIT: I noticed that the developer's guide for SXC 9 says




      A plugin can also take a dependency on another plugin to extend its functionality.




      This implies that it is okay to make direct references. But the Helix principles says that one feature module must never depend on another feature module, so perhaps the plugins should not be placed in the feature-layer like they are in this tutorial(?)









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 29 at 13:02

























      asked Aug 29 at 12:13









      ebug

      656




      656




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          The minion project lives inside of your Engine solution so you would not use a proxy. The proxy is mainly for projects which live outside of the Engine environment to communicate with the engine.



          You typically add the references via nuget packages for commerce plugins such as catalogs, orders, etc.



          Starting in commerce I had a million questions and with the community's help, I was able to connect some of the dots. The code base will give you a good idea as they are working solutions. I have uploaded the loyalty Commerce engine and Commerce website solutions to GitHub.



          Here is the link: https://github.com/konabos/Sitecore-Commerce-Loyalty



          A plugin should either live in a feature project or a foundation project depending on how crucial the plugin is. For instance, a payment processing plugin central to your system should be a foundation project.



          But an add on plugin such as custom fields, etc could live in a feature project in your commerce solution.



          I typically have not made it a habit of modifying the Engine project.



          Refer to: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce and https://github.com/sitecore/sitecore.habitathome.content - they are neatly structured.






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "664"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13598%2fhow-to-refer-to-types-declared-in-other-plugins%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            7
            down vote



            accepted










            The minion project lives inside of your Engine solution so you would not use a proxy. The proxy is mainly for projects which live outside of the Engine environment to communicate with the engine.



            You typically add the references via nuget packages for commerce plugins such as catalogs, orders, etc.



            Starting in commerce I had a million questions and with the community's help, I was able to connect some of the dots. The code base will give you a good idea as they are working solutions. I have uploaded the loyalty Commerce engine and Commerce website solutions to GitHub.



            Here is the link: https://github.com/konabos/Sitecore-Commerce-Loyalty



            A plugin should either live in a feature project or a foundation project depending on how crucial the plugin is. For instance, a payment processing plugin central to your system should be a foundation project.



            But an add on plugin such as custom fields, etc could live in a feature project in your commerce solution.



            I typically have not made it a habit of modifying the Engine project.



            Refer to: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce and https://github.com/sitecore/sitecore.habitathome.content - they are neatly structured.






            share|improve this answer


























              up vote
              7
              down vote



              accepted










              The minion project lives inside of your Engine solution so you would not use a proxy. The proxy is mainly for projects which live outside of the Engine environment to communicate with the engine.



              You typically add the references via nuget packages for commerce plugins such as catalogs, orders, etc.



              Starting in commerce I had a million questions and with the community's help, I was able to connect some of the dots. The code base will give you a good idea as they are working solutions. I have uploaded the loyalty Commerce engine and Commerce website solutions to GitHub.



              Here is the link: https://github.com/konabos/Sitecore-Commerce-Loyalty



              A plugin should either live in a feature project or a foundation project depending on how crucial the plugin is. For instance, a payment processing plugin central to your system should be a foundation project.



              But an add on plugin such as custom fields, etc could live in a feature project in your commerce solution.



              I typically have not made it a habit of modifying the Engine project.



              Refer to: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce and https://github.com/sitecore/sitecore.habitathome.content - they are neatly structured.






              share|improve this answer
























                up vote
                7
                down vote



                accepted







                up vote
                7
                down vote



                accepted






                The minion project lives inside of your Engine solution so you would not use a proxy. The proxy is mainly for projects which live outside of the Engine environment to communicate with the engine.



                You typically add the references via nuget packages for commerce plugins such as catalogs, orders, etc.



                Starting in commerce I had a million questions and with the community's help, I was able to connect some of the dots. The code base will give you a good idea as they are working solutions. I have uploaded the loyalty Commerce engine and Commerce website solutions to GitHub.



                Here is the link: https://github.com/konabos/Sitecore-Commerce-Loyalty



                A plugin should either live in a feature project or a foundation project depending on how crucial the plugin is. For instance, a payment processing plugin central to your system should be a foundation project.



                But an add on plugin such as custom fields, etc could live in a feature project in your commerce solution.



                I typically have not made it a habit of modifying the Engine project.



                Refer to: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce and https://github.com/sitecore/sitecore.habitathome.content - they are neatly structured.






                share|improve this answer














                The minion project lives inside of your Engine solution so you would not use a proxy. The proxy is mainly for projects which live outside of the Engine environment to communicate with the engine.



                You typically add the references via nuget packages for commerce plugins such as catalogs, orders, etc.



                Starting in commerce I had a million questions and with the community's help, I was able to connect some of the dots. The code base will give you a good idea as they are working solutions. I have uploaded the loyalty Commerce engine and Commerce website solutions to GitHub.



                Here is the link: https://github.com/konabos/Sitecore-Commerce-Loyalty



                A plugin should either live in a feature project or a foundation project depending on how crucial the plugin is. For instance, a payment processing plugin central to your system should be a foundation project.



                But an add on plugin such as custom fields, etc could live in a feature project in your commerce solution.



                I typically have not made it a habit of modifying the Engine project.



                Refer to: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce and https://github.com/sitecore/sitecore.habitathome.content - they are neatly structured.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 29 at 13:14

























                answered Aug 29 at 13:08









                ASura

                1,683527




                1,683527



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13598%2fhow-to-refer-to-types-declared-in-other-plugins%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery