<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!--
This file is subject to the terms and conditions defined in the
files 'LICENSE' and 'NOTICE', which are part of this source
code package.
-->

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">

    <simple-method method-name="createCustomer" short-description="Create Customer" login-required="false">
        <call-class-method class-name="org.ofbiz.product.store.ProductStoreWorker" method-name="getProductStore" ret-field="productStore">
            <field field="request" type="javax.servlet.ServletRequest"/>
        </call-class-method>

        <set from-field="productStore.allowPassword" field="allowPassword"/>
        <set from-field="productStore.defaultPassword" field="defaultPassword"/>
        <if-empty field="allowPassword">
            <set field="allowPassword" value="Y"/>
        </if-empty>
        <if-empty field="defaultPassword">
            <set field="defaultPassword" value="<PASSWORD>"/>
        </if-empty>

        <property-to-field resource="security" property="username.lowercase" default="false" field="username_lowercase"/>
        <property-to-field resource="security" property="password.lowercase" default="false" field="password_lowercase"/>

        <now-timestamp field="nowStamp"/>
        <set value="CUSTOMER" field="parameters.roleTypeId"/>

        <if-compare field="allowPassword" operator="not-equals" value="Y">
            <set from-field="defaultPassword" field="parameters.PASSWORD"/>
            <set from-field="defaultPassword" field="parameters.CONFIRM_PASSWORD"/>
            <set value="No hint set, account not yet enabled" field="parameters.PASSWORD_HINT"/>
        </if-compare>

        <if-compare field="productStore.usePrimaryEmailUsername" operator="equals" value="Y">
            <set field="parameters.USERNAME" from-field="parameters.CUSTOMER_EMAIL"/>
        </if-compare>

        <!-- if username and/or password should be lowercased, do that now -->
        <if-compare field="username_lowercase" operator="equals" value="true">
            <call-object-method obj-field="parameters.USERNAME" method-name="toLowerCase" ret-field="parameters.USERNAME"/>
        </if-compare>
        <if-compare field="password_lowercase" operator="equals" value="true">
            <call-object-method obj-field="parameters.PASSWORD" method-name="toLowerCase" ret-field="parameters.PASSWORD"/>
            <call-object-method obj-field="parameters.CONFIRM_PASSWORD" method-name="toLowerCase" ret-field="parameters.CONFIRM_PASSWORD"/>
        </if-compare>

        <!-- Create the UserLogin Record -->
        <call-map-processor in-map-name="parameters" out-map-name="userLoginContext">
            <simple-map-processor name="newUserLogin">
                <process field="USERNAME"><copy to-field="userLoginId"/><not-empty><fail-property resource="PartyUiLabels" property="PartyUserLoginMissingError"/></not-empty></process>
                <process field="PASSWORD"><copy to-field="currentPassword"/><not-empty><fail-property resource="PartyUiLabels" property="PartyPasswordMissing"/></not-empty></process>
                <process field="CONFIRM_PASSWORD">
                    <compare-field operator="equals" field="PASSWORD"><fail-property resource="PartyUiLabels" property="PartyPasswordMatchError"/></compare-field>
                    <copy to-field="currentPasswordVerify"/>
                </process>
                <process field="PASSWORD_HINT"><copy to-field="passwordHint"/></process>
            </simple-map-processor>
        </call-map-processor>
        <if-not-empty field="userLoginContext.userLoginId">
            <set from-field="userLoginContext.userLoginId" field="userLoginExistsMap.userLoginId"/>
            <find-by-primary-key entity-name="UserLogin" map="userLoginExistsMap" value-field="existingUserLogin"/>
            <if-not-empty field="existingUserLogin">
                <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyUserNameInUse"/>
                <string-to-list string="${tempErrorMessage}" message-field="USERNAME" list="error_list"/>
            </if-not-empty>
        </if-not-empty>

        <make-value entity-name="UserLogin" value-field="newUserLogin"/>
        <set from-field="userLoginContext.userLoginId" field="newUserLogin.userLoginId"/>
        <set from-field="userLoginContext.currentPassword" field="newUserLogin.currentPassword"/>
        <set from-field="userLoginContext.passwordHint" field="newUserLogin.passwordHint"/>

        <!-- Check the password, etc for validity -->
        <script lang="groovy"><![CDATA[
            String password = (String) userLoginContext.get("currentPassword");
            String confirmPassword = (String) userLoginContext.get("currentPasswordVerify");
            String passwordHint = (String) userLoginContext.get("passwordHint");
            org.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin, null, password, confirmPassword, passwordHint, error_list, true, locale);
        ]]></script>

        <!-- Create the Person -->
        <call-map-processor in-map-name="parameters" out-map-name="personContext">
            <simple-map-processor name="newPerson">
                <process field="USER_FIRST_NAME">
                    <copy to-field="firstName"/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyFirstNameMissing"/></not-empty>
                </process>
                <process field="USER_MIDDLE_NAME"><copy to-field="middleName"/></process>
                <process field="USER_LAST_NAME">
                    <copy to-field="lastName"/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyLastNameMissingError"/></not-empty>
                </process>
                <process field="USER_TITLE"><copy to-field="personalTitle"/></process>
                <process field="USER_SUFFIX"><copy to-field="suffix"/></process>
                <process field="USER_BIRTHDATE">
                    <convert type="Date" to-field="birthDate"><fail-property resource="PartyUiLabels" property="PartyBirthDateMissingError"/></convert>
                </process>
                <process field="USER_GENDER"><copy to-field="gender"/></process>
            </simple-map-processor>
        </call-map-processor>

        <log level="info" message="Creating new customer, newUserLogin=${newUserLogin}"/>

        <!-- Create the PartyRole -->
        <set from-field="parameters.roleTypeId" field="partyRoleContext.roleTypeId"/>

        <!-- Create the Postal Address -->
        <if-compare field="parameters.USE_ADDRESS" operator="equals" value="false">
            <!-- address not used, do nothing -->
            <else>
                <call-map-processor in-map-name="parameters" out-map-name="addressContext">
                    <simple-map-processor name="newPerson">
                        <make-in-string field="fullName">
                            <in-field field="USER_FIRST_NAME"/><constant> </constant>
                            <in-field field="USER_MIDDLE_NAME"/><constant> </constant>
                            <in-field field="USER_LAST_NAME"/>
                        </make-in-string>
                        <process field="roleTypeId"><copy/></process>
                        <process field="fullName"><copy to-field="toName"/></process>
                        <process field="CUSTOMER_ADDRESS1">
                            <copy to-field="address1"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyAddressLine1MissingError"/></not-empty>
                        </process>
                        <process field="CUSTOMER_ADDRESS2"><copy to-field="address2"/></process>
                        <process field="CUSTOMER_CITY">
                            <copy to-field="city"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyCityMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_STATE"><copy to-field="stateProvinceGeoId"/></process>
                        <process field="CUSTOMER_POSTAL_CODE">
                            <copy to-field="postalCode"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyZipCodeMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_COUNTRY">
                            <copy to-field="countryGeoId"/>
                            <not-empty><fail-property resource="CommonUiLabels" property="CommonCountryMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_ADDRESS_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                    </simple-map-processor>
                </call-map-processor>
                <if-compare value="USA" operator="equals" field="parameters.CUSTOMER_COUNTRY">
                    <if-empty field="parameters.CUSTOMER_STATE">
                        <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyStateInUsMissing"/>
                        <string-to-list string="${tempErrorMessage}" message-field="CUSTOMER_STATE" list="error_list"/>
                    </if-empty>
                </if-compare>
                <if-compare value="CAN" operator="equals" field="parameters.CUSTOMER_COUNTRY">
                    <if-empty field="parameters.CUSTOMER_STATE">
                        <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyStateInCanadaMissing"/>
                        <string-to-list string="${tempErrorMessage}" message-field="CUSTOMER_STATE" list="error_list"/>
                    </if-empty>
                </if-compare>
            </else>
        </if-compare>

        <!-- Create the Home Phone -->
        <if-not-empty field="parameters.CUSTOMER_HOME_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="homePhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_HOME_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_HOME_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_HOME_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_HOME_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_HOME_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Work Phone -->
        <if-not-empty field="parameters.CUSTOMER_WORK_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="workPhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_WORK_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_WORK_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_WORK_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_WORK_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_WORK_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Fax Phone -->
        <if-not-empty field="parameters.CUSTOMER_FAX_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="faxPhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_FAX_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_FAX_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_FAX_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_FAX_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_FAX_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Mobile Phone -->
        <if-not-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="mobilePhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_MOBILE_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_MOBILE_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_MOBILE_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_MOBILE_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_MOBILE_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Check for required Phone -->
        <if-compare field="parameters.REQUIRE_PHONE" operator="equals" value="true">
            <if-empty field="parameters.CUSTOMER_HOME_CONTACT">
                <if-empty field="parameters.CUSTOMER_WORK_CONTACT">
                    <if-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
                        <call-map-processor in-map-name="parameters" out-map-name="dummymap">
                            <simple-map-processor name="checkRequiredPhone">
                                <process field="REQUIRED_PHONE">
                                    <not-empty>
                                    <fail-property resource="PartyUiLabels" property="PartyContactTelephoneMissingError"/></not-empty>
                                </process>
                            </simple-map-processor>
                        </call-map-processor>
                    </if-empty>
                </if-empty>
            </if-empty>
        </if-compare>

        <!-- Create the email address -->

        <!-- Check for required E-Mail -->
        <if-compare field="parameters.REQUIRE_EMAIL" operator="not-equals" value="false">
            <call-map-processor in-map-name="parameters" out-map-name="emailContext">
                <simple-map-processor name="newEmail">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_EMAIL">
                        <copy to-field="emailAddress"/>
                        <not-empty><fail-property resource="PartyUiLabels" property="PartyEmailAddressMissingError"/></not-empty>
                        <validate-method method="isEmail"><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></validate-method>
                    </process>
                    <process field="CUSTOMER_EMAIL_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        <else>
            <call-map-processor in-map-name="parameters" out-map-name="emailContext">
                <simple-map-processor name="newEmail">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_EMAIL">
                        <copy to-field="emailAddress"/>
                        <validate-method method="isEmail"><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></validate-method>
                    </process>
                    <process field="CUSTOMER_EMAIL_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </else>
        </if-compare>

        <!-- create the PartyDataSource entry to track where this info came from... -->
        <make-value entity-name="PartyDataSource" value-field="partyDataSource"/>
        <set value="ECOMMERCE_SITE" field="partyDataSource.dataSourceId"/>
        <set from-field="nowStamp" field="partyDataSource.fromDate"/>
        <set value="Y" field="partyDataSource.isCreate"/>
        <!-- get the visit from the session to get the visitId -->
        <session-to-field field="visit"/>
        <set from-field="visit.visitId" field="partyDataSource.visitId"/>

        <!-- now that everything is validated & setup, check to see if there are errors, then call the services -->
        <check-errors/>

        <set-service-fields map="personContext" service-name="createPersonAndUserLogin" to-map="personUserLoginContext"/>
        <set-service-fields map="newUserLogin" service-name="createPersonAndUserLogin" to-map="personUserLoginContext"/>
        <set from-field="newUserLogin.currentPassword" field="personUserLoginContext.currentPasswordVerify"/>
        <!-- the above copy is okay since we checked already that they are the same -->
        <call-service service-name="createPersonAndUserLogin" in-map-name="personUserLoginContext">
            <result-to-field result-name="partyId" field="tempMap.partyId"/>
            <result-to-field result-name="newUserLogin" field="createdUserLogin"/>
        </call-service>
        <set-current-user-login value-field="createdUserLogin"/>

        <!-- now that we have the partyId, put it where it needs to go... -->
        <set from-field="tempMap.partyId" field="partyDataSource.partyId"/>
        <set from-field="tempMap.partyId" field="userLoginContext.partyId"/>
        <set from-field="tempMap.partyId" field="personContext.partyId"/>
        <set from-field="tempMap.partyId" field="partyRoleContext.partyId"/>
        <set from-field="tempMap.partyId" field="addressContext.partyId"/>
        <set from-field="tempMap.partyId" field="homePhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="workPhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="faxPhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="mobilePhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="emailContext.partyId"/>

        <create-value value-field="partyDataSource"/>
        <call-service service-name="createPartyRole" in-map-name="partyRoleContext" include-user-login="true"/>

        <!-- shipping address -->
        <if-compare field="parameters.USE_ADDRESS" operator="equals" value="false">
            <!-- address not used, do nothing -->
            <else>
                <call-service service-name="createPartyPostalAddress" in-map-name="addressContext">
                    <result-to-field result-name="contactMechId" field="addressPurposeContext.contactMechId"/>
                </call-service>
                <set from-field="tempMap.partyId" field="addressPurposeContext.partyId"/>
                <!-- create the shipping location -->
                <set value="SHIPPING_LOCATION" field="addressPurposeContext.contactMechPurposeTypeId"/>
                <call-service service-name="createPartyContactMechPurpose" in-map-name="addressPurposeContext"/>
                <!-- also consider this address the general correspondence address -->
                <set value="GENERAL_LOCATION" field="addressPurposeContext.contactMechPurposeTypeId"/>
                <call-service service-name="createPartyContactMechPurpose" in-map-name="addressPurposeContext"/>
            </else>
        </if-compare>

        <!-- home phone -->
        <if-not-empty field="parameters.CUSTOMER_HOME_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="homePhoneContext">
                <result-to-field result-name="contactMechId" field="homePhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="homePhonePurposeContext.partyId"/>
            <set value="PHONE_HOME" field="homePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="homePhonePurposeContext"/>
            <set value="PRIMARY_PHONE" field="homePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="homePhonePurposeContext"/>
        </if-not-empty>

        <!-- work phone -->
        <if-not-empty field="parameters.CUSTOMER_WORK_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="workPhoneContext">
                <result-to-field result-name="contactMechId" field="workPhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="workPhonePurposeContext.partyId"/>
            <set value="PHONE_WORK" field="workPhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="workPhonePurposeContext"/>
        </if-not-empty>

        <!-- fax phone -->
        <if-not-empty field="parameters.CUSTOMER_FAX_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="faxPhoneContext">
                <result-to-field result-name="contactMechId" field="faxPhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="faxPhonePurposeContext.partyId"/>
            <set value="FAX_NUMBER" field="faxPhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="faxPhonePurposeContext"/>
        </if-not-empty>

        <!-- mobile phone -->
        <if-not-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="mobilePhoneContext">
                <result-to-field result-name="contactMechId" field="mobilePhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="mobilePhonePurposeContext.partyId"/>
            <set value="PHONE_MOBILE" field="mobilePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="mobilePhonePurposeContext"/>
        </if-not-empty>

        <!-- email address -->
        <if-not-empty field="emailContext.emailAddress">
            <call-service service-name="createPartyEmailAddress" in-map-name="emailContext">
                <result-to-field result-name="contactMechId" field="emailPurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="emailPurposeContext.partyId"/>
            <set value="PRIMARY_EMAIL" field="emailPurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="emailPurposeContext"/>
        </if-not-empty>

        <!-- club number -->
        <if-not-empty field="parameters.REQUIRE_CLUB">
            <set from-field="tempMap.partyId" field="personLookup.partyId"/>
            <find-by-primary-key map="personLookup" value-field="personVo" entity-name="Person"/>
            <if-empty field="parameters.CLUB_NUMBER">
                <script lang="groovy"><![CDATA[
                    clubId = org.ofbiz.party.party.PartyWorker.createClubId(delegator, "999", 13);
                    parameters.put("CLUB_NUMBER", clubId);
                ]]></script>
            </if-empty>
            <set from-field="parameters.CLUB_NUMBER" field="personVo.memberId"/>
            <store-value value-field="personVo"/>
        </if-not-empty>

        <!-- Associated to Product Store (SCIPIO: Moved to before login) -->
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set field="createProductStoreRoleMap.userLogin" from-field="systemUserLogin"/>
        <set field="createProductStoreRoleMap.partyId" from-field="tempMap.partyId"/>
        <set field="createProductStoreRoleMap.roleTypeId" from-field="parameters.roleTypeId"/>
        <set field="createProductStoreRoleMap.productStoreId" from-field="parameters.emailProductStoreId"/>
        <call-service service-name="createProductStoreRole" in-map-name="createProductStoreRoleMap"/>

        <!-- security for manage profile (SCIPIO: Moved to before login) -->
        <set field="securityParams.userLoginId" from-field="createdUserLogin.userLoginId"/>
        <set field="securityParams.groupId" value="ECOMMERCE_CUSTOMER"/>
        <set field="securityParams.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="addUserLoginToSecurityGroup" in-map-name="securityParams"/>

        <!-- SCIPIO: If the store supports the default anon list, convert it now -->
        <if-not-empty field="createdUserLogin">
            <script lang="groovy"><![CDATA[
                context.convertListResult = org.ofbiz.order.shoppinglist.ShoppingListEvents.convertAnonShoppingListsToRegisteredForStore(request, response, context.createdUserLogin);
            ]]></script>
            <if-compare-field field="convertListResult" operator="not-equals" value="success">
                <add-error><fail-property resource="OrderErrorUiLabels" property="shoppinglistevents.error_converting_wishlist_contact_support"/></add-error>
                <check-errors/>
            </if-compare-field>
        </if-not-empty>

        <!-- now finished, log in the user and set the cart's partyId to that of the newly created customer ... -->
        <if-compare field="allowPassword" operator="equals" value="Y">
            <script lang="groovy"><![CDATA[
                import org.ofbiz.order.shoppingcart.*;
                org.ofbiz.webapp.control.LoginWorker.doBasicLogin(createdUserLogin, request);

                // SCIPIO: Run after-login events (based on doMainLogin)
                org.ofbiz.webapp.control.RequestHandler.getRequestHandler(request.getServletContext()).runAfterLoginEvents(request, response);

                org.ofbiz.webapp.control.LoginWorker.autoLoginSet(request, response);

                CartUpdate cartUpdate = CartUpdate.updateSection(request);
                try { // SCIPIO
                    cart = cartUpdate.getCartForUpdate();
                    
                    cart.setOrderPartyId(tempMap.get("partyId"));
                    
                    cart = cartUpdate.commit(cart); // SCIPIO
                } finally {
                    cartUpdate.close();
                }
            ]]></script>
        </if-compare>

        <!-- send off the registration email -->
        <if-not-empty field="emailContext.emailAddress">
            <set from-field="parameters.emailProductStoreId" field="storeEmailLookup.productStoreId"/>
            <set value="PRDS_CUST_REGISTER" field="storeEmailLookup.emailType"/>
            <find-by-primary-key map="storeEmailLookup" entity-name="ProductStoreEmailSetting"  value-field="storeEmail"/>
            <if-not-empty field="storeEmail.bodyScreenLocation">
                <get-related-one value-field="createdUserLogin" relation-name="Person" to-value-field="person"/>
                <set field="bodyParameters.person" from-field="person"/>
                <set field="emailParams.bodyParameters" from-field="bodyParameters"/>
                <set field="emailParams.sendTo" from-field="emailContext.emailAddress"/>
                <set field="emailParams.subject" from-field="storeEmail.subject"/>
                <set field="emailParams.sendFrom" from-field="storeEmail.fromAddress"/>
                <set field="emailParams.sendCc" from-field="storeEmail.ccAddress"/>
                <set field="emailParams.sendBcc" from-field="storeEmail.bccAddress"/>
                <set field="emailParams.contentType" from-field="storeEmail.contentType"/>
                <set field="emailParams.bodyScreenUri" from-field="storeEmail.bodyScreenLocation"/>
                <set field="emailParams.emailType" from-field="storeEmailLookup.emailType"/>
                <!-- SCIPIO: Determine webSiteId for store email -->
                <set field="emailParams.webSiteId" value="${groovy:org.ofbiz.webapp.website.WebSiteWorker.getWebSiteId(request)}"/>
                <call-service-asynch service-name="sendMailFromScreen" in-map-name="emailParams" include-user-login="true"/>
            </if-not-empty>
        </if-not-empty>

        <!-- tell the control servlet that we just logged in the user... -->
        <set value="TRUE" field="_LOGIN_PASSED_"/>
        <field-to-request field="_LOGIN_PASSED_"/>

        <!-- SCIPIO -->
        <property-to-field field="successMessage" resource="CommonUiLabels" property="CommonAccountRegistered"/>
        <set field="_event_message_" value="${successMessage}" />
    </simple-method>

    <!-- =========================================== -->
    <!-- ======== Anonymous Checkout Events ======== -->
    <!-- =========================================== --><commit_msg>stock patch: shop: CustomerEvents.xml: createUser: bugfix _LOGIN_PASSED_ set at wrong time<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!--
