g

Expression of Interest

An Expression of Interest is an input field shown to a user whenever the current product is out of stock. Once a product is back in stock, a mailing list for all the users who signed up asking for this product will run and then notify them by email. This script runs nightly. EOI can be used with Back Orders to stop sites from going into negative stock and provide a way for users to register their interest.

Two templates for Expression of Interest are required on the site directory 

  • sitedir/modules/prodcatalogue/templates/main_product_interest.html

  • sitedir/modules/prodcatalogue/templates/product_interest.html

product_interest must be included in the main main_product_interest.html by using the keyword *|productsHtml|*. product_interest will only have access to $products, $variants and $centre array/object.  

if these templates are not found, Core dna will use defaults. 

example product_interest.html:

<{if !empty($products)}>
<table>
    <thead>
    <tr>
        <td>Product name</td>
    </tr>
    </thead>
    <tbody>
    <{foreach from=$products item="product"}>
    <tr>
        <td>
            <{$product->getName()}>
        </td>
    </tr>
    <{/foreach}>
    <{foreach from=$variants item="variant"}>
    <tr>
        <td>
            <{$variant->getText()}>
        </td>
    </tr>
    <{/foreach}>
    </tbody>
</table>
<{/if}>

and an example main_product_interest.html

Hello,<br>These products are now back in stock!</br>
<br>
*|productsHtml|*
<br>
Thank you,<br>
<{$centre->getName()}>

First of all make sure that 'Expression Of Interest' is enabled for the centre by going to Core dna admin -> Catalogues module -> Configure -> Manage Configuration, then check 'Allow Expression Of Interest' switch as it is shown in the following screenshot:

The following block function can be used to display 'Register Your Interest' form:

<{if $allow_eoi && $product->getQty() <= 0}>
    <{show_block module='prodcatalogue'
    block='show_product_interest'
    product_id=$product->getID()
    template_name="block_show_product_interest"}>
<{/if}>

block_show_product_interest.html must live in sitedir/modules/prodcatalogue/templates/ and have the html/js code supplied below. This is required for the block function to work.

<div style="width: 400px">
    Register your interest for product: <{$product->getName()}><br>
    <label for="email">Email:</label>
    <input type="text" name="eoi_email" id="eoi_email" onkeyup='if (jQuery("#eoi_email").val()) { jQuery("#eoi_message").html(""); }' placeholder="Enter your email">
    <div id="eoi_message"></div>
    <button type="button" onclick="submitExpressionOfIntrest(<{$product->getID()}>)">Submit</button>
</div>
 
<script>
    function submitExpressionOfIntrest(productId) {
        var productId = productId || null;
        var email = jQuery('#eoi_email').val();
 
        if(!email) {
            jQuery("#eoi_message").html('Please enter an email address');
            return;
        }
        if (!productId) {
            jQuery("#eoi_message").html('There was an error');
            return;
        }
 
        jQuery.ajax({
            url: "/index.php?action=prodcatalogue&form_name=register_interest&type=json",
            type: 'POST',
            beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token''<{$eoi_csfrtoken}>')},
            data: {email: email, product_id: productId, variant_id: variantId},
        }).success(function (response) {
            if (response.success) {
                jQuery("#eoi_email").val('');
                jQuery("#eoi_message").html(response.message);
            else {
                jQuery("#eoi_message").html(response.message);
            }
        });
    }
</script>


Which results in the following form:

Upon submission the form the email is checked to see whether it is already registered for the product or not. If it is already registered the JSON response will be like this:

{"success":false,"message":"This email has already registered for this product"}

And this is the response upon successful submission:

{"success":true,"message":"Your interest submitted successfully"}

The relation between email and product id is stored in prodcat_products_interests table. There is CSRF security checking performed on this input, if this fails you will get a 401 forbidden response.


Sending Emails to Interested Customers

Go to the Hooks module (Cog Wheel -> Hooks) and add a new Hook. Choose the ExpressionOfInterestNotification event. This event will be triggered every time a product goes from zero to positive stock and has users waiting to receive an email. This event will be triggered separately for each user. This event will have the relevant product assigned as $product and the user as $user.

You can send mail using the following template:

<p>HI <{$user->getFirstname()}>, <strong><{$product->getName()}></strong> PRODUCT IS BACK IN STOCK</p>

Note: You must create an action to remove this user from the list of waiting for EOI's at the end of the Hook execution. All you need to do is create an Evaluate Template action with a template containing the following:

<!-- getField(email) is used because getEmail() has a guest check on it which returns nothing. We need this to work for guests.-->
<{$product->removeExpressionOfInterestByEmail($user->getField('email'))}>

Without this action, the user will never be removed from the pending list and will receive additional emails the next time this event is triggered.