Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
Hello Guys,

I have been searched through the forum for ideas similar to what I have in mind but to vain.

I have a site running couch cart that emails the cart details to both the admin and the customer. My plan is to incorporate the Extended Users functionality whereas the sole purpose would be: a logged in member will not have to re-enter the customer details required at checkout. (The checkout page has a form that the customer fills out details of their business, telephone, address etc for shipping purposes).

My questions thus are;

1. how best should i approach the integration of the Extended Users functionality so that when the logged in user gets to the checkout phase, his/her contact info is pre-filled?

2. Is it possible to show a history of the emails he/she had received from previous transactions? (I want to pre-assume this is not possible as Couch CMS aint an order management system)

Any ideas would be highly appreciated.

Thanks.
RE: point 2, you could show a history of emails/transactions if you used a clonable template.

This clonable template should link to the extended user ID either through an editable tag or a relation. Once each transaction is complete, you submit something similar to this

Code: Select all
<cms:db_persist _invalidate_cache='1' _mode='create' _masterpage='INSERT-TEMPLATE-NAME' k_page_title="INSERT-TRANSACTION-TITLE" extended_user=INSERT-EXTENDED-USER-ID/>


This code should be submitted in the k_success event

This is just a rough template but the functionality you requested is available through using databound forms and cloned pages.
Thanks alot @keakie for your assistance. I believe I should be able to use your solution to tackle the second phase of my problem. Although I will need to tackle the way to handle the Extended Users problem first.

Any suggestions regarding that?
@kajoe14,
if we treat 'extended-users' like ordinary Couch templates (which is actually what they are), then if a user is logged-in you can easily access all information from his record (cloned-page) the way we do with normal pages.

The retrieved info can then be used to pre-fill the checkout form.

As to where that info came from in the first place, either you can give the user a dedicated page to edit his 'profile' or if that is empty then the first time she uses the checkout form, serve it empty for her to fill out the details and then save it in her profile for future interactions.

So, in closing, I don't see any big complexity in the process.
If you are running against any specific problem, do let us know the details and we can discuss it further.
Thanks for your input @KK.

I will follow your suggestions and hopefully I will be able to achieve some positive result.
Hei @KK,

I did attempt to follow through your suggestions although I have to say I got stuck at some point.
Progress so far:

The data part of the databound is being captured at users/index.php. (The users folder is in the main directory)
users/index.php

Code: Select all
<?php require_once( '../couch/cms.php' ); ?>

<cms:template clonable='1' title='Users' hidden='1'>
   <cms:editable name="company_name" type='text'  />
    <cms:editable name='y_tunnus' type='text' ' />
    <cms:editable name='first_name' required='1' type='text'  />
    <cms:editable name='last_name' required='1' type='text'  />
    <cms:editable name="address" type='text' required='1' ' />
    <cms:editable name='postal_code' type='text' required='1'  />
    <cms:editable name='city' required='1' type='text' ' />
    <cms:editable name='country' required='1' type='dropdown' opt_values='Spain'  />
    <cms:editable name='email_address' required='1' validator='email' type='text'  />
    <cms:editable name='telephone' required='1' type='text'  />
</cms:template>

<?php COUCH::invoke(); ?>


I have tried to modify the checkout form using if/else statements to verify if the customer is registered or not before trying to pre-fill the customer's info. I have used the *id=k_user_id* to filter the customers details.
I want to assume this is where i am going wrong as when i tried to access the checkout page, the form had disappeared.

