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