int punchOutDocumentId; Int32.TryParse(ConfigurationManager.AppSettings["PunchOutDocumentId"], out punchOutDocumentId); var item = FindItemFromDocumentId(docId,cart,punchOutDocumentId); if (item == null) { // this wasn't an existing document so the new document id needs stamping on the last item item = cart.Last(); if (docId != null) { var attribute = new ProductVariantAttribute(); attribute.Id = punchOutDocumentId; // add this to the product attributes item.AttributesXml = _productAttributeParser.AddProductAttribute(item.AttributesXml, attribute, docId); _shoppingCartService.UpdateShoppingCartItemAttributes(_workContext.CurrentCustomer, item.Id, item.AttributesXml); }