Skip to content

Commit

Permalink
6.38.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Apr 24, 2023
1 parent 8fe7aae commit 5dc853c
Show file tree
Hide file tree
Showing 33 changed files with 190 additions and 481 deletions.
12 changes: 12 additions & 0 deletions app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @license Commercial use is forbidden
*/

use Ess_M2ePro_Model_Resource_Amazon_Listing_Product as Resource;

/**
* @method Ess_M2ePro_Model_Listing_Product getParentObject()
*/
Expand Down Expand Up @@ -1217,4 +1219,14 @@ public function mapChannelItemProduct()
}

//########################################

/**
* @return bool
*/
public function isStoppedManually()
{
return (bool)$this->getData(Resource::IS_STOPPED_MANUALLY_FIELD);
}

//########################################
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function processSuccess($params = array())
);

$data = $this->appendStatusChangerValue($data);
$data = $this->appendIsStoppedManually($data, false);

$this->getListingProduct()->addData($data);
$this->getListingProduct()->save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function processSuccess($params = array())
$data = $this->appendIdentifiersData($data, $generalId);
$data = $this->appendDetailsValues($data);
$data = $this->appendImagesValues($data);
$data = $this->appendIsStoppedManually($data, false);

$variationManager = $this->getAmazonListingProduct()->getVariationManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function processSuccess($params = array())
$data = $this->appendBusinessPriceValues($data);

$data = $this->processRecheckInstructions($data);
$data = $this->appendIsStoppedManually($data, false);

