Shipment Items Problems

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
catatonic67
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Thu Sep 25, 2008 10:06 pm

Shipment Items Problems

Post by catatonic67 » Thu Sep 25, 2008 10:16 pm

I ran into this today and it caused me considerable grief. I'm sure I'm doing something wrong--sequence thing or something--but I can't seem to add more than one item to a shipment. I put together a little test eliminate external influences and still I get the same result. I can add basket items without any trouble whatever.

Basket basket = new Basket();
basket.Save();

BasketShipment shipment = new BasketShipment();
shipment.BasketId = basket.BasketId;
shipment.AddressId = 45471;
shipment.ShipMessage = "aaaaaa";
shipment.WarehouseId = 1;
shipment.ShipMethodId = 3;
basket.Shipments.Add(shipment);
shipment.Save();

BasketItem item = new BasketItem();
item.BasketShipmentId = shipment.BasketShipmentId;
item.ParentItemId = 0;
item.ProductId = 150;
item.Weight = 0;
item.OrderItemTypeId = (int) OrderItemType.Product;
item.BasketId = basket.BasketId;
item.Name = "Item1";
item.Price = (decimal) 11.11;
item.Quantity = 1;
item.Sku = "111111";
item.TaxCodeId = 1;
item.ShippableId = (int)Shippable.Yes;
item.Save();
shipment.Items.Add(item);
Response.Write(shipment.Items.Count + " <br />");
shipment.Save();

item = new BasketItem();
item.BasketShipmentId = shipment.BasketShipmentId;
item.ParentItemId = 0;
item.ProductId = 151;
item.Weight = 0;
item.OrderItemTypeId = (int)OrderItemType.Product;
item.BasketId = basket.BasketId;
item.Name = "Item2";
item.Price = (decimal)11.12;
item.Quantity = 2;
item.Sku = "22222";
item.TaxCodeId = 1;
item.ShippableId = (int)Shippable.Yes;
item.Save();
shipment.Items.Add(item);
Response.Write(shipment.Items.Count + " <br />");
shipment.Save();

Response.Write(shipment.Items.Count);

/* Prints
* 1
* 1
* 1
* /

catatonic67
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Thu Sep 25, 2008 10:06 pm

Re: Shipment Items Problems

Post by catatonic67 » Fri Sep 26, 2008 5:04 am

Interesting. If I change the basket default constructor to the following, it works!

Basket basket = Token.Instance.User.Basket;

Still, I would expect none to work or all to work. I'm obviously not seeing something here.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Shipment Items Problems

Post by AbleMods » Fri Sep 26, 2008 8:22 pm

catatonic67 wrote:Basket basket = new Basket();
basket.Save();

BasketShipment shipment = new BasketShipment();
shipment.BasketId = basket.BasketId;
shipment.AddressId = 45471;
shipment.ShipMessage = "aaaaaa";
shipment.WarehouseId = 1;
shipment.ShipMethodId = 3;
basket.Shipments.Add(shipment);
shipment.Save();
I was leaning towards the fact you're added the shipment object to the basket object prior to actually saving the shipment object.

Instead of:
basket.Shipments.Add(shipment);
shipment.Save();

maybe try:
shipment.Save();
basket.Shipments.Add(shipment);

Not sure though - definitely behavior that is unexpected, at least from an outside perspective.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

Post Reply