Page 1 of 1

Shipment Items Problems

Posted: Thu Sep 25, 2008 10:16 pm
by catatonic67
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
* /

Re: Shipment Items Problems

Posted: Fri Sep 26, 2008 5:04 am
by catatonic67
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.

Re: Shipment Items Problems

Posted: Fri Sep 26, 2008 8:22 pm
by AbleMods
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.