Copied to clipboard

Flag this post as spam?

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


  • PierreD Savard 183 posts 290 karma points
    Jan 05, 2017 @ 20:55
    PierreD Savard
    0

    Adding ShipmentInfo

    Hi, I try to add new textArea in the ShipRateQuoteForm. This textArea will let the user enter some custom additional shipping information.

    I manage to add my ShippingInfo field in the StoreShipRateQuoteModel, then read it in the SaveShipRateQuote action. But Where I can save it? I add a function in the CheckoutManager.Shipping.SaveShipmentInfo(string info) but now I am stuck. I can't find some documentation on the data model behind merchello. Ideally I need to store this information in the order to be able to display it in the back end section.

    Any suggestion?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 06, 2017 @ 16:36
    Rusty Swayne
    0

    Would it work to add it to the ExtendedDataCollection of the shipping line item created when the rate quote is saved?

  • PierreD Savard 183 posts 290 karma points
    Jan 13, 2017 @ 15:30
    PierreD Savard
    0

    Thanks for your help. All is working now! Last question, Now I got a Merchello.web.dll and Merchello.web.store.dll with custom code. How I can set it by default in my production project. Normally when compiling, theses dll, are copied back from the Nuget local package. I try to remove the reference and add reference to my custom dll, but the package keep overwriting them.

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 13, 2017 @ 16:38
    Rusty Swayne
    0

    Normally you would not recompile the Merchello dlls - but add your code to your own library that references them via NuGet. Most of the classes allow you to either sub-class the Merchello class (inherit from) and override the methods you need to ...

    Have you found places where this was not possible - ex. something was internal that you needed to access?

  • PierreD Savard 183 posts 290 karma points
    Jan 16, 2017 @ 19:06
    PierreD Savard
    0

    Thank for you help Rusty. All this process is quite new for me! ;-)

    I start doing like you said and starting overriding class.

    So for now I override the CheckoutShipRateQuoteController in fastTrak:

    [PluginController("FastTrackLVC")]
    public class LVCCheckoutShipRateQuoteController: CheckoutShipRateQuoteControllerBase<LVCShipRateQuoteModel>
    {
        /// <summary>
        /// The handle ship rate quote save success.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        protected override ActionResult HandleShipRateQuoteSaveSuccess(LVCShipRateQuoteModel model)
        {
            return !model.SuccessRedirectUrl.IsNullOrWhiteSpace() ?
                this.Redirect(model.SuccessRedirectUrl)
                : base.HandleShipRateQuoteSaveSuccess(model);
        }
    
    
        /// <summary>
        /// Saves the shipment rate quote.
        /// </summary>
        /// <param name="model">
        /// The <see cref="ICheckoutShipRateQuoteModel"/>.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public override ActionResult SaveShipRateQuote(LVCShipRateQuoteModel model)
        {
            try
            {
                var shippingAddress = CheckoutManager.Customer.GetShipToAddress();
                if (shippingAddress == null) return CurrentUmbracoPage();
    
                if (!ModelState.IsValid) return CurrentUmbracoPage();
    
                CheckoutManager.Shipping.ClearShipmentRateQuotes();
    
                var quoteModel = CheckoutShipRateQuoteFactory.Create(Basket, shippingAddress);
    
                // merge the models for return override
                model.ShippingQuotes = quoteModel.ShippingQuotes;
                model.ProviderQuotes = quoteModel.ProviderQuotes;
    
                var accepted = quoteModel.ProviderQuotes.FirstOrDefault(x => x.ShipMethod.Key == model.ShipMethodKey);
                if (accepted == null) return CurrentUmbracoPage();
    
                CheckoutManager.Shipping.SaveShipmentRateQuote(accepted);
                //CheckoutManager.Shipping.SaveShipmentInfo(model.ShipmentInfo);
    
                return HandleShipRateQuoteSaveSuccess(model);
            }
            catch (Exception ex)
            {
                return this.HandleShipRateQuoteSaveException(model, ex);
            }
        }
    }
    

    then the ShipRateQuoteModel

    public class LVCShipRateQuoteModel: FastTrackShipRateQuoteModel
    {
        [Display(Name = "Informations supplémentaires")]
        public string ShipmentInfo { get; set; }
    }
    

    Then in the ShipRateQuoteForm.cshtml I change the inherits and the form controller for:

    umbLVC2.Custom.LVCShipRateQuoteModel

    using (Html.BeginUmbracoForm

    First question: After compiling, no error, but after hitting the save button in the ShipRateQuoteForm, my Save function inside my Custom controller is not called. DO I miss something?

    Second Question: In the LVCCheckoutShipRateQuoteController, I need to add a save function fot the ShipmentInfo. See this commented line: CheckoutManager.Shipping.SaveShipmentInfo(model.ShipmentInfo);

    How to overrideing the BasketCheckoutShippingManager to add my function:

        public void SaveShipmentInfo(string info)
        {
            var items = this.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).ToArray();
    
            foreach (var item in items)
            {
                item.ExtendedData.SetValue("ShipmentInfo", info);
            }
    
            this.Context.Services.ItemCacheService.Save(this.Context.ItemCache);
        }
    

    thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 16, 2017 @ 21:44
    Rusty Swayne
    0

    I think you may be missing the controller reference in your form:

    have you tried:

    @using (Html.BeginUmbracoForm<LVCCheckoutShipRateQuoteController>("SaveShipRateQuote", new { area = "FastTrackLVC" }))
    

    rather than:

     using (Html.BeginUmbracoForm("SaveShipRateQuote", new { area = "FastTrackLVC" }))
    
  • PierreD Savard 183 posts 290 karma points
    Jan 18, 2017 @ 00:48
    PierreD Savard
    0

    shame on me! lol... Thanks.

    What about adding my function SaveShipmentInfo in the CheckoutManager.Shipping ?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 18, 2017 @ 17:35
    Rusty Swayne
    0

    You can create your own CheckoutShippingManager and either inherit from the base class in the core (CheckoutShippingManagerBase) or, in your case probably easier to inherit from Merchello.Web.CheckoutManagers.BasketCheckoutShippingManager and add your method.

    You can replace the existing CheckoutShippingManager with your version by updating the reference in the merchello.config.

    <pluggable>
         <object alias="CustomerContext" type="Merchello.Web.CustomerContext, Merchello.Web" />
         <object alias="BasketCheckoutCustomerManager" type="Merchello.Web.CheckoutManagers.BasketCheckoutCustomerManager, Merchello.Web" />
         <object alias="BasketCheckoutOfferManager" type="Merchello.Web.CheckoutManagers.BasketCheckoutOfferManager, Merchello.Web" />
         <object alias="BasketCheckoutShippingManager" type="Merchello.Web.CheckoutManagers.BasketCheckoutShippingManager, Merchello.Web" />
         <object alias="BasketCheckoutExtendedManager" type="Merchello.Web.CheckoutManagers.BasketCheckoutExtendedManager, Merchello.Web" />
         <object alias="BasketCheckoutPaymentManager" type="Merchello.Web.CheckoutManagers.BasketCheckoutPaymentManager, Merchello.Web" />
         <object alias="RemoteLogger" type="Merchello.Web.Logging.DefaultEmptyRemoteLogger, Merchello.Web" />
         <object alias="PluginViewEditorProvider" type="Merchello.Web.Pluggable.PluginViewEditorProvider, Merchello.Web" />
    </pluggable> 
    

    Note: in order to use your method, you will have to implicitly call that method (since it isn't defined on the interface) - so something like

     var shippingManager = (MyShippingManager)checkoutManager.Shipping;
    
  • PierreD Savard 183 posts 290 karma points
    Jan 18, 2017 @ 19:32
    PierreD Savard
    0

    I create a new LVCBasketCheckoutShippingManager and change the Merchello.config file like you said.

    Now I got an exception in my custon LVCCheckoutShipRateQuoteController.SaveShipRateQuote function at the line:

    CheckoutManager.Shipping.ClearShipmentRateQuotes();
    

    Exception:

    Failed to create Type due to null Type or null constructor args

    trace stack:

    at Merchello.Web.Pluggable.PluggableObjectHelper.GetInstance[T](String configurationAlias, Object[] ctrArgValues) at Merchello.Web.CheckoutManagers.BasketCheckoutManager.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 19, 2017 @ 16:13
    Rusty Swayne
    0

    I'd have to step through it, but looking at it now, the BasketCheckoutShippingManager itself is internal so you will have to inherit from CheckoutShippingManagerBase which should force you to include the constructor (which is probably where the issue is originating - at least that is my guess without being able to see or test it directly).

    Here is the code implementation for the BasketCheckoutShippingManager https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/CheckoutManagers/BasketCheckoutShippingManager.cs

  • PierreD Savard 183 posts 290 karma points
    Jan 19, 2017 @ 23:43
    PierreD Savard
    0

    OUf! Complex! ;-)

    PlanB: de we have a way to get the shippingline like this

     this.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).ToArray();
    

    but outside the BasketShippingManager. In this case I can save it inside my custom view controler instead of overriding ShippingManager.

    IF NOT: I can't see where the internet class is defined. If inherit from CheckoutShippingManageBase, How I can call a custom inherited BasketCheckoutShippingManage? I will make som trace with source code, but I suspect this line to be in cause:

    his._shippingManager = new Lazy<ICheckoutShippingManager>(() => PluggableObjectHelper.GetInstance<BasketCheckoutShippingManager>("BasketCheckoutShippingManager", this.Context));            
    

    inside the Initialize function of the BasketCheckoutManager

  • PierreD Savard 183 posts 290 karma points
    Jan 20, 2017 @ 01:44
    PierreD Savard
    0

    Yes with tracing, I think the problem is located in the PluggableObjectHelper called several times in the checkout process. But my god! How I can override this. Too many internal class! ;-)

    I can't figure how to solve that. Normally i wil need to inherit and override the Initialize function to change the pluggableObject of the _shippingManager (BasketCheckoutManager line 119).

    But for that I will need to change the static class in CheckoutExtensions.cs that instantiate the BasketCheckoutManager but in this file we got several links to other internal class...

    I am stuck there. ;-)

  • PierreD Savard 183 posts 290 karma points
    Jan 20, 2017 @ 02:21
    PierreD Savard
    0

    Finnaly I choose to not add the function into the BasketShippingController. I way to complicated for me.

    I just add the code dirrectly in the CheckoutShipRateController because we have access to the Shiping Controler context

                    //Save
                var items = CheckoutManager.Shipping.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).ToArray();
    
                foreach (var item in items)
                {
                    item.ExtendedData.SetValue("ShipmentInfo", model.ShipmentInfo);
                    item.ExtendedData.SetValue("ClientDe", model.ClientDe);
                }
                CheckoutManager.Shipping.Context.Services.ItemCacheService.Save(CheckoutManager.Shipping.Context.ItemCache);
    
  • PierreD Savard 183 posts 290 karma points
    Jan 20, 2017 @ 15:01
    PierreD Savard
    0

    All is working now. I can save and display my information backend in the SaleOverview view.

    Question: When I copy my backend modification from dev server to prod server all is working for the checkout process, but the fields are empty in the backend section. I think the prod server use the old merchello.controllers.js file instead of the new custom one. I try to breakpoint in chrome or IE but I can't see any file merchello.controllers.js in the list. Some lazyloading.js file that it.

    What do I miss there? For now I overwrite all the App_plugings folders from Dev to prod.

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 23, 2017 @ 16:33
    Rusty Swayne
    0

    Hi Pierre,

    You can step through your JS code if you disable client dependency (compilation debug="Fasle")

  • PierreD Savard 183 posts 290 karma points
    Feb 02, 2017 @ 15:41
    PierreD Savard
    0

    EDIT:

    When I put debug=true in the

    But If I change it to debug=false, the problem return.

    I missing something?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 02, 2017 @ 19:34
    Rusty Swayne
    0

    Sounds like something is gummed up in ClientDependency. Can you tick the ClientDependency version and see if that clears things up?

  • PierreD Savard 183 posts 290 karma points
    Feb 03, 2017 @ 22:32
    PierreD Savard
    0

    mmm sory how I can do that?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 03, 2017 @ 23:27
    Rusty Swayne
    0

    It's the version number in the ClientDependency.config file.

  • PierreD Savard 183 posts 290 karma points
    Feb 05, 2017 @ 23:24
    PierreD Savard
    0

    version 219938318

  • PierreD Savard 183 posts 290 karma points
    Feb 08, 2017 @ 17:39
    PierreD Savard
    1

    After flushing all file on the server, upgraded to Merchello 2.4 the problem is gone. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft