Copied to clipboard

Flag this post as spam?

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


  • Calvin Frei 106 posts 314 karma points
    Jan 04, 2016 @ 14:47
    Calvin Frei
    0

    ItemCacheService.Saving removes Billing and Shipping address

    Hi

    I've used the ItemCacheService.Saving for changing the Price of a Basket Item.

    It worked (don't remember when) but after upgrading to 1.12.1 and then to 1.13.3 I figured out that it only works if the price is the same.

    private void ItemCacheService_Saving(IItemCacheService sender, SaveEventArgs<IItemCache> e)
    {
        foreach (IItemCache entity in e.SavedEntities)
            {
                // If it's a basket we try to update the price
                if (entity.ItemCacheType == ItemCacheType.Basket)
                {
                    foreach (ILineItem lineItem in entity.Items)
                    {
                        lineItem.Price = 10M;
                    }
                }
            }
    }
    

    The problem is, that when you save the shipping and billing address:

    _preparation.SaveBillToAddress(billingAddress.ToIBillingAddress());
    _preparation.SaveShipToAddress(shippingAddress.ToIShippingAddress());
    

    The billing/shipping address is empty when you try to receive it after redirect:

    IAddress shippingAddress = _preparation.GetShipToAddress();
    
    if (shippingAddress == null)
    {
        // Always here
    }
    

    I liked this way because when the user has something in the basket and leaves for some days and comes back the price will be re-assigned by this event.

    Thank you
    Calvin

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 04, 2016 @ 16:48
    Rusty Swayne
    100

    This is going to be the validation chain defined in the Merchello.config.

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

    Try removing (or better yet replacing) the

     <task type="Merchello.Web.Validation.Tasks.ValidateProductPriceTask, Merchello.Web" />
    
  • Calvin Frei 106 posts 314 karma points
    Jan 07, 2016 @ 07:35
    Calvin Frei
    1

    Hi Rusty

    Thank you for your answer. I've added merchLineItemAllowsValidation = false to the extended data and now it seems to work!

    But as you said It's probably better that I replace it with our custom ValidateProductPriceTask.

    Thank you Calvin

Please Sign in or register to post replies

Write your reply to:

Draft