Here is the checkout form:
Code: Select all
<!-- member logged-in -->
<cms:if k_logged_in >
    <cms:pages masterpage='users/index.php' id=k_user_id limit='1'>
     
     
  <cms:form masterpage='users/index.php' mode='create' enctype='multipart/form-data' method='post' anchor='0' class="type_2">
    <cms:if k_success >
      <cms:db_persist_form _invalidate_cache='0' _auto_title='1'  />
     
      <cms:set email_from='hello@xxx.com' />
      <cms:set email_bcc='kajoe14@xxx.com' />
      <cms:set email_subject='Your order with kajoe14' />
      <cms:set email_debug='1' />
      <cms:embed 'sales_email.html' />
     
      <cms:set_flash name='order_complete_msg' value="<cms:embed 'sales_success_msg.html' />"/>
      <cms:pp_empty_cart />
      <cms:redirect k_page_link />
    </cms:if>
    <cms:if k_error >
      <div class="alert_box error">
        <ul>
          <cms:each k_error >
            <li><cms:show item /></li>
          </cms:each>
        </ul>
        <button class="close"></button>
      </div>
    </cms:if>
    <ul>
      <li class="row">
        <div class="col-sm-12">
          <label for="company_name" >Company name</label>
          <cms:if k_logged_in >
            <cms:input name="company_name" type="bound" value="<cms:show frm_company_name />" />
          <cms:else />
          <cms:input name="company_name" type="bound" id="company_name" />
          <cms:if k_error_name ><cms:show k_error_company_name /></cms:if>
          </cms:if>
        </div>
      </li>
      <li class="row">
        <div class="col-sm-12">
          <label for="y_tunnus">Business ID</label>
          <cms:if k_logged_in >
            <cms:input name="y_tunnus" type="bound" value="<cms:show frm_y_tunnus />" />
          <cms:else />
          <cms:input name="y_tunnus" type="bound" id="y_tunnus" />
          <cms:if k_error_name ><cms:show k_error_y_tunnus /></cms:if>
          </cms:if>
        </div>
      </li>
      <li class="row">
        <div class="col-sm-6">
          <label for="first_name" class="required">first name</label>
          <cms:if k_logged_in >
            <cms:input name="first_name" type="bound" value="<cms:show frm_first_name />" />
          <cms:else />
          <cms:input name="first_name" type="bound" id="first_name"  />
          <cms:if k_error_name ><cms:show k_error_first_name /></cms:if>
          </cms:if>
        </div>
        <div class="col-sm-6">
          <label for="last_name" class="required">last name</label>
          <cms:if k_logged_in >
            <cms:input name="last_name" type="bound" value="<cms:show frm_last_name />" />
          <cms:else />
          <cms:input name="last_name" type="bound" id="last_name"  />
          <cms:if k_error_name ><cms:show k_error_last_name /></cms:if>
          </cms:if>
        </div>
      </li>
      <li class="row">
        <div class="col-xs-12">
          <label for="address" class="required">address</label>
          <cms:if k_logged_in >
            <cms:input name="address" type="bound" value="<cms:show frm_address />" />
          <cms:else />
          <cms:input name="address" type="bound" id="address"  />
          <cms:if k_error_name ><cms:show k_error_address /></cms:if>
          </cms:if>
        </div>
      </li>
      <li class="row">
        <div class="col-sm-6">
          <label for="postal_code" class="required">Postal code</label>
          <cms:if k_logged_in >
            <cms:input name="postal_code" type="bound" value="<cms:show frm_postal_code />" />
          <cms:else />
          <cms:input name="postal_code" type="bound" id="postal_code" />
          <cms:if k_error_name ><cms:show k_error_postal_code /></cms:if>
          </cms:if>
        </div>
        <div class="col-sm-6">
          <label for="city" class="required">city</label>
          <cms:if k_logged_in >
            <cms:input name="city" type="bound" value="<cms:show frm_city />" />
          <cms:else />
          <cms:input name="city" type="bound" id="city" />
          <cms:if k_error_name ><cms:show k_error_city /></cms:if>
          </cms:if>
        </div>
      </li>
      <li class="row">
        <div class="col-sm-12">
          <label class="required">country</label>
          <div class="custom_select">
            <cms:if k_logged_in >
            <cms:input name="country" type="bound" value="<cms:show frm_country />" />
          <cms:else />
            <cms:input type="bound" name="country" />
            <cms:if k_error_name ><cms:show k_error_country /></cms:if>
            </cms:if>
          </div>
        </div>
      </li>
      <li class="row">
        <div class="col-sm-6">
          <label for="email_address" class="required">emaili</label>
          <cms:if k_logged_in >
            <cms:input name="email_address" type="bound" value="<cms:show frm_email_address />" />
          <cms:else />
          <cms:input name="email_address" type="bound" id="email_address" />
          <cms:if k_error_name ><cms:show k_error_email_address /></cms:if>
          </cms:if>
        </div>
        <div class="col-sm-6">
          <label for="telephone" class="required">Phone</label>
          <cms:if k_logged_in >
            <cms:input name="telephone" type="bound" value="<cms:show frm_telephone />" />
          <cms:else />
          <cms:input name="telephone" type="bound" id="telephone" />
          <cms:if k_error_name ><cms:show k_error_telephone /></cms:if>
          </cms:if>
        </div>
      </li>
    </ul>
    <footer class="bottom_box on_the_sides">
      <div class="left_side">
        <button class="button_blue middle_btn" type="submit" name="submit">order</button>
      </div>
    </footer>
  </cms:form>
<!-- member loggedin -->
</cms:pages>
</cms:if>


I also tried to use the same databound form for the registration form. i.e, register form that is also located in the users folder but to no success.

I guess what am trying to say is that some further direction would be appreciated.

Thanks.
Hi,

A couple of questions before we move forward with this issue -
1. Would *only* logged-in user access the checkout page? Or even anonymous (i.e. non-registered users) can access it?

