Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions Block/Adminhtml/Configuration/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Exception\LocalizedException;
use Sequra\Core\Helper\UrlHelper;
use SeQura\Core\Infrastructure\Utility\RegexProvider;

class Index extends Template
{
Expand All @@ -18,24 +19,35 @@ class Index extends Template
* @var Session
*/
private $authSession;
/**
* @var RegexProvider
*/
private $regexProvider;

/**
* Content constructor.
*
* @param Context $context
* @param UrlHelper $urlHelper
* @param Session $authSession
* @param RegexProvider $regexProvider
* @param mixed[] $data
*/
public function __construct(Context $context, UrlHelper $urlHelper, Session $authSession, array $data = [])
{
public function __construct(
Context $context,
UrlHelper $urlHelper,
Session $authSession,
RegexProvider $regexProvider,
array $data = []
) {
if (!is_iterable($data)) {
throw new \InvalidArgumentException('Data must be iterable');
}
parent::__construct($context, $data);

$this->urlHelper = $urlHelper;
$this->authSession = $authSession;
$this->regexProvider = $regexProvider;
}

/**
Expand Down Expand Up @@ -109,4 +121,17 @@ public function getAdminLanguage(): string
$user = $this->authSession->getUser();
return strtoupper($user ? substr($user->getInterfaceLocale(), 0, 2) : 'en');
}

/**
* Get the regex in JSON format
*
* @return string
*/
public function getRegexJson(): string
{
$regex = $this->regexProvider->toArray();

$jsonEncoded = json_encode($regex);
return $jsonEncoded === false ? '' : $jsonEncoded;
}
}
56 changes: 56 additions & 0 deletions Controller/Adminhtml/Configuration/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Sequra\Core\Controller\Adminhtml\Configuration;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use SeQura\Core\BusinessLogic\AdminAPI\AdminAPI;
use SeQura\Core\BusinessLogic\AdminAPI\Connection\Requests\ReRegisterWebhookRequest;

class Connection extends BaseConfigurationController
{
/**
* Disconnect constructor.
*
* @param Context $context
* @param JsonFactory $jsonFactory
*/
public function __construct(Context $context, JsonFactory $jsonFactory)
{
parent::__construct($context, $jsonFactory);

$this->allowedActions = ['reRegisterWebhooks'];
}

/**
* Re-register webhooks on the Merchant Portal.
*
* @return Json
*/
protected function reRegisterWebhooks(): Json
{
/**
* @var array<string> $data
*/
$data = $this->getSequraPostData();
$environment = $data['environment'] ?? '';
$username = $data['username'] ?? '';
$password = $data['password'] ?? '';
$deployment = $data['deployment'] ?? '';

// @phpstan-ignore-next-line
$response = AdminAPI::get()->connection($this->storeId)->reRegisterWebhooks(
new ReRegisterWebhookRequest(
$environment,
'',
$username,
$password,
$deployment
)
);
$this->addResponseCode($response);

return $this->result->setData(['isSuccessful' => $response->isSuccessful()]);
}
}
15 changes: 0 additions & 15 deletions Controller/Adminhtml/Configuration/WidgetSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,8 @@ protected function getWidgetSettings(): Json
{
/** @var WidgetSettingsResponse $data */
$data = AdminAPI::get()->widgetConfiguration($this->storeId)->getWidgetSettings();

$result = $data->toArray();

if (empty($result)) {
$result['productPriceSelector'] = '.price-container .price';
$result['defaultProductLocationSelector'] = '.actions .action.primary.tocart';
$result['altProductPriceSelector'] = '[data-price-type="finalPrice"] .price';
$result['altProductPriceTriggerSelector'] = '.bundle-actions';
$result['cartPriceSelector'] = '.grand.totals .price';
$result['cartLocationSelector'] = '.cart-summary';

return $this->result->setData($result);
}

$result['widgetStyles'] = $result['widgetConfiguration'];
unset($result['widgetConfiguration']);

$this->addResponseCode($data);

return $this->result->setData($result);
Expand Down
16 changes: 16 additions & 0 deletions Services/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use SeQura\Core\BusinessLogic\Domain\Integration\SellingCountries\SellingCountriesServiceInterface;
use SeQura\Core\BusinessLogic\Domain\Integration\ShopOrderStatuses\ShopOrderStatusesServiceInterface;
use SeQura\Core\BusinessLogic\Domain\Integration\Store\StoreServiceInterface;
use SeQura\Core\BusinessLogic\Domain\Integration\StoreIntegration\StoreIntegrationServiceInterface;
use SeQura\Core\BusinessLogic\Domain\Integration\Version\VersionServiceInterface;
use SeQura\Core\BusinessLogic\Domain\Order\Models\SeQuraOrder;
use SeQura\Core\BusinessLogic\Domain\Order\RepositoryContracts\SeQuraOrderRepositoryInterface;
Expand Down Expand Up @@ -63,6 +64,7 @@
use Sequra\Core\Services\BusinessLogic\SellingCountriesService;
use Sequra\Core\Services\BusinessLogic\ShopOrderStatusesService;
use Sequra\Core\Services\BusinessLogic\StatisticalDataService;
use Sequra\Core\Services\BusinessLogic\StoreIntegrationService;
use Sequra\Core\Services\BusinessLogic\StoreService;
use Sequra\Core\Services\BusinessLogic\Utility\Encryptor;
use Sequra\Core\Services\BusinessLogic\VersionService;
Expand All @@ -89,6 +91,10 @@ class Bootstrap extends BootstrapComponent
* @var StoreService
*/
private $storeService;
/**
* @var StoreIntegrationService
*/
private $storeIntegrationService;
/**
* @var VersionService
*/
Expand Down Expand Up @@ -138,6 +144,7 @@ class Bootstrap extends BootstrapComponent
* @param LoggerService $loggerService
* @param ConfigurationService $configurationService
* @param StoreService $storeService
* @param StoreIntegrationService $storeIntegrationService
* @param VersionService $versionService
* @param SellingCountriesService $sellingCountriesService
* @param CategoryService $categoryService
Expand All @@ -155,6 +162,7 @@ public function __construct(
LoggerService $loggerService,
ConfigurationService $configurationService,
StoreService $storeService,
StoreIntegrationService $storeIntegrationService,
VersionService $versionService,
SellingCountriesService $sellingCountriesService,
CategoryService $categoryService,
Expand All @@ -171,6 +179,7 @@ public function __construct(
$this->loggerService = $loggerService;
$this->configurationService = $configurationService;
$this->storeService = $storeService;
$this->storeIntegrationService = $storeIntegrationService;
$this->versionService = $versionService;
$this->sellingCountriesService = $sellingCountriesService;
$this->categoryService = $categoryService;
Expand Down Expand Up @@ -258,6 +267,13 @@ static function () {
}
);

ServiceRegister::registerService(
StoreIntegrationServiceInterface::class,
static function () {
return static::$instance->storeIntegrationService;
}
);

ServiceRegister::registerService(
VersionServiceInterface::class,
static function () {
Expand Down
28 changes: 28 additions & 0 deletions Services/BusinessLogic/PromotionalWidget/WidgetConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Magento\Store\Model\Store;
use NumberFormatter;
use SeQura\Core\BusinessLogic\Domain\Integration\PromotionalWidgets\WidgetConfiguratorInterface;
use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Models\WidgetSettings;

class WidgetConfigurator implements WidgetConfiguratorInterface
{
Expand Down Expand Up @@ -83,6 +84,33 @@ public function getThousandsSeparator(): string
return (string) $this->getFormatter()->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
}

/**
* Returns an instance of WidgetSettings having the default values.
* See SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Models\WidgetSettings::createDefault().
*/
public function getDefaultWidgetSettings(): WidgetSettings
{
$productPriceSelector = '.price-container .price';
$productLocationSelector = '.actions .action.primary.tocart';
$cartPriceSelector = '.grand.totals .price';
$cartLocationSelector = '.cart-summary';
$listingPriceSelector = '';
$listingLocationSelector = '';
$altProductPriceSelector = '[data-price-type="finalPrice"] .price';
$altProductPriceTriggerSelector = '.bundle-actions';

return WidgetSettings::createDefault(
$productPriceSelector,
$productLocationSelector,
$cartPriceSelector,
$cartLocationSelector,
$listingPriceSelector,
$listingLocationSelector,
$altProductPriceSelector,
$altProductPriceTriggerSelector
);
}

/**
* Get formatter instance.
*
Expand Down
53 changes: 53 additions & 0 deletions Services/BusinessLogic/StoreIntegrationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Sequra\Core\Services\BusinessLogic;

use Magento\Framework\Exception\NoSuchEntityException;
use SeQura\Core\BusinessLogic\Domain\Integration\StoreIntegration\StoreIntegrationServiceInterface;
use SeQura\Core\BusinessLogic\Domain\StoreIntegration\Models\Capability;
use SeQura\Core\BusinessLogic\Domain\URL\Exceptions\InvalidUrlException;
use SeQura\Core\BusinessLogic\Domain\URL\Model\URL;
use Sequra\Core\Helper\UrlHelper;

class StoreIntegrationService implements StoreIntegrationServiceInterface
{
/**
* @var UrlHelper
*/
private $urlHelper;

/**
* @param UrlHelper $urlHelper
*/
public function __construct(urlHelper $urlHelper)
{
$this->urlHelper = $urlHelper;
}

/**
* Returns webhook url for integration.
*
* @return URL
*
* @throws NoSuchEntityException
* @throws InvalidUrlException
*/
public function getWebhookUrl(): URL
{
return new URL($this->urlHelper->getFrontendUrl('sequra/integrationwebhook/index'));
}

/**
* Returns an array of supported capabilities.
*
* @return Capability[]
*/
public function getSupportedCapabilities(): array
{
return [
Capability::storeInfo(),
Capability::general(),
Capability::widget()
];
}
}
41 changes: 41 additions & 0 deletions Setup/Patch/Data/Version400.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Sequra\Core\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use SeQura\Core\BusinessLogic\Domain\Migration\Tasks\StoreIntegrationMigrateTask;
use SeQura\Core\Infrastructure\Logger\Logger;
use Throwable;

class Version400 implements DataPatchInterface
{
/**
* @inheritDoc
*/
public static function getDependencies(): array
{
return [];
}

/**
* @inheritDoc
*/
public function getAliases(): array
{
return [];
}

/**
* @inheritDoc
*/
public function apply(): void
{
try {
(new StoreIntegrationMigrateTask())->execute();

Logger::logInfo('Migration ' . self::class . ' has been successfully finished.');
} catch (Throwable $e) {
Logger::logInfo('Update script V4.0.0 execution failed because: ' . $e->getMessage());
}
}
}
Loading