This file is subject to the terms and conditions defined in the
files 'LICENSE' and 'NOTICE', which are part of this source
code package.
-->

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">

    <simple-method method-name="createCustomer" short-description="Create Customer" login-required="false">
        <call-class-method class-name="org.ofbiz.product.store.ProductStoreWorker" method-name="getProductStore" ret-field="productStore">
            <field field="request" type="javax.servlet.ServletRequest"/>
        </call-class-method>

        <set from-field="productStore.allowPassword" field="allowPassword"/>
        <set from-field="productStore.defaultPassword" field="defaultPassword"/>
        <if-empty field="allowPassword">
            <set field="allowPassword" value="Y"/>
        </if-empty>
        <if-empty field="defaultPassword">
            <set field="defaultPassword" value="<PASSWORD>"/>
        </if-empty>

        <property-to-field resource="security" property="username.lowercase" default="false" field="username_lowercase"/>
        <property-to-field resource="security" property="password.lowercase" default="false" field="password_lowercase"/>

        <now-timestamp field="nowStamp"/>
        <set value="CUSTOMER" field="parameters.roleTypeId"/>

        <if-compare field="allowPassword" operator="not-equals" value="Y">
            <set from-field="defaultPassword" field="parameters.PASSWORD"/>
            <set from-field="defaultPassword" field="parameters.CONFIRM_PASSWORD"/>
            <set value="No hint set, account not yet enabled" field="parameters.PASSWORD_HINT"/>
        </if-compare>

        <if-compare field="productStore.usePrimaryEmailUsername" operator="equals" value="Y">
            <set field="parameters.USERNAME" from-field="parameters.CUSTOMER_EMAIL"/>
        </if-compare>

        <!-- if username and/or password should be lowercased, do that now -->
        <if-compare field="username_lowercase" operator="equals" value="true">
            <call-object-method obj-field="parameters.USERNAME" method-name="toLowerCase" ret-field="parameters.USERNAME"/>
        </if-compare>
        <if-compare field="password_lowercase" operator="equals" value="true">
            <call-object-method obj-field="parameters.PASSWORD" method-name="toLowerCase" ret-field="parameters.PASSWORD"/>
            <call-object-method obj-field="parameters.CONFIRM_PASSWORD" method-name="toLowerCase" ret-field="parameters.CONFIRM_PASSWORD"/>
        </if-compare>

        <!-- Create the UserLogin Record -->
        <call-map-processor in-map-name="parameters" out-map-name="userLoginContext">
            <simple-map-processor name="newUserLogin">
                <process field="USERNAME"><copy to-field="userLoginId"/><not-empty><fail-property resource="PartyUiLabels" property="PartyUserLoginMissingError"/></not-empty></process>
                <process field="PASSWORD"><copy to-field="currentPassword"/><not-empty><fail-property resource="PartyUiLabels" property="PartyPasswordMissing"/></not-empty></process>
                <process field="CONFIRM_PASSWORD">
                    <compare-field operator="equals" field="PASSWORD"><fail-property resource="PartyUiLabels" property="PartyPasswordMatchError"/></compare-field>
                    <copy to-field="currentPasswordVerify"/>
                </process>
                <process field="PASSWORD_HINT"><copy to-field="passwordHint"/></process>
            </simple-map-processor>
        </call-map-processor>
        <if-not-empty field="userLoginContext.userLoginId">
            <set from-field="userLoginContext.userLoginId" field="userLoginExistsMap.userLoginId"/>
            <find-by-primary-key entity-name="UserLogin" map="userLoginExistsMap" value-field="existingUserLogin"/>
            <if-not-empty field="existingUserLogin">
                <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyUserNameInUse"/>
                <string-to-list string="${tempErrorMessage}" message-field="USERNAME" list="error_list"/>
            </if-not-empty>
        </if-not-empty>

        <make-value entity-name="UserLogin" value-field="newUserLogin"/>
        <set from-field="userLoginContext.userLoginId" field="newUserLogin.userLoginId"/>
        <set from-field="userLoginContext.currentPassword" field="newUserLogin.currentPassword"/>
        <set from-field="userLoginContext.passwordHint" field="newUserLogin.passwordHint"/>

        <!-- Check the password, etc for validity -->
        <script lang="groovy"><![CDATA[
            String password = (String) userLoginContext.get("currentPassword");
            String confirmPassword = (String) userLoginContext.get("currentPasswordVerify");
            String passwordHint = (String) userLoginContext.get("passwordHint");
            org.ofbiz.common.login.LoginServices.checkNewPassword(newUserLogin, null, password, confirmPassword, passwordHint, error_list, true, locale);
        ]]></script>

        <!-- Create the Person -->
        <call-map-processor in-map-name="parameters" out-map-name="personContext">
            <simple-map-processor name="newPerson">
                <process field="USER_FIRST_NAME">
                    <copy to-field="firstName"/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyFirstNameMissing"/></not-empty>
                </process>
                <process field="USER_MIDDLE_NAME"><copy to-field="middleName"/></process>
                <process field="USER_LAST_NAME">
                    <copy to-field="lastName"/>
                    <not-empty><fail-property resource="PartyUiLabels" property="PartyLastNameMissingError"/></not-empty>
                </process>
                <process field="USER_TITLE"><copy to-field="personalTitle"/></process>
                <process field="USER_SUFFIX"><copy to-field="suffix"/></process>
                <process field="USER_BIRTHDATE">
                    <convert type="Date" to-field="birthDate"><fail-property resource="PartyUiLabels" property="PartyBirthDateMissingError"/></convert>
                </process>
                <process field="USER_GENDER"><copy to-field="gender"/></process>
            </simple-map-processor>
        </call-map-processor>

        <log level="info" message="Creating new customer, newUserLogin=${newUserLogin}"/>

        <!-- Create the PartyRole -->
        <set from-field="parameters.roleTypeId" field="partyRoleContext.roleTypeId"/>

        <!-- Create the Postal Address -->
        <if-compare field="parameters.USE_ADDRESS" operator="equals" value="false">
            <!-- address not used, do nothing -->
            <else>
                <call-map-processor in-map-name="parameters" out-map-name="addressContext">
                    <simple-map-processor name="newPerson">
                        <make-in-string field="fullName">
                            <in-field field="USER_FIRST_NAME"/><constant> </constant>
                            <in-field field="USER_MIDDLE_NAME"/><constant> </constant>
                            <in-field field="USER_LAST_NAME"/>
                        </make-in-string>
                        <process field="roleTypeId"><copy/></process>
                        <process field="fullName"><copy to-field="toName"/></process>
                        <process field="CUSTOMER_ADDRESS1">
                            <copy to-field="address1"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyAddressLine1MissingError"/></not-empty>
                        </process>
                        <process field="CUSTOMER_ADDRESS2"><copy to-field="address2"/></process>
                        <process field="CUSTOMER_CITY">
                            <copy to-field="city"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyCityMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_STATE"><copy to-field="stateProvinceGeoId"/></process>
                        <process field="CUSTOMER_POSTAL_CODE">
                            <copy to-field="postalCode"/>
                            <not-empty><fail-property resource="PartyUiLabels" property="PartyZipCodeMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_COUNTRY">
                            <copy to-field="countryGeoId"/>
                            <not-empty><fail-property resource="CommonUiLabels" property="CommonCountryMissing"/></not-empty>
                        </process>
                        <process field="CUSTOMER_ADDRESS_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                    </simple-map-processor>
                </call-map-processor>
                <if-compare value="USA" operator="equals" field="parameters.CUSTOMER_COUNTRY">
                    <if-empty field="parameters.CUSTOMER_STATE">
                        <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyStateInUsMissing"/>
                        <string-to-list string="${tempErrorMessage}" message-field="CUSTOMER_STATE" list="error_list"/>
                    </if-empty>
                </if-compare>
                <if-compare value="CAN" operator="equals" field="parameters.CUSTOMER_COUNTRY">
                    <if-empty field="parameters.CUSTOMER_STATE">
                        <property-to-field field="tempErrorMessage" resource="PartyUiLabels" property="PartyStateInCanadaMissing"/>
                        <string-to-list string="${tempErrorMessage}" message-field="CUSTOMER_STATE" list="error_list"/>
                    </if-empty>
                </if-compare>
            </else>
        </if-compare>

        <!-- Create the Home Phone -->
        <if-not-empty field="parameters.CUSTOMER_HOME_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="homePhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_HOME_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_HOME_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_HOME_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_HOME_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_HOME_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Work Phone -->
        <if-not-empty field="parameters.CUSTOMER_WORK_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="workPhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_WORK_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_WORK_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_WORK_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_WORK_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_WORK_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Fax Phone -->
        <if-not-empty field="parameters.CUSTOMER_FAX_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="faxPhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_FAX_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_FAX_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_FAX_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_FAX_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_FAX_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Create the Mobile Phone -->
        <if-not-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
            <call-map-processor in-map-name="parameters" out-map-name="mobilePhoneContext">
                <simple-map-processor name="newTelecomNumber">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_MOBILE_COUNTRY"><copy to-field="countryCode"/></process>
                    <process field="CUSTOMER_MOBILE_AREA"><copy to-field="areaCode"/></process>
                    <process field="CUSTOMER_MOBILE_CONTACT"><copy to-field="contactNumber"/></process>
                    <process field="CUSTOMER_MOBILE_EXT"><copy to-field="extension"/></process>
                    <process field="CUSTOMER_MOBILE_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </if-not-empty>

        <!-- Check for required Phone -->
        <if-compare field="parameters.REQUIRE_PHONE" operator="equals" value="true">
            <if-empty field="parameters.CUSTOMER_HOME_CONTACT">
                <if-empty field="parameters.CUSTOMER_WORK_CONTACT">
                    <if-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
                        <call-map-processor in-map-name="parameters" out-map-name="dummymap">
                            <simple-map-processor name="checkRequiredPhone">
                                <process field="REQUIRED_PHONE">
                                    <not-empty>
                                    <fail-property resource="PartyUiLabels" property="PartyContactTelephoneMissingError"/></not-empty>
                                </process>
                            </simple-map-processor>
                        </call-map-processor>
                    </if-empty>
                </if-empty>
            </if-empty>
        </if-compare>

        <!-- Create the email address -->

        <!-- Check for required E-Mail -->
        <if-compare field="parameters.REQUIRE_EMAIL" operator="not-equals" value="false">
            <call-map-processor in-map-name="parameters" out-map-name="emailContext">
                <simple-map-processor name="newEmail">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_EMAIL">
                        <copy to-field="emailAddress"/>
                        <not-empty><fail-property resource="PartyUiLabels" property="PartyEmailAddressMissingError"/></not-empty>
                        <validate-method method="isEmail"><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></validate-method>
                    </process>
                    <process field="CUSTOMER_EMAIL_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        <else>
            <call-map-processor in-map-name="parameters" out-map-name="emailContext">
                <simple-map-processor name="newEmail">
                    <process field="roleTypeId"><copy/></process>
                    <process field="CUSTOMER_EMAIL">
                        <copy to-field="emailAddress"/>
                        <validate-method method="isEmail"><fail-property resource="PartyUiLabels" property="PartyEmailAddressNotFormattedCorrectly"/></validate-method>
                    </process>
                    <process field="CUSTOMER_EMAIL_ALLOW_SOL"><copy to-field="allowSolicitation"/></process>
                </simple-map-processor>
            </call-map-processor>
        </else>
        </if-compare>

        <!-- create the PartyDataSource entry to track where this info came from... -->
        <make-value entity-name="PartyDataSource" value-field="partyDataSource"/>
        <set value="ECOMMERCE_SITE" field="partyDataSource.dataSourceId"/>
        <set from-field="nowStamp" field="partyDataSource.fromDate"/>
        <set value="Y" field="partyDataSource.isCreate"/>
        <!-- get the visit from the session to get the visitId -->
        <session-to-field field="visit"/>
        <set from-field="visit.visitId" field="partyDataSource.visitId"/>

        <!-- now that everything is validated & setup, check to see if there are errors, then call the services -->
        <check-errors/>

        <set-service-fields map="personContext" service-name="createPersonAndUserLogin" to-map="personUserLoginContext"/>
        <set-service-fields map="newUserLogin" service-name="createPersonAndUserLogin" to-map="personUserLoginContext"/>
        <set from-field="newUserLogin.currentPassword" field="personUserLoginContext.currentPasswordVerify"/>
        <!-- the above copy is okay since we checked already that they are the same -->
        <call-service service-name="createPersonAndUserLogin" in-map-name="personUserLoginContext">
            <result-to-field result-name="partyId" field="tempMap.partyId"/>
            <result-to-field result-name="newUserLogin" field="createdUserLogin"/>
        </call-service>
        <set-current-user-login value-field="createdUserLogin"/>

        <!-- now that we have the partyId, put it where it needs to go... -->
        <set from-field="tempMap.partyId" field="partyDataSource.partyId"/>
        <set from-field="tempMap.partyId" field="userLoginContext.partyId"/>
        <set from-field="tempMap.partyId" field="personContext.partyId"/>
        <set from-field="tempMap.partyId" field="partyRoleContext.partyId"/>
        <set from-field="tempMap.partyId" field="addressContext.partyId"/>
        <set from-field="tempMap.partyId" field="homePhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="workPhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="faxPhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="mobilePhoneContext.partyId"/>
        <set from-field="tempMap.partyId" field="emailContext.partyId"/>

        <create-value value-field="partyDataSource"/>
        <call-service service-name="createPartyRole" in-map-name="partyRoleContext" include-user-login="true"/>

        <!-- shipping address -->
        <if-compare field="parameters.USE_ADDRESS" operator="equals" value="false">
            <!-- address not used, do nothing -->
            <else>
                <call-service service-name="createPartyPostalAddress" in-map-name="addressContext">
                    <result-to-field result-name="contactMechId" field="addressPurposeContext.contactMechId"/>
                </call-service>
                <set from-field="tempMap.partyId" field="addressPurposeContext.partyId"/>
                <!-- create the shipping location -->
                <set value="SHIPPING_LOCATION" field="addressPurposeContext.contactMechPurposeTypeId"/>
                <call-service service-name="createPartyContactMechPurpose" in-map-name="addressPurposeContext"/>
                <!-- also consider this address the general correspondence address -->
                <set value="GENERAL_LOCATION" field="addressPurposeContext.contactMechPurposeTypeId"/>
                <call-service service-name="createPartyContactMechPurpose" in-map-name="addressPurposeContext"/>
            </else>
        </if-compare>

        <!-- home phone -->
        <if-not-empty field="parameters.CUSTOMER_HOME_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="homePhoneContext">
                <result-to-field result-name="contactMechId" field="homePhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="homePhonePurposeContext.partyId"/>
            <set value="PHONE_HOME" field="homePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="homePhonePurposeContext"/>
            <set value="PRIMARY_PHONE" field="homePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="homePhonePurposeContext"/>
        </if-not-empty>

        <!-- work phone -->
        <if-not-empty field="parameters.CUSTOMER_WORK_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="workPhoneContext">
                <result-to-field result-name="contactMechId" field="workPhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="workPhonePurposeContext.partyId"/>
            <set value="PHONE_WORK" field="workPhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="workPhonePurposeContext"/>
        </if-not-empty>

        <!-- fax phone -->
        <if-not-empty field="parameters.CUSTOMER_FAX_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="faxPhoneContext">
                <result-to-field result-name="contactMechId" field="faxPhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="faxPhonePurposeContext.partyId"/>
            <set value="FAX_NUMBER" field="faxPhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="faxPhonePurposeContext"/>
        </if-not-empty>

        <!-- mobile phone -->
        <if-not-empty field="parameters.CUSTOMER_MOBILE_CONTACT">
            <call-service service-name="createPartyTelecomNumber" in-map-name="mobilePhoneContext">
                <result-to-field result-name="contactMechId" field="mobilePhonePurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="mobilePhonePurposeContext.partyId"/>
            <set value="PHONE_MOBILE" field="mobilePhonePurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="mobilePhonePurposeContext"/>
        </if-not-empty>

        <!-- email address -->
        <if-not-empty field="emailContext.emailAddress">
            <call-service service-name="createPartyEmailAddress" in-map-name="emailContext">
                <result-to-field result-name="contactMechId" field="emailPurposeContext.contactMechId"/>
            </call-service>
            <set from-field="tempMap.partyId" field="emailPurposeContext.partyId"/>
            <set value="PRIMARY_EMAIL" field="emailPurposeContext.contactMechPurposeTypeId"/>
            <call-service service-name="createPartyContactMechPurpose" in-map-name="emailPurposeContext"/>
        </if-not-empty>

        <!-- club number -->
        <if-not-empty field="parameters.REQUIRE_CLUB">
            <set from-field="tempMap.partyId" field="personLookup.partyId"/>
            <find-by-primary-key map="personLookup" value-field="personVo" entity-name="Person"/>
            <if-empty field="parameters.CLUB_NUMBER">
                <script lang="groovy"><![CDATA[
                    clubId = org.ofbiz.party.party.PartyWorker.createClubId(delegator, "999", 13);
                    parameters.put("CLUB_NUMBER", clubId);
                ]]></script>
            </if-empty>
            <set from-field="parameters.CLUB_NUMBER" field="personVo.memberId"/>
            <store-value value-field="personVo"/>
        </if-not-empty>

        <!-- Associated to Product Store (SCIPIO: Moved to before login) -->
        <entity-one entity-name="UserLogin" value-field="systemUserLogin">
            <field-map field-name="userLoginId" value="system"/>
        </entity-one>
        <set field="createProductStoreRoleMap.userLogin" from-field="systemUserLogin"/>
        <set field="createProductStoreRoleMap.partyId" from-field="tempMap.partyId"/>
        <set field="createProductStoreRoleMap.roleTypeId" from-field="parameters.roleTypeId"/>
        <set field="createProductStoreRoleMap.productStoreId" from-field="parameters.emailProductStoreId"/>
        <call-service service-name="createProductStoreRole" in-map-name="createProductStoreRoleMap"/>

        <!-- security for manage profile (SCIPIO: Moved to before login) -->
        <set field="securityParams.userLoginId" from-field="createdUserLogin.userLoginId"/>
        <set field="securityParams.groupId" value="ECOMMERCE_CUSTOMER"/>
        <set field="securityParams.userLogin" from-field="systemUserLogin"/>
        <call-service service-name="addUserLoginToSecurityGroup" in-map-name="securityParams"/>

        <!-- SCIPIO: If the store supports the default anon list, convert it now -->
        <if-not-empty field="createdUserLogin">
            <script lang="groovy"><![CDATA[
                context.convertListResult = org.ofbiz.order.shoppinglist.ShoppingListEvents.convertAnonShoppingListsToRegisteredForStore(request, response, context.createdUserLogin);
            ]]></script>
            <if-compare-field field="convertListResult" operator="not-equals" value="success">
                <add-error><fail-property resource="OrderErrorUiLabels" property="shoppinglistevents.error_converting_wishlist_contact_support"/></add-error>
                <check-errors/>
            </if-compare-field>
        </if-not-empty>

        <!-- now finished, log in the user and set the cart's partyId to that of the newly created customer ... -->
        <if-compare field="allowPassword" operator="equals" value="Y">
            <script lang="groovy"><![CDATA[
                import org.ofbiz.order.shoppingcart.*;
                org.ofbiz.webapp.control.LoginWorker.doBasicLogin(createdUserLogin, request);

                // SCIPIO: Tell login passed _before_ the after-login events, so they can tell
                request.setAttribute("_LOGIN_PASSED_", "TRUE");

                // SCIPIO: Run after-login events (based on doMainLogin)
                org.ofbiz.webapp.control.RequestHandler.getRequestHandler(request.getServletContext()).runAfterLoginEvents(request, response);

                org.ofbiz.webapp.control.LoginWorker.autoLoginSet(request, response);

                CartUpdate cartUpdate = CartUpdate.updateSection(request);
                try { // SCIPIO
                    cart = cartUpdate.getCartForUpdate();
                    
                    cart.setOrderPartyId(tempMap.get("partyId"));
                    
                    cart = cartUpdate.commit(cart); // SCIPIO
                } finally {
                    cartUpdate.close();
                }
            ]]></script>
        </if-compare>

        <!-- send off the registration email -->
        <if-not-empty field="emailContext.emailAddress">
            <set from-field="parameters.emailProductStoreId" field="storeEmailLookup.productStoreId"/>
            <set value="PRDS_CUST_REGISTER" field="storeEmailLookup.emailType"/>
            <find-by-primary-key map="storeEmailLookup" entity-name="ProductStoreEmailSetting"  value-field="storeEmail"/>
            <if-not-empty field="storeEmail.bodyScreenLocation">
                <get-related-one value-field="createdUserLogin" relation-name="Person" to-value-field="person"/>
                <set field="bodyParameters.person" from-field="person"/>
                <set field="emailParams.bodyParameters" from-field="bodyParameters"/>
                <set field="emailParams.sendTo" from-field="emailContext.emailAddress"/>
                <set field="emailParams.subject" from-field="storeEmail.subject"/>
                <set field="emailParams.sendFrom" from-field="storeEmail.fromAddress"/>
                <set field="emailParams.sendCc" from-field="storeEmail.ccAddress"/>
                <set field="emailParams.sendBcc" from-field="storeEmail.bccAddress"/>
                <set field="emailParams.contentType" from-field="storeEmail.contentType"/>
                <set field="emailParams.bodyScreenUri" from-field="storeEmail.bodyScreenLocation"/>
                <set field="emailParams.emailType" from-field="storeEmailLookup.emailType"/>
                <!-- SCIPIO: Determine webSiteId for store email -->
                <set field="emailParams.webSiteId" value="${groovy:org.ofbiz.webapp.website.WebSiteWorker.getWebSiteId(request)}"/>
                <call-service-asynch service-name="sendMailFromScreen" in-map-name="emailParams" include-user-login="true"/>
            </if-not-empty>
        </if-not-empty>

        <!-- tell the control servlet that we just logged in the user...
            SCIPIO: This belongs above
        <set value="TRUE" field="_LOGIN_PASSED_"/>
        <field-to-request field="_LOGIN_PASSED_"/>
        -->

        <!-- SCIPIO -->
        <property-to-field field="successMessage" resource="CommonUiLabels" property="CommonAccountRegistered"/>
        <set field="_event_message_" value="${successMessage}" />
    </simple-method>

    <!-- =========================================== -->
    <!-- ======== Anonymous Checkout Events ======== -->
    <!-- =========================================== -->
{'fraction_non_alphanumeric': 0.13997051135982844, 'fraction_numerical': 0.0006366865491589036, 'mean_word_length': 2.539195920303605, 'pattern_counts': {'":': 0, '<': 1033, '<?xml version=': 2, '>': 1033, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4826393', 'n_tokens_mistral': 16294, 'n_tokens_neox': 15555, 'n_words': 2390}