Skip to content

Commit

Permalink
1.59.5 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Apr 29, 2024
1 parent 8d02415 commit cb9680f
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 28 deletions.
36 changes: 36 additions & 0 deletions Block/Adminhtml/Walmart/Account/Edit/Tabs/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,42 @@ protected function _prepareForm()
]
);

$fieldset = $form->addFieldset(
'magento_orders_reservation_rules',
[
'legend' => __('Quantity Reservation'),
'collapsable' => true,
'tooltip' => __(
'Use Reserve Quantity Option to keep Items from being sold before an
Order is created in Magento.<br>
The Reserve Quantity Option ensures that Items are deducted from Magento stock immediately
upon an Order being imported from the channel. Reserved quantity will be used to create an Order
in Magento or will be released once the QTY reservation period expires.'
),
]
);

$values = [];
for ($day = 1; $day <= 14; $day++) {
if ($day == 1) {
$values[$day] = __('For %number day', ['number' => $day]);
} else {
$values[$day] = __('For %number days', ['number' => $day]);
}
}

$fieldset->addField(
'magento_orders_qty_reservation_days',
'select',
[
'container_id' => 'magento_orders_qty_reservation_days_container',
'name' => 'magento_orders_settings[qty_reservation][days]',
'label' => __('Reserve Quantity'),
'values' => $values,
'value' => $formData['magento_orders_settings']['qty_reservation']['days'],
]
);

$fieldset = $form->addFieldset(
'magento_block_walmart_accounts_magento_orders_refund_and_cancellation',
[
Expand Down
1 change: 1 addition & 0 deletions Model/ChangeTracker/Base/BasePriceTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ protected function getPriceColumnCondition(int $mode, $modeAttribute): string
protected function getCurrencyRateSubQuery(): \Zend_Db_Expr
{
$select = $this->queryBuilder->makeSubQuery();
$select->distinct();
$select->addSelect('store', 'listing.store_id');
$select->addSelect('marketplace', 'marketplace.marketplace_id');
$select->addSelect('rate', 'rate.rate');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ess\M2ePro\Model\ChangeTracker\Common\PriceCondition;

use Ess\M2ePro\Model\ChangeTracker\Common\QueryBuilder\ProductAttributesQueryBuilder;
use Ess\M2ePro\Model\Listing\Product\PriceRounder;

abstract class AbstractPriceCondition
{
Expand Down Expand Up @@ -52,9 +53,10 @@ public function getCondition(): string
$queryData[] = [
'when' => (int)$sellingPolicy['id'],
'then' => $this->buildThenCondition(
$priceColumn,
$sellingPolicy['modifier'],
$sellingPolicy['vat'],
$priceColumn
(float)$sellingPolicy['vat'],
(int)($sellingPolicy['price_rounding'] ?? PriceRounder::PRICE_ROUNDING_NONE)
),
];
}
Expand Down Expand Up @@ -122,15 +124,12 @@ protected function getPriceColumnCondition(int $mode, string $modeAttribute): st
);
}

/**
* @param string $modifiers
* @param float $vat
* @param string $priceColumn
*
* @return string
*/
protected function buildThenCondition(string $modifiers, float $vat, string $priceColumn): string
{
protected function buildThenCondition(
string $priceColumn,
string $modifiers,
float $vat,
int $priceRounding
): string {
$modifiers = json_decode($modifiers, true);
$sql = $priceColumn;
foreach ($modifiers as $modifier) {
Expand Down Expand Up @@ -185,6 +184,22 @@ protected function buildThenCondition(string $modifiers, float $vat, string $pri
}
}

return "ROUND( $sql * (1+$vat/100), 2)";
if ($priceRounding === PriceRounder::PRICE_ROUNDING_NEAREST_HUNDREDTH) {
return "ROUND( $sql * (1+$vat/100), 1 ) - 0.01";
}

if ($priceRounding === PriceRounder::PRICE_ROUNDING_NEAREST_TENTH) {
return "ROUND( $sql * (1+$vat/100) ) - 0.01";
}

if ($priceRounding === PriceRounder::PRICE_ROUNDING_NEAREST_INT) {
return "ROUND( $sql * (1+$vat/100) )";
}

if ($priceRounding === PriceRounder::PRICE_ROUNDING_NEAREST_HUNDRED) {
return "ROUND( $sql * (1+$vat/100), -1 )";
}

return "ROUND( $sql * (1+$vat/100), 2 )";
}
}
4 changes: 3 additions & 1 deletion Model/ChangeTracker/Common/PriceCondition/Amazon.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ protected function loadSellingPolicyData(): array
->addSelect('vat', 'regular_price_vat_percent')
->addSelect('modifier', 'regular_price_modifier')
->addSelect('mode', 'regular_price_mode')
->addSelect('mode_attribute', 'regular_price_custom_attribute');
->addSelect('mode_attribute', 'regular_price_custom_attribute')
->addSelect('price_rounding', 'price_rounding_option')
;

$sellingPolicyQuery->from('t', 'm2epro_amazon_template_selling_format');

Expand Down
4 changes: 3 additions & 1 deletion Model/ChangeTracker/Common/PriceCondition/Ebay.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ protected function loadSellingPolicyData(): array
)
->addSelect('modifier', 'fixed_price_modifier')
->addSelect('mode', 'fixed_price_mode')
->addSelect('mode_attribute', 'fixed_price_custom_attribute');
->addSelect('mode_attribute', 'fixed_price_custom_attribute')
->addSelect('price_rounding', 'fixed_price_rounding_option')
;

