コード例 #1
0
    protected override void SaveStepData(object sender, StepEventArgs e)
    {
        base.SaveStepData(sender, e);

        // Just set current filed values into EditableObject, saving was canceled in OnBeforeSave
        customerForm.SaveData(null, false);

        var customer = customerForm.EditedObject as CustomerInfo;

        if (customer == null)
        {
            throw new InvalidOperationException("Customer cannot be null while saving step data.");
        }

        var typeSelector = TypeSelector;

        // Clear company fields for non-company type
        if ((typeSelector != null) && !typeSelector.Value.Equals(COMPANY_TYPE))
        {
            customer.CustomerCompany           = "";
            customer.CustomerOrganizationID    = "";
            customer.CustomerTaxRegistrationID = "";
        }

        if (customer.CustomerID < 1 && ShoppingCart.ShoppingCartUserID > 0)
        {
            // Connect newly created customer with registered user -> if user returns to the site, customer`s data will be filled
            customer.CustomerUserID = ShoppingCart.ShoppingCartUserID;
        }
        customer.CustomerSiteID = ShoppingCart.ShoppingCartSiteID;

        var shoppingService = Service.Resolve <IShoppingService>();

        shoppingService.SetCustomer(customer);

        // Address cannot be inserted before customer is saved (otherwise it would be an orphan address)
        // In case of address update - AddressName and AddressPersonalName should be re-generated according current customer info (if not present on the address form)
        if (((shoppingService.GetBillingAddress() == null) ||
             (shoppingService.GetShippingAddress() == null) ||
             (ShoppingCart.ShoppingCartCompanyAddress != null)) &&
            (customer.CustomerID > 0))
        {
            SaveCustomerAddresses(ShoppingCart);
        }

        ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);

        // Update contact with customer details
        var dci     = DataClassInfoProvider.GetDataClassInfo(customer.TypeInfo.ObjectClassName);
        var mapper  = new ContactDataMapper(dci.ClassName, dci.ClassContactOverwriteEnabled);
        var checker = new CustomerContactDataPropagationChecker();

        Service.Resolve <IContactDataInjector>().Inject(customer, ContactID, mapper, checker);
    }
コード例 #2
0
    protected override void SaveStepData(object sender, StepEventArgs e)
    {
        base.SaveStepData(sender, e);

        // Just set current filed values into EditableObject, saving was canceled in OnBeforeSave
        customerForm.SaveData(null, false);

        var customer     = customerForm.EditedObject as CustomerInfo;
        var typeSelector = TypeSelector;

        // Clear company fields for non-company type
        if ((customer != null) && (typeSelector != null) && !typeSelector.Value.Equals(COMPANY_TYPE))
        {
            customer.CustomerCompany           = "";
            customer.CustomerOrganizationID    = "";
            customer.CustomerTaxRegistrationID = "";
        }

        var cart = ShoppingCart;

        // Assign save customer to the shopping cart -> will be needed for addresses
        cart.Customer = SaveCustomer(customer, cart.ShoppingCartUserID, cart.ShoppingCartSiteID);

        // Address cannot be inserted before customer is saved (otherwise it would be an orphan address)
        // In case of address update - AddressName and AddressPersonalName should be re-generated according current customer info (if not present on the address form)
        if (((cart.ShoppingCartBillingAddress != null) ||
             (cart.ShoppingCartShippingAddress != null) ||
             (cart.ShoppingCartCompanyAddress != null)) &&
            (customer != null) && (customer.CustomerID > 0))
        {
            SaveCustomerAddresses(cart);
        }

        ShoppingCartInfoProvider.SetShoppingCartInfo(cart);

        // Update contact with customer details
        if (customer != null)
        {
            var dci     = DataClassInfoProvider.GetDataClassInfo(customer.TypeInfo.ObjectClassName);
            var mapper  = new ContactDataMapper(dci.ClassName, dci.ClassContactOverwriteEnabled);
            var checker = new CustomerContactDataPropagationChecker();
            Service.Resolve <IContactDataInjector>().Inject(customer, ContactID, mapper, checker);
        }
    }