Skip to content

Commit cd38578

Browse files
committed
1.74.0 (FINAL RELEASE)
1 parent 736a766 commit cd38578

File tree

34 files changed

+553
-246
lines changed

34 files changed

+553
-246
lines changed

Controller/Adminhtml/Walmart/Listing/Product/Add/Index.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ public function stepOneSourceCategories()
257257
private function processStep3(\Ess\M2ePro\Model\Marketplace $marketplace): void
258258
{
259259
if (
260-
!$marketplace->getChildObject()
261-
->isSupportedProductType()
260+
$this->isMovedFromOther($this->getListing())
261+
|| !$marketplace->getChildObject()
262+
->isSupportedProductType()
262263
) {
263264
$this->review($marketplace);
264265

@@ -313,12 +314,16 @@ private function review(\Ess\M2ePro\Model\Marketplace $marketplace): void
313314
return;
314315
}
315316

316-
if ($marketplace->getChildObject()->isSupportedProductType()) {
317+
$isMovedFromOther = $this->isMovedFromOther($this->getListing());
318+
if (
319+
!$isMovedFromOther
320+
&& $marketplace->getChildObject()->isSupportedProductType()
321+
) {
317322
$this->removeProductsWithoutProductTypes($additionalData['adding_listing_products_ids']);
318323
}
319324

320325
//-- Remove successfully moved Unmanaged items
321-
if (isset($additionalData['source']) && $additionalData['source'] == SourceModeBlock::MODE_OTHER) {
326+
if ($isMovedFromOther) {
322327
$this->deleteListingOthers();
323328
}
324329
//--
@@ -349,6 +354,13 @@ private function review(\Ess\M2ePro\Model\Marketplace $marketplace): void
349354
$this->addContent($blockReview);
350355
}
351356

357+
private function isMovedFromOther(\Ess\M2ePro\Model\Listing $listing): bool
358+
{
359+
$source = $listing->getSettings('additional_data')['source'] ?? null;
360+
361+
return $source === SourceModeBlock::MODE_OTHER;
362+
}
363+
352364
private function removeProductsWithoutProductTypes(array $addingListingProductsIds): void
353365
{
354366
/** @var \Ess\M2ePro\Model\ResourceModel\Listing\Product\Collection $collection */

Helper/Component/Amazon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ class Amazon
3232
public const MARKETPLACE_BE = 48;
3333
public const MARKETPLACE_ZA = 49;
3434
public const MARKETPLACE_SA = 50;
35+
public const MARKETPLACE_IE = 51;
3536

3637
public const NATIVE_ID_MARKETPLACE_SA = 22;
38+
public const NATIVE_ID_MARKETPLACE_IE = 23;
3739

3840
public const EEA_COUNTRY_CODES = [
3941
'AT', 'BE', 'BG', 'HR', 'CY',

Model/Amazon/Order.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,15 @@ public function refund(array $items = [], Creditmemo $creditMemo = null)
937937
'items' => $items
938938
];
939939

940-
$orderId = $this->getParentObject()->getId();
940+
$isRefundAction = $this->isShipped()
941+
|| $this->isPartiallyShipped()
942+
|| $this->getParentObject()->isOrderStatusUpdatingToShipped();
941943

942-
$action = \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL;
943-
if (
944-
$this->isShipped() || $this->isPartiallyShipped() ||
945-
$this->getParentObject()->isOrderStatusUpdatingToShipped()
946-
) {
944+
$action = $isRefundAction
945+
? \Ess\M2ePro\Model\Order\Change::ACTION_REFUND
946+
: \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL;
947+
948+
if ($action == \Ess\M2ePro\Model\Order\Change::ACTION_REFUND) {
947949
if (empty($items)) {
948950
$this->getParentObject()->addErrorLog(
949951
'Amazon Order was not refunded. Reason: %msg%',
@@ -958,16 +960,31 @@ public function refund(array $items = [], Creditmemo $creditMemo = null)
958960
return false;
959961
}
960962

961-
$action = \Ess\M2ePro\Model\Order\Change::ACTION_REFUND;
963+
if (
964+
empty($adjustmentFee)
965+
&& empty($adjustmentRefund)
966+
&& empty($shippingRefund)
967+
&& empty(array_sum(array_column($items, 'cancelled_qty')))
968+
) {
969+
$this->getParentObject()->addErrorLog(
970+
'Amazon order cannot be refunded: The Credit Memo does not specify any refund amount. ' .
971+
'Please ensure the Credit Memo includes a refund cost to process the refund.',
972+
);
973+
974+
return false;
975+
}
962976
}
963977

964-
if ($action == \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL && $this->isCancellationRequested()) {
978+
if (
979+
$action == \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL
980+
&& $this->isCancellationRequested()
981+
) {
965982
$params['cancel_reason'] =
966983
\Ess\M2ePro\Model\Amazon\Order\Creditmemo\Handler::AMAZON_REFUND_REASON_BUYER_CANCELED;
967984
}
968985

969986
$this->activeRecordFactory->getObject('Order\Change')->create(
970-
$orderId,
987+
$this->getParentObject()->getId(),
971988
$action,
972989
$this->getParentObject()->getLog()->getInitiator(),
973990
\Ess\M2ePro\Helper\Component\Amazon::NICK,

Model/Amazon/Order/Creditmemo/Handler.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ protected function getItemsToRefund(
4545
$price = $creditmemoItem->getPrice() ?? 0.0;
4646
$tax = $creditmemoItem->getTaxAmount() ?? 0.0;
4747

48-
if ($price > $item->getChildObject()->getPrice()) {
49-
$price = $item->getChildObject()->getPrice();
50-
}
51-
52-
if ($tax > $item->getChildObject()->getTaxAmount()) {
53-
$tax = $item->getChildObject()->getTaxAmount();
54-
}
55-
5648
$cancelledItemQty = $cancelledQty;
5749
if ($cancelledItemQty > $item->getChildObject()->getQtyPurchased()) {
5850
$cancelledItemQty = $item->getChildObject()->getQtyPurchased();

Model/ChangeTracker/Base/BaseInventoryTracker.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,27 @@ abstract class BaseInventoryTracker implements TrackerInterface
2121
private $attributesQueryBuilder;
2222
/** @var \Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker */
2323
private $enterpriseChecker;
24+
private int $listingProductIdFrom;
25+
private int $listingProductIdTo;
2426

2527
public function __construct(
2628
string $channel,
2729
QueryBuilderFactory $queryBuilderFactory,
2830
InventoryStock $inventoryStock,
2931
ProductAttributesQueryBuilder $attributesQueryBuilder,
3032
TrackerLogger $logger,
31-
\Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker $enterpriseChecker
33+
\Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker $enterpriseChecker,
34+
int $listingProductIdFrom,
35+
int $listingProductIdTo
3236
) {
3337
$this->channel = $channel;
3438
$this->inventoryStock = $inventoryStock;
3539
$this->queryBuilder = $queryBuilderFactory->make();
3640
$this->logger = $logger;
3741
$this->attributesQueryBuilder = $attributesQueryBuilder;
3842
$this->enterpriseChecker = $enterpriseChecker;
43+
$this->listingProductIdFrom = $listingProductIdFrom;
44+
$this->listingProductIdTo = $listingProductIdTo;
3945
}
4046

4147
/**
@@ -54,6 +60,16 @@ public function getChannel(): string
5460
return $this->channel;
5561
}
5662

63+
public function getListingProductIdFrom(): int
64+
{
65+
return $this->listingProductIdFrom;
66+
}
67+
68+
public function getListingProductIdTo(): int
69+
{
70+
return $this->listingProductIdTo;
71+
}
72+
5773
/**
5874
* @return \Magento\Framework\DB\Select
5975
* @throws \Exception
@@ -145,6 +161,7 @@ public function getDataQuery(): \Magento\Framework\DB\Select
145161
'query' => (string)$mainQuery->getQuery(),
146162
'type' => $this->getType(),
147163
'channel' => $this->getChannel(),
164+
'tracker' => $this
148165
]);
149166

150167
return $mainQuery->getQuery();
@@ -216,6 +233,13 @@ protected function productSubQuery(): SelectQueryBuilder
216233
'lpvo',
217234
'm2epro_listing_product_variation_option',
218235
'lpvo.listing_product_variation_id = lpv.id'
236+
)
237+
->andWhere(
238+
sprintf(
239+
'lp.id >= %s AND lp.id <= %s',
240+
$this->getListingProductIdFrom(),
241+
$this->getListingProductIdTo()
242+
)
219243
);
220244

221245
/* We do not include grouped and bundle products in the selection */
@@ -367,7 +391,7 @@ protected function getSelectQuery(): SelectQueryBuilder
367391
->from('product', $this->productSubQuery())
368392
->innerJoin(
369393
'stock',
370-
$this->inventoryStock->getInventoryStockTableName(),
394+
$this->inventoryStock->getInventoryStockTableName($this),
371395
'product.product_id = stock.product_id'
372396
)
373397
->leftJoin(

Model/ChangeTracker/Base/BasePriceTracker.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ abstract class BasePriceTracker implements TrackerInterface
2020
protected $attributesQueryBuilder;
2121
/** @var \Ess\M2ePro\Model\ChangeTracker\Common\PriceCondition\AbstractPriceCondition */
2222
private $priceConditionBuilder;
23+
private int $listingProductIdFrom;
24+
private int $listingProductIdTo;
2325

2426
public function __construct(
2527
string $channel,
2628
QueryBuilderFactory $queryBuilderFactory,
2729
ProductAttributesQueryBuilder $attributesQueryBuilder,
2830
PriceConditionFactory $conditionFactory,
29-
TrackerLogger $logger
31+
TrackerLogger $logger,
32+
int $listingProductIdFrom,
33+
int $listingProductIdTo
3034
) {
3135
$this->channel = $channel;
3236
$this->queryBuilder = $queryBuilderFactory->make();
3337
$this->attributesQueryBuilder = $attributesQueryBuilder;
3438
$this->priceConditionBuilder = $conditionFactory->create($channel);
3539
$this->logger = $logger;
40+
$this->listingProductIdFrom = $listingProductIdFrom;
41+
$this->listingProductIdTo = $listingProductIdTo;
3642
}
3743

3844
/**
@@ -51,6 +57,16 @@ public function getChannel(): string
5157
return $this->channel;
5258
}
5359

60+
public function getListingProductIdFrom(): int
61+
{
62+
return $this->listingProductIdFrom;
63+
}
64+
65+
public function getListingProductIdTo(): int
66+
{
67+
return $this->listingProductIdTo;
68+
}
69+
5470
/**
5571
* Condition for select, in which we calculate the online price of the product.
5672
* @return string
@@ -174,6 +190,12 @@ protected function productSubQuery(): SelectQueryBuilder
174190
'marketplace',
175191
$this->setChannelToTableName('m2epro_%s_marketplace'),
176192
'marketplace.marketplace_id = l.marketplace_id'
193+
)->andWhere(
194+
sprintf(
195+
'lp.id >= %s AND lp.id <= %s',
196+
$this->getListingProductIdFrom(),
197+
$this->getListingProductIdTo()
198+
)
177199
);
178200

179201
/* We do not include grouped and bundle products */
@@ -222,7 +244,7 @@ protected function getSelectQuery(): SelectQueryBuilder
222244

223245
/* Required selects */
224246
$query->addSelect('listing_product_id', 'product.listing_product_id');
225-
$query->addSelect('calculated_price', $this->priceConditionBuilder->getCondition());
247+
$query->addSelect('calculated_price', $this->priceConditionBuilder->getCondition($this));
226248

227249
$query->addSelect('product_id', 'product.product_id')
228250
->addSelect('status', 'product.status')
@@ -346,11 +368,24 @@ protected function getCurrencyRateSubQuery(): \Zend_Db_Expr
346368
);
347369
$select->andWhere('listing.component_mode = ?', $this->getChannel());
348370

371+
$select->leftJoin(
372+
'listing_product',
373+
'm2epro_listing_product',
374+
'listing.id = listing_product.listing_id'
375+
)->andWhere(
376+
sprintf(
377+
'listing_product.id >= %s AND listing_product.id <= %s',
378+
$this->getListingProductIdFrom(),
379+
$this->getListingProductIdTo()
380+
)
381+
);
382+
349383
$ratesByStores = $select->fetchAll();
350384

351-
$this->logger->info('Get Currency Rates', [
385+
$this->logger->debug('Get Currency Rates', [
352386
'sql' => $select->getQuery()->__tostring(),
353387
'result' => $ratesByStores,
388+
'tracker' => $this,
354389
]);
355390

356391
if ($ratesByStores === []) {

Model/ChangeTracker/Base/ChangeHolder.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
*/
4343
public function holdChanges(TrackerInterface $tracker): void
4444
{
45-
$this->logger->info(sprintf("%s Start collect changes", $this->logTags($tracker)));
45+
$this->logger->info('Start collect changes', ['tracker' => $tracker]);
4646

4747
// Prepare SQL query
4848
$this->profiler->start();
@@ -53,11 +53,8 @@ public function holdChanges(TrackerInterface $tracker): void
5353
}
5454
$this->profiler->stop();
5555
$this->logger->info(
56-
sprintf(
57-
'%s Prepare SQL query time - <b>%s</b> sec.',
58-
$this->logTags($tracker),
59-
$this->profiler->getTime()
60-
)
56+
sprintf('Prepare SQL query time - <b>%s</b> sec.', $this->profiler->getTime()),
57+
['tracker' => $tracker]
6158
);
6259

6360
// Execute SQL query
@@ -70,11 +67,8 @@ public function holdChanges(TrackerInterface $tracker): void
7067
}
7168
$this->profiler->stop();
7269
$this->logger->info(
73-
sprintf(
74-
'%s Execute SQL query time - <b>%s</b> sec.',
75-
$this->logTags($tracker),
76-
$this->profiler->getTime()
77-
)
70+
sprintf('Execute SQL query time - <b>%s</b> sec.', $this->profiler->getTime()),
71+
['tracker' => $tracker]
7872
);
7973

8074
// Insert instruction
@@ -90,19 +84,13 @@ public function holdChanges(TrackerInterface $tracker): void
9084
}
9185
$this->profiler->stop();
9286
$this->logger->info(
93-
sprintf(
94-
'%s Insert instructions time - <b>%s</b> sec.',
95-
$this->logTags($tracker),
96-
$this->profiler->getTime()
97-
)
87+
sprintf('Insert instructions time - <b>%s</b> sec.', $this->profiler->getTime()),
88+
['tracker' => $tracker]
9889
);
9990

10091
$this->logger->info(
101-
sprintf(
102-
'%s Added instructions: <b>%s</b>',
103-
$this->logTags($tracker),
104-
$instructionCounter
105-
)
92+
sprintf('Added instructions: <b>%s</b>', $instructionCounter),
93+
['tracker' => $tracker]
10694
);
10795
}
10896

@@ -166,13 +154,4 @@ private function processException(\Throwable $exception): void
166154

167155
throw $exception;
168156
}
169-
170-
private function logTags(\Ess\M2ePro\Model\ChangeTracker\Base\TrackerInterface $tracker): string
171-
{
172-
return sprintf(
173-
'<b>%s</b> >> <b>%s</b> >>',
174-
strtoupper($tracker->getChannel()),
175-
strtoupper($tracker->getType())
176-
);
177-
}
178157
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ess\M2ePro\Model\ChangeTracker\Base;
6+
7+
class ChangeHolderFactory
8+
{
9+
private \Magento\Framework\ObjectManagerInterface $objectManager;
10+
11+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
12+
{
13+
$this->objectManager = $objectManager;
14+
}
15+
16+
public function create(): ChangeHolder
17+
{
18+
return $this->objectManager->create(ChangeHolder::class);
19+
}
20+
}

0 commit comments

Comments
 (0)