Before reading this article, we suggest that you read the following:
Improve loading time, usability, and design of the contests storefront plugin
This article will explain how to manually change the Theme template files to embed the widget’s initialization script.
The store is not required to perform this step. However, embedding this script directly in the Theme templates will reduce the widget’s loading time on the pages and increase the usability of the app.
Steps to add our code to older themes (prior to 2.0 themes):
- Login to Shopify admin
- goto Online Store > Themes
- Under the Current Theme section, click on the Customize button
- In the theme menu, click Theme actions > Edit Code
- In the theme file’s list panel, click on the Add a new snippet link (Snippets folder)
- Name the new snippet blingrush-contest-page-init
- Copy and paste the code below into the snippet
{% assign pageType = 'other' %}
{% if product %}
{% assign pageType = 'product' %}
{% assign p = product %}
{% elsif order %}
{% assign pageType = 'order' %}
{% for li in order.line_items %}
{% if li.product.metafields.blingrush %}
{% assign p = li.product %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% if p %}
{% assign blingrushNs = p.metafields.blingrush %}
{% endif %}
<script id="blingrush-init-script" type="text/javascript">
window.blingrushWidgetInfo = {pageType:'{{pageType}}'};
{% if p %}
window.blingrushWidgetInfo.product = {
id: {{p.id}},
variant: {{p.variants.first.id}}
};
{% if blingrushNs and blingrushNs.iscontest %}
window.blingrushWidgetInfo.isContest = true;
window.blingrushWidgetInfo.contest = {
productId: {{ p.id }},
variantId:{{ p.variants.first.id }},
inventoryQuantityLeft:{{ p.variants.first.inventory_quantity }},
state: {{ blingrushNs.currstate }},
maxNumberOfParticipants: {{ blingrushNs.maxnumparticipants }},
currNumberOfParticipant: {{ blingrushNs.currnumparticipants }},
winnerDiscountCode : '{{ blingrushNs.winnerdiscount }}',
runnerupsDiscountCode : '{{ blingrushNs.runnerupdiscount }}',
participantDiscountCode : '{{ blingrushNs.participantdiscount }}',
lastDayToCompete : '{{ blingrushNs.contestclosedate }}',
runnerups : '{{ blingrushNs.runnerups }}',
gameID : '{{ blingrushNs.gameid }}',
directCheckout : '{{ blingrushNs.directcheckout }}',
winner : '{{ blingrushNs.winner }}'
};
{% else %}
window.blingrushWidgetInfo.isContest = false;
{% endif %}
{% endif %}
</script>
- Click on the Save button
- Locate and open the theme.liquid file in the theme files panel (Layout folder)
- Search the head closing tag
</head>
- Copy and paste the following code just before the closing tag
{% include 'blingrush-contest-page-init' %}
- Click on the Save button
Steps to add our code to 2.0-supported themes:
- Login to Shopify admin
- goto Online Store > Themes
- Under the Current Theme section, click on the Customize button
- From the templates drop-down at the top of the page perform the below steps for the Product, Cart, and Customer order templates
- Select any section on the page and click on the ‘Add Block’ button
- In the popup blocks menu find BlingRush app blocks and select the ‘General Extension’ block
- Save your changes