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,14 @@
# Apache 2.2
<IfModule !mod_authz_core.c>
<Files *.php>
order allow,deny
deny from all
</Files>
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
<Files *.php>
Require all denied
</Files>
</IfModule>

172
modules/ps_eventbus/LICENSE Normal file
View File

@@ -0,0 +1,172 @@
Open Software License ("OSL") v. 3.0
This Open Software License (the "License") applies to any original work of
authorship (the "Original Work") whose owner (the "Licensor") has placed the
following licensing notice adjacent to the copyright notice for the Original
Work:
Licensed under the Open Software License version 3.0
1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, for the duration of the copyright, to do
the following:
a) to reproduce the Original Work in copies, either alone or as part of a
collective work;
b) to translate, adapt, alter, transform, modify, or arrange the Original
Work, thereby creating derivative works ("Derivative Works") based upon the
Original Work;
c) to distribute or communicate copies of the Original Work and Derivative
Works to the public, with the proviso that copies of Original Work or
Derivative Works that You distribute or communicate shall be licensed under
this Open Software License;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2. Grant of Patent License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, under patent claims owned or controlled
by the Licensor that are embodied in the Original Work as furnished by the
Licensor, for the duration of the patents, to make, use, sell, offer for sale,
have made, and import the Original Work and Derivative Works.
3. Grant of Source Code License. The term "Source Code" means the preferred
form of the Original Work for making modifications to it and all available
documentation describing how to modify the Original Work. Licensor agrees to
provide a machine-readable copy of the Source Code of the Original Work along
with each copy of the Original Work that Licensor distributes. Licensor
reserves the right to satisfy this obligation by placing a machine-readable
copy of the Source Code in an information repository reasonably calculated to
permit inexpensive and convenient access by You for as long as Licensor
continues to distribute the Original Work.
4. Exclusions From License Grant. Neither the names of Licensor, nor the names
of any contributors to the Original Work, nor any of their trademarks or
service marks, may be used to endorse or promote products derived from this
Original Work without express prior permission of the Licensor. Except as
expressly stated herein, nothing in this License grants any license to
Licensor's trademarks, copyrights, patents, trade secrets or any other
intellectual property. No patent license is granted to make, use, sell, offer
for sale, have made, or import embodiments of any patent claims other than the
licensed claims defined in Section 2. No license is granted to the trademarks
of Licensor even if such marks are included in the Original Work. Nothing in
this License shall be interpreted to prohibit Licensor from licensing under
terms different from this License any Original Work that Licensor otherwise
would have a right to license.
5. External Deployment. The term "External Deployment" means the use,
distribution, or communication of the Original Work or Derivative Works in any
way such that the Original Work or Derivative Works may be used by anyone
other than You, whether those works are distributed or communicated to those
persons or made available as an application intended for use over a network.
As an express condition for the grants of license hereunder, You must treat
any External Deployment by You of the Original Work or a Derivative Work as a
distribution under section 1(c).
6. Attribution Rights. You must retain, in the Source Code of any Derivative
Works that You create, all copyright, patent, or trademark notices from the
Source Code of the Original Work, as well as any notices of licensing and any
descriptive text identified therein as an "Attribution Notice." You must cause
the Source Code for any Derivative Works that You create to carry a prominent
Attribution Notice reasonably calculated to inform recipients that You have
modified the Original Work.
7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
the copyright in and to the Original Work and the patent rights granted herein
by Licensor are owned by the Licensor or are sublicensed to You under the
terms of this License with the permission of the contributor(s) of those
copyrights and patent rights. Except as expressly stated in the immediately
preceding sentence, the Original Work is provided under this License on an "AS
IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without
limitation, the warranties of non-infringement, merchantability or fitness for
a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK
IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this
License. No license to the Original Work is granted by this License except
under this disclaimer.
8. Limitation of Liability. Under no circumstances and under no legal theory,
whether in tort (including negligence), contract, or otherwise, shall the
Licensor be liable to anyone for any indirect, special, incidental, or
consequential damages of any character arising as a result of this License or
the use of the Original Work including, without limitation, damages for loss
of goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses. This limitation of liability shall not
apply to the extent applicable law prohibits such limitation.
9. Acceptance and Termination. If, at any time, You expressly assented to this
License, that assent indicates your clear and irrevocable acceptance of this
License and all of its terms and conditions. If You distribute or communicate
copies of the Original Work or a Derivative Work, You must make a reasonable
effort under the circumstances to obtain the express assent of recipients to
the terms of this License. This License conditions your rights to undertake
the activities listed in Section 1, including your right to create Derivative
Works based upon the Original Work, and doing so without honoring these terms
and conditions is prohibited by copyright law and international treaty.
Nothing in this License is intended to affect copyright exceptions and
limitations (including "fair use" or "fair dealing"). This License shall
terminate immediately and You may no longer exercise any of the rights granted
to You by this License upon your failure to honor the conditions in Section
1(c).
10. Termination for Patent Action. This License shall terminate automatically
and You may no longer exercise any of the rights granted to You by this
License as of the date You commence an action, including a cross-claim or
counterclaim, against Licensor or any licensee alleging that the Original Work
infringes a patent. This termination provision shall not apply for an action
alleging patent infringement by combinations of the Original Work with other
software or hardware.
11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this
License may be brought only in the courts of a jurisdiction wherein the
Licensor resides or in which Licensor conducts its primary business, and under
the laws of that jurisdiction excluding its conflict-of-law provisions. The
application of the United Nations Convention on Contracts for the
International Sale of Goods is expressly excluded. Any use of the Original
Work outside the scope of this License or after its termination shall be
subject to the requirements and penalties of copyright or patent law in the
appropriate jurisdiction. This section shall survive the termination of this
License.
12. Attorneys' Fees. In any action to enforce the terms of this License or
seeking damages relating thereto, the prevailing party shall be entitled to
recover its costs and expenses, including, without limitation, reasonable
attorneys' fees and costs incurred in connection with such action, including
any appeal of such action. This section shall survive the termination of this
License.
13. Miscellaneous. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent necessary
to make it enforceable.
14. Definition of "You" in This License. "You" throughout this License,
whether in upper or lower case, means an individual or a legal entity
exercising rights under, and complying with all of the terms of, this License.
For legal entities, "You" includes any entity that controls, is controlled by,
or is under common control with you. For purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the direction or
management of such entity, whether by contract or otherwise, or (ii) ownership
of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
ownership of such entity.
15. Right to Use. You may use the Original Work in all ways not otherwise
restricted or conditioned by this License or by law, and Licensor promises not
to interfere with or be responsible for such uses by You.
16. Modification of This License. This License is Copyright © 2005 Lawrence
Rosen. Permission is granted to copy, distribute, or communicate this License
without modification. Nothing in this License permits You to modify this
License as applied to the Original Work or to Derivative Works. However, You
may modify the text of this License and copy, distribute or communicate your
modified version (the "Modified License") and apply it to other original works
of authorship subject to the following conditions: (i) You may not indicate in
any way that your Modified License is the "Open Software License" or "OSL" and
you may not use those names in the name of your Modified License; (ii) You
must replace the notice specified in the first paragraph above with the notice
"Licensed under <insert your license name here>" or with a notice of your own
that is not confusingly similar to the notice in this License; and (iii) You
may not claim that your original works are open source software unless your
Modified License has been approved by Open Source Initiative (OSI) and You
comply with its license review and certification process.

24
modules/ps_eventbus/composer.lock generated Normal file
View File

@@ -0,0 +1,24 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ad5e124e2e7361657c2472a85ef312a0",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.6",
"ext-json": "*"
},
"platform-dev": [],
"platform-overrides": {
"php": "5.6"
},
"plugin-api-version": "2.3.0"
}

View File

