Skip to content

Commit

Permalink
1.74.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Dec 26, 2024
1 parent 736a766 commit cd38578
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 246 deletions.
20 changes: 16 additions & 4 deletions Controller/Adminhtml/Walmart/Listing/Product/Add/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ public function stepOneSourceCategories()
private function processStep3(\Ess\M2ePro\Model\Marketplace $marketplace): void
{
if (
!$marketplace->getChildObject()
->isSupportedProductType()
$this->isMovedFromOther($this->getListing())
|| !$marketplace->getChildObject()
->isSupportedProductType()
) {
$this->review($marketplace);

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

if ($marketplace->getChildObject()->isSupportedProductType()) {
$isMovedFromOther = $this->isMovedFromOther($this->getListing());
if (
!$isMovedFromOther
&& $marketplace->getChildObject()->isSupportedProductType()
) {
$this->removeProductsWithoutProductTypes($additionalData['adding_listing_products_ids']);
}

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

private function isMovedFromOther(\Ess\M2ePro\Model\Listing $listing): bool
{
$source = $listing->getSettings('additional_data')['source'] ?? null;

return $source === SourceModeBlock::MODE_OTHER;
}

private function removeProductsWithoutProductTypes(array $addingListingProductsIds): void
{
/** @var \Ess\M2ePro\Model\ResourceModel\Listing\Product\Collection $collection */
Expand Down
2 changes: 2 additions & 0 deletions Helper/Component/Amazon.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class Amazon
public const MARKETPLACE_BE = 48;
public const MARKETPLACE_ZA = 49;
public const MARKETPLACE_SA = 50;
public const MARKETPLACE_IE = 51;

public const NATIVE_ID_MARKETPLACE_SA = 22;
public const NATIVE_ID_MARKETPLACE_IE = 23;

public const EEA_COUNTRY_CODES = [
'AT', 'BE', 'BG', 'HR', 'CY',
Expand Down
35 changes: 26 additions & 9 deletions Model/Amazon/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,13 +937,15 @@ public function refund(array $items = [], Creditmemo $creditMemo = null)
'items' => $items
];

$orderId = $this->getParentObject()->getId();
$isRefundAction = $this->isShipped()
|| $this->isPartiallyShipped()
|| $this->getParentObject()->isOrderStatusUpdatingToShipped();

$action = \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL;
if (
$this->isShipped() || $this->isPartiallyShipped() ||
$this->getParentObject()->isOrderStatusUpdatingToShipped()
) {
$action = $isRefundAction
? \Ess\M2ePro\Model\Order\Change::ACTION_REFUND
: \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL;

if ($action == \Ess\M2ePro\Model\Order\Change::ACTION_REFUND) {
if (empty($items)) {
$this->getParentObject()->addErrorLog(
'Amazon Order was not refunded. Reason: %msg%',
Expand All @@ -958,16 +960,31 @@ public function refund(array $items = [], Creditmemo $creditMemo = null)
return false;
}

$action = \Ess\M2ePro\Model\Order\Change::ACTION_REFUND;
if (
empty($adjustmentFee)
&& empty($adjustmentRefund)
&& empty($shippingRefund)
&& empty(array_sum(array_column($items, 'cancelled_qty')))
) {
$this->getParentObject()->addErrorLog(
'Amazon order cannot be refunded: The Credit Memo does not specify any refund amount. ' .
'Please ensure the Credit Memo includes a refund cost to process the refund.',
);

return false;
}
}

if ($action == \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL && $this->isCancellationRequested()) {
if (
$action == \Ess\M2ePro\Model\Order\Change::ACTION_CANCEL
&& $this->isCancellationRequested()
) {
$params['cancel_reason'] =
\Ess\M2ePro\Model\Amazon\Order\Creditmemo\Handler::AMAZON_REFUND_REASON_BUYER_CANCELED;
}

$this->activeRecordFactory->getObject('Order\Change')->create(
$orderId,
$this->getParentObject()->getId(),
$action,
$this->getParentObject()->getLog()->getInitiator(),
\Ess\M2ePro\Helper\Component\Amazon::NICK,
Expand Down
8 changes: 0 additions & 8 deletions Model/Amazon/Order/Creditmemo/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ protected function getItemsToRefund(
$price = $creditmemoItem->getPrice() ?? 0.0;
$tax = $creditmemoItem->getTaxAmount() ?? 0.0;

if ($price > $item->getChildObject()->getPrice()) {
$price = $item->getChildObject()->getPrice();
}

if ($tax > $item->getChildObject()->getTaxAmount()) {
$tax = $item->getChildObject()->getTaxAmount();
}

$cancelledItemQty = $cancelledQty;
if ($cancelledItemQty > $item->getChildObject()->getQtyPurchased()) {
$cancelledItemQty = $item->getChildObject()->getQtyPurchased();
Expand Down
28 changes: 26 additions & 2 deletions Model/ChangeTracker/Base/BaseInventoryTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ abstract class BaseInventoryTracker implements TrackerInterface
private $attributesQueryBuilder;
/** @var \Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker */
private $enterpriseChecker;
private int $listingProductIdFrom;
private int $listingProductIdTo;

public function __construct(
string $channel,
QueryBuilderFactory $queryBuilderFactory,
InventoryStock $inventoryStock,
ProductAttributesQueryBuilder $attributesQueryBuilder,
TrackerLogger $logger,
\Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker $enterpriseChecker
\Ess\M2ePro\Model\ChangeTracker\Common\Helpers\EnterpriseChecker $enterpriseChecker,
int $listingProductIdFrom,
int $listingProductIdTo
) {
$this->channel = $channel;
$this->inventoryStock = $inventoryStock;
$this->queryBuilder = $queryBuilderFactory->make();
$this->logger = $logger;
$this->attributesQueryBuilder = $attributesQueryBuilder;
$this->enterpriseChecker = $enterpriseChecker;
$this->listingProductIdFrom = $listingProductIdFrom;
$this->listingProductIdTo = $listingProductIdTo;
}

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

public function getListingProductIdFrom(): int
{
return $this->listingProductIdFrom;
}

public function getListingProductIdTo(): int
{
return $this->listingProductIdTo;
}

/**
* @return \Magento\Framework\DB\Select
* @throws \Exception
Expand Down Expand Up @@ -145,6 +161,7 @@ public function getDataQuery(): \Magento\Framework\DB\Select
'query' => (string)$mainQuery->getQuery(),
'type' => $this->getType(),
'channel' => $this->getChannel(),
'tracker' => $this
]);

return $mainQuery->getQuery();
Expand Down Expand Up @@ -216,6 +233,13 @@ protected function productSubQuery(): SelectQueryBuilder
'lpvo',
'm2epro_listing_product_variation_option',
'lpvo.listing_product_variation_id = lpv.id'
)
->andWhere(
sprintf(
'lp.id >= %s AND lp.id <= %s',
$this->getListingProductIdFrom(),
$this->getListingProductIdTo()
)
);

/* We do not include grouped and bundle products in the selection */
Expand Down Expand Up @@ -367,7 +391,7 @@ protected function getSelectQuery(): SelectQueryBuilder
->from('product', $this->productSubQuery())
->innerJoin(
'stock',
$this->inventoryStock->getInventoryStockTableName(),
$this->inventoryStock->getInventoryStockTableName($this),
'product.product_id = stock.product_id'
)
->leftJoin(
Expand Down
41 changes: 38 additions & 3 deletions Model/ChangeTracker/Base/BasePriceTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ abstract class BasePriceTracker implements TrackerInterface
protected $attributesQueryBuilder;
/** @var \Ess\M2ePro\Model\ChangeTracker\Common\PriceCondition\AbstractPriceCondition */
private $priceConditionBuilder;
private int $listingProductIdFrom;
private int $listingProductIdTo;

public function __construct(
string $channel,
QueryBuilderFactory $queryBuilderFactory,
ProductAttributesQueryBuilder $attributesQueryBuilder,
PriceConditionFactory $conditionFactory,
TrackerLogger $logger
TrackerLogger $logger,
int $listingProductIdFrom,
int $listingProductIdTo
) {
$this->channel = $channel;
$this->queryBuilder = $queryBuilderFactory->make();
$this->attributesQueryBuilder = $attributesQueryBuilder;
$this->priceConditionBuilder = $conditionFactory->create($channel);
$this->logger = $logger;
$this->listingProductIdFrom = $listingProductIdFrom;
$this->listingProductIdTo = $listingProductIdTo;
}

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

public function getListingProductIdFrom(): int
{
return $this->listingProductIdFrom;
}

public function getListingProductIdTo(): int
{
return $this->listingProductIdTo;
}

/**
* Condition for select, in which we calculate the online price of the product.
* @return string
Expand Down Expand Up @@ -174,6 +190,12 @@ protected function productSubQuery(): SelectQueryBuilder
'marketplace',
$this->setChannelToTableName('m2epro_%s_marketplace'),
'marketplace.marketplace_id = l.marketplace_id'
)->andWhere(
sprintf(
'lp.id >= %s AND lp.id <= %s',
$this->getListingProductIdFrom(),
$this->getListingProductIdTo()
)
);

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

/* Required selects */
$query->addSelect('listing_product_id', 'product.listing_product_id');
$query->addSelect('calculated_price', $this->priceConditionBuilder->getCondition());
$query->addSelect('calculated_price', $this->priceConditionBuilder->getCondition($this));

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

$select->leftJoin(
'listing_product',
'm2epro_listing_product',
'listing.id = listing_product.listing_id'
)->andWhere(
sprintf(
'listing_product.id >= %s AND listing_product.id <= %s',
$this->getListingProductIdFrom(),
$this->getListingProductIdTo()
)
);

$ratesByStores = $select->fetchAll();

$this->logger->info('Get Currency Rates', [
$this->logger->debug('Get Currency Rates', [
'sql' => $select->getQuery()->__tostring(),
'result' => $ratesByStores,
'tracker' => $this,
]);

if ($ratesByStores === []) {
Expand Down
39 changes: 9 additions & 30 deletions Model/ChangeTracker/Base/ChangeHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function holdChanges(TrackerInterface $tracker): void
{
$this->logger->info(sprintf("%s Start collect changes", $this->logTags($tracker)));
$this->logger->info('Start collect changes', ['tracker' => $tracker]);

// Prepare SQL query
$this->profiler->start();
Expand All @@ -53,11 +53,8 @@ public function holdChanges(TrackerInterface $tracker): void
}
$this->profiler->stop();
$this->logger->info(
sprintf(
'%s Prepare SQL query time - <b>%s</b> sec.',
$this->logTags($tracker),
$this->profiler->getTime()
)
sprintf('Prepare SQL query time - <b>%s</b> sec.', $this->profiler->getTime()),
['tracker' => $tracker]
);

// Execute SQL query
Expand All @@ -70,11 +67,8 @@ public function holdChanges(TrackerInterface $tracker): void
}
$this->profiler->stop();
$this->logger->info(
sprintf(
'%s Execute SQL query time - <b>%s</b> sec.',
$this->logTags($tracker),
$this->profiler->getTime()
)
sprintf('Execute SQL query time - <b>%s</b> sec.', $this->profiler->getTime()),
['tracker' => $tracker]
);

// Insert instruction
Expand All @@ -90,19 +84,13 @@ public function holdChanges(TrackerInterface $tracker): void
}
$this->profiler->stop();
$this->logger->info(
sprintf(
'%s Insert instructions time - <b>%s</b> sec.',
$this->logTags($tracker),
$this->profiler->getTime()
)
sprintf('Insert instructions time - <b>%s</b> sec.', $this->profiler->getTime()),
['tracker' => $tracker]
);

$this->logger->info(
sprintf(
'%s Added instructions: <b>%s</b>',
$this->logTags($tracker),
$instructionCounter
)
sprintf('Added instructions: <b>%s</b>', $instructionCounter),
['tracker' => $tracker]
);
}

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

throw $exception;
}

private function logTags(\Ess\M2ePro\Model\ChangeTracker\Base\TrackerInterface $tracker): string
{
return sprintf(
'<b>%s</b> >> <b>%s</b> >>',
strtoupper($tracker->getChannel()),
strtoupper($tracker->getType())
);
}
}
20 changes: 20 additions & 0 deletions Model/ChangeTracker/Base/ChangeHolderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Ess\M2ePro\Model\ChangeTracker\Base;

class ChangeHolderFactory
{
private \Magento\Framework\ObjectManagerInterface $objectManager;

public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}

public function create(): ChangeHolder
{
return $this->objectManager->create(ChangeHolder::class);
}
}
Loading

0 comments on commit cd38578

Please sign in to comment.