Skip to content

Commit

Permalink
Merge pull request #6 from wexo/6.5
Browse files Browse the repository at this point in the history
4.2.1 - Message queue serialization bugfix
  • Loading branch information
wexotht committed Jul 18, 2024
2 parents 1098c10 + 17e5808 commit c2b8e5b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.2.1
* Fehler bezüglich der Serialisierung der Nachrichtenwarteschlange behoben

# 4.2.0
* Autorisierungstoken zu allen Feeds hinzugefügt. Gehen Sie zu den Hello Retail-Vertriebskanälen und generieren Sie ein Token

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.2.1
* Fixed bug regarding message queue serialization

# 4.2.0
* Added authorization token to all feeds. Go to Hello Retail sales channels and generate token

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Hello Retail integration for Shopware 6",
"type": "shopware-platform-plugin",
"license": "proprietary",
"version": "4.2.0",
"version": "4.2.1",
"authors": [
{
"name": "WEXO A/S",
Expand Down
15 changes: 7 additions & 8 deletions src/Component/MessageQueue/HelloRetailExportHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceParameters;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Core\Framework\Uuid\Uuid;
Expand Down Expand Up @@ -65,15 +64,14 @@ public static function getHandledMessages(): iterable
public function __invoke(ExportEntityElement $message): void
{
$feedEntity = $message->getFeedEntity();
$salesChannelDomain = $feedEntity->getDomain();

$salesChannelId = $salesChannelDomain->getSalesChannelId();
$salesChannelId = $feedEntity->getSalesChannelId();
$salesChannelContext = $this->salesChannelContextService->get(new SalesChannelContextServiceParameters(
$salesChannelId,
'',
$salesChannelDomain->getLanguageId(),
$salesChannelDomain->getCurrencyId(),
$salesChannelDomain->getId()
$feedEntity->getSalesChannelDomainLanguageId(),
$feedEntity->getSalesChannelDomainCurrencyId(),
$feedEntity->getSalesChannelDomainId()
));

$context = $salesChannelContext->getContext();
Expand All @@ -95,8 +93,8 @@ public function __invoke(ExportEntityElement $message): void

$this->translator->injectSettings(
$salesChannelId,
$salesChannelDomain->getLanguageId(),
$salesChannelDomain->getLanguage()->getLocaleId(),
$feedEntity->getSalesChannelDomainLanguageId(),
$feedEntity->getSalesChannelDomainLanguageLocaleId(),
$context
);

Expand Down Expand Up @@ -193,6 +191,7 @@ public function __invoke(ExportEntityElement $message): void
$output = $this->helloRetailService->renderBody(
$feedEntity,
$salesChannelContext,
$feedEntity->getSalesChannelDomainUrl(),
$data
);

Expand Down
8 changes: 5 additions & 3 deletions src/Export/ExportEntityElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Helret\HelloRetail\Export;

class ExportEntityElement
use Shopware\Core\Framework\MessageQueue\AsyncMessageInterface;

class ExportEntityElement implements AsyncMessageInterface
{
protected ?array $allIds;
protected int $retryCount = 0;
Expand All @@ -11,7 +13,7 @@ class ExportEntityElement
public function __construct(
protected string $directory,
protected string $id,
protected FeedEntityInterface $feedEntity,
protected FeedEntity $feedEntity,
protected string $entityType,
protected string $templateType
) {
Expand All @@ -27,7 +29,7 @@ public function getId(): string
return $this->id;
}

public function getFeedEntity(): FeedEntityInterface
public function getFeedEntity(): FeedEntity
{
return $this->feedEntity;
}
Expand Down
69 changes: 62 additions & 7 deletions src/Export/FeedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,75 @@

namespace Helret\HelloRetail\Export;

use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainEntity;
use Shopware\Core\Framework\MessageQueue\AsyncMessageInterface;

class FeedEntity implements FeedEntityInterface
class FeedEntity implements FeedEntityInterface, AsyncMessageInterface
{
private string $feed;
private ?string $entity = null;
private string $feedDirectory;
private string $file;
private SalesChannelDomainEntity $salesChannelDomainEntity;
private string $salesChannelDomainId;
private string $salesChannelDomainLanguageId;
private string $salesChannelDomainLanguageLocaleId;
private string $salesChannelDomainCurrencyId;
private string $salesChannelId;
private string $salesChannelDomainUrl;
private array $associations = [];
private ?string $headerTemplate = null;
private ?string $bodyTemplate = null;
private ?string $footerTemplate = null;

public function getSalesChannelDomainUrl(): string
{
return $this->salesChannelDomainUrl;
}

public function setSalesChannelDomainUrl(string $salesChannelDomainUrl): void
{
$this->salesChannelDomainUrl = $salesChannelDomainUrl;
}

public function getSalesChannelDomainLanguageId(): string
{
return $this->salesChannelDomainLanguageId;
}

public function setSalesChannelDomainLanguageId(string $salesChannelDomainLanguageId): void
{
$this->salesChannelDomainLanguageId = $salesChannelDomainLanguageId;
}

public function getSalesChannelDomainLanguageLocaleId(): string
{
return $this->salesChannelDomainLanguageLocaleId;
}

public function setSalesChannelDomainLanguageLocaleId(string $salesChannelDomainLanguageLocaleId): void
{
$this->salesChannelDomainLanguageLocaleId = $salesChannelDomainLanguageLocaleId;
}

public function getSalesChannelDomainCurrencyId(): string
{
return $this->salesChannelDomainCurrencyId;
}

public function setSalesChannelDomainCurrencyId(string $salesChannelDomainCurrencyId): void
{
$this->salesChannelDomainCurrencyId = $salesChannelDomainCurrencyId;
}

public function getSalesChannelId(): string
{
return $this->salesChannelId;
}

public function setSalesChannelId(string $salesChannelId): void
{
$this->salesChannelId = $salesChannelId;
}

public function getFeed(): string
{
return $this->feed;
Expand All @@ -31,9 +86,9 @@ public function getFile(): string
return $this->file;
}

public function getDomain(): SalesChannelDomainEntity
public function getSalesChannelDomainId(): string
{
return $this->salesChannelDomainEntity;
return $this->salesChannelDomainId;
}

public function getAssociations(): array
Expand Down Expand Up @@ -71,9 +126,9 @@ public function setFile($file): void
$this->file = $file;
}

public function setDomain(SalesChannelDomainEntity $salesChannelDomainEntity): void
public function setSalesChannelDomainId(string $salesChannelDomainId): void
{
$this->salesChannelDomainEntity = $salesChannelDomainEntity;
$this->salesChannelDomainId = $salesChannelDomainId;
}

public function setAssociations($associations): void
Expand Down
6 changes: 2 additions & 4 deletions src/Export/FeedEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Helret\HelloRetail\Export;

use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainEntity;

interface FeedEntityInterface
{
public function getFeed(): string;
Expand All @@ -12,7 +10,7 @@ public function getFeedDirectory(): string;

public function getFile(): string;

public function getDomain(): SalesChannelDomainEntity;
public function getSalesChannelDomainId(): string;

public function getAssociations(): array;

Expand All @@ -28,7 +26,7 @@ public function setFeedDirectory(string $feedDirectory): void;

public function setFile(string $file): void;

public function setDomain(SalesChannelDomainEntity $salesChannelDomainEntity): void;
public function setSalesChannelDomainId(string $salesChannelDomainId): void;

public function setAssociations(array $associations): void;

Expand Down
26 changes: 12 additions & 14 deletions src/Service/HelloRetailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceParameters;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use TypeError;
use League\Flysystem\Filesystem;
use Monolog\Logger;
Expand All @@ -38,7 +31,6 @@
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\SerializerInterface;
Expand Down Expand Up @@ -134,7 +126,12 @@ public function export(ExportEntityInterface $exportEntity, string $feed): bool

$feedEntity->setFeedDirectory($exportEntity->getFeedDirectory());
$feedEntity->setFeed($feed);
$feedEntity->setDomain($salesChannelDomain);
$feedEntity->setSalesChannelDomainId($salesChannelDomain->getId());
$feedEntity->setSalesChannelDomainLanguageId($salesChannelDomain->getLanguageId());
$feedEntity->setSalesChannelDomainCurrencyId($salesChannelDomain->getCurrencyId());
$feedEntity->setSalesChannelDomainLanguageLocaleId($salesChannelDomain->getLanguage()->getLocaleId());
$feedEntity->setSalesChannelId($salesChannelDomain->getSalesChannelId());
$feedEntity->setSalesChannelDomainUrl($salesChannelDomain->getUrl());
$feedEntity->setEntity($exportFeed->getEntity());
$feedEntity->setFile($exportFeed->getFile());

Expand Down Expand Up @@ -241,7 +238,7 @@ public function export(ExportEntityInterface $exportEntity, string $feed): bool
);
$message->setExportConfig($config);

$this->bus->dispatch(new Envelope($message));
$this->bus->dispatch($message);
}

$footerElement = new ExportEntityElement(
Expand All @@ -255,7 +252,7 @@ public function export(ExportEntityInterface $exportEntity, string $feed): bool
$footerElement->setExportConfig($config);
$footerElement->setAllIds($entityIds);

$this->bus->dispatch(new Envelope($footerElement));
$this->bus->dispatch($footerElement);

return true;
}
Expand All @@ -271,11 +268,12 @@ public function renderHeader(
public function renderBody(
FeedEntityInterface $feedEntity,
SalesChannelContext $salesChannelContext,
string $domainUrl,
array $data = []
): string {
return $this->replaceSeoUrlPlaceholder(
$this->renderTemplate($feedEntity->getBodyTemplate(), $data, $salesChannelContext->getContext()),
$feedEntity->getDomain(),
$domainUrl,
$salesChannelContext
);
}
Expand All @@ -290,10 +288,10 @@ public function renderFooter(

public function replaceSeoUrlPlaceholder(
string $content,
SalesChannelDomainEntity $domain,
string $domainUrl,
SalesChannelContext $salesChannelContext
): string {
return $this->seoUrlPlaceholderHandler->replace($content, $domain->getUrl(), $salesChannelContext);
return $this->seoUrlPlaceholderHandler->replace($content, $domainUrl, $salesChannelContext);
}

public function exportLogger(
Expand Down

0 comments on commit c2b8e5b

Please sign in to comment.