Skip to content

Commit

Permalink
Support for Pages, Language for Clerk.js v2 and settings for live search
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperKN committed Nov 18, 2019
1 parent 2b60304 commit 4782630
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 78 deletions.
205 changes: 203 additions & 2 deletions clerk.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>clerk</name>
<displayName><![CDATA[Clerk]]></displayName>
<version><![CDATA[5.1.3]]></version>
<version><![CDATA[5.2.0]]></version>
<description><![CDATA[Clerk.io Turns More Browsers Into Buyers]]></description>
<author><![CDATA[Clerk]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion config_da.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>clerk</name>
<displayName><![CDATA[Clerk]]></displayName>
<version><![CDATA[5.1.3]]></version>
<version><![CDATA[5.2.0]]></version>
<description><![CDATA[Clerk.io Turns More Browsers Into Buyers]]></description>
<author><![CDATA[Clerk]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion config_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>clerk</name>
<displayName><![CDATA[Clerk]]></displayName>
<version><![CDATA[5.1.3]]></version>
<version><![CDATA[5.2.0]]></version>
<description><![CDATA[Clerk.io Turns More Browsers Into Buyers]]></description>
<author><![CDATA[Clerk]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion config_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>clerk</name>
<displayName><![CDATA[Clerk]]></displayName>
<version><![CDATA[5.1.3]]></version>
<version><![CDATA[5.2.0]]></version>
<description><![CDATA[Clerk.io Turns More Browsers Into Buyers]]></description>
<author><![CDATA[Clerk]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion config_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>clerk</name>
<displayName><![CDATA[Clerk]]></displayName>
<version><![CDATA[5.1.3]]></version>
<version><![CDATA[5.2.0]]></version>
<description><![CDATA[Clerk.io Turns More Browsers Into Buyers]]></description>
<author><![CDATA[Clerk]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
216 changes: 216 additions & 0 deletions controllers/front/page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php
/**
* @author Clerk.io
* @copyright Copyright (c) 2017 Clerk.io
*
* @license MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

require "ClerkAbstractFrontController.php";

class ClerkPageModuleFrontController extends ClerkAbstractFrontController
{
/**
* @var int
*/
private $language_id;

/**
* @var int
*/
private $shop_id;

/**
* @var
*/
protected $logger;

/**
* @var
*/
protected $url_base;


/**
* ClerkProductModuleFrontController constructor.
*/
public function __construct()
{
parent::__construct();

require_once (_PS_MODULE_DIR_. $this->module->name . '/controllers/admin/ClerkLogger.php');

$context = Context::getContext();

$this->shop_id = (!empty(Tools::getValue('clerk_shop_select'))) ? (int)Tools::getValue('clerk_shop_select') : $context->shop->id;
$this->language_id = (!empty(Tools::getValue('clerk_language_select'))) ? (int)Tools::getValue('clerk_language_select') : $context->language->id;

$this->logger = new ClerkLogger();

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')

$this->url_base = "http://".$_SERVER['HTTP_HOST'];

else {

$this->url_base = "http://".$_SERVER['HTTP_HOST'];

}

//Needed for PHP 5.3 support
$context = $this->context;


if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {



}
else {


}

}

/**
* Get response
*
* @return array
*/
public function getJsonResponse()
{
try {

if (Configuration::get('CLERK_DATASYNC_INCLUDE_PAGES', $this->language_id, null, $this->shop_id) != '0') {

$pages = CMS::getCMSPages($this->getLanguageId(), 1, true, $this->shop_id);

$response = array();

foreach ($pages as $page) {

$page_fields = explode(',', Configuration::get('CLERK_DATASYNC_PAGE_FIELDS', $this->language_id, null, $this->shop_id));

$item = [
'id' => $page['id_cms'],
'type' => 'CMS Page',
'url' => $this->context->link->getCMSLink($page['id_cms']),
'title' => $page['meta_title'],
'text' => $page['content']
];

foreach ($page_fields as $page_field) {

$page_field = str_replace(' ','',$page_field);

if (!empty($page_field)) {

$item[$page_field] = $page[$page_field];

}

}

$response[] = $item;

}

$this->logger->log('Fetched Pages', ['response' => $response]);

return $response;
}
else {

return [];

}

} catch (Exception $e) {

$this->logger->error('ERROR Pages getJsonResponse', ['error' => $e->getMessage()]);

}

}

/**
* Get default fields for products
*
* @return array
*/
protected function getDefaultFields()
{
try {

$default = array(
'id',
'name',
'description',
'price',
'list_price',
'image',
'url',
'categories',
'brand',
'sku',
'on_sale',
'qty',
'in_stock'
);

//Get custom fields from configuration
$fieldsConfig = Configuration::get('CLERK_DATASYNC_FIELDS', $this->getLanguageId(), null, $this->getShopId());

$fields = explode(',', $fieldsConfig);

return array_merge($default, $fields);

} catch (Exception $e) {

$this->logger->error('ERROR getDefaultFields', ['error' => $e->getMessage()]);

}
}

private function getStockForProduct($product)
{
try {

$id_product_attribute = isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null;

if (isset($this->stock[$product['id_product']][$id_product_attribute])) {
return $this->stock[$product['id_product']][$id_product_attribute];
}

$availableQuantity = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $id_product_attribute);

$this->stock[$product['id_product']][$id_product_attribute] = $availableQuantity;

return $this->stock[$product['id_product']][$id_product_attribute];

} catch (Exception $e) {

$this->logger->error('ERROR getStockForProduct', ['error' => $e->getMessage()]);

}
}
}
1 change: 1 addition & 0 deletions controllers/front/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function initContent()
$this->context->smarty->assign(array(
'search_template' => Tools::strtolower(str_replace(' ', '-', Configuration::get('CLERK_SEARCH_TEMPLATE', $this->context->language->id, null, $this->context->shop->id))),
'search_query' => $query,
'lang_iso' => $this->context->language->iso_code
));

if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {
Expand Down
22 changes: 0 additions & 22 deletions views/templates/front/powerstep17.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,7 @@
{extends file='page.tpl'}

{block name='page_content'}
<style>
.clerk-popup {
position: fixed;

top: 10%;
z-index: 16777271;
display: none;
padding: 20px;
margin: 0 5%;
background-color: white;
border: 1px solid #eee;
border-radius: 5px;
box-shadow: 0px 8px 40px 0px rgba(0, 0, 60, 0.15);
}
</style>
<div class="clerk-powerstep clerk-popup">
<div class="clerk-continue">
<a href="{$continue|escape:'html'}"
Expand Down
24 changes: 1 addition & 23 deletions views/templates/front/powerstepmodal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*}
<style>
.clerk-popup {
position: fixed;

top: 10%;
z-index: 16777271;
display: none;
padding: 20px;
margin: 0 5%;
background-color: white;
border: 1px solid #eee;
border-radius: 5px;
box-shadow: 0px 8px 40px 0px rgba(0, 0, 60, 0.15);
}
</style>
<div id="clerk_powerstep" class="clerk-popup" style="display: none;">
<div id="clerk_powerstep" class="clerk-popup">
<div class="clerk_powerstep_header">
<h2>{l s='You added %s to your shopping cart.' sprintf=[$product.name] mod='clerk'}</h2>
</div>
Expand Down
14 changes: 0 additions & 14 deletions views/templates/front/search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,3 @@

<ul id="clerk-search-results"></ul>
<div id="clerk-search-no-results" style="display: none;"></div>

<a id="clerk-search-load-more-button" href="javascript:_load_more();"
class="btn btn-default">{l s='Load More Results' mod='clerk'}</a>

<script type="text/javascript">
// this code assumes that you have jQuery v. 1.7
// if not replace jQuery with Clerk.ui.$
function _load_more() {
Clerk('content', '#clerk-search', 'more');
jQuery('#clerk-search-load-more-button').hide();
}
</script>
11 changes: 0 additions & 11 deletions views/templates/front/search17.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,5 @@
</span>
<ul id="clerk-search-results" style="overflow: hidden;"></ul>
<div id="clerk-search-no-results" style="display: none;"></div>
<a id="clerk-search-load-more-button" href="javascript:_load_more();"
class="btn btn-default">{l s='Load More Results' mod='clerk'}</a>
<script type="text/javascript">
// this code assumes that you have jQuery v. 1.7
// if not replace jQuery with Clerk.ui.$

function _load_more() {
Clerk('content', '#clerk-search', 'more');
jQuery('#clerk-search-load-more-button').hide();
}
</script>
{/block}
4 changes: 3 additions & 1 deletion views/templates/hook/clerk_js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
Clerk('config', {
key: '{$clerk_public_key}',
collect_email: {$clerk_datasync_collect_emails}
collect_email: {$clerk_datasync_collect_emails},
language: '{$language}',
});
</script>
<!-- End of Clerk.io E-commerce Personalisation tool - www.clerk.io -->
1 change: 1 addition & 0 deletions views/templates/hook/search-top.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
data-instant-search-categories="{$livesearch_number_categories}"
{/if}
data-instant-search-pages="{$livesearch_number_pages}"
data-instant-search-pages-type="{$livesearch_pages_type}"
data-instant-search="#search_query_top">
</span>
{/if}

0 comments on commit 4782630

Please sign in to comment.