2. The 'registration' form you have provided for new users - does it contain *all* the fields defined in 'users/index.php'?.
I.e. we can be sure that if a user is logged-in (registered), the address data is definitely available.

Awaiting reply.
1. The checkout form should/ will be used by anonymous members too. They do not need to have signed up to purchase the products- though, they will be required to fill out the checkout form for purposes of providing their shipping details.

2. Yes. The registration form is an exact copy of the users/index.php form. Although, it also contains the Username and Password for loging in. I have basically used the same files that you have provided in the forum while explaining the functionality of the extended users module.

Here is the users/register.php:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
    <cms:template title='Registration' hidden='1' />

    <cms:if k_logged_in >
        <!-- what is an already logged-in member doing on this page? Send back to homepage. -->
        <cms:redirect k_site_link />
    </cms:if>
   
    <!-- are there any success messages to show from previous actions? -->
    <cms:set success_msg="<cms:get_flash 'success_msg' />" />
    <cms:if success_msg >
        <div class="notice">
            <cms:if success_msg='1' >
                Your account has been created successfully and we have sent you an email.<br />
                Please click the verification link within that mail to activate your account.
            <cms:else />
                Activation was successful! You can now log in!<br />
                <a href="<cms:login_link redirect=k_site_link />">Login</a>
            </cms:if>
        </div>
    <cms:else />
       
        <!-- now the real work -->
        <cms:set action="<cms:gpc 'act' method='get'/>" />
       
        <!-- is the visitor here by clicking the account-activation link we emailed? -->
        <cms:if action='activate' >
            <h1>Activate account</h1>
       
            <cms:process_activation />
           
            <cms:if k_success >
                 <cms:set_flash name='success_msg' value='2' />
                 <cms:redirect k_page_link />         
            <cms:else />
                <cms:show k_error />
            </cms:if>
       
        <cms:else />
       
            <!-- show the registration form -->
            <style>
                form{ width:200px; }
            </style>
           
            <h1>Create an account</h1>

            <cms:form
                masterpage=k_user_template
                mode='create'
                enctype='multipart/form-data'
                method='post'
                anchor='0'
                >

                <cms:if k_success >       

                    <cms:check_spam email=frm_extended_user_email />           

                    <cms:db_persist_form
                        _invalidate_cache='0'
                        k_page_name = "<cms:random_name />"
                        k_publish_date = '0000-00-00 00:00:00'
                    />                   

                    <cms:if k_success >
                       
                        <cms:send_mail from="<cms:php>echo K_EMAIL_FROM;</cms:php>" to=frm_extended_user_email subject='New Account Confirmation' debug='1'>
                            Please click the following link to activate your account:
                            <cms:activation_link   frm_extended_user_email   />

                            Thanks,
                            Website Name
                        </cms:send_mail>                       
                                               
                        <cms:set_flash name='success_msg' value='1' />
                        <cms:redirect k_page_link />
                    </cms:if>
                </cms:if>

                <cms:if k_error >
                    <font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
                </cms:if>       

                DisplayName:<br />
                <cms:input name='k_page_title' type='bound' /><br />
               
                Email Address:<br />
                <cms:input name='extended_user_email' type='bound' /><br />
                   
                Password:<br />
                <cms:input name='extended_user_password' type='bound' /><br />
               
                Repeat Password:<br />
                <cms:input name='extended_user_password_repeat' type='bound' /><br />
               
               
                <ul>
                    <li class="row">
                      <div class="col-sm-12">
                        <label for="company_name" >Company</label>
                        <cms:input name="company_name" type="bound" id="company_name" />
                        <cms:if k_error_name ><cms:show k_error_company_name /></cms:if>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-sm-12">
                        <label for="y_tunnus">Business ID</label>
                        <cms:input name="y_tunnus" type="bound" id="y_tunnus" />
                        <cms:if k_error_name ><cms:show k_error_y_tunnus /></cms:if>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-sm-6">
                        <label for="first_name" class="required">First name</label>
                        <cms:input name="first_name" type="bound" id="first_name"  />
                        <cms:if k_error_name ><cms:show k_error_first_name /></cms:if>
                      </div>
                      <div class="col-sm-6">
                        <label for="last_name" class="required">last name</label>
                        <cms:input name="last_name" type="bound" id="last_name"  />
                        <cms:if k_error_name ><cms:show k_error_last_name /></cms:if>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-xs-12">
                        <label for="address" class="required">address</label>
                        <cms:input name="address" type="bound" id="address"  />
                        <cms:if k_error_name ><cms:show k_error_address /></cms:if>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-sm-6">
                        <label for="postal_code" class="required">Postal code</label>
                        <cms:input name="postal_code" type="bound" id="postal_code" />
                        <cms:if k_error_name ><cms:show k_error_postal_code /></cms:if>
                      </div>
                      <div class="col-sm-6">
                        <label for="city" class="required">City</label>
                        <cms:input name="city" type="bound" id="city" />
                        <cms:if k_error_name ><cms:show k_error_city /></cms:if>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-sm-12">
                        <label class="required">country</label>
                        <div class="custom_select">
                          <cms:input type="bound" name="country" />
                          <cms:if k_error_name ><cms:show k_error_country /></cms:if>
                        </div>
                      </div>
                    </li>
                    <li class="row">
                      <div class="col-sm-6">
                        <label for="email_address" class="required">email address</label>
                        <cms:input name="email_address" type="bound" id="email_address" />
                        <cms:if k_error_name ><cms:show k_error_email_address /></cms:if>
                      </div>
                      <div class="col-sm-6">
                        <label for="telephone" class="required">Phone</label>
                        <cms:input name="telephone" type="bound" id="telephone" />
                        <cms:if k_error_name ><cms:show k_error_telephone /></cms:if>
                      </div>
                    </li>
                  </ul>
               
                <input type="submit" name="submit" value="Create account"/>       

            </cms:form>
           
        </cms:if>
    </cms:if>   
   
   
