first commit
This commit is contained in:
245
modules/welcome/OnBoarding/Configuration.php
Normal file
245
modules/welcome/OnBoarding/Configuration.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace OnBoarding;
|
||||
|
||||
use Hook;
|
||||
use Module;
|
||||
use PrestaShopBundle\Service\Routing\Router;
|
||||
|
||||
class Configuration
|
||||
{
|
||||
/**
|
||||
* Module Dependency
|
||||
*/
|
||||
const FAKE_ID = 123456789;
|
||||
|
||||
const HOOK_CONFIGURATION = 'welcome_configuration';
|
||||
|
||||
const STEP_DASHBOARD = 'dashboard';
|
||||
const STEP_PRODUCT = 'product';
|
||||
const STEP_THEME = 'theme';
|
||||
const STEP_PAYMENT = 'payment';
|
||||
const STEP_SHIPPING = 'shipping';
|
||||
|
||||
private $translator;
|
||||
|
||||
public function __construct($translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getConfiguration(Router $router)
|
||||
{
|
||||
$contextLink = \Context::getContext()->link;
|
||||
|
||||
$productFormUrlPattern = $this->generateSfBaseUrl(
|
||||
$router,
|
||||
'admin_product_form',
|
||||
['id' => static::FAKE_ID]
|
||||
);
|
||||
|
||||
$data = [
|
||||
'templates' => [
|
||||
'lost',
|
||||
'popup',
|
||||
'tooltip',
|
||||
],
|
||||
'steps' => [
|
||||
'groups' => [
|
||||
[
|
||||
'name' => static::STEP_DASHBOARD,
|
||||
'steps' => [
|
||||
[
|
||||
'type' => 'popup',
|
||||
'text' => [
|
||||
'type' => 'template',
|
||||
'src' => 'welcome',
|
||||
],
|
||||
'options' => [
|
||||
'savepoint',
|
||||
'hideFooter',
|
||||
],
|
||||
'page' => $contextLink->getAdminLink('AdminDashboard'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => static::STEP_PRODUCT,
|
||||
'title' => $this->translator->trans('Let\'s create your first product', [], 'Modules.Welcome.Admin'),
|
||||
'subtitle' => [
|
||||
'1' => $this->translator->trans('What do you want to tell about it? Think about what your customers want to know.', [], 'Modules.Welcome.Admin'),
|
||||
'2' => $this->translator->trans('Add clear and attractive information. Don\'t worry, you can edit it later :)', [], 'Modules.Welcome.Admin'),
|
||||
],
|
||||
'steps' => [
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('Give your product a catchy name.', [], 'Modules.Welcome.Admin'),
|
||||
'options' => [
|
||||
'savepoint',
|
||||
],
|
||||
'page' => [
|
||||
$router->generate('admin_product_new'),
|
||||
$productFormUrlPattern,
|
||||
],
|
||||
'selector' => '#form_step1_name_1',
|
||||
'position' => 'right',
|
||||
],
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('Fill out the essential details in this tab. The other tabs are for more advanced information.', [], 'Modules.Welcome.Admin'),
|
||||
'page' => $productFormUrlPattern,
|
||||
'selector' => '#tab_step1',
|
||||
'position' => 'right',
|
||||
],
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('Add one or more pictures so your product looks tempting!', [], 'Modules.Welcome.Admin'),
|
||||
'page' => $productFormUrlPattern,
|
||||
'selector' => '#product-images-dropzone',
|
||||
'position' => 'right',
|
||||
],
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('How much do you want to sell it for?', [], 'Modules.Welcome.Admin'),
|
||||
'page' => $productFormUrlPattern,
|
||||
'selector' => '.right-column > .row > .col-md-12 > .form-group:nth-child(4) > .row > .col-md-6:first-child > .input-group',
|
||||
'position' => 'left',
|
||||
'action' => [
|
||||
'selector' => '#product_form_save_go_to_catalog_btn',
|
||||
'action' => 'click',
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('Yay! You just created your first product. Looks good, right?', [], 'Modules.Welcome.Admin'),
|
||||
'page' => $this->generateSfBaseUrl($router, 'admin_product_catalog'),
|
||||
'selector' => '#product_catalog_list table tr:first-child td:nth-child(3)',
|
||||
'position' => 'left',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => static::STEP_THEME,
|
||||
'title' => $this->translator->trans('Give your shop its own identity', [], 'Modules.Welcome.Admin'),
|
||||
'subtitle' => [
|
||||
'1' => $this->translator->trans('How do you want your shop to look? What makes it so special?', [], 'Modules.Welcome.Admin'),
|
||||
'2' => $this->translator->trans('Customize your theme or choose the best design from our theme catalog.', [], 'Modules.Welcome.Admin'),
|
||||
],
|
||||
'steps' => [
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('A good way to start is to add your own logo here!', [], 'Modules.Welcome.Admin'),
|
||||
'options' => [
|
||||
'savepoint',
|
||||
],
|
||||
'page' => $contextLink->getAdminLink('AdminThemes'),
|
||||
'selector' => '#form_shop_logos_header_logo, #form_header_logo',
|
||||
'position' => 'right',
|
||||
],
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('If you want something really special, have a look at the theme catalog!', [], 'Modules.Welcome.Admin'),
|
||||
'page' => $contextLink->getAdminLink('AdminThemesCatalog'),
|
||||
'selector' => '.addons-theme-one:first-child',
|
||||
'position' => 'right',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => static::STEP_PAYMENT,
|
||||
'title' => $this->translator->trans('Get your shop ready for payments', [], 'Modules.Welcome.Admin'),
|
||||
'subtitle' => [
|
||||
'1' => $this->translator->trans('How do you want your customers to pay you?', [], 'Modules.Welcome.Admin'),
|
||||
],
|
||||
'steps' => [
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('These payment methods are already available to your customers.', [], 'Modules.Welcome.Admin'),
|
||||
'options' => [
|
||||
'savepoint',
|
||||
],
|
||||
'page' => $contextLink->getAdminLink('AdminPayment'),
|
||||
'selector' => '.modules_list_container_tab:first tr:first-child .text-muted, .card:eq(0) .text-muted:eq(0)',
|
||||
'position' => 'right',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => static::STEP_SHIPPING,
|
||||
'title' => $this->translator->trans('Choose your shipping solutions', [], 'Modules.Welcome.Admin'),
|
||||
'subtitle' => [
|
||||
'1' => $this->translator->trans('How do you want to deliver your products?', [], 'Modules.Welcome.Admin'),
|
||||
],
|
||||
'steps' => [
|
||||
[
|
||||
'type' => 'tooltip',
|
||||
'text' => $this->translator->trans('Here are the shipping methods available on your shop today.', [], 'Modules.Welcome.Admin'),
|
||||
'options' => [
|
||||
'savepoint',
|
||||
],
|
||||
'page' => $contextLink->getAdminLink('AdminCarriers'),
|
||||
'selector' => '#table-carrier tr:eq(2) td:eq(3)',
|
||||
'position' => 'right',
|
||||
],
|
||||
[
|
||||
'type' => 'popup',
|
||||
'text' => [
|
||||
'type' => 'template',
|
||||
'src' => 'end',
|
||||
],
|
||||
'options' => [
|
||||
'savepoint',
|
||||
'hideFooter',
|
||||
],
|
||||
'page' => $contextLink->getAdminLink('AdminDashboard'),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Hook::exec(static::HOOK_CONFIGURATION, ['data' => &$data]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate url pattern to recognize the route as the current step url
|
||||
* here we replace the route specific parameters with wildcard to allow regexp matching
|
||||
*
|
||||
* @param \PrestaShopBundle\Service\Routing\Router $router
|
||||
* @param string $controller
|
||||
* @param array $fakeParameters
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected function generateSfBaseUrl(Router $router, string $controller, $fakeParameters = [])
|
||||
{
|
||||
$url = $router->getGenerator()->generate($controller, $fakeParameters);
|
||||
$url = substr($url, strlen(basename(__PS_BASE_URI__)) + 1);
|
||||
$url = str_replace('/' . basename(_PS_ADMIN_DIR_) . '/', '', $url);
|
||||
|
||||
$url = str_replace(array_values($fakeParameters), '.+', $url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
251
modules/welcome/OnBoarding/OnBoarding.php
Normal file
251
modules/welcome/OnBoarding/OnBoarding.php
Normal file
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace OnBoarding;
|
||||
|
||||
use Configuration as LegacyConfiguration;
|
||||
use Module;
|
||||
use PrestaShopBundle\Service\Routing\Router;
|
||||
use PrestaShopBundle\Translation\TranslatorComponent as Translator;
|
||||
use Smarty_Data;
|
||||
|
||||
/**
|
||||
* OnBoarding main class.
|
||||
*/
|
||||
class OnBoarding
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
/**
|
||||
* @var Module
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var Smarty_Data
|
||||
*/
|
||||
private $smarty;
|
||||
|
||||
/**
|
||||
* OnBoarding constructor.
|
||||
*
|
||||
* @param Translator $translator Twig environment needed to manage the templates
|
||||
* @param Smarty_Data $smarty
|
||||
* @param Module $module
|
||||
* @param Router $router
|
||||
*/
|
||||
public function __construct($translator, $smarty, $module, Router $router)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->smarty = $smarty;
|
||||
$this->module = $module;
|
||||
|
||||
$this->loadConfiguration($router);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the OnBoarding module content.
|
||||
*/
|
||||
public function showModuleContent()
|
||||
{
|
||||
$templates = [];
|
||||
foreach ($this->configuration['templates'] as $template) {
|
||||
$templates[] = [
|
||||
'name' => $template,
|
||||
'content' => str_replace(["\n", "\r", "\t"], '', $this->getTemplateContent("templates/$template")),
|
||||
];
|
||||
}
|
||||
|
||||
echo $this->getTemplateContent('content', [
|
||||
'currentStep' => $this->getCurrentStep(),
|
||||
'totalSteps' => $this->getTotalSteps(),
|
||||
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
|
||||
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps()) * 100),
|
||||
'isShutDown' => $this->isShutDown(),
|
||||
'steps' => $this->configuration['steps'],
|
||||
'jsonSteps' => json_encode($this->configuration['steps']),
|
||||
'templates' => $templates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the OnBoarding content for the nav bar.
|
||||
*/
|
||||
public function showModuleContentForNavBar()
|
||||
{
|
||||
echo $this->getTemplateContent('navbar', [
|
||||
'currentStep' => $this->getCurrentStep(),
|
||||
'totalSteps' => $this->getTotalSteps(),
|
||||
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
|
||||
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps()) * 100),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current step.
|
||||
*
|
||||
* @param int $step Current step ID
|
||||
*
|
||||
* @return bool Success of the configuration update
|
||||
*/
|
||||
public function setCurrentStep($step)
|
||||
{
|
||||
return LegacyConfiguration::updateValue('ONBOARDINGV2_CURRENT_STEP', $step);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the shut down status.
|
||||
*
|
||||
* @param bool $status Onboarding shut downed or not
|
||||
*
|
||||
* @return bool Success of the configuration update
|
||||
*/
|
||||
public function setShutDown($status)
|
||||
{
|
||||
return LegacyConfiguration::updateValue('ONBOARDINGV2_SHUT_DOWN', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the OnBoarding is finished.
|
||||
*
|
||||
* @return bool True if the OnBoarding is finished
|
||||
*/
|
||||
public function isFinished()
|
||||
{
|
||||
return $this->getCurrentStep() >= $this->getTotalSteps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the steps with the localized texts.
|
||||
*
|
||||
* @param Router $router
|
||||
*/
|
||||
private function loadConfiguration(Router $router)
|
||||
{
|
||||
$configuration = new Configuration($this->translator);
|
||||
$configuration = $configuration->getConfiguration($router);
|
||||
|
||||
foreach ($configuration['steps']['groups'] as &$currentGroup) {
|
||||
if (isset($currentGroup['title'])) {
|
||||
$currentGroup['title'] = $this->getTextFromSettings($currentGroup['title']);
|
||||
}
|
||||
if (isset($currentGroup['subtitle'])) {
|
||||
foreach ($currentGroup['subtitle'] as &$subtitle) {
|
||||
$subtitle = $this->getTextFromSettings($subtitle);
|
||||
}
|
||||
}
|
||||
foreach ($currentGroup['steps'] as &$currentStep) {
|
||||
$currentStep['text'] = $this->getTextFromSettings($currentStep['text']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a text from step text configuration.
|
||||
*
|
||||
* @param array $text Step text configuration
|
||||
*
|
||||
* @return array|mixed|string|null
|
||||
*/
|
||||
private function getTextFromSettings($text)
|
||||
{
|
||||
if (is_array($text)) {
|
||||
switch ($text['type']) {
|
||||
case 'template':
|
||||
return $this->getTemplateContent('contents/' . $text['src']);
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes a template.
|
||||
*
|
||||
* @param string $templateName Template name
|
||||
*/
|
||||
public function showTemplate($templateName)
|
||||
{
|
||||
echo $this->getTemplateContent($templateName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a template.
|
||||
*
|
||||
* @param string $templateName Template name
|
||||
* @param array $additionnalParameters Additionnal parameters to inject on the Twig template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemplateContent($templateName, $additionnalParameters = [])
|
||||
{
|
||||
$this->smarty->assign($additionnalParameters);
|
||||
|
||||
return $this->module->fetch(__DIR__ . '/../views/' . $templateName . '.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current step.
|
||||
*
|
||||
* @return int Current step
|
||||
*/
|
||||
private function getCurrentStep()
|
||||
{
|
||||
return (int) LegacyConfiguration::get('ONBOARDINGV2_CURRENT_STEP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the steps count.
|
||||
*
|
||||
* @return int Steps count
|
||||
*/
|
||||
private function getTotalSteps()
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
if (null != $this->configuration) {
|
||||
foreach ($this->configuration['steps']['groups'] as &$group) {
|
||||
$total += count($group['steps']);
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shut down status.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function isShutDown()
|
||||
{
|
||||
return (int) LegacyConfiguration::get('ONBOARDINGV2_SHUT_DOWN');
|
||||
}
|
||||
}
|
||||
34
modules/welcome/OnBoarding/index.php
Normal file
34
modules/welcome/OnBoarding/index.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user