* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ use PrestaShop\Module\PsAccounts\Account\Command\LinkShopCommand; use PrestaShop\Module\PsAccounts\Account\Command\UnlinkShopCommand; use PrestaShop\Module\PsAccounts\Account\Dto\LinkShop; use PrestaShop\Module\PsAccounts\Api\Controller\AbstractShopRestController; use PrestaShop\Module\PsAccounts\Api\Controller\Request\UpdateShopLinkAccountRequest; use PrestaShop\Module\PsAccounts\Cqrs\CommandBus; use PrestaShop\Module\PsAccounts\Exception\RefreshTokenException; class ps_AccountsApiV1ShopLinkAccountModuleFrontController extends AbstractShopRestController { /** * @var CommandBus */ private $commandBus; /** * @throws Exception */ public function __construct() { parent::__construct(); $this->commandBus = $this->module->getService(CommandBus::class); //$this->commandBus = $this->module->getContainer()->get('prestashop.command_bus'); } /** * @param Shop $shop * @param UpdateShopLinkAccountRequest $request * * @return array * * @throws RefreshTokenException * @throws Exception */ public function update(Shop $shop, UpdateShopLinkAccountRequest $request) { $this->commandBus->handle(new LinkShopCommand( new LinkShop([ 'shopId' => $request->shop_id, 'uid' => $request->uid, 'ownerUid' => $request->owner_uid, 'ownerEmail' => $request->owner_email, 'employeeId' => $request->employee_id, ]) )); return [ 'success' => true, 'message' => 'Link Account stored successfully', ]; } /** * @param Shop $shop * @param array $payload * * @return array * * @throws PrestaShopException * @throws Exception */ public function delete(Shop $shop, array $payload) { $this->commandBus->handle(new UnlinkShopCommand($shop->id)); return [ 'success' => true, 'message' => 'Link Account deleted successfully', ]; } }