Example #1
0
    private static void SaveEnquiryItems(Order order, Int32 jobId, Store store)
    {
        // Insert each Order Item
        using (SqlText insertItem = new SqlText(
                   "Insert Into [ALL_EnquiryItems] " +
                   "(JobId, ProductId, ProductCode, ProductLink, ProductSupplierName, ProductSupplierPublicUrl, Quantity ) " +
                   "Values (@JobId, @ProductId, @ProductCode, @ProductLink, @ProductSupplierName, @ProductSupplierPublicUrl, @Quantity )", crmConnectionStringName))
        {
            Int16 itemCount = 0;
            // Database connection is held open whilst each item is inserted
            foreach (OrderItem item in order.Items)
            {
                string prodCode = "";
                if (!string.IsNullOrEmpty(item.Sku))
                {
                    prodCode = item.Sku;
                }
                else
                {
                    prodCode = item.Product.ModelNumber;
                }

                string supplierLink = "";
                if (item.Product.CustomFields != null && item.Product.CustomFields.Count > 0)
                {
                    foreach (ProductCustomField fld in item.Product.CustomFields)
                    {
                        if (fld.FieldName == "SupplierPublicURL")
                        {
                            supplierLink = fld.FieldValue;
                        }
                    }
                }

                insertItem.AddParameter("@JobId", jobId);
                insertItem.AddParameter("@ProductId", item.ProductId);
                insertItem.AddParameter("@ProductCode", prodCode);
                insertItem.AddParameter("@ProductLink", store.StoreUrl.Trim() + item.Product.NavigateUrl.Substring(2));
                if (item.Product.Manufacturer != null && item.Product.Manufacturer.Name != null)
                {
                    insertItem.AddParameter("@ProductSupplierName", item.Product.Manufacturer.Name);
                }
                else
                {
                    insertItem.AddParameter("@ProductSupplierName", System.Data.SqlTypes.SqlString.Null);
                }
                insertItem.AddParameter("@ProductSupplierPublicUrl", supplierLink);
                insertItem.AddParameter("@Quantity", item.Quantity);

                int x = insertItem.ExecuteNonQuery();
                insertItem.ClearParameters();
            } // end foreach
        }
    }