Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
<?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 version 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.
*
* @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 version 3.0
*/
declare(strict_types=1);
namespace PrestaShop\Module\Mbo\Controller\Admin;
use PrestaShop\Module\Mbo\Helpers\ErrorHelper;
use PrestaShop\Module\Mbo\Module\Exception\ModuleUpgradeNotNeededException;
use PrestaShop\PrestaShop\Core\Module\ModuleManager;
use PrestaShop\PrestaShop\Core\Module\ModuleRepository;
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
if (!defined('_PS_VERSION_')) {
exit;
}
class AddonsController extends PrestaShopAdminController
{
public function upgradeModuleAction(
Request $request,
ModuleManager $moduleManager,
ModuleRepository $moduleRepository,
): JsonResponse {
$moduleName = $request->request->get('moduleName');
if (null === $moduleName) {
return new JsonResponse(null, Response::HTTP_BAD_REQUEST);
}
try {
$upgradeResponse = [
'status' => $moduleManager->upgrade($moduleName),
'msg' => '',
'module_name' => $moduleName,
];
if ($upgradeResponse['status'] === true) {
$upgradeResponse['msg'] = $this->trans(
'Module %module% successfully upgraded.',
['%module%' => $moduleName],
'Modules.Mbo.Modulescatalog',
);
$upgradeResponse['is_configurable'] = (bool) $moduleRepository
->getModule($moduleName)
->attributes
->get('is_configurable');
} else {
$error = $moduleManager->getError($moduleName);
$upgradeResponse['msg'] = $this->trans(
'Upgrade of module %module% failed. %error%',
[
'%module%' => $moduleName,
'%error%' => $error,
],
'Modules.Mbo.Modulescatalog',
);
}
} catch (\Exception $e) {
ErrorHelper::reportError($e);
if ($e->getPrevious() instanceof ModuleUpgradeNotNeededException) {
$upgradeResponse['status'] = true;
$upgradeResponse['msg'] = $this->trans(
'Module %module% is already up to date',
[
'%module%' => $moduleName,
],
'Modules.Mbo.Modulescatalog',
);
} else {
try {
$moduleManager->disable($moduleName);
} catch (\Exception $subE) {
ErrorHelper::reportError($subE);
}
$upgradeResponse['msg'] = $this->trans(
'Upgrade of module %module% failed. %error%',
[
'%module%' => $moduleName,
'%error%' => $e->getMessage(),
],
'Modules.Mbo.Modulescatalog',
);
}
}
return new JsonResponse($upgradeResponse);
}
}

View File

@@ -0,0 +1,181 @@
<?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 version 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.
*
* @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 version 3.0
*/
declare(strict_types=1);
namespace PrestaShop\Module\Mbo\Controller\Admin;
use PrestaShop\Module\Mbo\Addons\Toolbar;
use PrestaShop\Module\Mbo\Helpers\ErrorHelper;
use PrestaShop\Module\Mbo\Service\View\ContextBuilder;
use PrestaShop\PrestaShop\Core\Security\Permission;
use PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts;
use PrestaShop\PsAccountsInstaller\Installer\Installer;
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use PrestaShopBundle\Security\Attribute\AdminSecurity;
use Symfony\Component\HttpFoundation\Response;
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Responsible of "Improve > Modules > Modules Catalog" page display.
*/
class ModuleCatalogController extends PrestaShopAdminController
{
public const CONTROLLER_NAME = 'ADMINMODULESSF';
/**
* @var Toolbar
*/
private $addonsToolbar;
/**
* @var ContextBuilder
*/
private $contextBuilder;
/**
* @var PsAccounts
*/
private $psAccountsFacade;
/**
* @var Installer
*/
private $psAccountsInstaller;
public function __construct(
Toolbar $addonsToolbar,
ContextBuilder $contextBuilder,
PsAccounts $psAccountsFacade,
Installer $psAccountsInstaller,
) {
$this->addonsToolbar = $addonsToolbar;
$this->contextBuilder = $contextBuilder;
$this->psAccountsFacade = $psAccountsFacade;
$this->psAccountsInstaller = $psAccountsInstaller;
}
#[AdminSecurity(
"is_granted('read', request.get('_legacy_controller')) && is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller')) && is_granted('delete', request.get('_legacy_controller'))"
)]
public function indexAction(): Response
{
$extraParams = \ps_mbo::getCdcMediaUrl();
/*********************
* PrestaShop Account *
* *******************/
$urlAccountsCdn = '';
try {
$accountsService = $this->psAccountsFacade->getPsAccountsService();
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) {
// Seems the module is not here, try to install it
$this->psAccountsInstaller->install();
try {
$accountsService = $this->psAccountsFacade->getPsAccountsService();
} catch (\Exception $e) {
// Installation seems to not work properly
$accountsService = null;
ErrorHelper::reportError($e);
}
}
if (null !== $accountsService) {
try {
\Media::addJsDef([
'contextPsAccounts' => $this->psAccountsFacade->getPsAccountsPresenter()
->present('ps_mbo'),
]);
// Retrieve the PrestaShop Account CDN
$urlAccountsCdn = $accountsService->getAccountsCdn();
} catch (\Exception $e) {
ErrorHelper::reportError($e);
}
}
return $this->render(
'@Modules/ps_mbo/views/templates/admin/controllers/module_catalog/catalog.html.twig',
[
'layoutHeaderToolbarBtn' => $this->addonsToolbar->getToolbarButtons(),
'layoutTitle' => $this->trans('Marketplace', [], 'Modules.Mbo.Modulescatalog'),
'requireAddonsSearch' => true,
'requireBulkActions' => false,
'showContentHeader' => true,
'enableSidebar' => true,
'help_link' => $this->generateSidebarLink('AdminModules'),
'requireFilterStatus' => false,
'level' => $this->authorizationLevel(static::CONTROLLER_NAME),
'shop_context' => $this->contextBuilder->getViewContext(),
'urlAccountsCdn' => $urlAccountsCdn,
'errorMessage' => $this->trans(
'You do not have permission to add this.',
[],
'Admin.Notifications.Error'
),
] + $extraParams
);
}
/**
* Responsible for displaying error block when CDC cannot be loaded.
*
* @return Response
*/
public function cdcErrorAction(): Response
{
return $this->render(
'@Modules/ps_mbo/views/templates/admin/controllers/module_catalog/cdc-error.html.twig'
);
}
/**
* Checks if the attributes are granted against the current authentication token and optionally supplied object.
*
* @param string $controller name of the controller that token is tested against
*
* @return int
*
* @throws \LogicException
*/
private function authorizationLevel($controller)
{
if ($this->isGranted(Permission::DELETE, $controller)) {
return Permission::LEVEL_DELETE;
}
if ($this->isGranted(Permission::CREATE, $controller)) {
return Permission::LEVEL_CREATE;
}
if ($this->isGranted(Permission::UPDATE, $controller)) {
return Permission::LEVEL_UPDATE;
}
if ($this->isGranted(Permission::READ, $controller)) {
return Permission::LEVEL_READ;
}
return 0;
}
}

