Help with Creating a new plugin

1 2 Next
Posted: one year ago Quote #74542
So i created a new plugin following Skyler Svern's blog http://blog.csharpwebdeveloper.com/ .  My plugin is to add an entity (which was pretty straight forward following the blog), up until the very last 2 parts.  In my case this new entity i created, is supposed to add the entity to the database, and then link this new entity to OrderProductVariant class in nopcommerce as a way to store special customer data, that varies by productvariant.

Im not new to nopCommerce, but this is my first plugin.  The current way that my nopCommerce install was being used by a previous developer is by altering the core framework of nopCommerce, and in this case, I want to move away from that, and create plugins, but im having a hard time with this one without having to edit the core framework.  

In essence i need the plugin to:
1. Add a new entity in the database (implemented in the plugin but entity hasnt been added yet)
2. This entity is gonna get added and linked by ID to the OrderProductVariant (part im having trouble with, without having to change the core framework of NopCommerce).  

*note the entity will get added and linked when a brand new order is created, and when it gets to the part that it transitions the shoppingcartitems to orderproductvariants

orderproductvariant will also need to get modified to have a new field called customInfoID which is how i want the link to work.

Thanks for all your help guys!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #74572
Have a look at this article (Skyler's one but update to the latest nopCommerce version).

Also have a look at this topic. It could be helpful regarding linking ID and OrderProductVariant.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Best Regards,
Andrei Mazoulnitsyn
Posted: one year ago Quote #74614
thank you! ill have a look today to and see if i run into any issues
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #74632
the first article helped, because i was using old code from the blog, just had to make minor changes.  The second one is not very helpful in adding the field to orderproductvariant.  Im at the part of the controller

this is my controller, im good until the part where i have to make the linkeage.  OrderTagInfo is the new entity Im adding, and i need to link it to OrderProductVariant.

i still need to
1.  Update the entity OrderProductVariant to add a field to it without editing the sourcecode.  The field will be called OrderProductVariant.OrderTagInfoId and will have a foreign key to OrderTagInfo.Id

2.  Figure out how this entity will get inserted when each orderproductvariant gets created without editing the source code.  I know that The ShoppingCartItems go to OrderProductVariants in OrderProcessingService.PlaceOrder, and i could edit the source code, but would defeat the purpose of having this separate plugin in my opinion.

here's my source code, im gonna do more research to see if i can get part 1 done with some article in the forum, but part 2, im very lost as well. any and all input is appreciated, ty!


//controller
namespace Nop.Plugin.TaginfoTracker.Controllers
{
    public class TagInfoController : BaseNopController
    {
        private readonly IOrderTagInfoService _orderTagInfoService;
        private readonly IOrderService _orderService;
        private readonly IWorkContext _workContext;

        public TagInfoController(IWorkContext workContext,
                                 IOrderTagInfoService orderTagInfoService,
                                 IOrderService orderService)
        {
            _workContext = workContext;
            _orderTagInfoService = orderTagInfoService;
            _orderService = orderService;
        }

        [ChildActionOnly]
        public ActionResult AddTagToOrderProductVariant(int orderProductVariantId, string TagInfo)
        {
            OrderProductVariant orderProductVariantById = _orderService.GetOrderProductVariantById(orderProductVariantId);

            if (orderProductVariantById != null)
            {
                //Setup the product to save
                OrderTagInfo OrderTag = new OrderTagInfo();
                //json deserializer for json string colum part of each ShoppingCartItem
                VehicleInfo jsonTag = new VehicleInfo(TagInfo);

                OrderTag.TagNumber = jsonTag.TagNumber;
                OrderTag.Make = jsonTag.Make;
                OrderTag.ExpirationDate = DateTime.Parse(jsonTag.ExpirationDate);
                OrderTag.ContributionFee = Decimal.Parse(jsonTag.ContributionFee);
                OrderTag.StateFee = Decimal.Parse(jsonTag.StateFee);
                OrderTag.RenewalFee = Decimal.Parse(jsonTag.RenewalFee);
                OrderTag.ConvenienceFee = Decimal.Parse(jsonTag.ConvenienceFee);

                //TODO: Link OrderTagInfo to OrderProductVariant

                //Map the values we're interested in to our new entity
                _orderTagInfoService.InsertOrderTagInfo(OrderTag);
            }

            //Return the view, it doesn't need a model
            return Content("");
        }
    }
}

//and the route provider
namespace Nop.Plugin.TaginfoTracker
{
   public class TagInfoTrackerRouteProvider : IRouteProvider
    {

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Nop.Plugin.TaginfoTracker.InsertOrderTagInfo",
                            "taginfo/taginfoviews/{orderProductVariantId}",
                            new { controller = "TagInfo", action = "AddTagToOrderProductVariant" },
                            new[] { "Nop.Plugin.EZTagFL.TaginfoTracker.Controllers" });
        }

        public int Priority
        {
            get { return 0; }
        }
    }
}




