Copied to clipboard

Flag this post as spam?

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


  • Ben McKean 272 posts 549 karma points
    Jul 29, 2016 @ 16:22
    Ben McKean
    0

    Checkout process - Invoice always £0 when completing order

    Hi,

    I have an issue whereby when I go to checkout a user and generate an order/invoice the value is always £0 and there are no items.

    I'm not sure if this is an issue with Merchello or with my implementation.

    I've stepped through my code and I have have items in my basket but when I check whats in the invoice it has no line items and no orders. The invoice total is also £0. For now I'm just using the cash payment provider

    My code to create the order is as follows:

    var context = CheckoutContext.CreateCheckoutContext(CurrentCustomer, Basket.VersionKey);
    
    var checkoutManager = context.Customer.Basket().GetCheckoutManager();
    
    var isReady = checkoutManager.Payment.IsReadyToInvoice();
    
    var paymentMethod = checkoutManager.Payment.GetPaymentGatewayMethods().FirstOrDefault();
    
    checkoutManager.Payment.SavePaymentMethod(paymentMethod.PaymentMethod);
    
    var paymentResult = checkoutManager.Payment.AuthorizePayment(paymentMethod.PaymentMethod.Key);
    
    var invoice = paymentResult.Invoice;
    
    var paymentComplete = new PaymentComplete(finalPage);
    paymentComplete.Invoice = invoice;
    
    return View("PaymentComplete", paymentComplete);
    

    But Invoice.Total is 0 and Model.Invoice.Items only has a tax item in that.

    When I view the order in Merchello it doesn't have any items in it and the amount is £0.

    enter image description here

    Any advice appreciated

    Thanks

    Ben

  • David Peck 687 posts 1863 karma points c-trib
    Jul 29, 2016 @ 17:47
    David Peck
    1

    Merchello is sometimes too smart for its own good, e.g. removing items from the invoice if you've set to track your inventory and not set any products in the inventory. Also check the other checkbox options for the product. I forget all of them but they can result in the invoice being affected.

  • Ben McKean 272 posts 549 karma points
    Jul 29, 2016 @ 21:18
    Ben McKean
    0

    Thanks David.

    I've tried changing some of the options and tried various combinations but I still have no items.

    The products in the store are actually charitable purchases. So there is no inventory or physical stock.

    I have the product set up like this.

    enter image description here

    and the store settings likes this:

    enter image description here

    I don't understand why the basket would remove the items when I call AuthorizePayment...?? There are items in the basket up until this point.

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 11:37
    David Peck
    0

    Hi Ben,

    I can't see anything here that is wrong unfortunately.

    When you say it's removed from the basket, is it definitely removed from the invoice as well?

    You've got delivery addresses in there too? I had deliverable items removed when I didn't in an early version once.

    It sounds like only SOME items are removed, it that right? Can you see no difference between those removed and those that remain?

    I also had a funny issue with products that were copied from another compared with those that were created normally.

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 11:46
    Ben McKean
    0

    Thanks David.

    So I have the items in the basket up until the point where I call:

    checkoutManager.Payment.AuthorizePayment(paymentMethod.PaymentMethod.Key);
    

    After that, the basket is emptied which I think is expected behaviour with Merchello i.e. basket is emptied after payment has been made/invoice created.

    I add a couple of notes to the basket and also a billing address earlier on in the process. Both the notes and the address are maintained on the order.

    Any product that are in the basket, aren't in the order/invoice. The only remaining item on the order is tax. Where I expect any product I added and the tax.

    I created both products manually rather than copying

    Thanks

    Ben

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 12:13
    David Peck
    0

    When you say you've added the billing address and notes, you don't mean you've added these as line items do you?

    Also, when you create your invoice you're given an object (I forget the name) which supersedes the basket. I think you can forget the basket once you've done the sales preparation.

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 12:17
    Ben McKean
    0

    I add the billing address with this code:

            var checkoutManager = context.Customer.Basket().GetCheckoutManager();
    
            var customerManager = checkoutManager.Customer;
    
            // build up address object
    
            customerManager.SaveBillToAddress(address);
    

    Yes, to get the invoice I'm using the following code:

    var paymentResult = checkoutManager.Payment.AuthorizePayment(paymentMethod.PaymentMethod.Key);
    
    var invoice = paymentResult.Invoice;
    
  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 12:20
    David Peck
    0

    Looks like it's changed a bit in V2, but that looks about right.

    So your invoice has no line items in it?

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 12:22
    David Peck
    0

    You might do best tweeting Rusty or Lee. They're very helpful when they're in a position to be so.

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 12:23
    David Peck
    0

    I assume the log is empty too

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 12:26
    Ben McKean
    0

    Nope, here is the invoice obj

    enter image description here

    Just the tax as the only item...

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 12:33
    Ben McKean
    0

    Is it the normal Umbraco log or does Merchello have its own?

    I think Rusty and Lee are busy currently :(

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 13:01
    David Peck
    0

    You're checking out as an anonymous customer right? Your CustomerKey is null.

    I don't believe there is another log other than the UmbracoTraceLog.

    Otherwise all I can think is that you'll need to run the project against the Merchello source code. In each of the items in the invoice creation chain (see the merchello.config) you could set a break point to see if anything is going wrong. E.g an error here will result in items not being added (but also an error message). https://github.com/Merchello/Merchello/blob/9f4649ca3f453786316e1556f534ad5d71fab568/src/Merchello.Core/Chains/InvoiceCreation/CheckoutManager/ConvertItemCacheItemsToInvoiceItemsTask.cs

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 13:04
    Ben McKean
    0

    Yes, anonymous customer.

    There is nothing that I can see thats relevant in the Umbraco log.

    OK, thank you and thanks for your help.

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 14:32
    Ben McKean
    0

    I've not downloaded the Merchello source and debugged against my project and added a breakpoint to where you said. At this point this.CheckoutManager.Context.ItemCache.Items is 0 so it seems to be losing the items from the basket before then....

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 01, 2016 @ 15:06
    Rusty Swayne
    100

    Hey Ben,

    Just getting caught up with this, but my guess is the version key in your basket is changing somehow -

    Are you add/updating or removing anything after you've called the checkout manager?

    Every time there is a save in the basket the version key is updated. The item cache associated with the Basket remains, but (depending on the checkout context configuration) data from the checkout manager is purged - e.g. shipping and tax info by default.

    https://merchello.readme.io/docs/checkoutcontext

    I noticed you are passing the Basket version key into your CustomerContext instantiation which is perfectly valid if you are using the basket version keys for some reason externally:

     var context = CheckoutContext.CreateCheckoutContext(CurrentCustomer, Basket.VersionKey);
    

    However, if you're not, I suggest instantiating the CustomerContext via the UmbracoContext

      var customerContext = PluggableObjectHelper.GetInstance<CustomerContextBase>("CustomerContext", UmbracoContext);
    

    text = PluggableObjectHelper.GetInstance

    Can you give that a go and see if that does what you need?

    Other things you might try:

    In version 2.1.0, we've moved the default CheckoutContext settings to be configurable in the Merchello.config:

    <checkoutContextSettings>
        <setting alias="InvoiceNumberPrefix" value="FT" />
        <setting alias="ApplyTaxesToInvoice" value="true" />
        <setting alias="RaiseCustomerEvents" value="false" />
        <setting alias="ResetCustomerManagerDataOnVersionChange" value="false" />
        <setting alias="ResetPaymentManagerDataOnVersionChange" value="true" />
        <setting alias="ResetExtendedManagerDataOnVersionChange" value="true" />
        <setting alias="ResetShippingManagerDataOnVersionChange" value="true" />
        <setting alias="ResetOfferManagerDataOnVersionChange" value="true" />
        <setting alias="EmptyBasketOnPaymentSuccess" value="true" />
    </checkoutContextSettings>
    

    And if you don't want to augment the checkout processes validation (altering or removing line items) you can either remove the configurations for those tasks or write your own to make your own assertions:

    <taskChain alias="ItemCacheValidation">
      <!-- Added Merchello Version 1.11.0
      This chain validates basket and wish list items against values in the back office to assert that the customer has not
      added items to their basket that were subsequently changed in the back office prior to checkout.  The process is needed
      as the relation between the basket and wish list items are decoupled from the actual persisted values.
      -->
        <tasks>
            <task type="Merchello.Web.Validation.Tasks.ValidateProductsExistTask, Merchello.Web" />
            <!--
                The following task is intended to assert that pricing and/or on sale value has not changed in the back office since the
                customer has placed an item into their basket or wish list. If you have made custom pricing modifications in your
                implementation, you may either remove this task or adjust your code to add a new extended data value
                merchLineItemAllowsValidation = false
                to the line item so that it is skipped in the validation process.
            -->
            <task type="Merchello.Web.Validation.Tasks.ValidateProductPriceTask, Merchello.Web" />
            <!--
                Validates that products are still in inventory
            -->
            <task type="Merchello.Web.Validation.Tasks.ValidateProductInventoryTask, Merchello.Web" />
        </tasks>
    </taskChain>
    
  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 15:08
    David Peck
    1

    It was on the tip of my tongue to say that ;-)

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 15:14
    Ben McKean
    0

    Hi Rusty,

    In my checkout process, I call:

            var context = CheckoutContext.CreateCheckoutContext(CurrentCustomer, Basket.VersionKey);
    
            var checkoutManager = context.Customer.Basket().GetCheckoutManager();
    

    a few times. Basically when I add a billing address, add some notes and then finally, at the payment stage (which is failing at the moment because the value is £0).

    Should I not be calling CreateCheckoutContext each time?

    Nothing is changing in the basket at all.

    Just to confirm, should I try the following? Your code got broken up by the editor:

     var customerContext = PluggableObjectHelper.GetInstance<CustomerContextBase>("CustomerContext", UmbracoContext);
    

    Thanks

  • Ben McKean 272 posts 549 karma points
    Aug 01, 2016 @ 15:48
    Ben McKean
    0

    OK great.

    I've changed

    var context = CheckoutContext.CreateCheckoutContext(CurrentCustomer, Basket.VersionKey);
    

    to

     var customerContext = PluggableObjectHelper.GetInstance<CustomerContextBase>("CustomerContext", UmbracoContext);
    

    throughout and it looks like its working now.

    Now to figure out why its not redirecting to PayPal for payment.....

    Thanks both for your help.

Please Sign in or register to post replies

Write your reply to:

Draft