View File

@@ -0,0 +1,80 @@
<?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 version 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.
*
* @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 version 3.0
*/
declare(strict_types=1);
namespace PrestaShop\Module\Mbo\Controller\Admin;
use PrestaShop\Module\Mbo\Service\View\ContextBuilder;
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Responsible of render json data for ajax display of Recommended Modules.
*/
class ModuleRecommendedController extends PrestaShopAdminController
{
/**
* @return JsonResponse|RedirectResponse
*/
public function indexAction(
Request $request,
ContextBuilder $contextBuilder,
): Response {
$response = new JsonResponse();
try {
$tabClassName = $request->get('tabClassName');
if (null === $tabClassName) { // In case the recommended modules page is requested without giving tab context, we redirect to Modules catalog page
$routeParams = [];
$query = \Tools::getValue('bo_query');
if (false !== $query && !empty(trim($query))) {
$routeParams['keyword'] = trim($query);
}
return $this->redirectToRoute('admin_mbo_catalog_module', $routeParams);
}
$context = $contextBuilder->getRecommendedModulesContext($tabClassName);
$context['recommendation_format'] = $request->get('recommendation_format');
$response->setData([
'content' => $this->renderView(
'@Modules/ps_mbo/views/templates/admin/controllers/module_catalog/recommended-modules.html.twig',
[
'shop_context' => $context,
]
),
]);
} catch (ServiceUnavailableHttpException $exception) {
$response->setData([
'content' => $this->renderView('@Modules/ps_mbo/views/templates/admin/error.html.twig'),
]);
$response->setStatusCode($exception->getStatusCode());
$response->headers->add($exception->getHeaders());
}
return $response;
}
}

View File

@@ -0,0 +1,75 @@
<?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 version 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.
*
* @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 version 3.0
*/
declare(strict_types=1);
namespace PrestaShop\Module\Mbo\Controller\Admin;
use PrestaShop\Module\Mbo\Addons\Provider\LinksProvider;
use PrestaShop\Module\Mbo\Service\ExternalContentProvider\ExternalContentProviderInterface;
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use PrestaShopBundle\Security\Attribute\AdminSecurity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Responsible of "Improve > Design > Themes Catalog" page display.
*/
class ThemeCatalogController extends PrestaShopAdminController
{
#[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")]
public function indexAction(
Request $request,
LinksProvider $linksProvider,
ExternalContentProviderInterface $externalContentProvider,
): Response {
$response = new Response();
try {
$response->setContent($this->renderView(
'@Modules/ps_mbo/views/templates/admin/controllers/theme_catalog/addons_store.html.twig',
[
'pageContent' => $externalContentProvider->getContent(
$linksProvider->getSelectionLink()
),
'layoutHeaderToolbarBtn' => [],
'layoutTitle' => $this->trans('Themes Catalog', [], 'Modules.Mbo.Themescatalog'),
'requireAddonsSearch' => true,
'requireBulkActions' => false,
'showContentHeader' => true,
'enableSidebar' => true,
'help_link' => $this->generateSidebarLink($request->get('_legacy_controller')),
'requireFilterStatus' => false,
'level' => $this->getAuthorizationLevel($request->get('_legacy_controller')),
]
));
} catch (ServiceUnavailableHttpException $exception) {
$response->setContent($this->renderView('@Modules/ps_mbo/views/templates/admin/error.html.twig'));
$response->setStatusCode($exception->getStatusCode());
$response->headers->add($exception->getHeaders());
}
return $response;
}
}

View File

@@ -0,0 +1,28 @@
<?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 version 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.
*
* @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 version 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;

View File

@@ -0,0 +1,28 @@
<?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 version 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.
*
* @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 version 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;