コード例 #1
0
    private bool CreateOrder(ShoppingCartInfo shoppingCart)
    {
        try
        {
            // Set order culture
            shoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode;
            // Update customer preferences
            CustomerInfoProvider.SetCustomerPreferredSettings(shoppingCart);
            // Create order
            ShoppingCartInfoProvider.SetOrder(shoppingCart);
        }
        catch (Exception ex)
        {
            // Log exception
            loggedExceptions.Add(ex);
            return(false);
        }

        if (shoppingCart.OrderId > 0)
        {
            // Track order conversion
            var name = ECommerceSettings.OrderConversionName(shoppingCart.SiteName);
            ECommerceHelper.TrackOrderConversion(shoppingCart, name);
            ECommerceHelper.TrackOrderItemsConversions(shoppingCart);
            // Log purchase activity
            if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(MembershipContext.AuthenticatedUser))
            {
                var totalPriceInMainCurrency = shoppingCart.TotalPriceInMainCurrency;
                var formattedPrice           = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, CurrencyInfoProvider.GetMainCurrency(shoppingCart.ShoppingCartSiteID));

                TrackActivityPurchasedProducts(shoppingCart, ContactID);
                TrackActivityPurchase(shoppingCart.OrderId,
                                      ContactID,
                                      totalPriceInMainCurrency,
                                      formattedPrice);
            }

            return(true);
        }

        LogError("Save order action failed", EVENT_CODE_SAVING);
        return(false);
    }