Skip to content

Commit

Permalink
v3.0.3 (#77)
Browse files Browse the repository at this point in the history
* GAS-1805
* GAS-1964
* GAS-2138
  • Loading branch information
hellward authored Jun 10, 2024
1 parent 88364fa commit a79e0ca
Show file tree
Hide file tree
Showing 35 changed files with 564 additions and 78 deletions.
9 changes: 6 additions & 3 deletions Helper/Tracking/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ public function isFrontend(): bool
* Check is request use default scope
*
* @return bool
* @throws LocalizedException
*/
public function isAdminStore(): bool
public function isAdmin(): bool
{
return $this->isAdminLoggedIn() || $this->scopeResolver->getScope()->getCode() == Store::ADMIN_CODE;
return $this->isAdminLoggedIn() ||
$this->scopeResolver->getScope()->getCode() == Store::ADMIN_CODE ||
$this->state->getAreaCode() == Area::AREA_ADMINHTML;
}

/**
Expand All @@ -89,7 +92,7 @@ public function isAdminLoggedIn(): bool
*
* @return bool
*/
public function isLoggedIn(): bool
public function isCustomerLoggedIn(): bool
{
return $this->customerSession->isLoggedIn();
}
Expand Down
18 changes: 16 additions & 2 deletions MessageQueue/Consumer/Data/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Synerise\Integration\MessageQueue\Consumer\Data;

use Exception;
use Magento\Framework\Serialize\Serializer\Json;
use Synerise\Integration\Communication\Config;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\Model\MessageQueue\Retry;
Expand Down Expand Up @@ -56,28 +57,36 @@ class Item
*/
protected $filter;

/**
* @var Json
*/
protected $json;

/**
* @param Logger $logger
* @param ObjectManagerInterface $objectManager
* @param MessageEncoder $messageEncoder
* @param CollectionFactoryProvider $collectionFactoryProvider
* @param SenderFactory $senderFactory
* @param Filter $filter
* @param Json $json
*/
public function __construct(
Logger $logger,
ObjectManagerInterface $objectManager,
MessageEncoder $messageEncoder,
CollectionFactoryProvider $collectionFactoryProvider,
SenderFactory $senderFactory,
Filter $filter
Filter $filter,
Json $json
) {
$this->logger = $logger;
$this->objectManager = $objectManager;
$this->messageEncoder = $messageEncoder;
$this->collectionFactoryProvider = $collectionFactoryProvider;
$this->senderFactory = $senderFactory;
$this->filter = $filter;
$this->json = $json;
}

/**
Expand Down Expand Up @@ -146,7 +155,12 @@ protected function execute(ItemMessage $item)
$collection->addAttributeToSelect($attributes);
}

$sender->sendItems($collection, $item->getStoreId(), $item->getWebsiteId());
$sender->sendItems(
$collection,
$item->getStoreId(),
$item->getWebsiteId(),
$item->getOptions() ? $this->json->unserialize($item->getOptions()) : []
);
}

/**
Expand Down
36 changes: 33 additions & 3 deletions MessageQueue/Message/Data/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,33 @@ class Item
*/
private $retries;

/**
* @var string
*/
private $options;

/**
* @param string $model
* @param int $entity_id
* @param int $store_id
* @param int|null $website_id
* @param int $retries
*/
public function __construct(string $model, int $entity_id, int $store_id, ?int $website_id = null, int $retries = 0)
{
* @param string $options
*/
public function __construct(
string $model,
int $entity_id,
int $store_id,
?int $website_id = null,
int $retries = 0,
string $options = ''
) {
$this->model = $model;
$this->entityId = $entity_id;
$this->storeId = $store_id;
$this->websiteId = $website_id;
$this->retries = $retries;
$this->options = $options;

if ($model == Product::MODEL && !$website_id) {
throw new InvalidArgumentException('Website id required for Product');
Expand Down Expand Up @@ -155,4 +168,21 @@ public function setRetries(int $retries): void
{
$this->retries = $retries;
}

/**
* @return string
*/
public function getOptions(): string
{
return $this->options;
}

/**
* @param string $options
* @return void
*/
public function setOptions(string $options): void
{
$this->options = $options;
}
}
26 changes: 22 additions & 4 deletions MessageQueue/Publisher/Data/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Synerise\Integration\MessageQueue\Publisher\Data;

use Magento\Framework\MessageQueue\PublisherInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Synerise\Integration\MessageQueue\Message\Data\Item as MessageItem;

class Item
Expand All @@ -12,12 +13,19 @@ class Item
*/
private $publisher;

/**
* @var Json
*/
private $json;

/**
* @param PublisherInterface $publisher
* @param Json $json
*/
public function __construct(PublisherInterface $publisher)
public function __construct(PublisherInterface $publisher, Json $json)
{
$this->publisher = $publisher;
$this->json = $json;
}

public const TOPIC_NAME = 'synerise.queue.data.item';
Expand All @@ -28,12 +36,22 @@ public function __construct(PublisherInterface $publisher)
* @param string $model
* @param int $entityId
* @param int $storeId
* @param array $options
* @param int|null $websiteId
* @param int|null $retries
* @return void
*/
public function publish(string $model, int $entityId, int $storeId, ?int $websiteId = null, ?int $retries = 0)
{
$this->publisher->publish(self::TOPIC_NAME, new MessageItem($model, $entityId, $storeId, $websiteId, $retries));
public function publish(
string $model,
int $entityId,
int $storeId,
array $options = [],
?int $websiteId = null,
?int $retries = 0
) {
$this->publisher->publish(
self::TOPIC_NAME,
new MessageItem($model, $entityId, $storeId, $websiteId, $retries, $this->json->serialize($options))
);
}
}
1 change: 0 additions & 1 deletion MessageQueue/Publisher/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Synerise\Integration\MessageQueue\Publisher;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\MessageQueue\PublisherInterface;
use Magento\Framework\Serialize\Serializer\Json;

Expand Down
20 changes: 20 additions & 0 deletions Model/Tracking/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class ConfigFactory
*/
protected $objectManager = null;

/**
* @var Config[]
*/
protected $config;

/**
* Factory constructor
*
Expand All @@ -33,4 +38,19 @@ public function create(int $storeId): Config
{
return $this->objectManager->create(Config::class, ['storeId' => $storeId]);
}

/**
* Get tracking config for given store ID
*
* @param int $storeId
* @return Config
*/
public function get(int $storeId): Config
{
if (!isset($this->config[$storeId])) {
$this->config[$storeId] = $this->create($storeId);
}

return $this->config[$storeId];
}
}
10 changes: 8 additions & 2 deletions Observer/Data/OrderSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,21 @@ public function execute(Observer $observer)
return;
}

if ($this->stateHelper->isFrontend() && $order->getCustomerEmail()) {
if (!$this->stateHelper->isAdmin() && $order->getCustomerEmail()) {
$this->uuidHelper->manageByEmail(
$order->getCustomerEmail(),
$storeId
);
}

if ($this->synchronization->isModelEnabled(OrderSender::MODEL)) {
$this->dataItemPublisher->publish(OrderSender::MODEL, $order->getId(), $storeId);
$this->dataItemPublisher->publish(
OrderSender::MODEL, $order->getId(),
$storeId,
[
'snrs_params' => $this->cookieHelper->getSnrsParams()
]
);
}

if ($order->getCustomerIsGuest() && $order->getCustomerEmail()) {
Expand Down
23 changes: 10 additions & 13 deletions Observer/Data/ProductDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,23 @@ public function execute(Observer $observer)
$product = $observer->getEvent()->getProduct();

try {
$enabledStores = $this->synchronization->getConfiguredStores();
$productStores = $product->getStoreIds();
foreach ($productStores as $storeId) {
$config = $this->configFactory->create($storeId);
if (!$config->isEventTrackingEnabled(self::EVENT_FOR_CONFIG)) {
return;
}

if (in_array($storeId, $enabledStores)) {
$addItemRequest = $this->productCRUD->prepareRequest(
$product,
$this->getWebsiteIdByStoreId($storeId),
1
);

if ($config->isEventMessageQueueEnabled(self::EVENT_FOR_CONFIG)) {
$this->publisher->publish(self::EVENT, $addItemRequest, $storeId, $product->getEntityId());
} else {
$this->sender->deleteItem($addItemRequest, $storeId, $product->getEntityId());
}
$addItemRequest = $this->productCRUD->prepareRequest(
$product,
$this->getWebsiteIdByStoreId($storeId),
1
);

if ($config->isEventMessageQueueEnabled(self::EVENT_FOR_CONFIG)) {
$this->publisher->publish(self::EVENT, $addItemRequest, $storeId, $product->getEntityId());
} else {
$this->sender->deleteItem($addItemRequest, $storeId, $product->getEntityId());
}
}
} catch (\Exception $e) {
Expand Down
Loading

0 comments on commit a79e0ca

Please sign in to comment.