$sellingPolicyQuery->from('t', 'm2epro_ebay_template_selling_format');

Expand Down
4 changes: 3 additions & 1 deletion Model/ChangeTracker/Common/PriceCondition/Walmart.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ protected function loadSellingPolicyData(): array
->addSelect('vat', 'price_vat_percent')
->addSelect('modifier', 'price_modifier')
->addSelect('mode', 'price_mode')
->addSelect('mode_attribute', 'price_custom_attribute');
->addSelect('mode_attribute', 'price_custom_attribute')
->addSelect('price_rounding', 'price_rounding_option')
;

$sellingPolicyQuery->from('t', 'm2epro_walmart_template_selling_format');

Expand Down
4 changes: 4 additions & 0 deletions Model/Cron/Task/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ class Repository extends \Ess\M2ePro\Model\AbstractModel
'component' => \Ess\M2ePro\Helper\Component\Walmart::NICK,
'group' => self::GROUP_WALMART,
],
\Ess\M2ePro\Model\Cron\Task\Walmart\Order\ReserveCancel::NICK => [
'component' => \Ess\M2ePro\Helper\Component\Walmart::NICK,
'group' => self::GROUP_WALMART,
],
];

/** @var array */
Expand Down
126 changes: 126 additions & 0 deletions Model/Cron/Task/Walmart/Order/ReserveCancel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace Ess\M2ePro\Model\Cron\Task\Walmart\Order;

class ReserveCancel extends \Ess\M2ePro\Model\Cron\Task\AbstractModel
{
public const NICK = 'walmart/order/reserve_cancel';

/** @var \Ess\M2ePro\Model\ResourceModel\Order\CollectionFactory */
private $orderCollectionFactory;
/** @var \Ess\M2ePro\Model\ResourceModel\Account\CollectionFactory */
private $accountCollectionFactory;

public function __construct(
\Ess\M2ePro\Model\ResourceModel\Account\CollectionFactory $accountCollectionFactory,
\Ess\M2ePro\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
\Ess\M2ePro\Model\Cron\Manager $cronManager,
\Ess\M2ePro\Helper\Data $helperData,
\Magento\Framework\Event\Manager $eventManager,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Factory $parentFactory,
\Ess\M2ePro\Model\Factory $modelFactory,
\Ess\M2ePro\Model\ActiveRecord\Factory $activeRecordFactory,
\Ess\M2ePro\Helper\Factory $helperFactory,
\Ess\M2ePro\Model\Cron\Task\Repository $taskRepo,
\Magento\Framework\App\ResourceConnection $resource
) {
parent::__construct(
$cronManager,
$helperData,
$eventManager,
$parentFactory,
$modelFactory,
$activeRecordFactory,
$helperFactory,
$taskRepo,
$resource
);
$this->orderCollectionFactory = $orderCollectionFactory;
$this->accountCollectionFactory = $accountCollectionFactory;
}

protected function getSynchronizationLog(): \Ess\M2ePro\Model\Synchronization\Log
{
$synchronizationLog = parent::getSynchronizationLog();

$synchronizationLog->setComponentMode(\Ess\M2ePro\Helper\Component\Walmart::NICK);
$synchronizationLog->setSynchronizationTask(\Ess\M2ePro\Model\Synchronization\Log::TASK_ORDERS);

return $synchronizationLog;
}

// ----------------------------------------

protected function performActions()
{
$permittedAccounts = $this->getPermittedAccounts();
if (empty($permittedAccounts)) {
return;
}

$this->getSynchronizationLog()->setInitiator(\Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION);

foreach ($permittedAccounts as $account) {
$this->getOperationHistory()->addText('Starting Account "' . $account->getTitle() . '"');

try {
$this->processAccount($account);
} catch (\Exception $exception) {
$message = __(
'The "Reserve Cancellation" Action for Walmart Account "%account" was completed with error.',
['account' => $account->getTitle()]
);

$this->processTaskAccountException($message, __FILE__, __LINE__);
$this->processTaskException($exception);
}
}
}

// ----------------------------------------

/**
* @return \Ess\M2ePro\Model\Account[]
*/
private function getPermittedAccounts(): array
{
$accountsCollection = $this->accountCollectionFactory->createWithWalmartChildMode();

return $accountsCollection->getItems();
}

/**
* @throws \Ess\M2ePro\Model\Exception\Logic
*/
private function processAccount(\Ess\M2ePro\Model\Account $account)
{
foreach ($this->getOrdersForRelease($account) as $order) {
$order->getReserve()->release();
}
}

/**
* @return \Ess\M2ePro\Model\Order[]
* @throws \Ess\M2ePro\Model\Exception\Logic
* @throws \Exception
*/
private function getOrdersForRelease(\Ess\M2ePro\Model\Account $account): array
{
$collection = $this->orderCollectionFactory
->createWithWalmartChildMode()
->addFieldToFilter('account_id', $account->getId())
->addFieldToFilter('reservation_state', \Ess\M2ePro\Model\Order\Reserve::STATE_PLACED);

/** @var \Ess\M2ePro\Model\Walmart\Account $walmartAccount */
$walmartAccount = $account->getChildObject();
$reservationDays = $walmartAccount->getQtyReservationDays();

$minReservationStartDate = \Ess\M2ePro\Helper\Date::createCurrentGmt();
$minReservationStartDate->modify("- $reservationDays days");
$minReservationStartDate = $minReservationStartDate->format('Y-m-d H:i');

$collection->addFieldToFilter('reservation_start_date', ['lteq' => $minReservationStartDate]);

return $collection->getItems();
}
}
9 changes: 7 additions & 2 deletions Model/Ebay/Listing/Product/Action/Type/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ protected function validateIsVariationProductWithoutVariations()
protected function validateVariationsOptions(): bool
{
$totalVariationsCount = 0;
$totalVariationsCountWithoutDeleted = 0;
$totalDeletedVariationsCount = 0;
$uniqueAttributesValues = [];

Expand Down Expand Up @@ -350,10 +351,14 @@ protected function validateVariationsOptions(): bool
}