@@ -0,0 +1,27 @@
<?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
*/
return [
'ps_eventbus.proxy_api_url' => 'https://eventbus-proxy.psessentials.net',
'ps_eventbus.sync_api_url' => 'https://eventbus-sync.psessentials.net',
'ps_eventbus.live_sync_api_url' => 'https://api.cloudsync.prestashop.com/live-sync/v1',
'ps_eventbus.sentry_dsn' => 'https://457f191226df4b8f9a0d7bf6f250bab2@o298402.ingest.sentry.io/6066714',
'ps_eventbus.sentry_env' => 'production',
];

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>ps_eventbus</name>
<displayName><![CDATA[PrestaShop EventBus]]></displayName>
<version><![CDATA[4.0.13]]></version>
<description><![CDATA[Link your PrestaShop account to synchronize your shop data to a tech partner of your choice. Do not uninstall this module if you are already using a service, as it will prevent it from working.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
<confirmUninstall><![CDATA[This action will immediately prevent your PrestaShop services and Community services from working as they are using PrestaShop CloudSync for syncing.]]></confirmUninstall>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
</module>

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,4 @@
services:
PrestaShop\Module\PsEventbus\Service\PresenterService:
class: PrestaShop\Module\PsEventbus\Service\PresenterService
public: true

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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 @@
services:

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,55 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
use PrestaShop\Module\PsEventbus\Service\ApiHealthCheckService;
use PrestaShop\Module\PsEventbus\Service\CommonService;
if (!defined('_PS_VERSION_')) {
exit;
}
class ps_EventbusApiHealthCheckModuleFrontController extends ModuleFrontController
{
/**
* @return void
*
* @throws\PrestaShopException
*/
public function postProcess()
{
/** @var string $jobId */
$jobId = Tools::getValue('job_id');
/** @var Ps_eventbus $module */
$module = Module::getInstanceByName('ps_eventbus');
/** @var ApiHealthCheckService $apiHealthCheckService */
$apiHealthCheckService = $module->getService(ApiHealthCheckService::class);
$response = $apiHealthCheckService->getHealthCheck($jobId);
CommonService::exitWithResponse($response);
}
}

View File

@@ -0,0 +1,101 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
use PrestaShop\Module\PsEventbus\Service\ApiShopContentService;
if (!defined('_PS_VERSION_')) {
exit;
}
class ps_EventbusApiShopContentModuleFrontController extends ModuleFrontController
{
/**
* @return void
*
* @throws\PrestaShopException
*/
public function postProcess()
{
/** @var string $shopContent */
$shopContent = Tools::getValue('shop_content');
/** @var string $jobId */
$jobId = Tools::getValue('job_id');
/** @var string $langIso */
$langIso = Tools::getValue('lang_iso');
/** @var int $limit */
$limit = Tools::getValue('limit', 50);
/** @var bool $fullSyncRequested */
$fullSyncRequested = Tools::getValue('full', 0) == 1;
/** @var bool $explainSql */
$explainSql = Tools::getValue('explain_sql', 0) == 1;
/** @var bool $verbose */
$verbose = Tools::getValue('verbose', 0) == 1;
/** @var bool $psLogsEnabled */
$psLogsEnabled = Tools::getValue('ps_logs_enabled', 0) == 1;
/** @var Ps_eventbus $module */
$module = Module::getInstanceByName('ps_eventbus');
/** @var ApiShopContentService $apiShopContentService */
$apiShopContentService = $module->getService(ApiShopContentService::class);
// Define our 3 constants here to be retrieved later in the application (errorHandler, repositories)
if (!defined('PS_EVENTBUS_EXPLAIN_SQL_ENABLED')) {
define('PS_EVENTBUS_EXPLAIN_SQL_ENABLED', $explainSql);
}
if (!defined('PS_EVENTBUS_VERBOSE_ENABLED')) {
define('PS_EVENTBUS_VERBOSE_ENABLED', $verbose);
}
if (!defined('PS_EVENTBUS_LOGS_ENABLED')) {
define('PS_EVENTBUS_LOGS_ENABLED', $psLogsEnabled);
}
if (!defined('REQUEST_START_TIME')) {
define('REQUEST_START_TIME', microtime(true));
}
// edit shopContent for matching Config.php const
$shopContentEdited = str_replace('-', '_', $shopContent);
$apiShopContentService->handleDataSync(
$shopContentEdited,
$jobId,
$langIso,
$limit,
$fullSyncRequested
);
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,204 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
// DONT'T USE "use" STATEMENT HERE, IT'S NOT COMPAT WITH 1.6
// PREFER "use" IN CLASS DIRECTLY
require_once __DIR__ . '/vendor/autoload.php';
if (!defined('_PS_VERSION_')) {
exit;
}
class Ps_eventbus extends Module
{
// All hooks is here
use PrestaShop\Module\PsEventbus\Traits\UseHooks;
/**
* @var array<mixed>
*/
public $adminControllers;
/**
* @var string
*/
public $version;
/**
* @var PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer
*/
private $container;
/**
* @var int the unique shop identifier (uuid v4)
*/
private $shopId;
/**
* @var int Defines the multistore compatibility level of the module
*/
public $multistoreCompatibility;
/**
* @var string contact email of the maintainers (please consider using github issues)
*/
public $emailSupport;
/**
* @var string available terms of services
*/
public $termsOfServiceUrl;
/**
* __construct.
*/
public function __construct()
{
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.8.0', '>=')) {
$this->multistoreCompatibility = parent::MULTISTORE_COMPATIBILITY_YES;
}
// @see https://devdocs.prestashop-project.org/8/modules/concepts/module-class/
$this->name = 'ps_eventbus';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
$this->version = '4.0.13';
$this->module_key = '7d76e08a13331c6c393755886ec8d5ce';
parent::__construct();
$this->emailSupport = 'cloudsync-support@prestashop.com';
$this->termsOfServiceUrl = 'https://www.prestashop.com/en/prestashop-account-privacy';
$this->displayName = $this->l('PrestaShop EventBus');
$this->description = $this->l('Link your PrestaShop account to synchronize your shop data to a tech partner of your choice. Do not uninstall this module if you are already using a service, as it will prevent it from working.');
$this->confirmUninstall = $this->l('This action will immediately prevent your PrestaShop services and Community services from working as they are using PrestaShop CloudSync for syncing.');
$this->ps_versions_compliancy = ['min' => '1.6.1.11', 'max' => _PS_VERSION_];
$this->adminControllers = [];
// If PHP is not compliant, we will not load composer and the autoloader
if (!$this->isPhpVersionCompliant()) {
return;
}
if ($this->context->shop === null) {
throw new PrestaShopException('No shop context');
}
$this->shopId = (int) $this->context->shop->id;
}
/**
* @return Context
*/
public function getContext()
{
return $this->context;
}
/**
* @return array<mixed>
*/
public function getAdminControllers()
{
return $this->adminControllers;
}
/**
* @return bool
*/
public function install()
{
if (!$this->isPhpVersionCompliant()) {
$this->_errors[] = $this->l('This requires PHP 5.6 to work properly. Please upgrade your server configuration.');
// We return true during the installation of PrestaShop to not stop the whole process,
// Otherwise we warn properly the installation failed.
return defined('PS_INSTALLATION_IN_PROGRESS');
}
$installer = new PrestaShop\Module\PsEventbus\Module\Install($this, Db::getInstance());
return $installer->installDatabaseTables()
&& parent::install()
&& $this->registerHook($this->getHooks());
}
/**
* @return bool
*/
public function uninstall()
{
$uninstaller = new PrestaShop\Module\PsEventbus\Module\Uninstall($this, Db::getInstance());
return $uninstaller->uninstallMenu()
&& $uninstaller->uninstallDatabaseTables()
&& parent::uninstall();
}
/**
* @return PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer
*
* @throws Exception
*/
public function getServiceContainer()
{
if (null === $this->container) {
$this->container = PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer::createInstance(
__DIR__ . '/config.php'
);
}
return $this->container;
}
/**
* This function allows you to patch bugs that can be found related to "ServiceNotFoundException".
* It ensures that you have access to the SymfonyContainer, and also that you have access to FO services.
*
* @param string $serviceName
*
* @return mixed
*/
public function getService($serviceName)
{
return $this->getServiceContainer()->getService($serviceName);
}
/**
* Set PHP compatibility to 5.6
*
* @return bool
*/
private function isPhpVersionCompliant()
{
/* @phpstan-ignore-next-line */
return PHP_VERSION_ID >= 50600;
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,38 @@
CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_type_sync`
(
`type` VARCHAR(50) NOT NULL,
`offset` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`id_shop` INT(10) UNSIGNED NOT NULL,
`lang_iso` VARCHAR(3),
`full_sync_finished` TINYINT(1) NOT NULL DEFAULT 0,
`last_sync_date` DATETIME NOT NULL,
PRIMARY KEY (`type`, `id_shop`, `lang_iso`)
) ENGINE = ENGINE_TYPE
DEFAULT CHARSET = utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_job`
(
`job_id` VARCHAR(200) NOT NULL,
`created_at` DATETIME NOT NULL
) ENGINE = ENGINE_TYPE
DEFAULT CHARSET = utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_incremental_sync`
(
`type` VARCHAR(50) NOT NULL,
`action` VARCHAR(50) NOT NULL DEFAULT 'upsert',
`id_object` VARCHAR(50) NOT NULL,
`id_shop` INT(10) UNSIGNED NOT NULL,
`lang_iso` VARCHAR(3),
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`type`, `id_object`, `id_shop`, `lang_iso`)
) ENGINE = ENGINE_TYPE
DEFAULT CHARSET = utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_live_sync`
(
`shop_content` VARCHAR(50) NOT NULL,
`last_change_at` DATETIME NOT NULL,
PRIMARY KEY (`shop_content`)
) ENGINE = ENGINE_TYPE
DEFAULT CHARSET = utf8;

View File

@@ -0,0 +1,52 @@
-- Define the name of the database and the quantity desired for the clean
SET @db_name = 'prestashop';
set @quantity_needed = '1000000';
-- Retrieve the eventbus_incremental_sync table name with prefix
SET @eventbus_incremental_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_incremental_sync');
-- Retrieve the _eventbus_type_sync table name with prefix
SET @eventbus_type_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_type_sync');
-- enable full-sync for selected shop content
SET @enable_full_sync = CONCAT('
UPDATE ', @eventbus_type_sync_table, '
SET `offset` = 0, full_sync_finished = 0
WHERE type IN (
SELECT type
FROM (
SELECT type, COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
) AS subquery
);
');
-- Execute dynamic query
PREPARE enable_full_sync FROM @enable_full_sync;
EXECUTE enable_full_sync;
-- Delete entries with more than X entries of this type (set above via the variable @quantity_needed)
SET @delete_query = CONCAT('
DELETE FROM ', @eventbus_incremental_sync_table, '
WHERE type IN (
SELECT type
FROM (
SELECT type, COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
) AS subquery
);
');
-- Execute dynamic query
PREPARE delete_query FROM @delete_query;
EXECUTE delete_query;

View File

@@ -0,0 +1,22 @@
-- Define the name of the database and the quantity desired for the clean
SET @db_name = 'prestashop';
set @quantity_needed = '1000000';
-- Retrieve the eventbus_incremental_sync table name with prefix
SET @eventbus_incremental_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_incremental_sync');
-- Retrieves the input quantity and associated type
SET @get_content_with_extra_counts = CONCAT('
SELECT type,
COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
');
-- Execute dynamic query
PREPARE get_content_with_extra_counts FROM @get_content_with_extra_counts;
EXECUTE get_content_with_extra_counts;

View File

@@ -0,0 +1,137 @@
#!/bin/bash
# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Parameters
REPO_URL="https://github.com/PrestaShop/PrestaShop.git"
TABLE_COLUMN="$1"
REPO_PATH="$2"
FILE="install-dev/data/db_structure.sql"
if [ -z "$TABLE_COLUMN" ]; then
echo -e "${RED}❌ Usage : $0 <table.column> [repo_path]${NC}"
echo "Example : $0 connections.ip_address ~/projects/PrestaShop"
exit 1
fi
# Split table and column
TABLE=$(echo "$TABLE_COLUMN" | cut -d '.' -f 1)
COLUMN=$(echo "$TABLE_COLUMN" | cut -d '.' -f 2)
if [ -z "$TABLE" ] || [ -z "$COLUMN" ]; then
echo -e "${RED}❌ Invalid format. Use table.column (e.g., connections.ip_address)${NC}"
exit 1
fi
# Manage the repo (local or clone)
CLEANUP="false"
if [ -z "$REPO_PATH" ]; then
TMP_DIR=$(mktemp -d)
REPO_PATH="$TMP_DIR"
echo -e "${BLUE}🚀 Cloning repository from $REPO_URL...${NC}"
git clone --quiet "$REPO_URL" "$REPO_PATH"
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Failed to clone repository.${NC}"
exit 1
fi
CLEANUP="true"
else
if [ ! -d "$REPO_PATH/.git" ]; then
echo -e "${RED}❌ The provided path is not a valid Git repository: $REPO_PATH${NC}"
exit 1
fi
echo -e "${BLUE}📂 Using local repository: $REPO_PATH${NC}"
fi
cd "$REPO_PATH"
echo -e "${CYAN}🔍 Searching for column '$COLUMN' in table '$TABLE'...${NC}"
LAST_TABLE_BLOCK=""
ERROR_LOGS=""
check_column_in_commit() {
local commit=$1
CONTENT=$(git show "${commit}:${FILE}" 2>/dev/null)
if [ $? -ne 0 ]; then
ERROR_LOGS+="${RED}❌ [$commit] File $FILE does not exist in this commit.${NC}\n"
return 2
fi
TABLE_BLOCK=$(echo "$CONTENT" | awk -v table="PREFIX_${TABLE}" '
BEGIN {capture=0}
(toupper($0) ~ "CREATE[ ]*TABLE" && $0 ~ ("`" table "`")) {capture=1}
capture==1 {print}
capture==1 && $0 ~ /^[ ]*\)[ ]*ENGINE=/ {capture=0}
')
if [ -z "$TABLE_BLOCK" ]; then
ERROR_LOGS+="${RED}❌ [$commit] Table PREFIX_${TABLE} not found.${NC}\n"
return 3
fi
LAST_TABLE_BLOCK="$TABLE_BLOCK"
echo "$TABLE_BLOCK" | grep -q "\`${COLUMN}\`"
if [ $? -eq 0 ]; then
echo -e "${GREEN}🎯 [$commit] Column '${COLUMN}' found in table '${TABLE}'.${NC}"
return 0
else
return 1
fi
}
COMMITS=$(git log --format="%H" --reverse -- "$FILE")
FOUND="false"
for COMMIT in $COMMITS
do
check_column_in_commit "$COMMIT"
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e "${GREEN}✅ Column '${COLUMN}' exists in table '${TABLE}' since commit: $COMMIT${NC}"
TAGS=$(git tag --contains $COMMIT)
if [ -z "$TAGS" ]; then
echo -e "${YELLOW}⚠️ No tag found containing this commit (it may be in the development branch)${NC}"
else
CLEAN_TAGS=$(echo "$TAGS" | grep -Ev '^(list|show)$' | sort -V)
FIRST_TAG=$(echo "$CLEAN_TAGS" | head -n 1)
LAST_TAG=$(echo "$CLEAN_TAGS" | tail -n 1)
echo -e "${CYAN}🏷️ Present from tag: ${GREEN}$FIRST_TAG${CYAN} to ${GREEN}$LAST_TAG${NC}"
fi
echo -e "${BLUE}📜 Commit details :${NC}"
git --no-pager log -1 $COMMIT
echo -e "\n${CYAN}📄 Full table definition when the column was introduced:${NC}\n"
echo "$LAST_TABLE_BLOCK"
FOUND="true"
break
fi
done
if [ "$FOUND" == "false" ]; then
echo -e "$ERROR_LOGS"
echo -e "${RED}❌ The column '${COLUMN}' in table '${TABLE}' was not found in the history of $FILE${NC}"
fi
# Cleanup
if [ "$CLEANUP" == "true" ]; then
cd - > /dev/null
rm -rf "$TMP_DIR"
echo -e "${BLUE}🧹 Temporary folder removed.${NC}"
else
cd - > /dev/null
fi

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,4 @@
DROP TABLE IF EXISTS `PREFIX_eventbus_type_sync`;
DROP TABLE IF EXISTS `PREFIX_eventbus_job`;
DROP TABLE IF EXISTS `PREFIX_eventbus_incremental_sync`;
DROP TABLE IF EXISTS `PREFIX_eventbus_live_sync`;

View File

@@ -0,0 +1,242 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Api;
use PrestaShop\Module\PsEventbus\Service\PsAccountsAdapterService;
if (!defined('_PS_VERSION_')) {
exit;
}
class CloudSyncClient
{
/**
* @var string
*/
private $collectorApiUrl;
/**
* @var string
*/
private $liveSyncApiUrl;
/**
* @var string
*/
private $syncApiUrl;
/**
* @var HttpClient
*/
private $client;
/**
* @var \Ps_eventbus
*/
private $module;
/**
* Accounts JSON Web token
*
* @var string
*/
private $jwt;
/**
* Accounts Shop UUID
*
* @var string
*/
private $shopId;
/**
* Default maximum execution time in seconds
*
* @see https://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
*
* @var int
*/
private static $DEFAULT_MAX_EXECUTION_TIME = 30;
/**
* @param string $collectorApiUrl
* @param string $liveSyncApiUrl
* @param string $syncApiUrl
* @param \Ps_eventbus $module
* @param PsAccountsAdapterService $psAccountsAdapterService
*/
public function __construct(
$collectorApiUrl,
$liveSyncApiUrl,
$syncApiUrl,
\Ps_eventbus $module,
PsAccountsAdapterService $psAccountsAdapterService
) {
$this->module = $module;
$this->jwt = $psAccountsAdapterService->getOrRefreshToken();
$this->shopId = $psAccountsAdapterService->getShopUuid();
$this->collectorApiUrl = $collectorApiUrl;
$this->liveSyncApiUrl = $liveSyncApiUrl;
$this->syncApiUrl = $syncApiUrl;
$this->client = HttpClient::getInstance();
$this->client->setTimeout(3);
}
/**
* Push some ShopContents to CloudSync
*
* @param string $jobId
* @param array<mixed> $data
* @param int $startTime in seconds since epoch
* @param bool $fullSyncRequested
*
* @return array<mixed>
*/
public function upload($jobId, $data, $startTime, $fullSyncRequested = null)
{
$this->client->setTimeout($this->getRemainingTime($startTime));
$url = $this->collectorApiUrl . '/upload/' . $jobId;
$request = $this->client->post(
$url,
[
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->jwt,
'Full-Sync-Requested' => $fullSyncRequested ? '1' : '0',
'User-Agent' => 'ps-eventbus/' . $this->module->version,
],
$data,
true
);
return [
'status' => substr((string) $request->getHttpStatus(), 0, 1) === '2',
'httpCode' => $request->getHttpStatus(),
'body' => $request->getResponse(),
'upload_url' => $url,
];
}
/**
* @param string $shopContent
* @param string $action
*
* @return array<mixed>
*/
public function liveSync($shopContent, $action)
{
// shop content send to the API must be in kebab-case
$kebabCasedShopContent = str_replace('_', '-', $shopContent);
$request = $this->client->post(
$this->liveSyncApiUrl . '/notify/' . $this->shopId,
[
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->jwt,
'User-Agent' => 'ps-eventbus/' . $this->module->version,
'Content-Type' => 'application/json',
],
[
'shopContents' => [$kebabCasedShopContent],
'action' => $action,
]
);
return [
'status' => substr((string) $request->getHttpStatus(), 0, 1) === '2',
'httpCode' => $request->getHttpStatus(),
'body' => $request->getResponse(),
];
}
/**
* @param string $jobId
*
* @return array<mixed>
*/
public function validateJobId($jobId)
{
$request = $this->client->get(
$this->syncApiUrl . '/job/' . $jobId,
[
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->jwt,
'User-Agent' => 'ps-eventbus/' . $this->module->version,
]
);
return [
'status' => substr((string) $request->getHttpStatus(), 0, 1) === '2',
'httpCode' => $request->getHttpStatus(),
];
}
/**
* Get the remaining time of execution for the request. We keep a margin
* of 1.5s to parse and answser our own client
*
* @param int $startTime @optional start time in seconds since epoch
*
* @return int
*/
private function getRemainingTime($startTime = null)
{
/**
* Negative remaining time means an immediate timeout (0 means infinity)
*
* @see https://docs.guzzlephp.org/en/stable/request-options.html?highlight=timeout#timeout
*/
$maxExecutionTime = (int) ini_get('max_execution_time');
if ($maxExecutionTime <= 0) {
return CloudSyncClient::$DEFAULT_MAX_EXECUTION_TIME;
}
/*
* An extra 2s to be arbitrary substracted
* to keep time for the JSON parsing and state propagation in MySQL
*/
$extraOpsTime = 2;
/*
* Default to maximum timeout
*/
if (is_null($startTime)) {
return $maxExecutionTime - $extraOpsTime;
}
$remainingTime = $maxExecutionTime - $extraOpsTime - (time() - $startTime);
// A protection that might never be used, but who knows
if ($remainingTime <= 0) {
return CloudSyncClient::$DEFAULT_MAX_EXECUTION_TIME;
}
return $remainingTime;
}
}

View File

@@ -0,0 +1,882 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
/** This wrapper came from https://github.com/php-mod/curl
* The original code was modified to fit ps_eventbus needs
*/
namespace PrestaShop\Module\PsEventbus\Api;
if (!defined('_PS_VERSION_')) {
exit;
}
class HttpClient
{
/**
* @var HttpClient
*/
private static $instance;
/**
* @var string Type AUTH_BASIC
*/
const AUTH_BASIC = CURLAUTH_BASIC;
/**
* @var string Type AUTH_DIGEST
*/
const AUTH_DIGEST = CURLAUTH_DIGEST;
/**
* @var string Type AUTH_GSSNEGOTIATE
*/
const AUTH_GSSNEGOTIATE = CURLAUTH_GSSNEGOTIATE;
/**
* @var string Type AUTH_NTLM
*/
const AUTH_NTLM = CURLAUTH_NTLM;
/**
* @var string Type AUTH_ANY
*/
const AUTH_ANY = CURLAUTH_ANY;
/**
* @var string Type AUTH_ANYSAFE
*/
const AUTH_ANYSAFE = CURLAUTH_ANYSAFE;
/**
* @var string The user agent name which is set when making a request
*/
const USER_AGENT = 'PHP Curl/2.3';
private $_cookies = [];
private $_headers = [];
/**
* @var resource Contains the curl resource created by `curl_init()` function
*/
public $curl;
/**
* @var bool Whether an error occurred or not
*/
public $error = false;
/**
* @var int Contains the error code of the current request, 0 means no error happened
*/
public $error_code = 0;
/**
* @var string If the curl request failed, the error message is contained
*/
public $error_message;
/**
* @var bool Whether an error occurred or not
*/
public $curl_error = false;
/**
* @var int contains the error code of the current request, 0 means no error happened
*
* @see https://curl.haxx.se/libcurl/c/libcurl-errors.html
*/
public $curl_error_code = 0;
/**
* @var string If the curl request failed, the error message is contained
*/
public $curl_error_message;
/**
* @var bool Whether an error occurred or not
*/
public $http_error = false;
/**
* @var int contains the status code of the current processed request
*/
public $http_status_code = 0;
/**
* @var string If the curl request failed, the error message is contained
*/
public $http_error_message;
/**
* @var string|array TBD (ensure type) Contains the request header information
*/
public $request_headers;
/**
* @var string|array TBD (ensure type) Contains the response header information
*/
public $response_headers = [];
/**
* @var string|false|null Contains the response from the curl request
*/
public $response;
/**
* @var bool Whether the current section of response headers is after 'HTTP/1.1 100 Continue'
*/
protected $response_header_continue = false;
// Disable instantiation
private function __construct()
{
$this->init();
}
// Disable cloning
private function __clone()
{
}
// Unserialization of singleton is forbidden
public function __wakeup()
{
throw new \Exception('Cannot unserialize a singleton.');
}
/**
* Get the instance of the HttpClient.
*
* @return HttpClient
*/
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
} else {
self::$instance->reset();
}
return self::$instance;
}
/**
* Initializer for the curl resource.
*
* Is called by the __construct() of the class or when the curl request is reset.
*
* @return self
*/
private function init()
{
$this->curl = curl_init();
$this->setUserAgent(self::USER_AGENT);
$this->setOpt(CURLINFO_HEADER_OUT, true);
$this->setOpt(CURLOPT_HEADER, false);
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
$this->setOpt(CURLOPT_HEADERFUNCTION, [$this, 'addResponseHeaderLine']);
$this->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
return $this;
}
/**
* @param array<mixed> $data
*
* @return string
*/
private function formatNewlineJsonString($data)
{
$jsonArray = array_map(function ($dataItem) {
return json_encode($dataItem, JSON_UNESCAPED_SLASHES);
}, $data);
$json = implode("\r\n", $jsonArray);
return str_replace('\\u0000', '', $json);
}
/**
* Set the timeout for the current request.
*
* @param mixed $timeout
*
* @return $this
*/
public function setTimeout($timeout)
{
$this->setOpt(CURLOPT_TIMEOUT, $timeout);
return $this;
}
/**
* Handle writing the response headers
*
* @param resource $curl The current curl resource
* @param string $header_line A line from the list of response headers
*
* @return int Returns the length of the $header_line
*/
public function addResponseHeaderLine($curl, $header_line)
{
$trimmed_header = trim($header_line, "\r\n");
if ($trimmed_header === '') {
$this->response_header_continue = false;
} elseif (strtolower($trimmed_header) === 'http/1.1 100 continue') {
$this->response_header_continue = true;
} elseif (!$this->response_header_continue) {
$this->response_headers[] = $trimmed_header;
}
return strlen($header_line);
}
/**
* Execute the curl request based on the respective settings.
*
* @return int Returns the error code for the current curl request
*/
protected function exec()
{
$this->response_headers = [];
$this->response = curl_exec($this->curl);
$this->curl_error_code = curl_errno($this->curl);
$this->curl_error_message = curl_error($this->curl);
$this->curl_error = !($this->getErrorCode() === 0);
$this->http_status_code = intval(curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$this->http_error = $this->isError();
$this->error = $this->curl_error || $this->http_error;
$this->error_code = $this->error ? ($this->curl_error ? $this->getErrorCode() : $this->getHttpStatus()) : 0;
$this->request_headers = preg_split('/\r\n/', curl_getinfo($this->curl, CURLINFO_HEADER_OUT), -1, PREG_SPLIT_NO_EMPTY);
$this->http_error_message = $this->error ? (isset($this->response_headers['0']) ? $this->response_headers['0'] : '') : '';
$this->error_message = $this->curl_error ? $this->getErrorMessage() : $this->http_error_message;
return $this->error_code;
}
/**
* @param array|object|string $data
*/
protected function preparePayload($data)
{
$this->setOpt(CURLOPT_POST, true);
if (is_array($data) || is_object($data)) {
$skip = false;
foreach ($data as $key => $value) {
// If a value is an instance of CurlFile skip the http_build_query
// see issue https://github.com/php-mod/curl/issues/46
// suggestion from: https://stackoverflow.com/a/36603038/4611030
if ($value instanceof \CURLFile) {
$skip = true;
}
}
if (!$skip) {
$data = http_build_query($data);
}
}
$this->setOpt(CURLOPT_POSTFIELDS, $data);
}
/**
* Set the json payload informations to the postfield curl option.
*
* @param array $data the data to be sent
*
* @return void
*/
protected function prepareJsonPayload($data)
{
$this->setOpt(CURLOPT_POST, true);
$this->setOpt(CURLOPT_POSTFIELDS, json_encode($data));
}
/**
* Set auth options for the current request.
*
* Available auth types are:
*
* + self::AUTH_BASIC
* + self::AUTH_DIGEST
* + self::AUTH_GSSNEGOTIATE
* + self::AUTH_NTLM
* + self::AUTH_ANY
* + self::AUTH_ANYSAFE
*
* @param int $httpauth The type of authentication
*/
protected function setHttpAuth($httpauth)
{
$this->setOpt(CURLOPT_HTTPAUTH, $httpauth);
}
/**
* Make a get request with optional data.
*
* The get request has no body data, the data will be correctly added to the $url with the http_build_query() method.
*
* @param string $url The url to make the get request for
* @param array $headers Optional headers to pass to the url
* @param array $data Optional arguments who are part of the url
*
* @return self
*/
public function get($url, $headers, $data = null)
{
$this->setHeaders($headers);
if (!is_null($data) && is_array($data) && count($data) > 0) {
$this->setOpt(CURLOPT_URL, $url . '?' . http_build_query($data));
} else {
$this->setOpt(CURLOPT_URL, $url);
}
$this->setOpt(CURLOPT_HTTPGET, true);
$this->exec();
return $this;
}
/**
* Make a post request with optional post data.
*
* @param string $url The url to make the post request
* @param array $headers Optional headers to pass to the url
* @param array $data Post data to pass to the url
* @param bool $isFile If there is a multipart, set it to true or False if it is a json
*
* @return self
*/
public function post($url, array $headers = [], array $data = [], $isFile = null)
{
if (is_null($isFile)) {
$isFile = false;
}
$this->setHeaders($headers);
$this->setOpt(CURLOPT_URL, $url);
if ($isFile) {
// Créer un fichier temporaire
$temp = tmpfile();
fwrite($temp, $this->formatNewlineJsonString($data));
rewind($temp);
// Sauvegarder le fichier temporaire pour cURL
$tempPath = stream_get_meta_data($temp)['uri'];
$payload = ['file' => new \CURLFile($tempPath, 'text/plain', 'file')];
$this->preparePayload($payload);
} else {
$this->prepareJsonPayload($data);
}
$this->exec();
if ($isFile) {
fclose($temp);
}
return $this;
}
/**
* Make a put request with optional data.
*
* The put request data can be either sent via payload or as get parameters of the string.
*
* @param string $url The url to make the put request
* @param array $data Optional data to pass to the $url
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
*
* @return self
*/
public function put($url, $data = null, $payload = null)
{
if (is_null($data)) {
$data = [];
}
if (is_null($payload)) {
$payload = false;
}
if (!empty($data)) {
if ($payload === false) {
$url .= '?' . http_build_query($data);
} else {
$this->preparePayload($data);
}
}
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
$this->exec();
return $this;
}
/**
* Make a patch request with optional data.
*
* The patch request data can be either sent via payload or as get parameters of the string.
*
* @param string $url The url to make the patch request
* @param array $data Optional data to pass to the $url
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
*
* @return self
*/
public function patch($url, $data = null, $payload = null)
{
if (is_null($data)) {
$data = [];
}
if (is_null($payload)) {
$payload = false;
}
if (!empty($data)) {
if ($payload === false) {
$url .= '?' . http_build_query($data);
} else {
$this->preparePayload($data);
}
}
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->exec();
return $this;
}
/**
* Make a delete request with optional data.
*
* @param string $url The url to make the delete request
* @param array $data Optional data to pass to the $url
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
*
* @return self
*/
public function delete($url, $data = null, $payload = null)
{
if (is_null($data)) {
$data = [];
}
if (is_null($payload)) {
$payload = false;
}
if (!empty($data)) {
if ($payload === false) {
$url .= '?' . http_build_query($data);
} else {
$this->preparePayload($data);
}
}
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
$this->exec();
return $this;
}
/**
* Pass basic auth data.
*
* If the the requested url is secured by an htaccess basic auth mechanism you can use this method to provided the auth data.
*
* ```php
* $curl = new Curl();
* $curl->setBasicAuthentication('john', 'doe');
* $curl->get('http://example.com/secure.php');
* ```
*
* @param string $username The username for the authentication
* @param string $password The password for the given username for the authentication
*
* @return self
*/
public function setBasicAuthentication($username, $password)
{
$this->setHttpAuth(self::AUTH_BASIC);
$this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
return $this;
}
/**
* Provide optional headers information.
*
* In order to pass optional headers array with key value pairing:
*
* ```php
* $curl = new Curl();
* $curl->setHeaders(['X-Requested-With', 'XMLHttpRequest']);
* $curl->get('http://example.com/request.php');
* ```
*
* @param array $headers The headers to pass to the current request
*
* @return self
*/
public function setHeaders($headers)
{
if (!is_null($headers)) {
foreach ($headers as $key => $value) {
$this->_headers[$key] = $key . ': ' . $value;
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->_headers));
}
}
return $this;
}
/**
* Provide a User Agent.
*
* In order to provide you customized user agent name you can use this method.
*
* ```php
* $curl = new Curl();
* $curl->setUserAgent('My John Doe Agent 1.0');
* $curl->get('http://example.com/request.php');
* ```
*
* @param string $useragent The name of the user agent to set for the current request
*
* @return self
*/
public function setUserAgent($useragent)
{
$this->setOpt(CURLOPT_USERAGENT, $useragent);
return $this;
}
/**
* Set the HTTP referer header.
*
* The $referer Information can help identify the requested client where the requested was made.
*
* @param string $referer An url to pass and will be set as referer header
*
* @return self
*/
public function setReferer($referer)
{
$this->setOpt(CURLOPT_REFERER, $referer);
return $this;
}
/**
* Set contents of HTTP Cookie header.
*
* @param string $key The name of the cookie
* @param string $value The value for the provided cookie name
*
* @return self
*/
public function setCookie($key, $value)
{
$this->_cookies[$key] = $value;
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->_cookies, '', '; '));
return $this;
}
/**
* Set customized curl options.
*
* To see a full list of options: http://php.net/curl_setopt
*
* @see http://php.net/curl_setopt
*
* @param int $option The curl option constant e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
* @param mixed $value The value to pass for the given $option
*
* @return bool
*/
public function setOpt($option, $value)
{
return curl_setopt($this->curl, $option, $value);
}
/**
* Get customized curl options.
*
* To see a full list of options: http://php.net/curl_getinfo
*
* @see http://php.net/curl_getinfo
*
* @param int $option The curl option constant e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
* @param mixed The value to check for the given $option
*
* @return mixed
*/
public function getOpt($option)
{
return curl_getinfo($this->curl, $option);
}
/**
* Return the endpoint set for curl
*
* @see http://php.net/curl_getinfo
*
* @return string of endpoint
*/
public function getEndpoint()
{
return $this->getOpt(CURLINFO_EFFECTIVE_URL);
}
/**
* Enable verbosity.
*
* @param bool $on
*
* @return self
*/
public function setVerbose($on = null)
{
if (is_null($on)) {
$on = true;
}
$this->setOpt(CURLOPT_VERBOSE, $on);
return $this;
}
/**
* Reset all curl options.
*
* In order to make multiple requests with the same curl object all settings requires to be reset.
*
* @return self
*/
public function reset()
{
$this->close();
$this->_cookies = [];
$this->_headers = [];
$this->error = false;
$this->error_code = 0;
$this->error_message = null;
$this->curl_error = false;
$this->curl_error_code = 0;
$this->curl_error_message = null;
$this->http_error = false;
$this->http_status_code = 0;
$this->http_error_message = null;
$this->request_headers = null;
$this->response_headers = [];
$this->response = false;
$this->init();
return $this;
}
/**
* Closing the current open curl resource.
*
* @return self
*/
public function close()
{
if (is_resource($this->curl)) {
curl_close($this->curl);
}
return $this;
}
/**
* Close the connection when the Curl object will be destroyed.
*/
public function __destruct()
{
$this->close();
}
/**
* Was an 'info' header returned.
*
* @return bool
*/
public function isInfo()
{
return $this->getHttpStatus() >= 100 && $this->getHttpStatus() < 200;
}
/**
* Was an 'OK' response returned.
*
* @return bool
*/
public function isSuccess()
{
return $this->getHttpStatus() >= 200 && $this->getHttpStatus() < 300;
}
/**
* Was a 'redirect' returned.
*
* @return bool
*/
public function isRedirect()
{
return $this->getHttpStatus() >= 300 && $this->getHttpStatus() < 400;
}
/**
* Was an 'error' returned (client error or server error).
*
* @return bool
*/
public function isError()
{
return $this->getHttpStatus() >= 400 && $this->getHttpStatus() < 600;
}
/**
* Was a 'client error' returned.
*
* @return bool
*/
public function isClientError()
{
return $this->getHttpStatus() >= 400 && $this->getHttpStatus() < 500;
}
/**
* Was a 'server error' returned.
*
* @return bool
*/
public function isServerError()
{
return $this->getHttpStatus() >= 500 && $this->getHttpStatus() < 600;
}
/**
* Get a specific response header key or all values from the response headers array.
*
* Usage example:
*
* ```php
* $curl = (new Curl())->get('http://example.com');
*
* echo $curl->getResponseHeaders('Content-Type');
* ```
*
* Or in order to dump all keys with the given values use:
*
* ```php
* $curl = (new Curl())->get('http://example.com');
*
* var_dump($curl->getResponseHeaders());
* ```
*
* @param string $headerKey optional key to get from the array
*
* @return bool|string|array
*
* @since 1.9
*/
public function getResponseHeaders($headerKey = null)
{
$headers = [];
$headerKey = strtolower($headerKey);
foreach ($this->response_headers as $header) {
$parts = explode(':', $header, 2);
$key = isset($parts[0]) ? $parts[0] : '';
$value = isset($parts[1]) ? $parts[1] : '';
$headers[trim(strtolower($key))] = trim($value);
}
if ($headerKey) {
return isset($headers[$headerKey]) ? $headers[$headerKey] : false;
}
return $headers;
}
/**
* Get response from the curl request
*
* @return string|false
*/
public function getResponse()
{
return $this->response;
}
/**
* Get curl error code
*
* @return string
*/
public function getErrorCode()
{
return $this->curl_error_code;
}
/**
* Get curl error message
*
* @return string
*/
public function getErrorMessage()
{
return $this->curl_error_message;
}
/**
* Get http status code from the curl request
*
* @return int
*/
public function getHttpStatus()
{
return $this->http_status_code;
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,139 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Config;
if (!defined('_PS_VERSION_')) {
exit;
}
class Config
{
const MYSQL_DATE_FORMAT = 'Y-m-d H:i:s';
const INCREMENTAL_SYNC_TABLE_SIZE_CHECK_MOD = 20;
const INCREMENTAL_SYNC_MAX_TABLE_SIZE = 1000000;
const INCREMENTAL_TYPE_UPSERT = 'upsert';
const INCREMENTAL_TYPE_DELETE = 'delete';
const SYNC_SERVICE_NAME = 'PrestaShop\Module\PsEventbus\Service\SynchronizationService';
const COLLECTOR_MULTIPART_BOUNDARY = 'ps_eventbus_boundary';
const REFRESH_TOKEN_ERROR_CODE = 452;
const ENV_MISCONFIGURED_ERROR_CODE = 453;
const DATABASE_QUERY_ERROR_CODE = 454;
const DATABASE_INSERT_ERROR_CODE = 455;
const PS_FACEBOOK_NOT_INSTALLED = 456;
const INVALID_URL_QUERY = 458;
const INVALID_PS_ACCOUNTS_VERSION = 459;
const PS_ACCOUNTS_NOT_INSTALLED = 460;
const HTTP_STATUS_MESSAGES = [
self::REFRESH_TOKEN_ERROR_CODE => 'Cannot refresh token',
self::ENV_MISCONFIGURED_ERROR_CODE => 'Environment misconfigured',
self::DATABASE_QUERY_ERROR_CODE => 'Database syntax error',
self::DATABASE_INSERT_ERROR_CODE => 'Failed to write to database',
self::PS_FACEBOOK_NOT_INSTALLED => 'Cannot sync Taxonomies without Facebook module',
self::INVALID_URL_QUERY => 'Invalid URL query',
self::INVALID_PS_ACCOUNTS_VERSION => 'Invalid PsAccounts version',
self::PS_ACCOUNTS_NOT_INSTALLED => 'PsAccounts not installed',
];
const COLLECTION_BUNDLES = 'bundles';
const COLLECTION_CARRIERS = 'carriers';
const COLLECTION_CARRIER_DETAILS = 'carrier_details';
const COLLECTION_CARRIER_TAXES = 'carrier_taxes';
const COLLECTION_CARTS = 'carts';
const COLLECTION_CART_PRODUCTS = 'cart_products';
const COLLECTION_CART_RULES = 'cart_rules';
const COLLECTION_CATEGORIES = 'categories';
const COLLECTION_CURRENCIES = 'currencies';
const COLLECTION_CUSTOMERS = 'customers';
const COLLECTION_CUSTOM_PRODUCT_CARRIERS = 'custom_product_carriers';
const COLLECTION_EMPLOYEES = 'employees';
const COLLECTION_IMAGES = 'images';
const COLLECTION_IMAGE_TYPES = 'image_types'; // NO INCREMENTAL
const COLLECTION_LANGUAGES = 'languages';
const COLLECTION_MANUFACTURERS = 'manufacturers';
const COLLECTION_MODULES = 'modules'; // NO INCREMENTAL
const COLLECTION_ORDERS = 'orders';
const COLLECTION_ORDER_CARRIERS = 'order_carriers';
const COLLECTION_ORDER_CART_RULES = 'order_cart_rules';
const COLLECTION_ORDER_DETAILS = 'order_details';
const COLLECTION_ORDER_STATUS_HISTORY = 'order_status_history';
const COLLECTION_PRODUCTS = 'products';
const COLLECTION_PRODUCT_SUPPLIERS = 'product_suppliers';
const COLLECTION_INFO = 'info'; // NO INCREMENTAL
const COLLECTION_SPECIFIC_PRICES = 'specific_prices';
const COLLECTION_STOCKS = 'stocks';
const COLLECTION_STOCK_MOVEMENTS = 'stock_movements';
const COLLECTION_STORES = 'stores';
const COLLECTION_SUPPLIERS = 'suppliers';
const COLLECTION_TAXONOMIES = 'taxonomies'; // NO INCREMENTAL
const COLLECTION_THEMES = 'themes'; // NO INCREMENTAL
const COLLECTION_TRANSLATIONS = 'translations';
const COLLECTION_WISHLISTS = 'wishlists';
const COLLECTION_WISHLIST_PRODUCTS = 'wishlist_products';
const SHOP_CONTENTS = [
self::COLLECTION_BUNDLES,
self::COLLECTION_CARRIERS,
self::COLLECTION_CARRIER_DETAILS,
self::COLLECTION_CARRIER_TAXES,
self::COLLECTION_CARTS,
self::COLLECTION_CART_PRODUCTS,
self::COLLECTION_CART_RULES,
self::COLLECTION_CATEGORIES,
self::COLLECTION_CURRENCIES,
self::COLLECTION_CUSTOMERS,
self::COLLECTION_EMPLOYEES,
self::COLLECTION_IMAGES,
self::COLLECTION_IMAGE_TYPES,
self::COLLECTION_LANGUAGES,
self::COLLECTION_MANUFACTURERS,
self::COLLECTION_MODULES,
self::COLLECTION_ORDERS,
self::COLLECTION_ORDER_CARRIERS,
self::COLLECTION_ORDER_CART_RULES,
self::COLLECTION_ORDER_DETAILS,
self::COLLECTION_ORDER_STATUS_HISTORY,
self::COLLECTION_PRODUCTS,
self::COLLECTION_CUSTOM_PRODUCT_CARRIERS,
self::COLLECTION_PRODUCT_SUPPLIERS,
self::COLLECTION_INFO,
self::COLLECTION_SPECIFIC_PRICES,
self::COLLECTION_STOCKS,
self::COLLECTION_STOCK_MOVEMENTS,
self::COLLECTION_STORES,
self::COLLECTION_SUPPLIERS,
self::COLLECTION_TAXONOMIES,
self::COLLECTION_THEMES,
self::COLLECTION_TRANSLATIONS,
self::COLLECTION_WISHLISTS,
self::COLLECTION_WISHLIST_PRODUCTS,
];
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Exception;
if (!defined('_PS_VERSION_')) {
exit;
}
class ApiException extends \Exception
{
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Exception;
if (!defined('_PS_VERSION_')) {
exit;
}
class EnvVarException extends \Exception
{
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Exception;
if (!defined('_PS_VERSION_')) {
exit;
}
class FirebaseException extends \Exception
{
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Exception;
if (!defined('_PS_VERSION_')) {
exit;
}
class QueryParamsException extends \Exception
{
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,134 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Factory;
if (!defined('_PS_VERSION_')) {
exit;
}
class ContextFactory
{
/**
* @return \Context|null
*/
public static function getContext()
{
return \Context::getContext();
}
/**
* @return mixed
*/
public static function getLanguage()
{
$language = \Context::getContext()->language;
if ($language == null) {
throw new \PrestaShopException('Context is null');
}
return $language;
}
/**
* @return \Currency|null
*/
public static function getCurrency()
{
return \Context::getContext()->currency;
}
/**
* @return \Smarty
*/
public static function getSmarty()
{
$smarty = \Context::getContext()->smarty;
if ($smarty == null) {
throw new \PrestaShopException('Context is null');
}
return $smarty;
}
/**
* @return \Shop
*/
public static function getShop()
{
$shop = \Context::getContext()->shop;
if ($shop == null) {
throw new \PrestaShopException('Context is null');
}
return $shop;
}
/**
* @return \AdminController|\FrontController|\PrestaShopBundle\Bridge\AdminController\LegacyControllerBridgeInterface|null
*/
public static function getController()
{
$controller = \Context::getContext()->controller;
if ($controller == null) {
throw new \PrestaShopException('Context is null');
}
return $controller;
}
/**
* @return \Cookie
*/
public static function getCookie()
{
$cookie = \Context::getContext()->cookie;
if ($cookie == null) {
throw new \PrestaShopException('Context is null');
}
return $cookie;
}
/**
* @return \Link
*/
public static function getLink()
{
$link = \Context::getContext()->link;
if ($link == null) {
throw new \PrestaShopException('Context is null');
}
return $link;
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,87 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Formatter;
if (!defined('_PS_VERSION_')) {
exit;
}
class ArrayFormatter
{
/**
* @param array<mixed> $data
* @param string $separator
*
* @return string
*/
public function arrayToString($data, $separator = ';')
{
return implode($separator, $data);
}
/**
* @param array<mixed> $data
* @param string|int $key
* @param bool $unique
*
* @return array<mixed>
*/
public function formatValueArray($data, $key, $unique = null)
{
$result = array_map(function ($dataItem) use ($key) {
return $dataItem[$key];
}, $data);
if ($unique) {
return $this->unique($result);
}
return $result;
}
/**
* @param array<mixed> $data
*
* @return array<mixed>
*/
private function unique($data)
{
return array_unique($data);
}
/**
* @param array<mixed> $data
* @param string|int $key
* @param string $separator
*
* @return string
*/
public function formatValueString($data, $key, $separator = ';')
{
return implode($separator, $this->formatValueArray($data, $key));
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,415 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Handler\ErrorHandler;
use PrestaShop\Module\PsEventbus\Api\HttpClient;
use PrestaShop\Module\PsEventbus\Exception\EnvVarException;
use PrestaShop\Module\PsEventbus\Exception\FirebaseException;
use PrestaShop\Module\PsEventbus\Service\CommonService;
if (!defined('_PS_VERSION_')) {
exit;
}
class ErrorHandler
{
/** @var string|null */
private $sentryUrl;
/** @var string */
private $sentryKey;
/** @var string */
private $sentryEnv;
/** @var array<mixed> */
private $tags = [];
// Disable cloning
private function __clone()
{
}
/**
* @param string $sentryDsn
* @param string $sentryEnv
*/
public function __construct($sentryDsn, $sentryEnv)
{
try {
$parts = parse_url($sentryDsn);
if ($parts === false) {
throw new \InvalidArgumentException('Invalid Sentry DSN');
}
if (!isset($parts['host'], $parts['path'], $parts['user'])) {
throw new \PrestaShopException('Invalid Sentry DSN');
}
$projectId = ltrim($parts['path'], '/');
$this->sentryKey = $parts['user'];
$this->sentryUrl = sprintf('https://%s/api/%s/store/', $parts['host'], $projectId);
$this->sentryEnv = $sentryEnv;
$accountsModule = \Module::getInstanceByName('ps_accounts');
$eventbusModule = \Module::getInstanceByName('ps_eventbus');
$shopUuid = $psAccountVersion = null;
if ($accountsModule) {
$accountService = $accountsModule->getService(
'PrestaShop\Module\PsAccounts\Service\PsAccountsService'
);
$shopUuid = $accountService->getShopUuid();
$psAccountVersion = $accountsModule->version;
}
$this->tags = [
'shop_id' => $shopUuid,
'ps_eventbus_version' => $eventbusModule ? $eventbusModule->version : null,
'ps_accounts_version' => $psAccountVersion,
'php_version' => phpversion(),
'prestashop_version' => _PS_VERSION_,
'ps_eventbus_is_enabled' => \Module::isEnabled('ps_eventbus'),
'ps_eventbus_is_installed' => \Module::isInstalled('ps_eventbus'),
];
} catch (\Exception $e) {
$this->sentryUrl = null;
}
}
/**
* @param \Exception $exception
* @param bool|null $silent
*
* @return void
*/
public function handle($exception, $silent = null)
{
$logsEnabled = defined('PS_EVENTBUS_LOGS_ENABLED') ? PS_EVENTBUS_LOGS_ENABLED : false;
$verboseEnabled = defined('PS_EVENTBUS_VERBOSE_ENABLED') ? PS_EVENTBUS_VERBOSE_ENABLED : false;
if ($logsEnabled) {
\PrestaShopLogger::addLog(
$exception->getMessage() . ' : ' . $exception->getFile() . ':' . $exception->getLine() . ' | ' . $exception->getTraceAsString(),
3,
$exception->getCode() > 0 ? $exception->getCode() : 500,
'Module',
\Module::getModuleIdByName('ps_eventbus'),
true
);
}
if (_PS_MODE_DEV_ && $verboseEnabled) {
throw $exception;
}
if ($this->sentryUrl) {
$this->sendToSentry($exception);
}
if (!$silent) {
CommonService::exitWithExceptionMessage($exception);
}
}
/**
* @param \Throwable $exception
*
* @return void
*/
private function sendToSentry(\Throwable $exception)
{
$level = $this->mapExceptionToCategory($exception);
$configurationPsShopEmail = \Configuration::get('PS_SHOP_EMAIL');
$exceptionTags = [
'exception_class' => get_class($exception),
'code' => (string) $exception->getCode(),
];
$event = [
'message' => $exception->getMessage(),
'level' => $level,
'logger' => 'ps_eventbus',
'platform' => 'php',
'environment' => $this->sentryEnv,
'tags' => array_merge($this->tags, $exceptionTags),
'user' => [
'id' => $this->tags['shop_id'] ? $this->tags['shop_id'] : null,
'email' => $configurationPsShopEmail,
],
'exception' => [
'values' => [[
'type' => get_class($exception),
'value' => $exception->getMessage(),
'stacktrace' => [
'frames' => $this->buildFrames($exception->getTrace()),
],
]],
],
'extra' => [
'code' => $exception->getCode(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
],
'timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
];
HttpClient::getInstance()->post(
(string) $this->sentryUrl,
[
'Authorization' => 'Sentry sentry_version=7, sentry_client=ps_eventbus/1.0, sentry_key=' . $this->sentryKey,
'Content-Type' => 'application/json',
],
$event
);
}
/**
* Determines a Sentry level from PrestaShop/Symfony exception types
*
* @param \Throwable $e
*
* @return string
*/
private function mapExceptionToCategory(\Throwable $e)
{
switch ($e) {
case $e instanceof \PrestaShopDatabaseException:
return 'fatal';
case $e instanceof EnvVarException:
return 'error';
case $e instanceof FirebaseException:
return 'warning';
}
if ($e instanceof \ErrorException) {
switch ($e->getSeverity()) {
case E_NOTICE:
case E_USER_NOTICE:
case E_DEPRECATED:
case E_USER_DEPRECATED:
return 'info';
case E_WARNING:
case E_USER_WARNING:
return 'warning';
case E_RECOVERABLE_ERROR:
return 'error';
case E_ERROR:
case E_USER_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_PARSE:
return 'fatal';
default:
return 'error';
}
}
return 'error';
}
/**
* Build Sentry stack frames from a PHP error stack trace.
*
* @param array<mixed> $trace
*
* @return array<mixed>
*/
private function buildFrames(array $trace)
{
$frames = [];
foreach (array_reverse($trace) as $t) {
$file = $t['file'] ? $t['file'] : null;
$line = (int) ($t['line'] ? $t['line'] : 0);
// 1) Variables/args (scrub + truncate)
$vars = [];
if (!empty($t['args'])) {
foreach ($t['args'] as $i => $arg) {
$vars['arg' . $i] = $this->scrubAndNormalize($arg, 0);
}
}
// 2) Code Context
$codeContext = $this->getCodeContext($file, $line, 3);
$frames[] = [
'filename' => $file ?: '<internal>',
'lineno' => $line,
'function' => $t['function'] ? $t['function'] : '',
'in_app' => $this->isInApp($file),
'vars' => $vars ?: null,
'context_line' => $codeContext[0],
'pre_context' => $codeContext[1] ?: null,
'post_context' => $codeContext[2] ?: null,
];
}
return $frames;
}
/**
* Check if the file is part of the application code.
*
* @param string $file
*
* @return bool
*/
private function isInApp(string $file)
{
if (!$file) {
return false;
}
// Mark module files as "in_app" for better readability
return (bool) preg_match('#/modules/ps_eventbus/#', $file);
}
/**
* Get the code context around a specific line in a file.
*
* @param string $file
* @param int $line
* @param int $radius
*
* @return array<mixed>
*/
private function getCodeContext(string $file, int $line, int $radius)
{
if (!$radius) {
$radius = 3; // Default radius if not specified
}
if (!$file || $line <= 0 || !is_readable($file)) {
return [null, [], []];
}
$lines = @file($file, FILE_IGNORE_NEW_LINES);
if (!$lines) {
return [null, [], []];
}
$idx = $line - 1;
$start = max(0, $idx - $radius);
$end = min(count($lines) - 1, $idx + $radius);
$pre = array_slice($lines, $start, max(0, $idx - $start));
$curr = $lines[$idx] ? $lines[$idx] : null;
$post = array_slice($lines, $idx + 1, max(0, $end - $idx));
// Hard size limit to avoid exceeding event size
$truncate = function ($s) {
return mb_strimwidth((string) $s, 0, 500, '…');
};
$pre = array_map($truncate, $pre);
$curr = $curr ? $truncate($curr) : null;
$post = array_map($truncate, $post);
return [$curr, $pre, $post];
}
/**
* Scrub and normalize a value for safe logging.
*
* @param mixed $value
* @param int $depth
*
* @return mixed
*/
private function scrubAndNormalize($value, int $depth)
{
if ($depth > 3) { // avoid giant structures
return '/* depth limit */';
}
// Scalar types
if (is_null($value) || is_bool($value) || is_int($value) || is_float($value)) {
return $value;
}
if (is_string($value)) {
// Truncate very long strings
if (strlen($value) > 2000) {
return mb_substr($value, 0, 2000) . '…';
}
return $value;
}
// Objets
if (is_object($value)) {
// Do not serialize PDO, cURL, etc. resources
if ($value instanceof \Throwable) {
return sprintf('Throwable(%s): %s', get_class($value), $value->getMessage());
}
// Simple representation of objects
$out = ['__class' => get_class($value)];
// Attempt to extract public properties
foreach (get_object_vars($value) as $k => $v) {
$out[$k] = $this->scrubAndNormalize($v, $depth + 1);
}
return $out;
}
if (is_array($value)) {
// Scrub sensitive keys
$scrubKeys = ['password', 'passwd', 'pwd', 'secret', 'token', 'api_key', 'apikey', 'authorization', 'cookie', 'set-cookie', 'bearer'];
$out = [];
foreach ($value as $k => $v) {
$lk = is_string($k) ? strtolower($k) : $k;
if (is_string($lk) && in_array($lk, $scrubKeys, true)) {
$out[$k] = '***';
} else {
$out[$k] = $this->scrubAndNormalize($v, $depth + 1);
}
}
// Hard size limit for array
if (count($out) > 50) {
$out = array_slice($out, 0, 50, true) + ['__truncated' => '…'];
}
return $out;
}
if (is_resource($value)) {
return sprintf('resource(%s)', get_resource_type($value));
}
return '(unserializable)';
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,120 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Helper;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
if (!defined('_PS_VERSION_')) {
exit;
}
class ModuleHelper
{
/**
* @var \PrestaShop\PrestaShop\Core\Module\ModuleManager|\PrestaShop\PrestaShop\Core\Addon\Module\ModuleManager
*/
private $moduleManager;
public function __construct()
{
$moduleManagerBuilder = null;
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
}
if (is_null($moduleManagerBuilder)) {
return;
}
$this->moduleManager = $moduleManagerBuilder->build();
}
/**
* returns the module install status
*
* @param string $moduleName
*
* @return bool|null
*/
public function isInstalled($moduleName)
{
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '<')) {
$module = \Module::getInstanceByName($moduleName);
if ($module) {
return true;
}
return null;
}
return $this->moduleManager->isInstalled($moduleName);
}
/**
* returns the module enable status
*
* @param string $moduleName
*
* @return bool|null
*/
public function isEnabled($moduleName)
{
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '<')) {
$module = \Module::getInstanceByName($moduleName);
if ($module && $module->active) {
return true;
}
return null;
}
return $this->moduleManager->isEnabled($moduleName);
}
/**
* @param string $moduleName
*
* @return bool
*/
public function isInstalledAndActive($moduleName)
{
return $this->isInstalled($moduleName) && $this->isEnabled($moduleName);
}
/**
* @param string $moduleName
*
* @return false|\ModuleCore
*/
public function getInstanceByName($moduleName)
{
return \ModuleCore::getInstanceByName($moduleName);
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,85 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Module;
if (!defined('_PS_VERSION_')) {
exit;
}
class Install
{
const PARENT_TAB_NAME = -1;
const TAB_ACTIVE = 0;
/**
* @var \Ps_eventbus
*/
private $module;
/**
* @var \Db
*/
private $db;
public function __construct(\Ps_eventbus $module, \Db $db)
{
$this->module = $module;
$this->db = $db;
}
/**
* Installs database tables
*
* @return bool
*/
public function installDatabaseTables()
{
$dbInstallFile = "{$this->module->getLocalPath()}/sql/install.sql";
if (!file_exists($dbInstallFile)) {
return false;
}
$sql = \Tools::file_get_contents($dbInstallFile);
if (empty($sql) || !is_string($sql)) {
return false;
}
$sql = str_replace(['PREFIX_', 'ENGINE_TYPE'], [_DB_PREFIX_, _MYSQL_ENGINE_], $sql);
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
if (!empty($sql)) {
foreach ($sql as $query) {
if (!$this->db->execute($query)) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,103 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Module;
if (!defined('_PS_VERSION_')) {
exit;
}
class Uninstall
{
/**
* @var \Ps_eventbus
*/
private $module;
/**
* @var \Db
*/
private $db;
public function __construct(\Ps_eventbus $module, \Db $db)
{
$this->module = $module;
$this->db = $db;
}
/**
* uninstallMenu.
*
* @return bool
*/
public function uninstallMenu()
{
// foreach( ['configure', 'hmac', 'ajax'] as $aliasController){
foreach ($this->module->adminControllers as $controllerName) {
$tabId = (int) \Tab::getIdFromClassName($controllerName);
if (!$tabId) {
return true;
}
$tab = new \Tab($tabId);
return $tab->delete();
}
return true;
}
/**
* @return bool
*/
public function uninstallDatabaseTables()
{
$dbUninstallFile = "{$this->module->getLocalPath()}/sql/uninstall.sql";
if (!file_exists($dbUninstallFile)) {
return false;
}
$sql = \Tools::file_get_contents($dbUninstallFile);
if (empty($sql) || !is_string($sql)) {
return false;
}
$sql = str_replace(['PREFIX_', 'ENGINE_TYPE'], [_DB_PREFIX_, _MYSQL_ENGINE_], $sql);
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
if (!empty($sql)) {
foreach ($sql as $query) {
if (!$this->db->execute($query)) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,165 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
use PrestaShop\Module\PsEventbus\Service\CommonService;
if (!defined('_PS_VERSION_')) {
exit;
}
abstract class AbstractRepository
{
/**
* @var \Context
*/
private $context;
/**
* @var \Db
*/
protected $db;
/**
* @var \DbQuery
*/
protected $query;
public function __construct()
{
$context = \Context::getContext();
if ($context == null) {
throw new \PrestaShopException('Context not found');
}
$this->context = $context;
$this->db = \Db::getInstance();
}
/**
* @param string $tableName
* @param string|null $alias
*
* @return void
*/
protected function generateMinimalQuery($tableName, $alias = null)
{
$this->query = new \DbQuery();
$this->query->from($tableName, $alias);
}
/**
* @return \Context
*/
protected function getContext()
{
return $this->context;
}
/**
* @return \Shop
*
* @throws \PrestaShopException
*/
protected function getShopContext()
{
if ($this->context->shop === null) {
throw new \PrestaShopException('No shop context');
}
return $this->context->shop;
}
/**
* @param bool $disableCurrentExplain
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
protected function runQuery($disableCurrentExplain = null)
{
$explainSql = false;
if (defined('PS_EVENTBUS_EXPLAIN_SQL_ENABLED')) {
$explainSql = PS_EVENTBUS_EXPLAIN_SQL_ENABLED;
}
if ($explainSql && !$disableCurrentExplain) {
$this->debugQuery();
}
/*
* This is a workaround to avoid case where the table does not exist
* Exemple with Taxonomies. 'fb_category_match' table does not exist in some cases
* and the query will throw an exception.
*
* Previously, we have used the 'checkIfTableExist' method in parent class to check if the table exists
* but it is not enough because explain_sql is not reachable in this case.
*
* The solution is to catch the exception and return an empty array when error code is '42S02' (Table does not exist error code)
*/
try {
$result = $this->db->executeS($this->query);
// for 1.6 compatibility. executeS returns false if no result
if ($result == false) {
return [];
}
return (array) $result;
} catch (\Exception $e) {
if (!is_null($e->getPrevious()) && $e->getPrevious()->getCode() === '42S02') {
return [];
}
throw $e;
}
}
/**
* @return void
*
* @throws \PrestaShopException
*/
private function debugQuery()
{
$queryStringified = preg_replace('/\s+/', ' ', $this->query->build());
$queryStringified = str_replace(['"'], ["'"], (string) $queryStringified);
$response = array_merge(
(array) $this->query,
['queryStringified' => $queryStringified]
);
CommonService::exitWithResponse($response);
}
}

View File

@@ -0,0 +1,128 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class BundleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'pack';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'pac');
$this->query
->innerJoin('product', 'p', 'p.id_product = pac.id_product_pack')
->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product AND ps.id_shop = ' . parent::getShopContext()->id)
->leftJoin('product_attribute_shop', 'pas', 'pas.id_product = p.id_product AND pas.id_shop = ps.id_shop')
->where('p.cache_is_pack=1')
;
if ($withSelecParameters) {
$this->query
->select('pac.id_product_item as id_product')
->select("CONCAT(p.id_product, '-', IFNULL(pas.id_product_attribute, 0), '-', '" . pSQL($langIso) . "') as unique_product_id")
->select('pac.id_product_pack as id_bundle')
->select('pac.id_product_attribute_item as id_product_attribute')
->select('pac.quantity')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("pac.id_product_pack IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,191 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarrierDetailRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'carrier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ca');
// Create temporary table to get the latest delivery prices
$this->db->execute('
CREATE TEMPORARY TABLE IF NOT EXISTS TEMP_TABLE_latest_delivery_prices (
id_carrier INT UNSIGNED NOT NULL,
price DECIMAL(20,6) NOT NULL,
PRIMARY KEY (id_carrier)
);
');
// insert the latest delivery prices into the temporary table
$this->db->execute('
INSERT IGNORE INTO TEMP_TABLE_latest_delivery_prices (id_carrier, price)
SELECT
d.id_carrier,
d.price
FROM ' . _DB_PREFIX_ . 'delivery d
INNER JOIN (
SELECT id_carrier, MAX(id_delivery) AS max_delivery
FROM ' . _DB_PREFIX_ . 'delivery
WHERE price IS NOT NULL
GROUP BY id_carrier
) latest ON d.id_carrier = latest.id_carrier AND d.id_delivery = latest.max_delivery
WHERE d.price IS NOT NULL;
');
$psShippingMethod = \Configuration::get('PS_SHIPPING_METHOD');
// minimal query for countable query
$this->query
->join('INNER JOIN TEMP_TABLE_latest_delivery_prices ldp ON ca.id_carrier = ldp.id_carrier')
->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL')
->innerJoin('country', 'co', 'd.id_zone = co.id_zone AND co.iso_code IS NOT NULL AND co.active = 1')
->leftJoin('range_weight', 'rw', 'ca.id_carrier = rw.id_carrier AND d.id_range_weight = rw.id_range_weight')
->leftJoin('range_price', 'rp', 'ca.id_carrier = rp.id_carrier AND d.id_range_price = rp.id_range_price')
->leftJoin('state', 's', 'co.id_zone = s.id_zone AND co.id_country = s.id_country AND s.active = 1')
->select('ca.id_reference')
->groupBy('ca.id_reference, co.id_zone, id_range')
;
if ($withSelecParameters) {
$this->query
->select('d.id_zone')
->select('ldp.price')
->select('
CASE
WHEN d.id_range_weight IS NOT NULL AND d.id_range_weight != 0 THEN d.id_range_weight
WHEN d.id_range_price IS NOT NULL AND d.id_range_price != 0 THEN d.id_range_price
END AS id_range
')
->select("
CASE
WHEN ca.is_free = 1 THEN 'free_shipping'
WHEN ca.shipping_method = 0 AND {$psShippingMethod} = 0 THEN 'range_price'
WHEN ca.shipping_method = 0 AND {$psShippingMethod} = 1 THEN 'range_weight'
WHEN ca.shipping_method = 1 THEN 'range_weight'
WHEN ca.shipping_method = 2 THEN 'range_price'
END AS shipping_method
")
->select('COALESCE(rw.delimiter1, rp.delimiter1) AS delimiter1')
->select('COALESCE(rw.delimiter2, rp.delimiter2) AS delimiter2')
->select('
GROUP_CONCAT(
DISTINCT co.iso_code
ORDER BY co.iso_code ASC
SEPARATOR \',\'
) AS country_ids
')
->select('
GROUP_CONCAT(
DISTINCT
s.iso_code
ORDER BY s.iso_code ASC
SEPARATOR \',\'
) AS state_ids
')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("ca.id_carrier IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
// ->limit($limit) Sub shop content depend from another, temporary disabled
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$result = $this->db->executeS('
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');
return is_array($result) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,146 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarrierRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'carrier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$langId = (int) \Language::getIdByIso($langIso);
$this->generateMinimalQuery(self::TABLE_NAME, 'c');
$this->query
->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . $langId)
->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier')
;
$this->query
->where('cs.id_shop = ' . (int) parent::getShopContext()->id)
->where('deleted=0')
;
if ($withSelecParameters) {
$this->query
->select('c.id_carrier')
->select('c.id_reference')
->select('c.name')
->select('c.url')
->select('c.active')
->select('c.deleted')
->select('c.range_behavior AS disable_carrier_when_out_of_range')
->select('c.is_module')
->select('c.is_free')
->select('c.shipping_external')
->select('c.need_range')
->select('c.external_module_name')
->select('c.max_width')
->select('c.max_height')
->select('c.max_depth')
->select('c.max_weight')
->select('c.grade')
->select('cl.delay AS delay')
->select('c.shipping_handling')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("c.id_carrier IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit);
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,148 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarrierTaxeRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'carrier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ca');
// minimal query for countable query
$this->query
->innerJoin('carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier')
->innerJoin('tax_rule', 'tr', 'ctrgs.id_tax_rules_group = tr.id_tax_rules_group')
->innerJoin('country', 'co', 'tr.id_country = co.id_country AND co.iso_code IS NOT NULL AND co.active = 1')
->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL')
->innerJoin('tax', 't', 'tr.id_tax = t.id_tax AND t.active = 1')
->leftJoin('state', 's', 'tr.id_state = s.id_state AND s.active = 1')
->where('(co.id_zone = d.id_zone OR s.id_zone = d.id_zone)')
->select('ca.id_reference')
->groupBy('ca.id_reference, co.id_zone, id_range, country_id')
;
if ($withSelecParameters) {
$this->query
->select('co.id_zone')
->select('
CASE
WHEN d.id_range_weight IS NOT NULL AND d.id_range_weight != 0 THEN d.id_range_weight
WHEN d.id_range_price IS NOT NULL AND d.id_range_price != 0 THEN d.id_range_price
END AS id_range
')
->select('ctrgs.id_tax_rules_group AS id_carrier_tax')
->select('co.iso_code as country_id')
->select('
GROUP_CONCAT(
DISTINCT
s.iso_code
ORDER BY s.iso_code ASC
SEPARATOR \',\'
) AS state_ids
')
->select('t.rate AS tax_rate')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("ca.id_carrier IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
// ->limit($limit) Sub shop content depend from another, temporary disabled
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$result = $this->db->executeS('
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');
return is_array($result) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,123 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartProductRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'cart_product';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'cp');
$this->query->where('cp.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('cp.id_cart')
->select('cp.id_product')
->select('cp.id_product_attribute')
->select('cp.quantity')
->select('cp.date_add as created_at')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("cp.id_cart IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
// ->limit($limit) Sub shop content depend from another, temporary disabled
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,121 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'cart';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'c');
$this->query->where('c.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('c.id_cart')
->select('date_add as created_at')
->select('date_upd as updated_at')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("c.id_cart IN('" . implode("','", array_map('intval', $contentIds ?: [-1] ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,152 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartRuleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'cart_rule';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'cr');
if ($withSelecParameters) {
$this->query
->select('cr.id_cart_rule')
->select('cr.id_customer')
->select('cr.code')
->select('cr.date_from AS "from"')
->select('cr.date_to AS "to"')
->select('cr.description')
->select('cr.quantity')
->select('cr.quantity_per_user')
->select('cr.priority')
->select('cr.partial_use')
->select('cr.minimum_amount')
->select('cr.minimum_amount_tax')
->select('cr.minimum_amount_currency')
->select('cr.minimum_amount_shipping')
->select('cr.country_restriction')
->select('cr.carrier_restriction')
->select('cr.group_restriction')
->select('cr.cart_rule_restriction')
->select('cr.product_restriction')
->select('cr.shop_restriction')
->select('cr.free_shipping')
->select('cr.reduction_percent')
->select('cr.reduction_amount')
->select('cr.reduction_tax')
->select('cr.reduction_currency')
->select('cr.reduction_product')
->select('cr.gift_product')
->select('cr.gift_product_attribute')
->select('cr.highlight')
->select('cr.active')
->select('cr.date_add AS created_at')
->select('cr.date_upd AS updated_at')
;
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->query->select('cr.reduction_exclude_special');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("cr.id_cart_rule IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,168 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CategoryRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'category_shop';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'cs');
$this->query
->innerJoin('category', 'c', 'cs.id_category = c.id_category')
->leftJoin('category_lang', 'cl', 'cl.id_category = cs.id_category')
->leftJoin('lang', 'l', 'l.id_lang = cl.id_lang')
->where('cs.id_shop = ' . parent::getShopContext()->id)
->where('cl.id_shop = cs.id_shop')
->where('l.iso_code = "' . pSQL($langIso) . '"')
;
if ($withSelecParameters) {
$this->query
->select('CONCAT(cs.id_category, "-", l.iso_code) as unique_category_id')
->select('cs.id_category')
->select('c.id_parent')
->select('cl.name')
->select('cl.description')
->select('cl.link_rewrite')
->select('cl.meta_title')
->select('cl.meta_description')
->select('l.iso_code')
->select('c.date_add as created_at')
->select('c.date_upd as updated_at')
;
// REMOVED HERE: https://github.com/PrestaShop/PrestaShop/commit/f37a8f61017654bae160b528a1a2eaf49edbdac0
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '9.0', '<')) {
$this->query->select('cl.meta_keywords');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("cs.id_category IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @param int $langId
* @param int $shopId
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getCategoriesWithParentInfo($langId, $shopId)
{
$this->generateMinimalQuery('category', 'c');
$this->query
->leftJoin('category_lang', 'cl', 'cl.id_category = c.id_category AND cl.id_shop = ' . (int) $shopId)
->where('cl.id_lang = ' . (int) $langId)
->orderBy('cl.id_category')
;
$this->query
->select('c.id_category')
->select('cl.name')
->select('c.id_parent')
;
return $this->runQuery(true);
}
}

View File

@@ -0,0 +1,144 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CurrencyRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'currency';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'c');
if ($this->isCurrencyLangAvailable()) {
$this->query->innerJoin('currency_lang', 'cl', 'cl.id_currency = c.id_currency');
}
if ($withSelecParameters) {
$this->query
->select('c.id_currency')
->select('c.iso_code')
->select('c.conversion_rate')
->select('c.deleted')
->select('c.active')
;
if ($this->isCurrencyLangAvailable()) {
$this->query->select('cl.name');
} else {
$this->query->select('\'\' as name');
}
// https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6.0', '>=')) {
$this->query->select('c.precision');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("c.id_currency IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @return mixed
*/
private function isCurrencyLangAvailable()
{
return defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6', '>=');
}
}

View File

@@ -0,0 +1,153 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CustomProductCarrierRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'product_carrier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'pc');
$this->query->where('pc.id_shop = ' . parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query->select('pc.*');
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("CONCAT(pc.id_product, '-', IFNULL(pc.id_carrier_reference, 0)) IN('" . implode("','", array_map('strval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @param int $idProduct
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function getCustomProductCarrierIdsByProductId($idProduct)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'pc');
$this->query->select("CONCAT(pc.id_product, '-', COALESCE(pc.id_carrier_reference, 0)) AS id_custom_product_carrier");
$this->query
->where('pc.id_product = ' . (int) $idProduct)
->where('pc.id_shop = ' . parent::getShopContext()->id)
;
return $this->runQuery(true);
}
/**
* @param int $productId
*
* @return array<mixed>
*/
public function getAllAvailableProductCarrierIdsForProduct($productId)
{
$this->generateMinimalQuery('carrier', 'c');
$this->query->select("CONCAT('" . $productId . "', '-', c.id_carrier) AS custom_product_carrier_id");
return $this->runQuery();
}
}

View File

@@ -0,0 +1,129 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CustomerRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'customer';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'c');
$this->query->where('c.id_shop = ' . parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('c.id_customer')
->select('c.id_lang')
->select('c.email')
->select('c.newsletter')
->select('c.newsletter_date_add')
->select('c.optin')
->select('c.active')
->select('c.is_guest')
->select('c.deleted')
->select('c.date_add as created_at')
->select('c.date_upd as updated_at')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("c.id_customer IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,143 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class EmployeeRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'employee';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'e');
$this->query
->leftJoin('employee_shop', 'es', 'es.id_employee = e.id_employee')
->where('es.id_shop = ' . parent::getShopContext()->id)
;
if ($withSelecParameters) {
$this->query
->select('e.id_employee')
->select('e.id_profile')
->select('e.id_lang')
->select('e.email')
->select('e.bo_color')
->select('e.bo_theme')
->select('e.bo_css')
->select('e.default_tab')
->select('e.bo_width')
->select('e.bo_menu')
->select('e.active')
->select('e.optin')
->select('e.id_last_order')
->select('e.id_last_customer_message')
->select('e.id_last_customer')
->select('e.last_connection_date')
->select('es.id_shop as id_shop')
;
// https://github.com/PrestaShop/PrestaShop/commit/20f1d9fe8a03559dfa9d1f7109de1f70c99f1874#diff-cde6a9d4a58afb13ff068801ee09c0e712c5e90b0cbf5632a0cc965f15cb6802R107
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.8.0', '>=')) {
$this->query->select('e.has_enabled_gravatar');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("e.id_employee IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,128 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ImageRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'image';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'i');
$this->query
->leftJoin('image_lang', 'il', 'il.id_image = i.id_image')
->leftJoin('image_shop', 'is', 'is.id_image = i.id_image');
if ($withSelecParameters) {
$this->query
->select('i.id_image')
->select('i.id_product')
->select('i.position')
->select('i.cover')
->select('il.id_lang')
->select('il.legend')
->select('is.id_shop')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("i.id_image IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,125 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ImageTypeRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'image_type';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'it');
if ($withSelecParameters) {
$this->query
->select('it.id_image_type')
->select('it.name')
->select('it.width')
->select('it.height')
->select('it.products')
->select('it.categories')
->select('it.manufacturers')
->select('it.suppliers')
->select('it.stores')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("it.id_image_type IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,219 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler;
if (!defined('_PS_VERSION_')) {
exit;
}
class IncrementalSyncRepository extends AbstractRepository
{
const TABLE_NAME = 'eventbus_incremental_sync';
/**
* @var ErrorHandler
*/
private $errorHandler;
public function __construct(ErrorHandler $errorHandler)
{
$this->errorHandler = $errorHandler;
parent::__construct();
}
/**
* @param array<mixed> $data
*
* @return bool
*/
public function insertIncrementalObject($data)
{
try {
$arrayOfData = $data;
if (!is_array($data[0])) {
$arrayOfData = [$data];
}
$elementsCount = count($arrayOfData);
$index = 0;
$query = 'INSERT INTO `' . _DB_PREFIX_ . self::TABLE_NAME . '` (type, id_object, id_shop, lang_iso, action, created_at) VALUES ';
foreach ($arrayOfData as $currenData) {
$dateTime = new \DateTime($currenData['created_at']);
$date = $dateTime->format('Y-m-d H:i:s');
$query .= "(
'{$this->db->escape($currenData['type'])}',
'{$this->db->escape($currenData['id_object'])}',
{$this->db->escape($currenData['id_shop'])},
'{$this->db->escape($currenData['lang_iso'])}',
'{$this->db->escape($currenData['action'])}',
'{$this->db->escape($date)}'
)";
if (++$index < $elementsCount) {
$query .= ',';
}
}
$query .= '
ON DUPLICATE KEY UPDATE
type = VALUES(type),
id_object = VALUES(id_object),
id_shop = VALUES(id_shop),
lang_iso = VALUES(lang_iso),
action = VALUES(action),
created_at = VALUES(created_at)
';
return (bool) $this->db->query($query);
} catch (\PrestaShopDatabaseException $exception) {
$this->errorHandler->handle(
new \PrestaShopDatabaseException('Failed to insert incremental object', $exception->getCode(), $exception)
);
return false;
}
}
/**
* @param string $type
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return bool
*/
public function removeIncrementalSyncObjects($type, $contentIds, $langIso)
{
return $this->db->delete(
self::TABLE_NAME,
"type = '" . pSQL($type) . "'
AND id_shop = " . parent::getShopContext()->id . "
AND id_object IN('" . implode("','", $contentIds) . "')
AND lang_iso = '" . pSQL($langIso) . "'"
);
}
/**
* @param string $shopContent
* @param string $langIso
* @param int $limit
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getIncrementalSyncObjects($shopContent, $langIso, $limit)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'eis');
$this->query
->where('eis.lang_iso = "' . pSQL($langIso) . '"')
->where('eis.id_shop = "' . parent::getShopContext()->id . '"')
->where('eis.type = "' . pSQL($shopContent) . '"')
->limit($limit)
;
$this->query
->select('eis.type')
->select('eis.id_object as id')
->select('eis.action')
;
return $this->runQuery(true);
}
/**
* @param string $type
* @param string $langIso
*
* @return int
*/
public function getRemainingIncrementalObjects($type, $langIso)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'eis');
$this->query
->where('eis.lang_iso = "' . pSQL($langIso) . '"')
->where('eis.id_shop = "' . parent::getShopContext()->id . '"')
->where('eis.type = "' . pSQL($type) . '"')
;
$this->query->select('COUNT(eis.id_object) as count');
return (int) $this->db->getValue($this->query);
}
/**
* @param string $type
* @param int $objectId
*
* @return bool
*/
public function removeIncrementalSyncObject($type, $objectId)
{
return $this->db->delete(
self::TABLE_NAME,
'type = "' . pSQL($type) . '"
AND id_shop = ' . parent::getShopContext()->id . '
AND id_object = ' . (int) $objectId
);
}
/**
* @param string $type
*
* @return int
*/
public function getIncrementalSyncObjectCountByType($type)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'eis');
$this->query->where('eis.type = "' . psql($type) . '"');
$this->query->select('COUNT(eis.type) as count');
return (int) $this->db->getValue($this->query);
}
/**
* @param string $type
*
* @return bool
*/
public function removeIncrementaSyncObjectByType($type)
{
return $this->db->delete(
self::TABLE_NAME,
'type = "' . pSQL($type) . '"'
);
}
}

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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class InfoRepository extends AbstractRepository
{
/**
* @return int
*/
public function getMultiShopCount()
{
$this->generateMinimalQuery('shop', 's');
$this->query->where('s.active = 1 and s.deleted = 0');
$this->query->select('COUNT(s.id_shop)');
return (int) $this->db->getValue($this->query);
}
/**
* @return string
*/
public function getCreatedAt()
{
$this->generateMinimalQuery('configuration', 'c');
$this->query->where('c.name = "PS_INSTALL_VERSION"');
$this->query->select('c.date_add as created_at');
return (string) $this->db->getValue($this->query);
}
/**
* Gives back the first iso_code registered, which correspond to the default country of this shop
*
* @return string
*/
public function getShopCountryCode()
{
$this->generateMinimalQuery('country', 'c');
$this->query->where('c.id_country = ' . \Configuration::get('PS_COUNTRY_DEFAULT'));
$this->query->select('c.iso_code');
return (string) $this->db->getValue($this->query);
}
}

View File

@@ -0,0 +1,132 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class LanguageRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'lang';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'la');
$this->query->innerJoin('lang_shop', 'las', 'la.id_lang = las.id_lang AND las.id_shop = ' . parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('la.id_lang')
->select('la.name')
->select('la.active')
->select('la.iso_code')
->select('la.language_code')
->select('la.date_format_lite')
->select('la.date_format_full')
->select('la.is_rtl')
->select('las.id_shop')
;
// https://github.com/PrestaShop/PrestaShop/commit/481111b8274ed005e1c4a8ce2cf2b3ebbeb9a270#diff-c123d3d30d9c9e012a826a21887fccce6600a2f2a848a58d5910e55f0f8f5093R41
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
$this->query->select('la.locale');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("la.id_lang IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,89 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class LiveSyncRepository
{
const TABLE_NAME = 'eventbus_live_sync';
/**
* @var \Db
*/
private $db;
public function __construct()
{
$this->db = \Db::getInstance();
}
/**
* @param string $shopContent
*
* @return array<mixed>|null
*
* @throws \PrestaShopDatabaseException
*/
public function getShopContentInfo($shopContent)
{
$query = '
SELECT `eb_ls`.`shop_content`, `eb_ls`.`last_change_at`
FROM `' . _DB_PREFIX_ . 'eventbus_live_sync` `eb_ls`
WHERE `eb_ls`.`shop_content` = "' . pSQL($shopContent) . '";
';
$result = $this->db->executeS($query);
if (is_array($result) && count($result) > 0) {
return $result[0];
}
return null;
}
/**
* @param string $shopContent
* @param string $lastChangeAt
*
* @return bool
*
* @throws \PrestaShopDatabaseException
*/
public function upsertDebounce($shopContent, $lastChangeAt)
{
$query = '
INSERT INTO `' . _DB_PREFIX_ . 'eventbus_live_sync` (`shop_content`, `last_change_at`)
VALUES ("' . pSQL($shopContent) . '", "' . pSQL($lastChangeAt) . '")
ON DUPLICATE KEY UPDATE `last_change_at` = "' . pSQL($lastChangeAt) . '";
';
return $this->db->execute($query);
}
}

View File

@@ -0,0 +1,136 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ManufacturerRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'manufacturer';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ma');
$this->query
->innerJoin('manufacturer_lang', 'mal', 'ma.id_manufacturer = mal.id_manufacturer AND mal.id_lang = ' . (int) parent::getShopContext()->id)
->innerJoin('manufacturer_shop', 'mas', 'ma.id_manufacturer = mas.id_manufacturer AND mas.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('ma.id_manufacturer')
->select('ma.name')
->select('ma.date_add as created_at')
->select('ma.date_upd as updated_at')
->select('ma.active')
->select('mal.id_lang')
->select('mal.description')
->select('mal.short_description')
->select('mal.meta_title')
->select('mal.meta_description')
->select('mas.id_shop')
;
// REMOVED HERE: https://github.com/PrestaShop/PrestaShop/commit/f37a8f61017654bae160b528a1a2eaf49edbdac0
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '9.0', '<')) {
$this->query->select('mal.meta_keywords');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("ma.id_manufacturer IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,138 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ModuleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'module';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'm');
$this->query->leftJoin('module_shop', 'm_shop', 'm.id_module = m_shop.id_module');
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->query->leftJoin('module_history', 'h', 'm.id_module = h.id_module');
}
if ($withSelecParameters) {
/*
* The `active` field of the "ps_module" table has been deprecated,
* this is why we use the "ps_module_shop" table to check if a module is active or not
*/
$this->query
->select('m.id_module as module_id')
->select('name')
->select('version as module_version')
->select('IF(m_shop.enable_device, 1, 0) as active')
;
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->query
->select('date_add as created_at')
->select('date_upd as updated_at')
;
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("m.id_module IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,125 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderCarrierRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'order_carrier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'oc');
if ($withSelecParameters) {
$this->query
->select('oc.id_order_carrier')
->select('oc.id_order')
->select('oc.id_carrier')
->select('oc.id_order_invoice')
->select('oc.weight')
->select('oc.shipping_cost_tax_excl')
->select('oc.shipping_cost_tax_incl')
->select('oc.tracking_number')
->select('oc.date_add')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("oc.id_order_carrier IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,127 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderCartRuleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'order_cart_rule';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ocr');
if ($withSelecParameters) {
$this->query
->select('ocr.id_order_cart_rule')
->select('ocr.id_order')
->select('ocr.id_cart_rule')
->select('ocr.id_order_invoice')
->select('ocr.name')
->select('ocr.value')
->select('ocr.value_tax_excl')
->select('ocr.free_shipping');
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.7.0', '>=')) {
$this->query->select('ocr.deleted');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("ocr.id_order_cart_rule IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,186 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderDetailRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'order_detail';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$context = \Context::getContext();
if ($context == null) {
throw new \PrestaShopException('Context is null');
}
if ($context->shop === null) {
throw new \PrestaShopException('No shop context');
}
$this->generateMinimalQuery(self::TABLE_NAME, 'od');
$this->query
->innerJoin('orders', 'o', 'od.id_order = o.id_order')
->leftJoin('product_shop', 'ps', 'od.product_id = ps.id_product AND ps.id_shop = ' . (int) $context->shop->id)
->leftJoin('currency', 'c', 'c.id_currency = o.id_currency')
->leftJoin('lang', 'l', 'o.id_lang = l.id_lang')
->select('od.id_order_detail')
;
$refundRequest = '(SELECT osd.total_price_tax_incl
FROM ' . _DB_PREFIX_ . 'order_slip_detail osd
WHERE osd.id_order_detail = od.id_order_detail) AS refund';
$refundTaxExclRequest = '(SELECT osd.total_price_tax_excl
FROM ' . _DB_PREFIX_ . 'order_slip_detail osd
WHERE osd.id_order_detail = od.id_order_detail) AS refund_tax_excl';
if ($withSelecParameters) {
$this->query
->select('od.id_order')
->select('od.product_id')
->select('od.product_attribute_id')
->select('od.product_quantity')
->select('od.unit_price_tax_incl')
->select('od.unit_price_tax_excl')
->select($refundRequest)
->select($refundTaxExclRequest)
->select('c.iso_code as currency')
->select('ps.id_category_default as category')
->select('l.iso_code')
->select('o.conversion_rate as conversion_rate')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$context = \Context::getContext();
if ($context == null) {
throw new \PrestaShopException('Context is null');
}
if ($context->shop === null) {
throw new \PrestaShopException('No shop context');
}
$seekStartIdResult = $this->db->executeS(
'SELECT id_order_detail
FROM ' . _DB_PREFIX_ . self::TABLE_NAME . '
WHERE id_shop = ' . (int) $context->shop->id . '
ORDER BY id_order_detail
LIMIT ' . (int) $offset . ', 1'
);
$seekStartId = 0;
if (
is_array($seekStartIdResult)
&& !empty($seekStartIdResult)
&& isset($seekStartIdResult[0]['id_order_detail'])
) {
$seekStartId = (int) $seekStartIdResult[0]['id_order_detail'];
}
$this->query
->where('od.id_order_detail >=' . $seekStartId)
->limit((int) $limit);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("od.id_order_detail IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$result = $this->db->executeS('
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');
return is_array($result) ? $result[0]['count'] : 0;
}
}

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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'orders';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'o');
// minimal query for countable query
$this->query
->leftJoin('currency', 'c', 'o.id_currency = c.id_currency')
->leftJoin('order_slip', 'os', 'o.id_order = os.id_order')
->leftJoin('address', 'ad', 'ad.id_address = o.id_address_delivery')
->leftJoin('address', 'ai', 'ai.id_address = o.id_address_invoice')
->leftJoin('country', 'cntd', 'cntd.id_country = ad.id_country')
->leftJoin('country', 'cnti', 'cnti.id_country = ai.id_country')
->leftJoin('order_state_lang', 'osl', 'o.current_state = osl.id_order_state')
->leftJoin('order_state', 'ost', 'o.current_state = ost.id_order_state')
->where('o.id_shop = ' . (int) parent::getShopContext()->id)
->select('o.id_order')
->groupBy('o.id_order')
;
if ($withSelecParameters) {
$this->query
->select('o.reference')
->select('o.id_customer')
->select('o.id_cart')
->select('o.current_state')
->select('o.conversion_rate')
->select('o.total_paid_tax_excl')
->select('o.total_paid_tax_incl')
->select('c.iso_code as currency')
->select('o.module as payment_module')
->select('o.payment as payment_mode')
->select('o.total_paid_real')
->select('o.total_shipping as shipping_cost')
->select('o.date_add as created_at')
->select('o.date_upd as updated_at')
->select('o.id_carrier')
->select('o.payment as payment_name')
->select('o.valid as is_validated')
->select('ost.paid as is_paid')
->select('ost.shipped as is_shipped')
->select('osl.name as status_label')
->select('o.module as payment_name')
->select('o.id_shop_group')
->select('o.id_shop')
->select('o.id_lang')
->select('o.id_currency')
->select('o.recyclable')
->select('o.gift')
->select('o.total_discounts')
->select('o.total_discounts_tax_incl')
->select('o.total_discounts_tax_excl')
->select('o.total_products')
->select('o.total_products_wt')
->select('o.total_shipping_tax_incl')
->select('o.total_shipping_tax_excl')
->select('o.carrier_tax_rate')
->select('o.total_wrapping')
->select('o.total_wrapping_tax_incl')
->select('o.total_wrapping_tax_excl')
->select('o.round_mode')
->select('o.round_type')
->select('o.invoice_number')
->select('o.delivery_number')
->select('o.invoice_date')
->select('o.delivery_date')
->select('o.valid')
->select('SUM(os.total_products_tax_incl + os.total_shipping_tax_incl) as refund')
->select('SUM(os.total_products_tax_excl + os.total_shipping_tax_excl) as refund_tax_excl')
->select('CONCAT(CONCAT("delivery", ":", cntd.iso_code), ",", CONCAT("invoice", ":", cnti.iso_code)) as address_iso')
->select('IF((SELECT so.id_order FROM `' . _DB_PREFIX_ . 'orders` so WHERE so.id_customer = o.id_customer AND so.id_order < o.id_order LIMIT 1) > 0, 0, 1) as new_customer')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("o.id_order IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$result = $this->db->executeS('
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');
return is_array($result) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,155 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderStatusHistoryRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'order_history';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$langId = (int) \Language::getIdByIso($langIso);
$this->generateMinimalQuery(self::TABLE_NAME, 'oh');
$this->query
->innerJoin('order_state', 'os', 'os.id_order_state = oh.id_order_State')
->innerJoin('order_state_lang', 'osl', 'osl.id_order_state = os.id_order_State AND osl.id_lang = ' . (int) $langId)
;
if ($withSelecParameters) {
$this->query
->select('oh.id_order_state')
->select('osl.name')
->select('osl.template')
->select('oh.date_add')
->select('oh.id_order')
->select('oh.id_order_history')
->select('os.logable AS is_validated')
->select('os.delivery AS is_delivered')
->select('os.shipped AS is_shipped')
->select('os.paid AS is_paid')
->select('os.deleted AS is_deleted')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("oh.id_order_history IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @param array<mixed> $orderIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getOrderStatusHistoriesByOrderIds($orderIds, $langIso)
{
if (!$orderIds) {
return [];
}
$this->generateFullQuery($langIso, true);
$this->query->where("oh.id_order IN ('" . implode("','", array_map('intval', $orderIds)) . "')");
return $this->runQuery();
}
}

View File

@@ -0,0 +1,386 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ProductRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'product';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$shopIdGroup = (int) parent::getShopContext()->id_shop_group;
$langId = (int) \Language::getIdByIso($langIso);
// WTF IS THAT ?
if (!parent::getContext()->employee instanceof \Employee) {
$employees = \Employee::getEmployees();
if ($employees) {
parent::getContext()->employee = new \Employee($employees[0]['id_employee']);
}
}
$this->generateMinimalQuery(self::TABLE_NAME, 'p');
$this->query
->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product AND ps.id_shop = ' . parent::getShopContext()->id)
->innerJoin('product_lang', 'pl', 'pl.id_product = ps.id_product AND pl.id_shop = ps.id_shop AND pl.id_lang = ' . $langId)
->leftJoin('product_attribute_shop', 'pas', 'pas.id_product = p.id_product AND pas.id_shop = ps.id_shop')
->leftJoin('product_attribute', 'pa', 'pas.id_product_attribute = pa.id_product_attribute')
->leftJoin('category_lang', 'cl', 'ps.id_category_default = cl.id_category AND ps.id_shop = cl.id_shop AND cl.id_lang = ' . $langId)
->leftJoin('manufacturer', 'm', 'p.id_manufacturer = m.id_manufacturer')
;
if (parent::getShopContext()->getGroup()->share_stock) {
$this->query->leftJoin(
'stock_available',
'sa',
'sa.id_product = p.id_product AND sa.id_product_attribute = IFNULL(pas.id_product_attribute, 0) AND sa.id_shop_group = ' . $shopIdGroup)
;
} else {
$this->query->leftJoin(
'stock_available',
'sa',
'sa.id_product = p.id_product AND sa.id_product_attribute = IFNULL(pas.id_product_attribute, 0) AND sa.id_shop = ps.id_shop')
;
}
if ($withSelecParameters) {
$this->query
->select('p.id_product')
->select('p.id_manufacturer')
->select('p.id_supplier')
->select('pas.id_product_attribute as id_attribute')
->select('pas.default_on as is_default_attribute')
->select('pl.name')
->select('pl.description')
->select('pl.description_short')
->select('pl.link_rewrite')
->select('cl.name as default_category')
->select('ps.id_category_default')
->select('IFNULL(NULLIF(pa.reference, ""), p.reference) as reference')
->select('IFNULL(NULLIF(pa.upc, ""), p.upc) as upc')
->select('IFNULL(NULLIF(pa.ean13, ""), p.ean13) as ean')
->select('ps.condition')
->select('ps.visibility')
->select('ps.active')
->select('sa.quantity')
->select('m.name as manufacturer')
->select('(p.weight + IFNULL(pas.weight, 0)) as weight')
->select('(ps.price + IFNULL(pas.price, 0)) as price_tax_excl')
->select('p.date_add as created_at')
->select('p.date_upd as updated_at')
->select('p.available_for_order')
->select('p.available_date')
->select('p.cache_is_pack as is_bundle')
->select('p.is_virtual')
->select('p.unity')
->select('p.unit_price_ratio')
->select('p.width')
->select('p.height')
->select('p.depth')
->select('p.additional_shipping_cost')
->select("CONCAT(p.id_product, '-', IFNULL(pas.id_product_attribute, 0), '-', '" . pSQL($langIso) . "') AS unique_product_id")
->select("CONCAT(p.id_product, '-', IFNULL(pas.id_product_attribute, 0)) AS id_product_attribute")
->select("'" . pSQL($langIso) . "' as iso_code")
;
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->query->select('IFNULL(NULLIF(pa.isbn, ""), p.isbn) as isbn');
}
// https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.3.0', '>=')) {
$this->query
->select('p.additional_delivery_times')
->select('pl.delivery_in_stock')
->select('pl.delivery_out_stock')
;
}
// https://github.com/PrestaShop/PrestaShop/commit/75fcc335a85c4e3acb2444ef9584590a59fc2d62#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R1615
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.7.0', '>=')) {
$this->query->select('p.mpn');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("CONCAT(p.id_product, '-', IFNULL(pas.id_product_attribute, 0)) IN('" . implode("','", array_map('strval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @param array<mixed> $attributeIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getProductAttributeValues($attributeIds, $langIso)
{
$langId = (int) \Language::getIdByIso($langIso);
$this->generateMinimalQuery('product_attribute_shop', 'pas');
$this->query
->leftJoin('product_attribute_combination', 'pac', 'pac.id_product_attribute = pas.id_product_attribute')
->leftJoin('attribute', 'a', 'a.id_attribute = pac.id_attribute')
->leftJoin('attribute_group_lang', 'agl', 'agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = ' . $langId)
->leftJoin('attribute_lang', 'al', 'al.id_attribute = pac.id_attribute AND al.id_lang = agl.id_lang')
->where("pas.id_product_attribute IN ('" . implode("','", array_map('intval', $attributeIds)) . "') AND pas.id_shop = " . parent::getShopContext()->id)
;
$this->query
->select('pas.id_product_attribute, agl.name as name, al.name as value')
->select('agl.name as name')
->select('al.name as value')
;
$attributes = $this->runQuery(true);
$resultArray = [];
foreach ($attributes as $attribute) {
$resultArray[$attribute['id_product_attribute']][$attribute['name']] = $attribute['value'];
}
return $resultArray;
}
/**
* @param array<mixed> $productIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getProductFeatures($productIds, $langIso)
{
$langId = (int) \Language::getIdByIso($langIso);
$this->generateMinimalQuery('feature_product', 'fp');
$this->query
->leftJoin('feature_lang', 'fl', 'fl.id_feature = fp.id_feature AND fl.id_lang = ' . $langId)
->leftJoin('feature_value_lang', 'fvl', 'fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = fl.id_lang')
->where("fp.id_product IN ('" . implode("','", array_map('intval', $productIds)) . "')")
;
$this->query
->select('fp.id_product')
->select('fl.name')
->select('fvl.value')
;
$features = $this->runQuery(true);
$resultArray = [];
foreach ($features as $feature) {
$resultArray[$feature['id_product']][$feature['name']] = $feature['value'];
}
return $resultArray;
}
/**
* @param array<mixed> $productIds
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getProductImages($productIds)
{
$this->generateMinimalQuery('image_shop', 'imgs');
$this->query
->where('imgs.id_shop = ' . parent::getShopContext()->id . " AND imgs.id_product IN ('" . implode("','", array_map('intval', $productIds)) . "')");
$this->query
->select('imgs.id_product, imgs.id_image, IFNULL(imgs.cover, 0) as cover')
->select('imgs.id_image')
->select('IFNULL(imgs.cover, 0) as cover')
;
return $this->runQuery(true);
}
/**
* @param array<mixed> $attributeIds
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getAttributeImages($attributeIds)
{
$this->generateMinimalQuery('product_attribute_image', 'pai');
$this->query
->where("pai.id_product_attribute IN ('" . implode("','", array_map('intval', $attributeIds)) . "')")
;
$this->query
->select('id_product_attribute, id_image')
->select('id_image')
;
return $this->runQuery(true);
}
/**
* @param int $productId
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function getProductPriceAndDeclinations($productId)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'p');
$this->query->where('p.`id_product` = ' . (int) $productId);
$this->query->innerJoin(
'product_shop', 'ps', '(ps.id_product=p.id_product AND ps.id_shop = ' . (int) parent::getShopContext()->id . ')');
$this->query
->select('ps.price')
->select('ps.ecotax')
;
if (\Combination::isFeatureActive()) {
$this->query->leftJoin(
'product_attribute_shop', 'pas', '(pas.id_product = p.id_product AND pas.id_shop = ' . (int) parent::getShopContext()->id . ')');
$this->query
->select('IFNULL(pas.id_product_attribute,0) id_product_attribute')
->select('pas.`price` AS attribute_price')
->select('pas.default_on')
;
} else {
$this->query->select('0 as id_product_attribute');
}
return $this->runQuery(true);
}
/**
* @param int $productId
*
* @return array<mixed>
*/
public function getUniqueProductIdsFromProductId($productId)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'p');
$this->query
->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product AND ps.id_shop = ' . parent::getShopContext()->id)
->leftJoin('product_attribute_shop', 'pas', 'pas.id_product = p.id_product AND pas.id_shop = ps.id_shop')
;
$this->query->select("CONCAT(p.id_product, '-', COALESCE(pas.id_product_attribute, 0)) AS id_product_attribute");
$this->query->where("p.id_product = '" . $productId . "'");
return $this->runQuery(true);
}
}

View File

@@ -0,0 +1,123 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ProductSupplierRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'product_supplier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ps');
if ($withSelecParameters) {
$this->query
->select('ps.id_product_supplier')
->select('ps.id_product')
->select('ps.id_product_attribute')
->select('ps.id_supplier')
->select('ps.product_supplier_reference')
->select('ps.product_supplier_price_te')
->select('ps.id_currency')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("ps.id_product IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
// ->limit($limit) Sub shop content depend from another, temporary disabled
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* @property \DbQuery $query
*/
interface RepositoryInterface
{
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*/
public function generateFullQuery($langIso, $withSelecParameters);
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function retrieveContentsForFull($offset, $limit, $langIso);
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso);
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso);
}

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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class SpecificPriceRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'specific_price';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'sp');
$this->query
->leftJoin('country', 'c', 'c.id_country = sp.id_country')
->leftJoin('currency', 'cur', 'cur.id_currency = sp.id_currency')
;
$this->query->where('sp.id_shop = 0 OR sp.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('sp.id_specific_price')
->select('sp.id_product')
->select('sp.id_shop')
->select('sp.id_shop_group')
->select('sp.id_currency')
->select('sp.id_country')
->select('sp.id_group') // different
->select('sp.id_customer')
->select('sp.id_product_attribute')
->select('sp.price')
->select('sp.from_quantity')
->select('sp.reduction')
->select('sp.reduction_tax')
->select('sp.from')
->select('sp.to')
->select('sp.reduction_type')
->select('c.iso_code as country') // different
->select('cur.iso_code as currency') // different
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("sp.id_specific_price IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
/**
* @param int $specificPriceId
*
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
public function getSpecificPriceById($specificPriceId)
{
if (!$specificPriceId) {
return [];
}
$this->generateMinimalQuery(self::TABLE_NAME, 'sp');
$this->query->where('sp.id_specific_price= ' . (int) $specificPriceId);
$this->query
->select('sp.id_specific_price')
->select('sp.id_product')
->select('sp.id_shop')
->select('sp.id_shop_group')
->select('sp.id_currency')
->select('sp.id_country')
->select('sp.id_customer')
->select('sp.id_product_attribute')
->select('sp.price')
->select('sp.from_quantity')
->select('sp.reduction')
->select('sp.reduction_tax')
->select('sp.from')
->select('sp.to')
->select('sp.reduction_type')
->select('sp.id_specific_price_rule') // different
->select('sp.id_cart') // different
;
return $this->runQuery(true);
}
}

View File

@@ -0,0 +1,135 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class StockMovementRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'stock_mvt';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'sm');
$this->query
->innerJoin('stock_mvt_reason', 'smr', 'sm.id_stock_mvt_reason = smr.id_stock_mvt_reason')
->innerJoin('stock_mvt_reason_lang', 'smrl', 'sm.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('sm.id_stock_mvt')
->select('sm.id_stock')
->select('sm.id_order')
->select('sm.id_supply_order')
->select('sm.id_stock_mvt_reason')
->select('smrl.name')
->select('smrl.id_lang')
->select('sm.id_employee')
->select('sm.employee_lastname')
->select('sm.employee_firstname')
->select('sm.physical_quantity')
->select('sm.date_add')
->select('sm.sign')
->select('sm.price_te')
->select('sm.last_wa')
->select('sm.current_wa')
->select('sm.referer')
->select('smr.deleted')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->where("sm.id_stock_mvt IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')");
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,139 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class StockRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'stock_available';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'sa');
$this->query->where('sa.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('sa.id_stock_available')
->select('sa.id_product')
->select('sa.id_product_attribute')
->select('sa.id_shop')
->select('sa.id_shop_group')
->select('sa.quantity')
->select('sa.depends_on_stock')
->select('sa.out_of_stock')
;
// https://github.com/PrestaShop/PrestaShop/commit/2a3269ad93b1985f2615d6604458061d4989f0ea#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2186
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.2.0', '>=')) {
$this->query
->select('sa.physical_quantity')
->select('sa.reserved_quantity')
;
}
// https://github.com/PrestaShop/PrestaShop/commit/4c7d58a905dfb61c7fb2ef4a1f9b4fab2a8d8ecb#diff-e57fb1deeaab9e9079505333394d58f0bf7bb40280b4382aad1278c08c73e2e8R58
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.5.0', '>=')) {
$this->query->select('sa.location');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("sa.id_stock_available IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,154 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class StoreRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'store';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 's');
$langId = (int) \Language::getIdByIso($langIso);
// https://github.com/PrestaShop/PrestaShop/commit/7dda2be62d8bd606edc269fa051c36ea68f81682#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2004
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.3.0', '>=')) {
$this->query
->leftJoin('store_lang', 'sl', 's.id_store = sl.id_store')
->leftJoin('store_shop', 'ss', 's.id_store = ss.id_store')
->where('ss.id_shop = ' . (int) parent::getShopContext()->id)
->where('sl.id_lang = ' . (int) $langId)
;
}
if ($withSelecParameters) {
$this->query
->select('s.id_store')
->select('s.id_country')
->select('s.id_state')
->select('s.city')
->select('s.postcode')
->select('s.active')
->select('s.date_add as created_at')
->select('s.date_upd as updated_at')
;
// https://github.com/PrestaShop/PrestaShop/commit/7dda2be62d8bd606edc269fa051c36ea68f81682#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2004
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.3.0', '>=')) {
$this->query
->select('sl.id_lang')
->select('sl.name')
->select('sl.address1')
->select('sl.address2')
->select('sl.hours')
->select('ss.id_shop')
;
} else {
$this->query
->select('s.name')
->select('s.address1')
->select('s.address2')
->select('s.hours')
;
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("s.id_store IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,138 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class SupplierRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'supplier';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'su');
$langId = (int) \Language::getIdByIso($langIso);
$this->query
->innerJoin('supplier_lang', 'sul', 'su.id_supplier = sul.id_supplier AND sul.id_lang = ' . (int) $langId)
->innerJoin('supplier_shop', 'sus', 'su.id_supplier = sus.id_supplier AND sus.id_shop = ' . parent::getShopContext()->id)
;
if ($withSelecParameters) {
$this->query
->select('su.id_supplier')
->select('su.name')
->select('su.date_add as created_at')
->select('su.date_upd as updated_at')
->select('su.active')
->select('sul.id_lang')
->select('sul.description')
->select('sul.meta_title')
->select('sul.meta_description')
->select('sus.id_shop')
;
// REMOVED HERE: https://github.com/PrestaShop/PrestaShop/commit/f37a8f61017654bae160b528a1a2eaf49edbdac0
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '9.0', '<')) {
$this->query->select('sul.meta_keywords');
}
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("su.id_supplier IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,140 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class SyncRepository extends AbstractRepository
{
const TYPE_SYNC_TABLE_NAME = 'eventbus_type_sync';
const JOB_TABLE_NAME = 'eventbus_job';
/**
* @param string $type
* @param int $offset
* @param string $date
* @param bool $fullSyncFinished
* @param string $langIso
*
* @return bool
*/
public function upsertTypeSync($type, $offset, $date, $fullSyncFinished, $langIso = null)
{
return $this->db->insert(
self::TYPE_SYNC_TABLE_NAME,
[
'type' => pSQL((string) $type),
'offset' => (int) $offset,
'id_shop' => parent::getShopContext()->id,
'lang_iso' => pSQL((string) $langIso),
'full_sync_finished' => (int) $fullSyncFinished,
'last_sync_date' => pSQL($date),
],
false,
true,
\Db::ON_DUPLICATE_KEY
);
}
/**
* @param string $jobId
* @param string $date
*
* @return bool
*
* @throws \PrestaShopDatabaseException
*/
public function insertJob($jobId, $date)
{
return $this->db->insert(
self::JOB_TABLE_NAME,
[
'job_id' => pSQL($jobId),
'created_at' => pSQL($date),
]
);
}
/**
* @param string $jobId
*
* @return array<mixed>|bool|false|object|null
*/
public function findJobById($jobId)
{
$this->generateMinimalQuery(self::JOB_TABLE_NAME, 'ej');
$this->query->where('ej.job_id = "' . pSQL($jobId) . '"');
$this->query->select('ej.*');
return $this->db->getRow($this->query);
}
/**
* @param string $type
* @param string $langIso
*
* @return array<mixed>|bool|object|null
*/
public function findTypeSync($type, $langIso = null)
{
$this->generateMinimalQuery(self::TYPE_SYNC_TABLE_NAME, 'ets');
$this->query
->where('ets.type = "' . pSQL($type) . '"')
->where('ets.lang_iso = "' . pSQL((string) $langIso) . '"')
->where('ets.id_shop = ' . parent::getShopContext()->id)
;
$this->query->select('ets.*');
return $this->db->getRow($this->query);
}
/**
* @param string $type
* @param string $langIso
*
* @return bool
*/
public function isFullSyncDoneForThisTypeSync($type, $langIso = null)
{
$this->generateMinimalQuery(self::TYPE_SYNC_TABLE_NAME, 'ets');
$this->query
->where('ets.type = "' . pSQL($type) . '"')
->where('ets.lang_iso = "' . pSQL((string) $langIso) . '"')
->where('ets.id_shop = ' . parent::getShopContext()->id)
;
$this->query->select('ets.full_sync_finished');
return (bool) $this->db->getValue($this->query);
}
}

View File

@@ -0,0 +1,120 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class TaxonomyRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'fb_category_match';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'fbcm');
$this->query->where('fbcm.id_shop = ' . (int) parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('fbcm.id_category')
->select('fbcm.google_category_id')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("fbcm.id_category IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,122 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class TranslationRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'translation';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 't');
if ($withSelecParameters) {
$this->query
->select('t.id_translation')
->select('t.id_lang')
->select('t.key')
->select('t.translation')
->select('t.domain')
->select('t.theme')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("t.id_translation IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,122 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class WishlistProductRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'wishlist_product';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'wp');
if ($withSelecParameters) {
$this->query
->select('wp.id_wishlist_product')
->select('wp.id_wishlist')
->select('wp.id_product')
->select('wp.id_product_attribute')
->select('wp.quantity')
->select('wp.priority')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("wp.id_wishlist IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
// ->limit($limit) Sub shop content depend from another, temporary disabled
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,128 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Repository;
if (!defined('_PS_VERSION_')) {
exit;
}
class WishlistRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'wishlist';
/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'w');
$this->query->where('w.id_shop = ' . parent::getShopContext()->id);
if ($withSelecParameters) {
$this->query
->select('w.id_wishlist')
->select('w.id_customer')
->select('w.id_shop')
->select('w.id_shop_group')
->select('w.token')
->select('w.name')
->select('w.counter')
->select('w.date_add AS created_at')
->select('w.date_upd as updated_at')
->select('w.default')
;
}
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query->limit((int) $limit, (int) $offset);
return $this->runQuery();
}
/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
{
$this->generateFullQuery($langIso, true);
$this->query
->where("w.id_wishlist IN('" . implode("','", array_map('intval', $contentIds ?: [-1])) . "')")
->limit($limit)
;
return $this->runQuery();
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);
$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$result = $this->runQuery(true);
return !empty($result[0]['count']) ? $result[0]['count'] : 0;
}
}

View File

@@ -0,0 +1,35 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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,140 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
use PrestaShop\Module\PsEventbus\Api\CloudSyncClient;
use PrestaShop\Module\PsEventbus\Exception\EnvVarException;
use PrestaShop\Module\PsEventbus\Exception\FirebaseException;
use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler;
use PrestaShop\Module\PsEventbus\Repository\SyncRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class ApiAuthorizationService
{
/** @var SyncRepository */
private $syncRepository;
/** @var CloudSyncClient */
private $cloudSyncClient;
/** @var PsAccountsAdapterService */
private $psAccountsAdapterService;
/** @var ErrorHandler */
private $errorHandler;
public function __construct(
SyncRepository $syncRepository,
CloudSyncClient $cloudSyncClient,
PsAccountsAdapterService $psAccountsAdapterService,
ErrorHandler $errorHandler
) {
$this->syncRepository = $syncRepository;
$this->cloudSyncClient = $cloudSyncClient;
$this->psAccountsAdapterService = $psAccountsAdapterService;
$this->errorHandler = $errorHandler;
}
/**
* @param string $jobId
* @param bool $isHealthCheck
*
* @return bool
*
* @throws \PrestaShopDatabaseException|EnvVarException|FirebaseException
*/
public function authorize($jobId, $isHealthCheck)
{
try {
$authorizationResponse = $this->authorizeCall($jobId);
if (!$authorizationResponse) {
throw new \PrestaShopDatabaseException('Failed saving job id to database');
}
try {
$token = $this->psAccountsAdapterService->getOrRefreshToken();
} catch (\Exception $exception) {
throw new FirebaseException($exception->getMessage());
}
if (!$token) {
throw new FirebaseException('Invalid token');
}
return true;
} catch (\Exception $exception) {
// For ApiHealthCheck, handle the error, and return false
if ($isHealthCheck) {
return false;
}
switch ($exception) {
case $exception instanceof \PrestaShopDatabaseException:
case $exception instanceof EnvVarException:
case $exception instanceof FirebaseException:
$this->errorHandler->handle($exception);
break;
default:
break;
}
return false;
}
}
/**
* Authorizes and cache job ids
*
* @param string $jobId
*
* @return bool
*/
private function authorizeCall($jobId)
{
// Check if the job already exists
$job = $this->syncRepository->findJobById($jobId);
if ($job) {
return true;
}
// Check the jobId validity to avoid Denial Of Service
$jobValidationResponse = $this->cloudSyncClient->validateJobId($jobId);
if ((int) $jobValidationResponse['httpCode'] !== 201) {
return false;
}
// Cache the valid jobId
return $this->syncRepository->insertJob($jobId, date(DATE_ATOM));
}
}

View File

@@ -0,0 +1,191 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
use PrestaShop\Module\PsAccounts\Api\Client\AccountsClient;
use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler;
if (!defined('_PS_VERSION_')) {
exit;
}
class ApiHealthCheckService
{
/** @var \Db */
private $db;
/** @var PsAccountsAdapterService */
private $psAccountsAdapterService;
/** @var ApiAuthorizationService */
private $apiAuthorizationService;
/** @var array<mixed> */
private $configuration;
/** @var ErrorHandler */
private $errorHandler;
/**
* @var array<mixed>
*/
const REQUIRED_TABLES = [
'eventbus_type_sync',
'eventbus_job',
'eventbus_incremental_sync',
];
/**
* @param PsAccountsAdapterService $psAccountsAdapterService
* @param ErrorHandler $errorHandler
* @param string $eventbusSyncApiUrl
* @param string $eventbusLiveSyncApiUrl
* @param string $eventbusProxyApiUrl
*
* @return void
*/
public function __construct(
PsAccountsAdapterService $psAccountsAdapterService,
ApiAuthorizationService $apiAuthorizationService,
ErrorHandler $errorHandler,
$eventbusSyncApiUrl,
$eventbusLiveSyncApiUrl,
$eventbusProxyApiUrl
) {
$this->db = \Db::getInstance();
$this->apiAuthorizationService = $apiAuthorizationService;
$this->psAccountsAdapterService = $psAccountsAdapterService;
$this->configuration = [
'EVENT_BUS_SYNC_API_URL' => $eventbusSyncApiUrl,
'EVENT_BUS_LIVE_SYNC_API_URL' => $eventbusLiveSyncApiUrl,
'EVENT_BUS_PROXY_API_URL' => $eventbusProxyApiUrl,
];
$this->errorHandler = $errorHandler;
}
/**
* @param string $jobId
*
* @return array<mixed>
*
* @throws \PrestaShopException
*/
public function getHealthCheck($jobId)
{
$tokenValid = false;
$tokenIsSet = false;
$allTablesInstalled = false;
$isAuthentified = $this->apiAuthorizationService->authorize($jobId, true);
try {
$token = $this->psAccountsAdapterService->getOrRefreshToken();
if ($token) {
$psAccount = \Module::getInstanceByName('ps_accounts');
/* @phpstan-ignore-next-line */
$accountsClient = $psAccount->getService(AccountsClient::class);
$tokenIsSet = true;
/** @phpstan-ignore-next-line */
$response = $accountsClient->verifyToken($token);
if ($response && true === $response['status']) {
$tokenValid = true;
}
}
} catch (\Exception $exception) {
$this->errorHandler->handle($exception);
$tokenIsSet = false;
}
$missingTables = $this->getMissingRequiredTables();
if (count($missingTables) == 0) {
$allTablesInstalled = true;
}
if (defined('PHP_VERSION') && defined('PHP_EXTRA_VERSION')) {
$phpVersion = str_replace(PHP_EXTRA_VERSION, '', PHP_VERSION);
} else {
$phpVersion = (string) explode('-', (string) phpversion())[0];
}
$psEventbus = \Module::getInstanceByName('ps_eventbus');
if ($psEventbus == false) {
throw new \Exception('ps_eventbus module is not installed');
}
$sensibleInformation = [
'prestashop_version' => _PS_VERSION_,
'ps_eventbus_version' => $psEventbus->version,
'ps_accounts_version' => defined('Ps_accounts::VERSION') ? \Ps_accounts::VERSION : false, /* @phpstan-ignore-line */
'php_version' => $phpVersion,
'shop_id' => $this->psAccountsAdapterService->getShopUuid(),
];
$serverInformation = [
'ps_account' => $tokenIsSet,
'is_valid_jwt' => $tokenValid,
'ps_eventbus' => $allTablesInstalled,
'env' => [
'EVENT_BUS_PROXY_API_URL' => isset($this->configuration['EVENT_BUS_PROXY_API_URL']) ? $this->configuration['EVENT_BUS_PROXY_API_URL'] : null,
'EVENT_BUS_SYNC_API_URL' => isset($this->configuration['EVENT_BUS_SYNC_API_URL']) ? $this->configuration['EVENT_BUS_SYNC_API_URL'] : null,
'EVENT_BUS_LIVE_SYNC_API_URL' => isset($this->configuration['EVENT_BUS_LIVE_SYNC_API_URL']) ? $this->configuration['EVENT_BUS_LIVE_SYNC_API_URL'] : null,
],
];
if ($isAuthentified) {
$serverInformation = array_merge($sensibleInformation, $serverInformation);
}
return $serverInformation;
}
/**
* @return array<mixed>
*
* @throws \PrestaShopDatabaseException
*/
private function getMissingRequiredTables()
{
$requiredTablesQuery = 'SELECT TABLE_NAME FROM information_schema.tables WHERE table_name LIKE \'%eventbus%\';';
$requiredTablesResponse = (array) $this->db->executeS($requiredTablesQuery);
// Transform 2D array into array<string>
$requiredTables = array_column($requiredTablesResponse, 'TABLE_NAME');
// Remove the prefix of the tables (ex: ps_)
$filteredRequiredTables = array_map(function ($item) {
return substr($item, strlen(_DB_PREFIX_));
}, $requiredTables);
// return array<string>, with list of missing required table
return array_diff(self::REQUIRED_TABLES, $filteredRequiredTables);
}
}

View File

@@ -0,0 +1,176 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Exception\QueryParamsException;
use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler;
use PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository;
use PrestaShop\Module\PsEventbus\Repository\SyncRepository;
use PrestaShop\Module\PsEventbus\Service\ShopContent\LanguagesService;
if (!defined('_PS_VERSION_')) {
exit;
}
class ApiShopContentService
{
/** @var int */
public $startTime;
/** @var ApiAuthorizationService */
private $apiAuthorizationService;
/** @var SyncRepository */
private $syncRepository;
/** @var SynchronizationService */
private $synchronizationService;
/** @var \Ps_eventbus */
private $module;
/** @var ErrorHandler */
private $errorHandler;
public function __construct(
\Ps_eventbus $module,
ApiAuthorizationService $apiAuthorizationService,
SynchronizationService $synchronizationService,
SyncRepository $syncRepository,
ErrorHandler $errorHandler
) {
$this->startTime = time();
$this->module = $module;
$this->errorHandler = $errorHandler;
$this->apiAuthorizationService = $apiAuthorizationService;
$this->synchronizationService = $synchronizationService;
$this->syncRepository = $syncRepository;
}
/**
* @param string $shopContent
* @param string $jobId
* @param string $langIso
* @param int $limit
* @param bool $fullSyncRequested
*
* @return void
*/
public function handleDataSync($shopContent, $jobId, $langIso, $limit, $fullSyncRequested)
{
try {
if (!in_array($shopContent, Config::SHOP_CONTENTS, true)) {
CommonService::exitWithExceptionMessage(new QueryParamsException('404 - ShopContent not found', Config::INVALID_URL_QUERY));
}
if ($limit < 0) {
CommonService::exitWithExceptionMessage(new QueryParamsException('Invalid URL Parameters', Config::INVALID_URL_QUERY));
}
$this->apiAuthorizationService->authorize($jobId, false);
$response = [];
/** @var LanguagesService $languagesService */
$languagesService = $this->module->getService(LanguagesService::class);
$timezone = (string) \Configuration::get('PS_TIMEZONE');
$dateNow = (new \DateTime('now', new \DateTimeZone($timezone)))->format(Config::MYSQL_DATE_FORMAT);
$langIso = $langIso ? $langIso : $languagesService->getDefaultLanguageIsoCode();
$typeSync = $this->syncRepository->findTypeSync($shopContent, $langIso);
// If no typesync exist, or if fullsync is requested by user
if (!is_array($typeSync) || $fullSyncRequested) {
$isFullSync = true;
$fullSyncIsFinished = false;
$offset = 0;
if ($typeSync) {
/** @var IncrementalSyncRepository $incrementalSyncRepository */
$incrementalSyncRepository = $this->module->getService(IncrementalSyncRepository::class);
$incrementalSyncRepository->removeIncrementaSyncObjectByType($shopContent);
}
$this->syncRepository->upsertTypeSync(
$shopContent,
$offset,
$dateNow,
$fullSyncIsFinished,
$langIso
);
// Else if fullsync is not finished
} elseif (!boolval($typeSync['full_sync_finished'])) {
$isFullSync = true;
$fullSyncIsFinished = false;
$offset = (int) $typeSync['offset'];
// Else, we are in incremental sync
} else {
$isFullSync = false;
$fullSyncIsFinished = $typeSync['full_sync_finished'];
$offset = (int) $typeSync['offset'];
}
if ($isFullSync) {
$response = $this->synchronizationService->sendFullSync(
$shopContent,
$jobId,
$langIso,
$offset,
$limit,
$this->startTime,
$dateNow
);
} else {
$response = $this->synchronizationService->sendIncrementalSync(
$shopContent,
$jobId,
$langIso,
$limit,
$this->startTime
);
}
CommonService::exitWithResponse(
array_merge(
[
'job_id' => $jobId,
'object_type' => $shopContent,
'syncType' => $isFullSync ? 'full' : 'incremental',
'execution_time_in_seconds' => round(microtime(true) - REQUEST_START_TIME, 2),
],
$response
)
);
} catch (\Exception $exception) {
$this->errorHandler->handle($exception);
}
}
}

View File

@@ -0,0 +1,155 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Exception\EnvVarException;
use PrestaShop\Module\PsEventbus\Exception\FirebaseException;
use PrestaShop\Module\PsEventbus\Exception\QueryParamsException;
if (!defined('_PS_VERSION_')) {
exit;
}
class CommonService
{
/**
* @param mixed $response
*
* @return void
*/
public static function exitWithResponse($response)
{
if (!is_array($response)) {
$response = [$response];
}
$httpCode = isset($response['httpCode']) ? (int) $response['httpCode'] : 200;
self::dieWithResponse($response, $httpCode);
}
/**
* @param \Exception $exception
*
* @return void
*/
public static function exitWithExceptionMessage(\Exception $exception)
{
switch ($exception) {
case $exception instanceof \PrestaShopDatabaseException:
$code = Config::DATABASE_QUERY_ERROR_CODE;
break;
case $exception instanceof EnvVarException:
$code = Config::ENV_MISCONFIGURED_ERROR_CODE;
break;
case $exception instanceof FirebaseException:
$code = Config::REFRESH_TOKEN_ERROR_CODE;
break;
case $exception instanceof QueryParamsException:
$code = Config::INVALID_URL_QUERY;
break;
default:
$code = 500;
}
$response = [
'object_type' => \Tools::getValue('shopContent'),
'status' => false,
'httpCode' => $code,
'message' => $code == 500 ? 'Server error' : $exception->getMessage(),
];
self::dieWithResponse($response, (int) $code);
}
/**
* @param array<mixed> $response
* @param int $code
*
* @return void
*/
public static function dieWithResponse($response, $code)
{
$httpStatusText = "HTTP/1.1 $code";
if (array_key_exists((int) $code, Config::HTTP_STATUS_MESSAGES)) {
$httpStatusText .= ' ' . Config::HTTP_STATUS_MESSAGES[(int) $code];
} elseif (isset($response['body']['statusText'])) {
$httpStatusText .= ' ' . $response['body']['statusText'];
}
$response['httpCode'] = (int) $code;
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/json;charset=utf-8');
header($httpStatusText);
echo json_encode($response, JSON_UNESCAPED_SLASHES);
exit;
}
/**
* @param array<mixed> $payload
*
* @return void
*
* @throws \Exception
*/
public static function convertDateFormat(&$payload)
{
// use hardcoded format to avoid problems with interface change in PHP 7.2
$ISO8601 = 'Y-m-d\TH:i:sO';
$dateFields = [
'created_at',
'updated_at',
'last_connection_date',
'folder_created_at',
'date_add',
'newsletter_date_add',
'from',
'to',
];
$timezone = (string) \Configuration::get('PS_TIMEZONE');
foreach ($payload as &$payloadItem) {
foreach ($dateFields as $dateField) {
if (isset($payloadItem['properties'][$dateField])) {
$date = &$payloadItem['properties'][$dateField];
if (!empty($date) && $date !== '0000-00-00 00:00:00') {
$dateTime = new \DateTime($date, new \DateTimeZone($timezone));
$date = $dateTime->format($ISO8601);
} else {
$date = null;
}
}
}
}
}
}

View File

@@ -0,0 +1,112 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
if (!defined('_PS_VERSION_')) {
exit;
}
class PresenterService
{
/**
* @var PsAccountsAdapterService
*/
private $psAccountsAdapterService;
public function __construct()
{
/** @var \Ps_eventbus */
$psEventbus = \Module::getInstanceByName('ps_eventbus');
$psAccountsAdapterService = $psEventbus->getService(PsAccountsAdapterService::class);
$this->psAccountsAdapterService = $psAccountsAdapterService;
}
/**
* @param \ModuleCore $module
* @param array<mixed> $requiredConsents
* @param array<mixed> $optionalConsents
*
* @return array<mixed>
*/
public function expose(\ModuleCore $module, $requiredConsents = [], $optionalConsents = [])
{
if (!in_array('info', $requiredConsents)) {
array_unshift($requiredConsents, 'info');
}
if ($this->psAccountsAdapterService == null) {
return [];
}
$language = \Context::getContext()->language;
if ($language == null) {
throw new \PrestaShopException('No language context');
}
return [
'jwt' => $this->psAccountsAdapterService->getOrRefreshToken(),
'requiredConsents' => $requiredConsents,
'optionalConsents' => $optionalConsents,
'module' => array_merge([
'logoUrl' => \Tools::getHttpHost(true) . '/modules/' . $module->name . '/logo.png',
], $this->convertObjectToArray($module)),
'shop' => [
/* @phpstan-ignore-next-line */
'id' => $this->psAccountsAdapterService->getShopUuid(),
'name' => \Configuration::get('PS_SHOP_NAME'),
'url' => \Tools::getHttpHost(true),
'lang' => $language->iso_code,
],
'psEventbusModule' => $this->convertObjectToArray(\Module::getInstanceByName('ps_eventbus')),
];
}
/**
* @param object|\ModuleCore|false $object
*
* @return array<mixed>
*/
private function convertObjectToArray($object)
{
if (!$object) {
return [];
}
$array = [];
/* @phpstan-ignore-next-line */ // TODO understand why phpstan complains about this
foreach ($object as $key => $value) {
if (is_object($value)) {
$array[$key] = $this->convertObjectToArray($value);
} else {
$array[$key] = $value;
}
}
return $array;
}
}

View File

@@ -0,0 +1,165 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service;
use PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler;
use PrestaShop\Module\PsEventbus\Helper\ModuleHelper;
if (!defined('_PS_VERSION_')) {
exit;
}
class PsAccountsAdapterService
{
/**
* @var ModuleHelper
*/
private $moduleHelper;
/**
* @var ErrorHandler
*/
private $errorHandler;
/**
* @var false|\ModuleCore
*/
private $psAccountModule;
public function __construct(ModuleHelper $moduleHelper, ErrorHandler $errorHandler)
{
$this->moduleHelper = $moduleHelper;
$this->errorHandler = $errorHandler;
$this->psAccountModule = $this->moduleHelper->getInstanceByName('ps_accounts');
}
/**
* Get psAccounts module main class, or null if module is'nt ready
*
* @return false|\ModuleCore
*/
public function getModule()
{
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) {
return false;
}
return $this->psAccountModule;
}
/**
* Get psAccounts service, or null if module is'nt ready
*
* @return mixed
*/
public function getService()
{
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) {
return false;
}
try {
return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Service\PsAccountsService');
} catch (\Exception $e) {
$this->errorHandler->handle(
new \PrestaShopException('Failed to load PsAccountsService', 0, $e),
true
);
return false;
}
}
/**
* Get presenter from psAccounts, or null if module is'nt ready
*
* @return mixed
*/
public function getPresenter()
{
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
return false;
}
try {
return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter');
} catch (\Exception $e) {
$this->errorHandler->handle(
new \PrestaShopException('Failed to load PsAccountsPresenter', 0, $e),
true
);
return false;
}
}
/**
* Get shopUuid from psAccounts, or null if module is'nt ready
*
* @return string
*/
public function getShopUuid()
{
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
return '';
}
try {
return $this->getService()->getShopUuid();
} catch (\Exception $e) {
$this->errorHandler->handle(
new \PrestaShopException('Failed to get shop uuid from ps_account', 0, $e),
true
);
return '';
}
}
/**
* Get refreshToken from psAccounts, or null if module is'nt ready
*
* @return string
*/
public function getOrRefreshToken()
{
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
return '';
}
try {
return $this->getService()->getOrRefreshToken();
} catch (\Exception $e) {
$this->errorHandler->handle(
new \PrestaShopException('Failed to get refresh token from ps_account', 0, $e),
true
);
return '';
}
}
}

View File

@@ -0,0 +1,117 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\BundleRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class BundlesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var BundleRepository */
private $bundleRepository;
public function __construct(BundleRepository $bundleRepository)
{
$this->bundleRepository = $bundleRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->bundleRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castBundles($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_BUNDLES,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->bundleRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castBundles($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_BUNDLES, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->bundleRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $bundles
*
* @return void
*/
private function castBundles(&$bundles)
{
foreach ($bundles as &$bundle) {
$bundle['id_product'] = (string) $bundle['id_product'];
$bundle['id_bundle'] = (string) $bundle['id_bundle'];
$bundle['id_product_attribute'] = (string) $bundle['id_product_attribute'];
$bundle['quantity'] = (string) $bundle['quantity'];
}
}
}

View File

@@ -0,0 +1,123 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CarrierDetailRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarrierDetailsService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CarrierDetailRepository */
private $carrierDetailRepository;
public function __construct(CarrierDetailRepository $carrierDetailRepository)
{
$this->carrierDetailRepository = $carrierDetailRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->carrierDetailRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCarrierDetails($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CARRIER_DETAILS,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->carrierDetailRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCarrierDetails($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_DETAILS, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->carrierDetailRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $carrierDetails
*
* @return void
*/
private function castCarrierDetails(&$carrierDetails)
{
foreach ($carrierDetails as &$carrierDetail) {
$carrierDetail['id_reference'] = (string) $carrierDetail['id_reference'];
$carrierDetail['id_zone'] = (string) $carrierDetail['id_zone'];
$carrierDetail['id_range'] = (string) $carrierDetail['id_range'];
$carrierDetail['id_carrier_detail'] = (string) $carrierDetail['id_range']; // same value as id_range
$carrierDetail['shipping_method'] = (string) $carrierDetail['shipping_method'];
$carrierDetail['delimiter1'] = (float) $carrierDetail['delimiter1'];
$carrierDetail['delimiter2'] = (float) $carrierDetail['delimiter2'];
$carrierDetail['country_ids'] = (string) $carrierDetail['country_ids'];
$carrierDetail['state_ids'] = (string) $carrierDetail['state_ids'];
$carrierDetail['price'] = (float) $carrierDetail['price'];
}
}
}

View File

@@ -0,0 +1,120 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CarrierTaxeRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarrierTaxesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CarrierTaxeRepository */
private $carrierTaxeRepository;
public function __construct(CarrierTaxeRepository $carrierTaxeRepository)
{
$this->carrierTaxeRepository = $carrierTaxeRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->carrierTaxeRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCarrierTaxes($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CARRIER_TAXES,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->carrierTaxeRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCarrierTaxes($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIER_TAXES, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->carrierTaxeRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $carrierTaxes
*
* @return void
*/
private function castCarrierTaxes(&$carrierTaxes)
{
foreach ($carrierTaxes as &$carrierTaxe) {
$carrierTaxe['id_reference'] = (string) $carrierTaxe['id_reference'];
$carrierTaxe['id_zone'] = (string) $carrierTaxe['id_zone'];
$carrierTaxe['id_range'] = (string) $carrierTaxe['id_range'];
$carrierTaxe['id_carrier_tax'] = (string) $carrierTaxe['id_carrier_tax'];
$carrierTaxe['country_id'] = (string) $carrierTaxe['country_id'];
$carrierTaxe['state_ids'] = (string) $carrierTaxe['state_ids'];
$carrierTaxe['tax_rate'] = (float) $carrierTaxe['tax_rate'];
}
}
}

View File

@@ -0,0 +1,182 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CarrierRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CarriersService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CarrierRepository */
private $carrierRepository;
public function __construct(CarrierRepository $carrierRepository)
{
$this->carrierRepository = $carrierRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->carrierRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCarriers($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CARRIERS,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->carrierRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCarriers($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARRIERS, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->carrierRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param \Carrier $carrier
* @param array<mixed> $delivery
*
* @return false|\RangeWeight|\RangePrice
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public static function generateRange($carrier, $delivery)
{
$rangeTable = $carrier->getRangeTable();
if ($rangeTable === 'range_weight') {
return new \RangeWeight($delivery['id_range_weight']);
}
if ($rangeTable === 'range_price') {
return new \RangePrice($delivery['id_range_price']);
}
return false;
}
/**
* @param array<mixed> $carriers
*
* @return void
*/
private function castCarriers(&$carriers)
{
$context = \Context::getContext();
if ($context == null) {
throw new \PrestaShopException('Context is null');
}
$currency = new \Currency((int) \Configuration::get('PS_CURRENCY_DEFAULT'));
$freeShippingStartsAtPrice = (float) \Configuration::get('PS_SHIPPING_FREE_PRICE');
$freeShippingStartsAtWeight = (float) \Configuration::get('PS_SHIPPING_FREE_WEIGHT');
/** @var string $psWeightUnit */
$psWeightUnit = \Configuration::get('PS_WEIGHT_UNIT');
foreach ($carriers as &$carrier) {
$carrierTaxesRatesGroupId = \Carrier::getIdTaxRulesGroupByIdCarrier((int) $carrier['id_carrier'], \Context::getContext());
$shippingHandling = 0.0;
if ($carrier['shipping_handling']) {
$shippingHandling = (float) \Configuration::get('PS_SHIPPING_HANDLING');
}
$carrier['id_carrier'] = (string) $carrier['id_carrier'];
$carrier['id_reference'] = (string) $carrier['id_reference'];
$carrier['name'] = (string) $carrier['name'];
$carrier['carrier_taxes_rates_group_id'] = (string) $carrierTaxesRatesGroupId;
$carrier['url'] = (string) $carrier['url'];
$carrier['active'] = (bool) $carrier['active'];
$carrier['deleted'] = (bool) $carrier['deleted'];
$carrier['shipping_handling'] = (float) $shippingHandling;
$carrier['free_shipping_starts_at_price'] = (float) $freeShippingStartsAtPrice;
$carrier['free_shipping_starts_at_weight'] = (float) $freeShippingStartsAtWeight;
$carrier['disable_carrier_when_out_of_range'] = (bool) $carrier['disable_carrier_when_out_of_range'];
$carrier['is_module'] = (bool) $carrier['is_module'];
$carrier['is_free'] = (bool) $carrier['is_free'];
$carrier['shipping_external'] = (bool) $carrier['shipping_external'];
$carrier['need_range'] = (bool) $carrier['need_range'];
$carrier['external_module_name'] = (string) $carrier['external_module_name'];
$carrier['max_width'] = (float) $carrier['max_width'];
$carrier['max_height'] = (float) $carrier['max_height'];
$carrier['max_depth'] = (float) $carrier['max_depth'];
$carrier['max_weight'] = (float) $carrier['max_weight'];
$carrier['grade'] = (int) $carrier['grade'];
$carrier['delay'] = (string) $carrier['delay'];
$carrier['currency'] = (string) $currency->iso_code;
$carrier['weight_unit'] = (string) $psWeightUnit;
}
}
}

View File

@@ -0,0 +1,118 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CartProductRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartProductsService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CartProductRepository */
private $cartProductRepository;
public function __construct(CartProductRepository $cartProductRepository)
{
$this->cartProductRepository = $cartProductRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->cartProductRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCartProducts($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CART_PRODUCTS,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->cartProductRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCartProducts($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CART_PRODUCTS, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->cartProductRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $cartProducts
*
* @return void
*/
private function castCartProducts(&$cartProducts)
{
foreach ($cartProducts as &$cartProduct) {
$cartProduct['id_cart_product'] = (string) "{$cartProduct['id_cart']}-{$cartProduct['id_product']}-{$cartProduct['id_product_attribute']}";
$cartProduct['id_cart'] = (string) $cartProduct['id_cart'];
$cartProduct['id_product'] = (string) $cartProduct['id_product'];
$cartProduct['id_product_attribute'] = (string) $cartProduct['id_product_attribute'];
$cartProduct['quantity'] = (int) $cartProduct['quantity'];
}
}
}

View File

@@ -0,0 +1,144 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CartRuleRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartRulesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CartRuleRepository */
private $cartRuleRepository;
public function __construct(CartRuleRepository $cartRuleRepository)
{
$this->cartRuleRepository = $cartRuleRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->cartRuleRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCartRules($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CART_RULES,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->cartRuleRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCartRules($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CART_RULES, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->cartRuleRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $cartRules
*
* @return void
*/
private function castCartRules(&$cartRules)
{
foreach ($cartRules as &$cartRule) {
$cartRule['id_cart_rule'] = (int) $cartRule['id_cart_rule'];
$cartRule['id_customer'] = (int) $cartRule['id_customer'];
$cartRule['quantity'] = (int) $cartRule['quantity'];
$cartRule['quantity_per_user'] = (int) $cartRule['quantity_per_user'];
$cartRule['priority'] = (int) $cartRule['priority'];
$cartRule['partial_use'] = (bool) $cartRule['partial_use'];
$cartRule['minimum_amount'] = (float) $cartRule['minimum_amount'];
$cartRule['minimum_amount_tax'] = (bool) $cartRule['minimum_amount_tax'];
$cartRule['minimum_amount_currency'] = (int) $cartRule['minimum_amount_currency'];
$cartRule['minimum_amount_shipping'] = (bool) $cartRule['minimum_amount_shipping'];
$cartRule['country_restriction'] = (bool) $cartRule['country_restriction'];
$cartRule['carrier_restriction'] = (bool) $cartRule['carrier_restriction'];
$cartRule['group_restriction'] = (bool) $cartRule['group_restriction'];
$cartRule['cart_rule_restriction'] = (bool) $cartRule['cart_rule_restriction'];
$cartRule['product_restriction'] = (bool) $cartRule['product_restriction'];
$cartRule['shop_restriction'] = (bool) $cartRule['shop_restriction'];
$cartRule['free_shipping'] = (bool) $cartRule['free_shipping'];
$cartRule['reduction_percent'] = (float) $cartRule['reduction_percent'];
$cartRule['reduction_amount'] = (float) $cartRule['reduction_amount'];
$cartRule['reduction_tax'] = (bool) $cartRule['reduction_tax'];
$cartRule['reduction_currency'] = (int) $cartRule['reduction_currency'];
$cartRule['reduction_product'] = (int) $cartRule['reduction_product'];
$cartRule['gift_product'] = (int) $cartRule['gift_product'];
$cartRule['gift_product_attribute'] = (int) $cartRule['gift_product_attribute'];
$cartRule['highlight'] = (bool) $cartRule['highlight'];
$cartRule['active'] = (bool) $cartRule['active'];
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$cartRule['reduction_exclude_special'] = (bool) $cartRule['reduction_exclude_special'];
}
}
}
}

View File

@@ -0,0 +1,116 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CartRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CartsService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CartRepository */
private $cartRepository;
public function __construct(CartRepository $cartRepository)
{
$this->cartRepository = $cartRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->cartRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCarts($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CARTS,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->cartRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCarts($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CARTS, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->cartRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param array<mixed> $carts
*
* @return void
*/
private function castCarts(&$carts)
{
foreach ($carts as &$cart) {
$cart['id_cart'] = (string) $cart['id_cart'];
$cart['created_at'] = (string) $cart['created_at'];
$cart['updated_at'] = (string) $cart['updated_at'];
}
}
}

View File

@@ -0,0 +1,174 @@
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
*/
namespace PrestaShop\Module\PsEventbus\Service\ShopContent;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Repository\CategoryRepository;
if (!defined('_PS_VERSION_')) {
exit;
}
class CategoriesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
/** @var CategoryRepository */
private $categoryRepository;
public function __construct(CategoryRepository $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForFull($offset, $limit, $langIso)
{
$result = $this->categoryRepository->retrieveContentsForFull($offset, $limit, $langIso);
if (empty($result)) {
return [];
}
$this->castCategories($result);
return array_map(function ($item) {
return [
'action' => Config::INCREMENTAL_TYPE_UPSERT,
'collection' => Config::COLLECTION_CATEGORIES,
'properties' => $item,
];
}, $result);
}
/**
* @param int $limit
* @param array<mixed> $upsertedContents
* @param array<mixed> $deletedContents
* @param string $langIso
*
* @return array<mixed>
*/
public function getContentsForIncremental($limit, $upsertedContents, $deletedContents, $langIso)
{
$result = $this->categoryRepository->retrieveContentsForIncremental($limit, array_column($upsertedContents, 'id'), $langIso);
if (!empty($result)) {
$this->castCategories($result);
}
return parent::formatIncrementalSyncResponse(Config::COLLECTION_CATEGORIES, $result, $deletedContents);
}
/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*/
public function getFullSyncContentLeft($offset, $limit, $langIso)
{
return $this->categoryRepository->countFullSyncContentLeft($offset, $limit, $langIso);
}
/**
* @param int $topCategoryId
* @param int $langId
* @param int $shopId
*
* @return array<mixed>
*/
public function getCategoryPaths($topCategoryId, $langId, $shopId)
{
if ((int) $topCategoryId === 0) {
return [
'category_path' => '',
'category_id_path' => '',
];
}
$categories = [];
try {
$categoriesWithParentsInfo = $this->categoryRepository->getCategoriesWithParentInfo($langId, $shopId);
} catch (\PrestaShopDatabaseException $e) {
return [
'category_path' => '',
'category_id_path' => '',
];
}
$this->buildCategoryPaths($categoriesWithParentsInfo, $topCategoryId, $categories);
$categories = array_reverse($categories);
return [
'category_path' => implode(' > ', array_map(function ($category) {
return $category['name'];
}, $categories)),
'category_id_path' => implode(' > ', array_map(function ($category) {
return $category['id_category'];
}, $categories)),
];
}
/**
* @param array<mixed> $categoriesWithParentsInfo
* @param int $currentCategoryId
* @param array<mixed> $categories
*
* @return void
*/
private function buildCategoryPaths($categoriesWithParentsInfo, $currentCategoryId, &$categories)
{
foreach ($categoriesWithParentsInfo as $category) {
if ($category['id_category'] == $currentCategoryId) {
$categories[] = $category;
$this->buildCategoryPaths($categoriesWithParentsInfo, $category['id_parent'], $categories);
}
}
}
/**
* @param array<mixed> $categories
*
* @return void
*/
private function castCategories(&$categories)
{
foreach ($categories as &$category) {
$category['id_category'] = (int) $category['id_category'];
$category['id_parent'] = (int) $category['id_parent'];
$category['description'] = base64_encode($category['description']);
}
}
}

Some files were not shown because too many files have changed in this diff Show More