<?php COUCH::invoke(); ?>


Thanks.
Thanks for the clarification.

OK, my suggestion is that you use a simple form (as opposed to a databound form) for the checkout.
Just before the form, fetch all data for a logged-in user and then use it in the form.

Following simplified version of your form with only a few inputs should make this clear -
Code: Select all
<cms:if k_logged_in >
    <cms:pages masterpage='users/index.php' id=k_user_id limit='1'>
        <cms:set g_first_name=first_name 'global' />
        <cms:set g_last_name=last_name 'global' />
        <cms:set g_address=address 'global' />
    </cms:pages>
</cms:if>   
   
<cms:form enctype='multipart/form-data' method='post' anchor='0'>
    <cms:if k_success >
        <cms:set email_from='hello@xxx.com' />
        <cms:set email_bcc='kajoe14@xxx.com' />
        <cms:set email_subject='Your order with kajoe14' />
        <cms:set email_debug='1' />
        <cms:embed 'sales_email.html' />

        <cms:set_flash name='order_complete_msg' value="<cms:embed 'sales_success_msg.html' />"/>
        <cms:pp_empty_cart />
        <cms:redirect k_page_link />
    </cms:if>
    <cms:if k_error >
        ...
    </cms:if>
   
    <cms:input name="first_name" type="text" value="<cms:show g_first_name />" /><br>
    <cms:input name="last_name" type="text" value="<cms:show g_last_name />" /><br>
    <cms:input name="address" type="text" value="<cms:show g_address />" /><br>
   
    <button type="submit" name="submit">order</button><br>
</cms:form>

Notice how we are fetching user data into 'g_first_name' etc. variables above the from and then using them inside it.

This way we'll handle bot anonymous and registered users.
Logged-in users will see the values they entered while registering while the anonymous users will see blank inputs.

The logged-in users can. of course, modify the shown values but we will not persist those back into their profiles. This is because it is a common scenario that a user enters an address of someone else she might be buying something for.

Use a separate 'profile' template to allow the registered users to modify their data.

One last point, with extended users anybody registering from the front-end will necessarily have a record (i.e. cloned-page) in the 'users/index.php' template. However, user-accounts that existed in the system *before* extended-users addon was activated (e.g. the super-admin account) will not automatically have such a record. Therefore it is quite possible that if you test things while logged-in as super-admin, you don't see the values being fetched.

To rectify this, please go into the admin-panel, open the edit screen for the account in question and press 'save'. This will trigger the creation of the associated cloned-page.

Hope it helps.
Hello KK,

Thank you very much for your assistance. The solution worked out perfectly. Thanks a bunch.

I am however still stuck with the second part of my previous query:

2. Is it possible to show a history of the emails he/she had received from previous transactions? (I want to pre-assume this is not possible as Couch CMS aint an order management system)


I attempted to follow through what @keakie had suggested by trying to send the code below via the k_success event.

Code: Select all
<cms:db_persist _invalidate_cache='1' _mode='create' _masterpage='users/inde.php' k_page_title="Transaction History" extended_user='k_user_id' />


It didn't work out though, plus I was also wondering what variables I should (have) use to preview the email content in the respective customer's profile. (I intend to create a a Transaction History tab in the users/profile.php to preview the transactions.)

I hope it is not too much to ask.

Again, thanks for your un-ending support.
10 posts Page 1 of 1