New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading time of carriers & payment pages #23 #29

Merged
merged 5 commits into from Sep 6, 2018
Jump to file or symbol
Failed to load files and symbols.
+201 −88
Diff settings

Always

Just for now

@@ -40,6 +40,11 @@ public function __construct()
$this->bootstrap = true;
parent::__construct();
$this->controller_quick_name = 'module';
if ($this->ajax) {
$this->display_header = false;
$this->display_header_javascript = false;
$this->display_footer = false;
}
}
/**
@@ -74,6 +79,9 @@ public function initContent()
$this->context->smarty->assign(array(
'shop_name' => Configuration::get('PS_SHOP_NAME'),
'img_dir' => _PS_IMG_,
'iso' => $this->context->language->iso_code,
'bootstrap' => 1,
'configure_type' => $this->controller_quick_name,
'template_dir' => $this->module->template_dir,
@@ -137,9 +145,9 @@ public function ajaxProcessGetModulesList()
$container = SymfonyContainer::getInstance();
$container->set('translator', Context::getContext()->getTranslator());
$modulesProvider = $container->get('prestashop.core.admin.data_provider.module_interface');
$moduleRepository = $container->get('prestashop.core.admin.module.repository');
$filteredList = $moduleRepository->getFilteredList($filters);
@@ -161,10 +169,15 @@ public function ajaxProcessGetModulesList()
$modules = $this->getPresentedProducts($modules);
foreach ($modules as $key => &$module) {
$module['attributes']['description'] = html_entity_decode($module['attributes']['description']);
$module['attributes']['description'] = htmlspecialchars_decode($module['attributes']['description'], ENT_QUOTES);
$module['attributes']['description'] = htmlspecialchars_decode(
$module['attributes']['description'],
ENT_QUOTES
);
$module['attributes']['visible'] = true;
$module['attributes']['price'] = (isset($module['attributes']['price'][Context::getContext()->currency->iso_code])) ? $module['attributes']['price'][Context::getContext()->currency->iso_code] : '';
$module['attributes']['price'] = isset($module['attributes']['price'][Context::getContext()->currency->iso_code]) ?
$module['attributes']['price'][Context::getContext()->currency->iso_code] :
'';
// only one badge to display
$i = 0;
@@ -177,12 +190,14 @@ public function ajaxProcessGetModulesList()
}
}
die(json_encode(
[
'modules' => $modules,
'categories' => $categories['categories']
]
));
$this->ajaxRender(
json_encode(
[
'modules' => $modules,
'categories' => $categories['categories']
]
)
);
}
private function getPresentedProducts(array &$modules)
@@ -228,13 +243,13 @@ public function ajaxProcessGetModuleQuickView()
'id_currency' => Context::getContext()->currency->id
));
die($this->context->smarty->fetch($this->module->template_dir . '/quickview.tpl'));
$this->ajaxRender($this->context->smarty->fetch($this->module->template_dir . '/quickview.tpl'));
}
public function ajaxProcessGetTabModulesList()
{
$result = $this->module->fetchModulesByController(true);
ob_start();
if ($result !== false) {
$this->context->smarty->assign(array(
'controller_name' => $result['controller_name'],
@@ -245,10 +260,15 @@ public function ajaxProcessGetTabModulesList()
'host_mode' => defined('_PS_HOST_MODE_') ? 1 : 0,
'from' => 'tab'
));
$this->smartyOutputContent($this->module->template_dir . '/admin-end-content.tpl');
$this->smartyOutputContent($this->module->template_dir . '/include/admin-end-content-footer.tpl');
}
exit;
$this->ajaxRender(ob_get_clean());
}
public function ajaxProcessFetchModules()
{
$this->ajaxRender($this->module->fetchModules(Tools::getValue('controller_page')));
}
public function getModulesByInstallation($tab_modules_list = null, $install_source_tracking = false)
@@ -305,6 +325,6 @@ public function ajaxProcessGetMboAddonsThemes()
$activity = Configuration::get('PS_SHOP_ACTIVITY');
$addons_url = Tools::getCurrentUrlProtocolPrefix() . 'addons.prestashop.com/iframe/search-1.7.php?psVersion=' . _PS_VERSION_ . '&onlyThemes=1&isoLang=' . pSQL($iso_lang) . '&isoCurrency=' . pSQL($iso_currency) . '&isoCountry=' . pSQL($iso_country) . '&activity=' . (int) $activity . '&parentUrl=' . pSQL($parent_domain);
die(Tools::file_get_contents($addons_url));
$this->ajaxRender(Tools::file_get_contents($addons_url));
}
}
}
View
@@ -136,6 +136,42 @@ protected function installTabs()
return true;
}
public function fetchModules($controller)
{
$controllerWhiteList = array('AdminCarriers', 'AdminPayment');
if (!in_array($controller, $controllerWhiteList)) {
return false;
}
$data = array();
switch ($controller) {
case 'AdminCarriers':
$modules = $this->getCarriersMboModules();
$data['panel_id'] = 'recommended-carriers-panel';
$data['panel_title'] = $this->trans(
'Use one of our recommended carrier modules',
[],
'Admin.Shipping.Feature'
);
break;
case 'AdminPayment':
$modules = $this->getPaymentMboModules();
break;
}
if (empty($modules)) {
return false;
}
$data['controller_name'] = $controller;
$data['admin_module_ajax_url_psmbo'] = $this->front_controller[0];
$data['from'] = 'footer';
$data['modules_list'] = $modules;
$this->context->smarty->assign($data);
return $this->context->smarty->fetch($this->template_dir . '/include/admin-end-content-footer.tpl');
}
public function fetchModulesByController($ajax = false)
{
$controller = Tools::getValue('controllerName');
@@ -194,33 +230,58 @@ public function fetchModulesByController($ajax = false)
return $data;
}
return $this->context->smarty->fetch($this->template_dir . '/admin-end-content.tpl');
return $this->context->smarty->fetch($this->template_dir . '/include/admin-end-content-footer.tpl');
}
public function hookDisplayAdminEndContent()
protected function handleAddonsConnectWithMbo()
{
if (Tools::getIsset('controller') && Tools::getValue('controller') == 'AdminPsMboModule') {
$addonsConnect = $this->getAddonsConnectToolbar();
if (Tools::getValue('controller') !== 'AdminPsMboModule') {
return false;
}
$this->context->smarty->assign(array(
'addons_connect' => $addonsConnect,
));
$addonsConnect = $this->getAddonsConnectToolbar();
$this->context->smarty->assign(array(
'addons_connect' => $addonsConnect,
));
return $this->context->smarty->fetch($this->template_dir . '/include/modal_addons_connect.tpl');
}
protected function handleTheme()
{
if (Tools::getValue('controller') !== 'AdminThemes') {
return false;
}
return $this->context->smarty->fetch($this->template_dir . '/include/modal_addons_connect.tpl');
$this->context->smarty->assign([
'admin_module_ajax_url_psmbo' => $this->front_controller[0]
]);
return $this->context->smarty->fetch($this->template_dir . '/admin-end-content-theme.tpl');
}
public function hookDisplayAdminEndContent()
{
$connectWithMbo = $this->handleAddonsConnectWithMbo();
if ($connectWithMbo !== false) {
return $connectWithMbo;
}
$controller = Tools::getValue('controller');
if ($controller == 'AdminThemes') {
$this->context->smarty->assign(array(
'admin_module_ajax_url_psmbo' => $this->front_controller[0]
));
return $this->context->smarty->fetch($this->template_dir . '/admin-end-content-theme.tpl');
$handleTheme = $this->handleTheme();
if ($handleTheme !== false) {
return $handleTheme;
}
$content = '';
$content .= $this->context->smarty->fetch($this->template_dir . '/modal.tpl');
if ($this->fetchModulesByController() !== false) {
$controller_page = (Tools::getIsset('controller')) ? Tools::getValue('controller') : '';
$controllerWhiteList = array('AdminCarriers', 'AdminPayment');
if (in_array($controller_page, $controllerWhiteList)) {
$this->context->smarty->assign(array(
'admin_module_ajax_url_psmbo' => $this->front_controller[0],
'controller_page' => $controller_page
));
$content .= $this->context->smarty->fetch($this->template_dir . '/admin-end-content.tpl');
}
@@ -229,7 +290,7 @@ public function hookDisplayAdminEndContent()
public function hookDisplayDashboardToolbarTopMenu()
{
if (Tools::getIsset('controller') && Tools::getValue('controller') == 'AdminPsMboModule') {
if (Tools::getValue('controller') === 'AdminPsMboModule') {
$addonsConnect = $this->getAddonsConnectToolbar();
$this->context->smarty->assign(array(
@@ -261,13 +322,21 @@ private function getAddonsConnectToolbar()
return array(
'connected' => true,
'email' => $addonsEmail['username_addons'],
'logout_url' => $container->get('router')->generate('admin_addons_logout', [], UrlGeneratorInterface::ABSOLUTE_URL)
'logout_url' => $container->get('router')->generate(
'admin_addons_logout',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
);
}
return array(
'connected' => false,
'login_url' => $container->get('router')->generate('admin_addons_login', [], UrlGeneratorInterface::ABSOLUTE_URL)
'login_url' => $container->get('router')->generate(
'admin_addons_login',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
);
}
@@ -22,63 +22,34 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if isset($from) && $from == 'footer'}
<div class="panel" {if isset($panel_id)}id="{$panel_id}"{/if}>
<h3>
<i class="icon-list-ul"></i>
{if isset($panel_title)}{$panel_title|escape:'html':'UTF-8'}{else}{l s='Modules list'}{/if}
</h3>
{/if}
<div class="modules_list_container_tab row">
<div class="col-lg-12">
{if count($modules_list)}
<table class="table">
{counter start=1 assign="count"}
{foreach from=$modules_list item=module}
{include file='./include/tab_module_line.tpl' class_row={cycle values=",row alt"}}
{counter}
{/foreach}
</table>
{if $controller_name == 'AdminPayment' && isset($view_all)}
<div class="panel-footer">
<div class="col-lg-4 col-lg-offset-4">
<a class="btn btn-default btn-block" href="{$link->getAdminLink('AdminPsMboModule', true, [], ['filterCategoryTab' => 'payments_gateways'])|escape:'html':'UTF-8'}">
<i class="process-icon-payment"></i>
{l s='View all available payments solutions'}
</a>
</div>
</div>
{/if}
{else}
<table class="table">
<tr>
<td>
<div class="alert alert-warning">
{if $controller_name == 'AdminPayment'}
{l s='It seems there are no recommended payment solutions for your country.'}<br />
<a class="_blank" href="https://www.prestashop.com/en/contact-us">{l s='Do you think there should be one? Let us know!'}</a>
{else}{l s='No modules available in this section.'}{/if}</div>
</td>
</tr>
</table>
{/if}
</div>
</div>
{if isset($from) && $from == 'footer'}
</div>
{/if}
{if isset($from) && $from == 'tab'}
<div class="alert alert-addons row-margin-top" role="alert">
<p class="alert-text">
<a href="http://addons.prestashop.com/?utm_source=back-office&amp;utm_medium=dispatch&amp;utm_campaign=back-office-en-US&amp;utm_content=download" onclick="return !window.open(this.href);">{l s='More modules on addons.prestashop.com'}</a>
</p>
</div>
{/if}
<div id="admin-end-content-footer">
</div>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: '{$admin_module_ajax_url_psmbo}',
async: true,
cache: false,
dataType : "html",
data: {
ajax: '1',
action:'fetchModules',
controller_page: '{$controller_page}'
},
beforeSend: function() {
$('#admin-end-content-footer').html('<i class="icon-refresh icon-spin"></i>');
},
success: function(data) {
$('#admin-end-content-footer').html(data);
}
});
$('.controller-quick-view').each(function() {
$(this).fancybox({
type: 'ajax',
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.