Skip to content

Commit c08464d

Browse files
authored
Merge pull request #70 from PrestaShopCorp/care-center
Care center and final modifications
2 parents 50e4e70 + a882f8e commit c08464d

27 files changed

+251
-213
lines changed

.env.dist

Lines changed: 0 additions & 1 deletion
This file was deleted.

ps_classic_edition.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
use PrestaShop\Module\PsClassicEdition\Actions\Uninstall;
2424
use PrestaShop\Module\PsClassicEdition\Install\Tabs\TabsInstaller;
25-
use Symfony\Component\Dotenv\Dotenv;
2625

2726
define('PS_CLASSIC_EDITION_SETTINGS_WHITE_LIST', json_decode(file_get_contents(__DIR__ . '/settingsWhiteList.json'), true));
2827
define('PS_CLASSIC_EDITION_SETTINGS_BLACK_LIST', json_decode(file_get_contents(__DIR__ . '/settingsBlackList.json'), true));
@@ -36,21 +35,12 @@
3635
require_once __DIR__ . '/vendor/autoload.php';
3736
}
3837

39-
(new Dotenv())
40-
// DO NOT use putEnv
41-
->usePutenv(false)
42-
// Loads .env file from the root of module
43-
->loadEnv(__DIR__ . '/.env')
44-
;
45-
4638
class ps_classic_edition extends Module
4739
{
4840
use PrestaShop\Module\PsClassicEdition\Traits\UseHooks;
4941

5042
private string $userflow_id;
5143

52-
public int $addons_id = 91027;
53-
5444
public function __construct()
5545
{
5646
$this->name = 'ps_classic_edition';
@@ -83,11 +73,20 @@ public function install(): bool
8373
{
8474
$this->uninstallBasicEditionModule();
8575

86-
return
76+
$installed =
8777
parent::install()
8878
&& (new TabsInstaller($this->name, $this->getTranslator()))->installTabs()
8979
&& $this->registerHook($this->getHooksNames())
9080
;
81+
if (!$installed) {
82+
return false;
83+
}
84+
85+
// We hide the setup guide by default on install, if we want to enable it again later
86+
// we'll just have to remove this line
87+
Configuration::updateGlobalValue('PS_SETUP_GUIDE_MODAL_IS_HIDDEN', 1);
88+
89+
return true;
9190
}
9291

9392
/**

src/Controller/AdminPsClassicEditionHomepageController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,22 @@ public function indexAction(
6767
$psAccountsSettings = $psAccountHelper->loadAccountSettings();
6868

6969
return $this->render('@Modules/ps_classic_edition/views/templates/admin/homepage.html.twig', [
70-
'layoutTitle' => $this->trans('Home', [], 'Modules.Classicedition.Admin'),
70+
'layoutTitle' => $this->trans('Care Center', [], 'Modules.Classicedition.Admin'),
7171
'urlAccountsCdn' => $psAccountsSettings['urlAccountsCdn'],
7272
'enableSidebar' => true,
7373
'jsContext' => json_encode([
7474
'SETUP_GUIDE_API_URL' => $setupGuideApiUrl,
7575
'SETUP_GUIDE_API_URL_EDIT' => $setupGuideApiUrlEdit,
7676
'SETUP_GUIDE_API_URL_MODAL_HIDDEN' => $setupGuideApiUrlModalHidden,
77+
'SETUP_GUIDE_MODAL_IS_HIDDEN' => (bool) $this->getConfiguration()->get('PS_SETUP_GUIDE_MODAL_IS_HIDDEN'),
7778
'PS_CLASSIC_EDITION_PS_ACADEMY_API_URL' => $psAcademyApiUrl,
78-
'MAINTENANCE_URL' => $this->generateUrl('admin_maintenance'),
7979
'moduleName' => $modulePsClassicEdition->displayName,
8080
'moduleSlug' => $modulePsClassicEdition->name,
8181
'moduleVersion' => $modulePsClassicEdition->version,
8282
'userToken' => $psAccountsSettings['accountUserToken'],
8383
'psAccountShopID' => $psAccountsSettings['psShopID'],
8484
'psAccountID' => $psAccountsSettings['psAccountID'],
8585
'shopName' => (string) $this->getConfiguration()->get('PS_SHOP_NAME'),
86-
'isShopEnabled' => (bool) $this->getConfiguration()->get('PS_SHOP_ENABLE'),
8786
'callBack' => [
8887
'isCalledBack' => (bool) $this->getConfiguration()->get('PS_IS_CALLED_BACK'),
8988
],

src/Install/Tabs/Tabs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public static function getTabs(): array
4646
[
4747
'class_name' => 'AdminPsClassicEditionHomepageController',
4848
'route_name' => 'ps_classic_edition_homepage',
49-
'icon' => 'home',
49+
'icon' => 'support_agent',
5050
'parent' => 'HOME',
5151
'position' => 0,
5252
'active' => true,
5353
'enabled' => true,
54-
'wording' => 'Home',
54+
'wording' => 'Care Center',
5555
'wording_domain' => 'Modules.Classicedition.Admin',
5656
],
5757
];

src/Install/Tabs/TabsInstaller.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,7 @@ public function installTabs(): bool
7272
$tab = new \Tab(\Tab::getIdFromClassName('AdminDashboard'));
7373
$tab->id_parent = \Tab::getIdFromClassName('HOME');
7474
$tab->save();
75-
$tab->updatePosition(false, 1);
76-
77-
$updateTabEnvVariables = $_ENV['PS_CLASSIC_EDITION_UPDATE_HOMEPAGE'] ?? $_SERVER['PS_CLASSIC_EDITION_UPDATE_HOMEPAGE'] ?? (getenv('PS_CLASSIC_EDITION_HOMEPAGE') ?: true);
78-
$updateTabEnvVariables = filter_var($updateTabEnvVariables, FILTER_VALIDATE_BOOLEAN);
79-
80-
if ($updateTabEnvVariables) {
81-
// Update employees default tab if they were using the dashboard and they are admin
82-
$homepageTab = new \Tab(\Tab::getIdFromClassName('AdminPsClassicEditionHomepageController'));
83-
$dashboardTab = new \Tab(\Tab::getIdFromClassName('AdminDashboard'));
84-
if (!empty($homepageTab->id) && !empty($dashboardTab->id)) {
85-
\Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . "employee SET default_tab = '$homepageTab->id' WHERE id_profile = '1' AND default_tab = '$dashboardTab->id';");
86-
}
87-
}
75+
$tab->updatePosition(false, 0);
8876

8977
return $result;
9078
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace PrestaShop\Module\PsClassicEdition\Traits\Hooks;
24+
25+
trait UseDisplayAdminStoreInformation {
26+
public function hookDisplayAdminStoreInformation(): string
27+
{
28+
$metadataFile = _PS_ROOT_DIR_ . '/app/metadata.json';
29+
if (file_exists($metadataFile)) {
30+
$metadata = json_decode(file_get_contents($metadataFile), true);
31+
if (!empty($metadata['distribution']) && !empty($metadata['distributionVersion'])) {
32+
return <<<END
33+
<p class="mb-0">
34+
<strong>{$this->trans('PrestaShop distribution:', [], 'Modules.Classicedition.Admin')}</strong> {$metadata['distribution']}
35+
</p>
36+
<p class="mb-0">
37+
<strong>{$this->trans('PrestaShop distribution version:', [], 'Modules.Classicedition.Admin')}</strong> {$metadata['distributionVersion']}
38+
</p>
39+
END;
40+
}
41+
}
42+
43+
return '';
44+
}
45+
}

src/Traits/Hooks/UseDisplayBackOfficeHeader.php

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,7 @@ trait UseDisplayBackOfficeHeader
3131
{
3232
public function hookDisplayBackOfficeHeader(): string
3333
{
34-
$controller = \Tools::getValue('controller');
35-
$minimizedGuideHtml = '';
36-
if ($controller !== 'AdminPsClassicEditionHomepageController') {
37-
$setupGuideDataPresenter = \Context::getContext()->controller->getContainer()->get(SetupGuideDataPresenter::class);
38-
$setupData = $setupGuideDataPresenter->getSetupGuideData();
39-
$remainingStepsToComplete = false;
40-
foreach ($setupData as $setupStep) {
41-
if (!$setupStep['isCompleted']) {
42-
$remainingStepsToComplete = true;
43-
break;
44-
}
45-
}
46-
47-
// Only display the minimized setup guide when there are remaining steps to finish
48-
if ($remainingStepsToComplete) {
49-
// Init URLs for setup guide
50-
$router = \Context::getContext()->controller->getContainer()->get('router');
51-
$setupGuideApiUrl = $router->generate('ps_classic_edition_setup_guide_api_index', [], UrlGeneratorInterface::ABSOLUTE_URL);
52-
$setupGuideApiUrlEdit = $router->generate('ps_classic_edition_setup_guide_api_edit', [], UrlGeneratorInterface::ABSOLUTE_URL);
53-
54-
// Init accounts
55-
$psAccountHelper = \Context::getContext()->controller->getContainer()->get(PsAccountHelper::class);
56-
$psAccountsSettings = $psAccountHelper->loadAccountSettings();
57-
$urlAccountsCdn = $psAccountsSettings['urlAccountsCdn'];
58-
$accountsUserToken = $psAccountsSettings['accountUserToken'];
59-
$psShopID = $psAccountsSettings['psShopID'];
60-
$psAccountID = $psAccountsSettings['psAccountID'];
61-
62-
// Include the minimized setup guide (only if some steps are still needed)
63-
$baseLink = \Context::getContext()->link->getAdminBaseLink();
64-
$minimizedGuideHtml = '<script type="module" src="' . $baseLink . '/modules/ps_classic_edition/views/js/vue/assets/index.js"></script>';
65-
$minimizedGuideHtml .= PHP_EOL . "
66-
<script src=\"$urlAccountsCdn\" rel=\"preload\"></script>
67-
<script>
68-
window.minimizedGuideContext = {
69-
\"SETUP_GUIDE_API_URL\": \"$setupGuideApiUrl\",
70-
\"SETUP_GUIDE_API_URL_EDIT\": \"$setupGuideApiUrlEdit\",
71-
\"'userToken\": \"$accountsUserToken\",
72-
\"psAccountShopID\": \"$psShopID\",
73-
\"psAccountID\": \"$psAccountID\"
74-
};
75-
</script>
76-
";
77-
}
78-
}
34+
$minimizedGuideHtml = $this->getMinimizedGuideHtml();
7935

8036
return <<<END
8137
{$minimizedGuideHtml}
@@ -85,4 +41,62 @@ public function hookDisplayBackOfficeHeader(): string
8541
</script>
8642
END;
8743
}
44+
45+
private function getMinimizedGuideHtml(): string
46+
{
47+
$controller = \Tools::getValue('controller');
48+
if ($controller === 'AdminPsClassicEditionHomepageController') {
49+
return '';
50+
}
51+
52+
if ((bool) \Configuration::get('PS_SETUP_GUIDE_MODAL_IS_HIDDEN')) {
53+
return '';
54+
}
55+
56+
$setupGuideDataPresenter = \Context::getContext()->controller->getContainer()->get(SetupGuideDataPresenter::class);
57+
$setupData = $setupGuideDataPresenter->getSetupGuideData();
58+
$remainingStepsToComplete = false;
59+
foreach ($setupData as $setupStep) {
60+
if (!$setupStep['isCompleted']) {
61+
$remainingStepsToComplete = true;
62+
break;
63+
}
64+
}
65+
66+
// Only display the minimized setup guide when there are remaining steps to finish
67+
if (!$remainingStepsToComplete) {
68+
return '';
69+
}
70+
71+
// Init URLs for setup guide
72+
$router = \Context::getContext()->controller->getContainer()->get('router');
73+
$setupGuideApiUrl = $router->generate('ps_classic_edition_setup_guide_api_index', [], UrlGeneratorInterface::ABSOLUTE_URL);
74+
$setupGuideApiUrlEdit = $router->generate('ps_classic_edition_setup_guide_api_edit', [], UrlGeneratorInterface::ABSOLUTE_URL);
75+
76+
// Init accounts
77+
$psAccountHelper = \Context::getContext()->controller->getContainer()->get(PsAccountHelper::class);
78+
$psAccountsSettings = $psAccountHelper->loadAccountSettings();
79+
$urlAccountsCdn = $psAccountsSettings['urlAccountsCdn'];
80+
$accountsUserToken = $psAccountsSettings['accountUserToken'];
81+
$psShopID = $psAccountsSettings['psShopID'];
82+
$psAccountID = $psAccountsSettings['psAccountID'];
83+
84+
// Include the minimized setup guide (only if some steps are still needed)
85+
$baseLink = \Context::getContext()->link->getAdminBaseLink();
86+
$minimizedGuideHtml = '<script type="module" src="' . $baseLink . '/modules/ps_classic_edition/views/js/vue/assets/index.js"></script>';
87+
$minimizedGuideHtml .= PHP_EOL . "
88+
<script src=\"$urlAccountsCdn\" rel=\"preload\"></script>
89+
<script>
90+
window.minimizedGuideContext = {
91+
\"SETUP_GUIDE_API_URL\": \"$setupGuideApiUrl\",
92+
\"SETUP_GUIDE_API_URL_EDIT\": \"$setupGuideApiUrlEdit\",
93+
\"'userToken\": \"$accountsUserToken\",
94+
\"psAccountShopID\": \"$psShopID\",
95+
\"psAccountID\": \"$psAccountID\"
96+
};
97+
</script>
98+
";
99+
100+
return $minimizedGuideHtml;
101+
}
88102
}

src/Traits/UseHooks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
trait UseHooks
2727
{
2828
use Hooks\UseDisplayBackOfficeHeader;
29+
use Hooks\UseDisplayAdminStoreInformation;
2930

3031
/**
3132
* @var array An array of method that can be called to register media in the actionAdminControllerSetMedia hook

translations/en-US/ModulesClassiceditionAdmin.en-US.xlf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<target state="translated">Welcome</target>
1818
<note>Line: </note>
1919
</trans-unit>
20-
<trans-unit id="8cf04a9734132302f96da8e113e80ce5">
21-
<source>Home</source>
22-
<target state="translated">Home</target>
20+
<trans-unit id="d2c38c5a6cb52b133d58e66470e14daa">
21+
<source>Care Center</source>
22+
<target state="translated">Care Center</target>
2323
<note>Line: </note>
2424
</trans-unit>
2525
<trans-unit id="f4f70727dc34561dfde1a3c529b6205c">
@@ -162,6 +162,16 @@
162162
<target state="translated">Settings updated</target>
163163
<note>Line: </note>
164164
</trans-unit>
165+
<trans-unit id="981d0481276dad6df56cb70e95eafb14">
166+
<source>PrestaShop distribution:</source>
167+
<target state="translated">PrestaShop distribution:</target>
168+
<note>Line: </note>
169+
</trans-unit>
170+
<trans-unit id="224ba70d3a567aa327af41e8b6d79430">
171+
<source>PrestaShop distribution version:</source>
172+
<target state="translated">PrestaShop distribution version:</target>
173+
<note>Line: </note>
174+
</trans-unit>
165175
</body>
166176
</file>
167177
</xliff>

translations/es-ES/ModulesClassiceditionAdmin.es-ES.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<target state="translated">Bienvenido</target>
1818
<note>Line: </note>
1919
</trans-unit>
20-
<trans-unit id="8cf04a9734132302f96da8e113e80ce5">
21-
<source>Home</source>
22-
<target state="translated">Inicio</target>
20+
<trans-unit id="d2c38c5a6cb52b133d58e66470e14daa">
21+
<source>Care Center</source>
22+
<target state="translated">Care Center</target>
2323
<note>Line: </note>
2424
</trans-unit>
2525
<trans-unit id="f4f70727dc34561dfde1a3c529b6205c">

0 commit comments

Comments
 (0)