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
* /
Shipment Items Problems
-
- Ensign (ENS)
- Posts: 3
- Joined: Thu Sep 25, 2008 10:06 pm
Re: Shipment Items Problems
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.
Basket basket = Token.Instance.User.Basket;
Still, I would expect none to work or all to work. I'm obviously not seeing something here.
Re: Shipment Items Problems
I was leaning towards the fact you're added the shipment object to the basket object prior to actually saving the shipment object.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();
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
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