This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #74650
After some research maybe im not thinking of this in the right way..... I have the plugin for the new entity that gets added to the database.  I guess will have to modify the source code a little.  I thought the concept of a plugin was for it to be a standalone installation....

Unless you can think of a better solution im gonna:

1. Edit the main source code of the OrderProductVariant class and add a field called orderTagInfoId that links to my new entity created in the plugin.

2.  Edit the main source code where the ShoppingCartItem gets transitioned into a OrderProductVariant (OrderProcessingService=> PlaceOrder) and add a line to link the OPV to my new entity...
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #74678
sigh, my solution is counter intuitive to having a standalone plugin.  I shouldnt have to edit the source code, so if you have any other resource, any help would be appreciated
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #75225
If anybody could give me a viable solution for this, i would greatly appreciate it.....
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #75226
not a solution but there is a bug in MapRoute, the namespace should read


new[] { "Nop.Plugin.TaginfoTracker.Controllers" });


without the EZTagFL
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #75228
hey bud thanks, actually i removed that a few days back, but im not sure how to update posts, dont think i can lol, but thanks!

Update:

So instead of trying to update the base entity OrderProductVariant to map to my new entity, i opted to put a foreign key in my new entity that maps to an OrderProductVariantId passed in.  so that's gotten me to the point where all i need to worry about is somehow add the entity and link it, when The ShoppingcartItems get turned into OrderProductVariants.  I wish the was some kind of event i could hook into or something that would allow me to do this, the goal is still to not touch the sourcecode (if at all possible), and contain it in the plugin.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: one year ago Quote #75638
Update


so im extremely close to getting this plugin done.  Ive checked out a few articles and checked out about event handling using the IConsumer<EntityInserted<OrderProductVariant>> interface on my plugin.  I did that, and the event is not firing after a OrderProductVariant is inserted in the code.  can anybody thing of anything as to why its not working?

this is my code... i created this class inside of my plugin, and the event thats not firing is HandleEvent


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nop.Core.Domain.Orders;
using Nop.Core.Events;
using Nop.Core.Plugins;
using Nop.Services.Orders;
using Nop.Core;
using Nop.Plugin.TaginfoTracker.Controllers;
using Nop.Plugin.TaginfoTracker.Domain;
using Nop.Plugin.TaginfoTracker.Services;
using Nop.Core.Domain;

namespace Nop.Plugin.TaginfoTracker
{
    public class OrderPlacedEventConsumer : IConsumer<EntityInserted<OrderProductVariant>>
    {
        private readonly IPluginFinder _pluginFinder;
        private readonly IOrderService _orderService;        
        private readonly IShoppingCartService _shoopingCartService;
        private readonly IWorkContext _workContext;
        private readonly IOrderTagInfoService _orderTagInfoService;

        public OrderPlacedEventConsumer(IPluginFinder pluginFinder, IOrderService orderService,
                                        IShoppingCartService shoppingCartService, IWorkContext workContext,
                                        IOrderTagInfoService orderTagInfoService)
        {
            _pluginFinder = pluginFinder;
            _orderService = orderService;
            _orderService = orderService;
            _shoopingCartService = shoppingCartService;
            _workContext = workContext;
            _orderTagInfoService = orderTagInfoService;
        }


        void IConsumer<EntityInserted<OrderProductVariant>>.HandleEvent(EntityInserted<OrderProductVariant> eventMessage)
        {
            
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            var opv = eventMessage.Entity;
            foreach (ShoppingCartItem sci in cart)
            {
                if (sci.ProductVariantId == opv.ProductVariantId &&
                    sci.CustomerEnteredPrice == opv.PriceInclTax)
                {
                    //do something
                }
            }
        }
    
    }
}



thanks for your help guys!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
1 2 Next
nopCommerce on facebook