if (isset($data['additional_data'])) {
$data['additional_data'] = Mage::helper('M2ePro')->jsonEncode($data['additional_data']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ protected function appendImagesValues($data)
return $data;
}

/**
* @param array $data
* @param bool $value
* @return array
*/
protected function appendIsStoppedManually($data, $value)
{
$data[Ess_M2ePro_Model_Resource_Amazon_Listing_Product::IS_STOPPED_MANUALLY_FIELD] = $value;
return $data;
}

//########################################

protected function appendGiftSettingsStatus($data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function processSuccess($params = array())
$data = $this->appendGiftSettingsStatus($data);
$data = $this->appendDetailsValues($data);
$data = $this->appendImagesValues($data);
$data = $this->appendIsStoppedManually($data, false);

if (isset($data['additional_data'])) {
$data['additional_data'] = Mage::helper('M2ePro')->jsonEncode($data['additional_data']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function processSuccess($params = array())
$data = $this->appendStatusChangerValue($data);
$data = $this->appendQtyValues($data);

$isStoppedManually = $this->getListingProduct()->isStopped() && $this->getListingProduct()->getStatusChanger()
=== Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER;
$data = $this->appendIsStoppedManually($data, $isStoppedManually);

$this->getListingProduct()->addData($data);

$this->setLastSynchronizationDates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ public function isMeetRelistRequirements()
return false;
}

if ($amazonSynchronizationTemplate->isRelistFilterUserLock() &&
$listingProduct->getStatusChanger() == Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER) {
if (
$amazonSynchronizationTemplate->isRelistFilterUserLock()
&& $amazonListingProduct->isStoppedManually()
) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public function processEbayOrders(Ess_M2ePro_Model_Account $account, array $orde
{
$orders = array();
$accountCreateDate = new DateTime($account->getData('create_date'), new DateTimeZone('UTC'));
$boundaryCreationDate = (new DateTime('now', new DateTimeZone('UTC')));
$boundaryCreationDate = $boundaryCreationDate->modify('-90 days');

foreach ($ordersData as $ebayOrderData) {
try {
$orderCreateDate = new DateTime($ebayOrderData['purchase_create_date'], new DateTimeZone('UTC'));
if ($this->_validateAccountCreateDate && $orderCreateDate < $accountCreateDate) {
if (
$this->_validateAccountCreateDate
&& ($orderCreateDate < $accountCreateDate || $orderCreateDate < $boundaryCreationDate)
) {
continue;
}

Expand Down
4 changes: 0 additions & 4 deletions app/code/community/Ess/M2ePro/Model/Cron/Task/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ class Ess_M2ePro_Model_Cron_Task_Repository
'component' => Ess_M2ePro_Helper_Component_Walmart::NICK,
'group' => self::GROUP_WALMART,
),
Ess_M2ePro_Model_Cron_Task_Walmart_Order_ReceiveWithCancellationRequested::NICK => array(
'component' => Ess_M2ePro_Helper_Component_Walmart::NICK,
'group' => self::GROUP_WALMART,
),
Ess_M2ePro_Model_Cron_Task_Walmart_Order_CreateFailed::NICK => array(
'component' => Ess_M2ePro_Helper_Component_Walmart::NICK,
'group' => self::GROUP_WALMART,
Expand Down
164 changes: 39 additions & 125 deletions app/code/community/Ess/M2ePro/Model/Cron/Task/Walmart/Order/Receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function performActions()
$processedWalmartOrders = $ordersCreator->processWalmartOrders($account, $responseData['items']);
$ordersCreator->processMagentoOrders($processedWalmartOrders);

$account->getChildObject()->setData('orders_last_synchronization', $responseData['to_create_date']);
$account->getChildObject()->setData('orders_last_synchronization', $responseData['to_update_date']);
$account->getChildObject()->save();
} catch (Exception $exception) {
$message = Mage::helper('M2ePro')->__(
Expand All @@ -84,7 +84,7 @@ protected function performActions()
protected function receiveWalmartOrdersData(Ess_M2ePro_Model_Account $account)
{
$fromDate = $this->prepareFromDate($account->getData('orders_last_synchronization'));
$toDate = $this->prepareToDate();
$toDate = new DateTime('now', new DateTimeZone('UTC'));

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

Expand All @@ -97,64 +97,53 @@ protected function receiveWalmartOrdersData(Ess_M2ePro_Model_Account $account)

/** @var Ess_M2ePro_Model_Walmart_Connector_Dispatcher $dispatcherObject */
$dispatcherObject = Mage::getModel('M2ePro/Walmart_Connector_Dispatcher');
$orders = array(array());
$breakDate = null;

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

do {
$connectorObj = $dispatcherObject->getVirtualConnector(
'orders', 'get', 'items',
array(
'account' => $account->getData('server_hash'),
'from_create_date' => $fromDate->format('Y-m-d H:i:s'),
'to_create_date' => $toDate->format('Y-m-d H:i:s')
)
);
$dispatcherObject->process($connectorObj);

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

$this->processResponseMessages($connectorObj->getResponseMessages());

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

$responseData = $connectorObj->getResponseData();
if (!isset($responseData['items']) || !isset($responseData['to_create_date'])) {
Mage::helper('M2ePro/Module_Logger')->process(
array(
'from_create_date' => $fromDate->format('Y-m-d H:i:s'),
'to_create_date' => $toDate->format('Y-m-d H:i:s'),
'account_id' => $account->getId(),
'response_data' => $responseData,
'response_messages' => $connectorObj->getResponseMessages()
),
'Walmart orders receive task - empty response'
);
$connectorObj = $dispatcherObject->getVirtualConnector(
'orders',
'get',
'items',
array(
'account' => $account->getData('server_hash'),
'from_update_date' => $fromDate->format('Y-m-d H:i:s'),
'to_update_date' => $toDate->format('Y-m-d H:i:s')
)
);
$dispatcherObject->process($connectorObj);

return array();
}
// ----------------------------------------

// ----------------------------------------
$this->processResponseMessages($connectorObj->getResponseMessages());

$fromDate = new DateTime($responseData['to_create_date'], new DateTimeZone('UTC'));
if ($breakDate !== null && $breakDate->getTimestamp() === $fromDate->getTimestamp()) {
break;
}
// ----------------------------------------

$orders[] = $responseData['items'];
$breakDate = $fromDate;
$responseData = $connectorObj->getResponseData();
if (!isset($responseData['items'])) {
Mage::helper('M2ePro/Module_Logger')->process(
array(
'from_update_date' => $fromDate->format('Y-m-d H:i:s'),
'to_update_date' => $toDate->format('Y-m-d H:i:s'),
'account_id' => $account->getId(),
'response_data' => $responseData,
'response_messages' => $connectorObj->getResponseMessages()
),
'Walmart orders receive task - empty response'
);

if ($fromDate > $toDate) {
break;
}
} while (!empty($responseData['items']));
return array();
}

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

return array(
'items' => call_user_func_array('array_merge', $orders),
'to_create_date' => $responseData['to_create_date']
'items' => $responseData['items'],
'to_create_date' => isset($responseData['to_create_date'])
? $responseData['to_create_date']
: $toDate->format('Y-m-d H:i:s'),
'to_update_date' => count($responseData['items']) > 0
? $responseData['to_update_date']
: $toDate->format('Y-m-d H:i:s'),
);
}

Expand All @@ -179,45 +168,6 @@ protected function processResponseMessages(array $messages = array())
}
}

//########################################

/**
* @param DateTime $minPurchaseDateTime
* @return DateTime|null
* @throws Exception
*/
protected function getMinPurchaseDateTime(DateTime $minPurchaseDateTime)
{
/** @var Ess_M2ePro_Model_Resource_Order_Collection $collection */
$collection = Mage::helper('M2ePro/Component_Walmart')->getCollection('Order');
$collection->addFieldToFilter(
'status',
array(
'from' => Ess_M2ePro_Model_Walmart_Order::STATUS_CREATED,
'to' => Ess_M2ePro_Model_Walmart_Order::STATUS_SHIPPED_PARTIALLY
)
);
$collection->addFieldToFilter(
'purchase_create_date',
array('from' => $minPurchaseDateTime->format('Y-m-d H:i:s'))
);
$collection->getSelect()->limit(1);

/** @var Ess_M2ePro_Model_Order $order */
$order = $collection->getFirstItem();
if ($order->getId() === null) {
return null;
}

$purchaseDateTime = new DateTime(
$order->getChildObject()->getPurchaseCreateDate(),
new DateTimeZone('UTC')
);
$purchaseDateTime->modify('-1 second');

return $purchaseDateTime;
}

//####################################

/**
Expand All @@ -233,49 +183,13 @@ protected function prepareFromDate($lastFromDate)

if (!empty($lastFromDate)) {
$lastFromDate = new DateTime($lastFromDate, new DateTimeZone('UTC'));
}

if (empty($lastFromDate)) {
} else {
$lastFromDate = clone $nowDateTime;
$lastFromDate = $lastFromDate->modify('-1 day');
}

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

$minDateTime = clone $nowDateTime;
$minDateTime->modify('-1 day');

if ($lastFromDate > $minDateTime) {
$minPurchaseDateTime = $this->getMinPurchaseDateTime($minDateTime);
if ($minPurchaseDateTime !== null) {
$lastFromDate = $minPurchaseDateTime;
}
}

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

$minDateTime = clone $nowDateTime;
$minDateTime->modify('-30 days');

if ((int)$lastFromDate->format('U') < (int)$minDateTime->format('U')) {
$lastFromDate = $minDateTime;
}

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

return $lastFromDate;
}

/**
* @return DateTime
* @throws Exception
*/
protected function prepareToDate()
{
$operationHistory = $this->getOperationHistory()->getParentObject('cron_runner');
$toDate = $operationHistory !== null ? $operationHistory->getData('start_date') : 'now';

return new DateTime($toDate, new DateTimeZone('UTC'));
}

//########################################
}
Loading

0 comments on commit 5dc853c

Please sign in to comment.