Skip to content

Commit 33161f4

Browse files
alexandr-parkhomenko24198
authored andcommitted
MM-35: Fix issue 'Removed special product price won't sync on Magento side' (#58)
1 parent eddf031 commit 33161f4

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/Marello/Bundle/Magento2Bundle/EventListener/Doctrine/ProductPriceListener.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,36 @@ class ProductPriceListener
3030
/** @var ProductRepository */
3131
protected $productRepository;
3232

33+
/** @var array */
34+
protected $trackedPriceTypes;
35+
3336
/**
3437
* @param ProductChangesByChannelStack $productChangesStack
3538
* @param TrackedSalesChannelProvider $salesChannelProvider
3639
* @param ProductRepository $productRepository
40+
* @param array $trackedPriceTypes
3741
*/
3842
public function __construct(
3943
ProductChangesByChannelStack $productChangesStack,
4044
TrackedSalesChannelProvider $salesChannelProvider,
41-
ProductRepository $productRepository
45+
ProductRepository $productRepository,
46+
array $trackedPriceTypes
4247
) {
4348
$this->productChangesStack = $productChangesStack;
4449
$this->salesChannelProvider = $salesChannelProvider;
4550
$this->productRepository = $productRepository;
51+
$this->trackedPriceTypes = $trackedPriceTypes;
4652
}
4753

4854
/**
4955
* @param OnFlushEventArgs $args
5056
*/
5157
public function onFlush(OnFlushEventArgs $args)
5258
{
59+
if (empty($this->trackedPriceTypes)) {
60+
return;
61+
}
62+
5363
if (false === $this->salesChannelProvider->hasTrackedSalesChannels(false)) {
5464
return;
5565
}
@@ -78,9 +88,14 @@ protected function loadRemovedAndCreatedEntities(UnitOfWork $unitOfWork): void
7888
$salesChannelInfoArray = $this->salesChannelProvider->getSalesChannelsInfoArray();
7989
$currenciesWSChInfos = $this->salesChannelProvider->getTrackedSalesChannelCurrenciesWithSalesChannelInfos();
8090
foreach ($entities as $entity) {
81-
if (($entity instanceof ProductChannelPrice || $entity instanceof ProductPrice) &&
82-
$entity->getProduct()->getId() === null) {
83-
continue;
91+
if ($entity instanceof ProductChannelPrice || $entity instanceof ProductPrice) {
92+
if ($entity->getProduct()->getId() === null) {
93+
continue;
94+
}
95+
96+
if (!\in_array($entity->getType()->getName(), $this->trackedPriceTypes, true)) {
97+
continue;
98+
}
8499
}
85100

86101
if ($entity instanceof ProductChannelPrice) {
@@ -112,6 +127,12 @@ protected function loadUpdatedEntities(UnitOfWork $unitOfWork): void
112127
$salesChannelInfoArray = $this->salesChannelProvider->getSalesChannelsInfoArray();
113128
$currenciesWSChInfos = $this->salesChannelProvider->getTrackedSalesChannelCurrenciesWithSalesChannelInfos();
114129
foreach ($entities as $entity) {
130+
if ($entity instanceof ProductChannelPrice || $entity instanceof ProductPrice) {
131+
if (!\in_array($entity->getType()->getName(), $this->trackedPriceTypes, true)) {
132+
continue;
133+
}
134+
}
135+
115136
if ($entity instanceof ProductChannelPrice) {
116137
$entityChangeSet = $unitOfWork->getEntityChangeSet($entity);
117138
if (\array_key_exists(self::PRICE_CHANNEL_FIELD_NAME, $entityChangeSet)) {

src/Marello/Bundle/Magento2Bundle/Resources/config/services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ services:
6060
- '@marello_magento2.stack.product_changes_by_channel'
6161
- '@marello_magento2.provider.tracked_sales_channel'
6262
- '@marello_product.repository.product'
63+
-
64+
- !php/const Marello\Bundle\PricingBundle\Model\PriceTypeInterface::DEFAULT_PRICE
65+
- !php/const Marello\Bundle\PricingBundle\Model\PriceTypeInterface::SPECIAL_PRICE
6366
tags:
6467
- { name: doctrine.event_listener, event: onFlush }
6568

0 commit comments

Comments
 (0)