$totalVariationsCount++;
$ebayVariation->isDelete() && $totalDeletedVariationsCount++;
if ($ebayVariation->isDelete()) {
$totalDeletedVariationsCount++;
} else {
$totalVariationsCountWithoutDeleted++;
}

// Not more than 250 possible variations
if ($totalVariationsCount > 250) {
if ($totalVariationsCountWithoutDeleted > 250) {
$this->addMessage(
'Variations of this Magento Product are out of the eBay Variational Item limits.
The Number of Variations is more than 250. That is why, this Product cannot be updated on eBay.
Expand Down
1 change: 1 addition & 0 deletions Model/Setup/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class Upgrader
'1.59.1' => ['1.59.2'],
'1.59.2' => ['1.59.3'],
'1.59.3' => ['1.59.4'],
'1.59.4' => ['1.59.5'],
];

//########################################
Expand Down
12 changes: 6 additions & 6 deletions Model/Walmart/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,14 @@ public function getMagentoOrdersNumberWFSPrefix(): string

// ---------------------------------------

/**
* @return int
*/
public function getQtyReservationDays()
public function getQtyReservationDays(): int
{
$setting = $this->getSetting('magento_orders_settings', ['qty_reservation', 'days']);
$reservationDays = $this->getSetting('magento_orders_settings', ['qty_reservation', 'days']);
if (empty($reservationDays)) {
return 1;
}

return (int)$setting;
return (int)$reservationDays;
}

// ---------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions Model/Walmart/Account/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ protected function prepareData()
}
}

// qty reservation
// ---------------------------------------
if (isset($this->rawData['magento_orders_settings']['qty_reservation']['days'])) {
$data['magento_orders_settings']['qty_reservation']['days']
= $this->rawData['magento_orders_settings']['qty_reservation']['days'];
}

// Shipping information
// ---------------------------------------
$tempKey = 'shipping_information';
Expand Down Expand Up @@ -426,6 +433,9 @@ public function getDefaultData()
'ship_by_date' => 1,
'shipping_address_region_override' => 1,
],
'qty_reservation' => [
'days' => 1
]
],
'create_magento_invoice' => 1,
'create_magento_shipment' => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function prepare()
$this->getProcessingAction()->save();

$accountId = (int)$params['account_id'];
$sku = (string)$params['requester_params']['sku'];
$sku = (string)$params['request_data']['sku'];

$processingActionList = $this->activeRecordFactory->getObject('Walmart_Listing_Product_Action_ProcessingList');
$processingActionList->setData(
Expand Down
13 changes: 13 additions & 0 deletions Setup/Upgrade/v1_59_4__v1_59_5/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Ess\M2ePro\Setup\Upgrade\v1_59_4__v1_59_5;

use Ess\M2ePro\Model\Setup\Upgrade\Entity\AbstractConfig;

class Config extends AbstractConfig
{
public function getFeaturesList(): array
{
return [];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "m2e/ebay-amazon-magento2",
"description": "M2E Pro is a Magento trusted (TM), award-winning extension, which allows merchants of all sizes to fully integrate Magento based system(s) into eBay/Amazon/Walmart platforms.",
"type": "magento2-module",
"version": "1.59.4",
"version": "1.59.5",
"license": "proprietary",
"keywords": ["ebay", "amazon", "walmart", "magento"],
"homepage": "https://m2epro.com/",
Expand Down
Loading

0 comments on commit cb9680f

Please sign in to comment.