Copied to clipboard

Flag this post as spam?

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


  • Flavio Spezi 128 posts 314 karma points
    Jan 14, 2015 @ 17:58
    Flavio Spezi
    0

    When Basket is converted to Invoice?

    In the workflow of Merchello, when Basket is transformed to Invoice, and Basket does not exists anymore?

    My issue is this:
    I would to allow buyer to manage Basket to the confirm of Basket. After this time the basket can generate Invoice, and Basket can be deleted.
    If buyer want to pay with credit card (example PayPal), the confirm proces does not delete the Basket: I would that the Basket is the current basket of current Customer.

    Instead of this, what I look in my project is this: when the Buyer click to Confirm button of Basket workflow (with PayPal plugin), the Buyer is redirect to PayPal where he will do login to pay. At the same time the Basket is deleted, and a new Invoice is creaded and editable by backoffice. The "payment status" is "unpaid", but in "Sale Information" I look this:

    • "Payment procedded by: PayPal"
    • "Authorized: $123.00"

    But the buyer has not confirmed any payment in PayPal website.

    Then I am to search the method that create/confirm the Invoice (and Basket deleted).

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 15, 2015 @ 21:26
    Rusty Swayne
    100

    The basket is deleted in the Merchello.Core.Sales.SalesPrepartionEvents class by handling the SalesPrepartionBase.Finalizing event.

    This event is raised when a payment is processed but you bring up a good use case for cancelling the event.

    You could simply use the invoice service to save the prepared invoice and then use the extension method off of the invoice to capture the authorize payment which would circumvent the event altogether.

     var invoice = salesPreparation.PrepareInvoice();
     var invoiceService = MerchelloContext.Current.Services.InvoiceService;
    
     // invoice must be saved before applying a payment albeit typically the provider checks this and should do it for you. 
     invoiceService.Save(invoice); 
    
     var paymentResult = invoice.AuthorizePayment([PayPalPaymentMethod]);
     // then redirect
    

    Haven't tested it but I think it would do exactly what you want.

  • Flavio Spezi 128 posts 314 karma points
    Jan 16, 2015 @ 15:32
    Flavio Spezi
    0

    Perfect!

    It works fine! Thanks!

    My previous line code was:
    var paymentResult = salesPreparation.AuthorizePayment(paymentMethodKey.Value, processorArgs);

    The issue is solved with this line code:
    var paymentResult = invoice.AuthorizePayment(paymentMethodKey.Value, processorArgs);

    Now, when buyer abort payment in PayPal website, he return to check-up step of basket. It is exactly what I want.

    If buyer confirm payment in PayPal website, he go to confirmed step of basket. Ok.
    But the basket is not empty.

    What is the best practice now?
    I need to invoke basket.Empty()?
    Or I forgot something?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 16, 2015 @ 16:22
    Rusty Swayne
    0

    basket.Empty() will clear all of the items in the basket.

    There will be some orphaned information (sale prepartion data) in the merchItemCache and merchItemCacheItem table. If the checkout is anonymous, this could be cleaned automatically if you configure the RemoveAnonymousCustomers scheduled task

    In /Config/umbracoSettings.config

     <scheduledTasks>
          <!-- add Merchello remove anonymous customs task -->
          <task log="true" alias="removeAnonymousCustomers" interval="14400" url="http://[YOUR DOMAIN]/umbraco/Merchello/ScheduledTasksApi/RemoveAnonymousCustomers"/>
    

    Otherwise you can delete the information by doing something like:

     if (customer == null) 
     {
            var itemCacheService = MerchelloContext.Current.Services.ItemCacheService;
            var itemCache = itemCacheService.GetItemCacheByCustomer(customer,  ItemCacheType.Checkout);
            itemCacheService.Delete(itemCache);
     }
    

    or create another scheduled task to clear out this info after X days or something.

  • Flavio Spezi 128 posts 314 karma points
    Jan 17, 2015 @ 11:46
    Flavio Spezi
    1

    The code that you suggest fires an exception: NullReferenceException.

    Stack:

    • in Merchello.Core.Persistence.Repositories.ItemCacheRepository.PersistDeletedItem(IItemCache entity) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Persistence\Repositories\ItemCacheRepository.cs:line 133
    • in Merchello.Core.Persistence.Repositories.MerchelloRepositoryBase`1.PersistDeletedItem(IEntity entity) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Persistence\Repositories\MerchelloRepositoryBase.cs:line 126
    • in Merchello.Core.Persistence.UnitOfWork.PetaPocoUnitOfWork.Commit(Action`1 transactionCompleting) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Persistence\UnitOfWork\PetaPocoUnitOfWork.cs:line 115
    • in Merchello.Core.Services.ItemCacheService.Delete(IItemCache itemCache, Boolean raiseEvents) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Services\ItemCacheService.cs:line 177

    The behavior is this:

    • add article to basket
    • invoke method with your code: the exception is not fired; basket is empty sometimes.
    • invoke method with your code more times: the exception is fired; basket does not change.

    Now, if user add another article to basket, the cycle restart.

    I try to use basket.Empty(). It seems to do what I need: a basket ready to a new customer order.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies