-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
367 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
.../M2ePro/Model/Cron/Task/Ebay/Channel/SynchronizeChanges/ItemsProcessor/StatusResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
//######################################## | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.