Skip to content

Commit

Permalink
6.14.3 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Oct 13, 2021
1 parent dd62ddd commit 5286440
Show file tree
Hide file tree
Showing 18 changed files with 367 additions and 77 deletions.
11 changes: 10 additions & 1 deletion app/code/community/Ess/M2ePro/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
* 6.14.2 (30/09/2021)
* 6.14.3 (13/10/2021)

eBay: [Fixed] Best Offer value is not updated during Automatic Revise after changing product price in Magento [#2523]
eBay: [Fixed] Magento Product cannot be saved after upgrade to 6.14.2 [#2988]
eBay: [Fixed] Product status is displayed as Inactive (Stopped) for Active eBay Items [#2926]
eBay: [Fixed] Exception "Instance must be loaded first" occurs when importing Combined orders in Canceled status [#2574]
Amazon: [Fixed] Item price is not updated during Manual Revise [#2518]
Walmart: [Fixed] Unmanaged Listings are not imported from the Channel [#1236]

* 6.14.2 (30/09/2021)

[eBay] [Fixed] eBay order was not refunded as per Magento credit memo creation [#1220]
[eBay] [Fixed] Magento Order was not created. Reason: Warning: A non-numeric value encountered [#2594]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
* @license Commercial use is forbidden
*/

use Ess_M2ePro_Model_Cron_Task_Ebay_Channel_SynchronizeChanges_ItemsProcessor_StatusResolver as StatusResolver;

class Ess_M2ePro_Model_Cron_Task_Ebay_Channel_SynchronizeChanges_ItemsProcessor
{
const INSTRUCTION_INITIATOR = 'channel_changes_synchronization';

const EBAY_STATUS_ACTIVE = 'Active';
const EBAY_STATUS_ENDED = 'Ended';
const EBAY_STATUS_COMPLETED = 'Completed';


const INCREASE_SINCE_TIME_MAX_ATTEMPTS = 10;
const INCREASE_SINCE_TIME_BY = 2;
const INCREASE_SINCE_TIME_MIN_INTERVAL_SEC = 10;
Expand Down Expand Up @@ -60,7 +58,7 @@ public function process()
protected function processAccount(Ess_M2ePro_Model_Account $account)
{
$changesByAccount = $this->getChangesByAccount($account);

if (!isset($changesByAccount['items']) || !isset($changesByAccount['to_time'])) {
return;
}
Expand Down Expand Up @@ -95,15 +93,25 @@ protected function processAccount(Ess_M2ePro_Model_Account $account)
continue;
}

// Listing product isn't listed and it child must have another item_id
if ($listingProduct->getStatus() != Ess_M2ePro_Model_Listing_Product::STATUS_LISTED &&
$listingProduct->getStatus() != Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN) {
/** @var StatusResolver $statusResolver */
$statusResolver = Mage::getModel(
'M2ePro/Cron_Task_Ebay_Channel_SynchronizeChanges_ItemsProcessor_StatusResolver'
);

$isStatusResolved = $statusResolver->resolveStatus(
(int)$change['quantity'] <= 0 ? 0 : (int)$change['quantity'],
(int)$change['quantitySold'] <= 0 ? 0 : (int)$change['quantitySold'],
$change['listingStatus'],
$listingProduct
);

if (!$isStatusResolved) {
continue;
}

$dataForUpdate = array_merge(
$this->getProductStatusChanges($listingProduct, $statusResolver),
$this->getProductDatesChanges($change),
$this->getProductStatusChanges($listingProduct, $change),
$this->getProductQtyChanges($listingProduct, $change)
);

Expand Down Expand Up @@ -295,37 +303,22 @@ protected function getProductDatesChanges(array $change)
'end_date' => Mage::helper('M2ePro/Component_Ebay')->timeToString($change['endTime'])
);
}

protected function getProductStatusChanges(Ess_M2ePro_Model_Listing_Product $listingProduct, array $change)
{

protected function getProductStatusChanges(
Ess_M2ePro_Model_Listing_Product $listingProduct,
StatusResolver $statusResolver
) {
$data = array();
$data['status'] = $statusResolver->getProductStatus();

$qty = (int)$change['quantity'] < 0 ? 0 : (int)$change['quantity'];
$qtySold = (int)$change['quantitySold'] < 0 ? 0 : (int)$change['quantitySold'];

if (($change['listingStatus'] == self::EBAY_STATUS_COMPLETED ||
$change['listingStatus'] == self::EBAY_STATUS_ENDED) &&
$listingProduct->getStatus() != Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN &&
$qty == $qtySold
) {
$data['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_SOLD;
} else if ($change['listingStatus'] == self::EBAY_STATUS_COMPLETED) {
$data['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED;
} else if ($change['listingStatus'] == self::EBAY_STATUS_ENDED) {
$data['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_FINISHED;
} else if ($change['listingStatus'] == self::EBAY_STATUS_ACTIVE && $qty - $qtySold <= 0) {
$data['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN;
} else if ($change['listingStatus'] == self::EBAY_STATUS_ACTIVE) {
$data['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_LISTED;
}

if ($data['status'] == Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN) {
// Listed Hidden Status can be only for GTC items
if ($listingProduct->getChildObject()->getOnlineDuration() === null) {
$data['online_duration'] = Ess_M2ePro_Helper_Component_Ebay::LISTING_DURATION_GTC;
}
if ($onlineDuration = $statusResolver->getOnlineDuration()) {
$data['online_duration'] = $onlineDuration;
}


if ($additionalData = $statusResolver->getProductAdditionalData()) {
$data['additional_data'] = $additionalData;
}

if ($listingProduct->getStatus() == $data['status']) {
return $data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

/*
* @author M2E Pro Developers Team
* @copyright M2E LTD
* @license Commercial use is forbidden
*/

class Ess_M2ePro_Model_Cron_Task_Ebay_Channel_SynchronizeChanges_ItemsProcessor_StatusResolver
{
const EBAY_STATUS_ACTIVE = 'Active';
const EBAY_STATUS_ENDED = 'Ended';
const EBAY_STATUS_COMPLETED = 'Completed';

const SKIP_FLAG_KEY = 'skip_first_completed_status_on_sync';

/** @var Ess_M2ePro_Model_Listing_Product */
protected $_listingProduct;
protected $_channelQty = 0;
protected $_channelQtySold = 0;

protected $_productStatus = null;
protected $_onlineDuration = null;
protected $_productAdditionalData = null;

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

public function resolveStatus(
$channelQty,
$channelQtySold,
$ebayStatus,
Ess_M2ePro_Model_Listing_Product $listingProduct
) {
$this->_channelQty = $channelQty;
$this->_channelQtySold = $channelQtySold;
$this->_listingProduct = $listingProduct;

$isBehaviorOfGtc = $ebayStatus == self::EBAY_STATUS_ACTIVE &&
$this->_channelQty - $this->_channelQtySold > 0 &&
$this->_listingProduct->isStopped();

// Listing product isn't listed and it child must have another item_id
$isAllowedProductStatus = $this->_listingProduct->isListed() || $this->_listingProduct->isHidden();

if (!$isBehaviorOfGtc && !$isAllowedProductStatus) {
return false;
}

switch ($ebayStatus) {
case self::EBAY_STATUS_ACTIVE:
$this->handleActiveStatus();
break;
case self::EBAY_STATUS_COMPLETED:
$this->handleCompletedStatus();
break;
case self::EBAY_STATUS_ENDED:
$this->handleEndedStatus();
break;
default:
throw new Ess_M2ePro_Model_Exception('Unknown eBay listing status');
}

return true;
}

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

protected function handleActiveStatus()
{
if ($this->_channelQty - $this->_channelQtySold <= 0) {
// Listed Hidden Status can be only for GTC items
if ($this->_listingProduct->getChildObject()->getOnlineDuration() === null) {
$this->_onlineDuration = Ess_M2ePro_Helper_Component_Ebay::LISTING_DURATION_GTC;
}

$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN;
return;
}

if ($this->_channelQty - $this->_channelQtySold > 0 && $this->statusCompletedIsAlreadySkipped()) {
$this->unsetSkipFlag();
}

$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_LISTED;
}

protected function handleCompletedStatus()
{
if ($this->setProductStatusSold()) {
return;
}

if ($this->_channelQty - $this->_channelQtySold > 0) {
if ($this->statusCompletedIsAlreadySkipped()) {
$this->unsetSkipFlag();
$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED;
} else {
$this->setSkipFlag();
$this->_productStatus = $this->_listingProduct->getStatus();
}

return;
}

$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED;
}

protected function handleEndedStatus()
{
if (!$this->setProductStatusSold()) {
$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_FINISHED;
}
}

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

protected function setProductStatusSold()
{
if ($this->_listingProduct->isHidden() && $this->_channelQty == $this->_channelQtySold) {
$this->_productStatus = Ess_M2ePro_Model_Listing_Product::STATUS_SOLD;
return true;
}

return false;
}

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

public function statusCompletedIsAlreadySkipped()
{
$additionalData = $this->_listingProduct->getAdditionalData();
return isset($additionalData[self::SKIP_FLAG_KEY]);
}

protected function setSkipFlag()
{
$additionalData = $this->_listingProduct->getAdditionalData();
$additionalData[self::SKIP_FLAG_KEY] = true;
$this->_productAdditionalData = Mage::helper('M2ePro')->jsonEncode($additionalData);
}

protected function unsetSkipFlag()
{
$additionalData = $this->_listingProduct->getAdditionalData();
unset($additionalData[self::SKIP_FLAG_KEY]);
$this->_productAdditionalData = Mage::helper('M2ePro')->jsonEncode($additionalData);
}

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

public function getProductStatus()
{
return $this->_productStatus;
}

public function getOnlineDuration()
{
return $this->_onlineDuration;
}

public function getProductAdditionalData()
{
return $this->_productAdditionalData;
}

//########################################
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function getData()
$this->getConditionData(),
$this->getConditionNoteData(),
$this->getVatTaxData(),
$this->getBestOfferData(),
$this->getCharityData(),
$this->getLotSizeData()
);
Expand Down Expand Up @@ -80,23 +79,6 @@ protected function getVatTaxData()
return $data;
}

/**
* @return array
*/
protected function getBestOfferData()
{
$data = array(
'bestoffer_mode' => $this->getEbayListingProduct()->getEbaySellingFormatTemplate()->isBestOfferEnabled(),
);

if ($data['bestoffer_mode']) {
$data['bestoffer_accept_price'] = $this->getEbayListingProduct()->getBestOfferAcceptPrice();
$data['bestoffer_reject_price'] = $this->getEbayListingProduct()->getBestOfferRejectPrice();
}

return $data;
}

/**
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function getData()
$data = array_merge(
$data,
$this->getPriceDiscountStpData(),
$this->getPriceDiscountMapData()
$this->getPriceDiscountMapData(),
$this->getBestOfferData()
);

return $data;
Expand Down Expand Up @@ -82,11 +83,26 @@ protected function getPriceDiscountMapData()
return array('price_discount_map' => $data);
}

/**
* @return array
*/
protected function getBestOfferData()
{
$data = array(
'bestoffer_mode' => $this->getEbayListingProduct()->getEbaySellingFormatTemplate()->isBestOfferEnabled(),
);

if ($data['bestoffer_mode']) {
$data['bestoffer_accept_price'] = $this->getEbayListingProduct()->getBestOfferAcceptPrice();
$data['bestoffer_reject_price'] = $this->getEbayListingProduct()->getBestOfferRejectPrice();
}

return $data;
}

public static function getPriceDiscountMapExposureType($type)
{
switch ($type) {
case Ess_M2ePro_Model_Ebay_Template_SellingFormat::PRICE_DISCOUNT_MAP_EXPOSURE_NONE:
return self::PRICE_DISCOUNT_MAP_EXPOSURE_NONE;

case Ess_M2ePro_Model_Ebay_Template_SellingFormat::PRICE_DISCOUNT_MAP_EXPOSURE_DURING_CHECKOUT:
return self::PRICE_DISCOUNT_MAP_EXPOSURE_DURING_CHECKOUT;
Expand Down
Loading

0 comments on commit 5286440

Please sign in to comment.