Update BasketItem Shipping

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
SkylineTech
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 22
Joined: Tue Jul 13, 2010 9:12 am

Update BasketItem Shipping

Post by SkylineTech » Wed Aug 25, 2010 8:17 am

I am trying to update the Price of a BasketItem of type OrderItemType.Shipping. In other words, when looping through the BasketItems of the current Basket, when the OrderItemType is Shipping, I need to update the Price. When I try to do this, the Price is updated, but it doesn't seem to "stick" when I display the same BasketItem on another page. For instance, in the PaymentPage UserControl, in the ShipmentItemsGrid_RowDataBound Event, I can find the BasketItem I am looking for. I update the Price and this change is reflected on the screen. Now, when I go to the ShipMethodPage UserControl, the Price of said BasketItem is reverted back to what it was before I updated it. It looks to me that the BasketItemId is changing from page to page. Furthermore, the updated Price is not reflected in the BasketTotalSummary UserControl either.

Basically, what I need to do is update the Price of the BasketItem that corresponds to Shipping and have the value "stick" from screen to screen. Aslo, why does the BasketItemId change from screen to screen - it's like the BasketItems are always being deleted and re-added as you move from screen to screen - is this true?

My custom code in PaymentPage.ascx.cs. This will actually update the Price and display the updated Price on the screen.

Code: Select all

    protected void ShipmentItemsGrid_RowDataBound(object sender, GridViewRowEventArgs e) {

        if (e.Row.RowType == DataControlRowType.DataRow) {
            BasketItem currentItem = (BasketItem)e.Row.DataItem;

            // Are we reading the shipping Line Item.  If so, then adjust the Price.        
            if (currentItem.OrderItemType == OrderItemType.Shipping) {
                Label priceLabel = (Label)e.Row.FindControl("Price");

                Basket basket = Token.Instance.User.Basket;
                BasketItem basketItem = currentItem;
                
                basket.DeleteItem(currentItem.BasketItemId);
                basketItem.Price = CalculateShippingCost(currentItem.Price);
                basket.Items.Add(basketItem);

                basket.Save();
                basket.Recalculate();

                priceLabel.Text = basketItem.Price.ToString("ulc");
            }
        }

    }  // End ShipmentItemsGrid_RowDataBound Event.

My custom code in ShipMethod.ascx.cs. The BasketItem Price is back to what it was prior to updating.

Code: Select all

    protected void ShipmentItemsGrid_RowDataBound(object sender, GridViewRowEventArgs e) {

        if (e.Row.RowType == DataControlRowType.DataRow) {
            BasketItem currentItem = (BasketItem)e.Row.DataItem;

            // Are we reading the shipping Line Item.  If so, then adjust the Price.        
            if (currentItem.OrderItemType == OrderItemType.Shipping) {
                Label priceLabel = (Label)e.Row.FindControl("Price");

                Basket basket = Token.Instance.User.Basket;
                BasketItem basketItem = basket.Items.Find(delegate(BasketItem i) { return i.BasketItemId == currentItem.BasketItemId; });

                priceLabel.Text = basketItem.Price.ToString("ulc");
            }
        }

    }  // End ShipmentItemsGrid_RowDataBound Event.
Thanks for the help!

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Update BasketItem Shipping

Post by mazhar » Thu Aug 26, 2010 12:29 am

Reason is that AbleCommerce API recalculates the shipping at different points during checkout process and then updates the data back into database. That's why your custom values are changing back to API calculations because you injected that price into the system. When system recalculates the shipping prices it doesn't know any thing about your custom price causing a revert to actual shipping amount.

SkylineTech
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 22
Joined: Tue Jul 13, 2010 9:12 am

Re: Update BasketItem Shipping

Post by SkylineTech » Thu Aug 26, 2010 11:57 am

Thank you mazhar . . .

Post Reply