Skip to content

Commit

Permalink
6.41.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Jun 2, 2023
1 parent 781b1c8 commit e489112
Show file tree
Hide file tree
Showing 31 changed files with 621 additions and 258 deletions.
18 changes: 13 additions & 5 deletions app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,19 @@ protected function _toHtml()

$confirm = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_dialog_confirm')->toHtml();

$text = 'If you confirm the deletion of your Account, it will be removed from the M2E Pro instance only, ';
$text .= 'your Subscription and Billing for this Channel Account won`t be affected. <br><br>';
$text .= 'If you want to delete a Channel Account that you no longer need to manage under your M2E Pro ';
$text .= 'Subscription plan, you should go to <a href="%url%" target="_blank">M2E Accounts</a>.';
$text = Mage::helper('M2ePro')->__($text, Mage::helper('M2ePro/Module_Support')->getAccountsUrl());

$text = Mage::helper('M2ePro')->__(
<<<HTML
<p>You are about to delete your eBay/Amazon/Walmart seller account from M2E Pro. This will remove the
account-related Listings and Products from the extension and disconnect the synchronization.
Your listings on the channel will <b>not</b> be affected.</p>
<p>Please confirm if you would like to delete the account.</p>
<p>Note: once the account is no longer connected to your M2E Pro, please remember to delete it from
<a href="%url%">M2E Accounts</a></p>
HTML
,
Mage::helper('M2ePro/Module_Support')->getAccountsUrl()
);

$translations = Mage::helper('M2ePro')->jsonEncode(
array(
Expand Down
36 changes: 0 additions & 36 deletions app/code/community/Ess/M2ePro/Model/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,6 @@ public function isLocked($onlyMainConditions = false)
->getSize();
}

public function deleteInstance()
{
if ($this->isLocked()) {
return false;
}

$otherListings = $this->_activeRecordFactory->getObjectCollection('Listing_Other');
$otherListings->addFieldToFilter('account_id', $this->getId());
foreach ($otherListings->getItems() as $otherListing) {
/** @var Ess_M2ePro_Model_Listing_Other $otherListing */
$otherListing->deleteInstance();
}

if ($this->isComponentModeEbay() && $this->getChildObject()->isModeSandbox()) {
$listings = $this->_activeRecordFactory->getObjectCollection('Listing');
$listings->addFieldToFilter('account_id', $this->getId());

foreach ($listings->getItems() as $listing) {
/** @var Ess_M2ePro_Model_Listing $listing */
$listing->deleteInstance();
}
}

$orders = $this->_activeRecordFactory->getObjectCollection('Order');
$orders->addFieldToFilter('account_id', $this->getId());
foreach ($orders->getItems() as $order) {
/** @var Ess_M2ePro_Model_Order $order */
$order->deleteInstance();
}

$this->deleteChildInstance();
$this->delete();

return true;
}

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

public function getTitle()
Expand Down
45 changes: 19 additions & 26 deletions app/code/community/Ess/M2ePro/Model/Amazon/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,6 @@ public function _construct()

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

public function deleteInstance()
{
if ($this->isLocked()) {
return false;
}

$itemCollection = $this->_activeRecordFactory->getObjectCollection('Amazon_Item');
$itemCollection->addFieldToFilter('account_id', $this->getId());
foreach ($itemCollection->getItems() as $item) {
$item->deleteInstance();
}

if ($this->isRepricing()) {
$this->getRepricing()->deleteInstance();
$this->_repricingModel = null;
}

$this->_marketplaceModel = null;

$this->delete();

return true;
}

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

/**
* @return Ess_M2ePro_Model_Marketplace
*/
Expand Down Expand Up @@ -179,6 +153,25 @@ public function getRepricing()
return $this->_repricingModel;
}

public function deleteInventorySku()
{
$inventorySkuCollection = $this->_activeRecordFactory->getObjectCollection('Amazon_Inventory_Sku');
$inventorySkuCollection->addFieldToFilter('account_id', $this->getId());
foreach ($inventorySkuCollection->getItems() as $item) {
$item->deleteInstance();
}
}

public function deleteProcessingListSku()
{
$processingListSkuCollection = $this->_activeRecordFactory
->getObjectCollection('Amazon_Listing_Product_Action_ProcessingListSku');
$processingListSkuCollection->addFieldToFilter('account_id', $this->getId());
foreach ($processingListSkuCollection->getItems() as $item) {
$item->deleteInstance();
}
}

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

public function setServerHash($value)
Expand Down
102 changes: 102 additions & 0 deletions app/code/community/Ess/M2ePro/Model/Amazon/Account/DeleteManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

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

class Ess_M2ePro_Model_Amazon_Account_DeleteManager
{
/** @var Ess_M2ePro_Model_ActiveRecord_Factory */
protected $_activeRecordFactory;

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

public function __construct()
{
$this->_activeRecordFactory = Mage::getSingleton('M2ePro/ActiveRecord_Factory');
}

/**
* @param \Ess_M2ePro_Model_Account $account
* @return void
* @throws \Ess_M2ePro_Model_Exception_Logic|\Ess_M2ePro_Model_Exception
*/
public function process(Ess_M2ePro_Model_Account $account)
{
$otherListings = $this->_activeRecordFactory->getObjectCollection('Listing_Other');
$otherListings->addFieldToFilter('account_id', $account->getId());
/** @var Ess_M2ePro_Model_Listing_Other $otherListing */
foreach ($otherListings->getItems() as $otherListing) {
$otherListing->deleteProcessings();
$otherListing->deleteProcessingLocks();

$this->assertSuccess($otherListing->deleteInstance(), 'Listing Other');
}

$listings = $this->_activeRecordFactory->getObjectCollection('Listing');
$listings->addFieldToFilter('account_id', $account->getId());
/** @var Ess_M2ePro_Model_Listing $listing */
foreach ($listings->getItems() as $listing) {
$listing->deleteProcessings();
$listing->deleteProcessingLocks();

$listing->deleteListingProductsForce();

$this->assertSuccess($listing->deleteInstance(), 'Listing');
}

$orders = $this->_activeRecordFactory->getObjectCollection('Order');
$orders->addFieldToFilter('account_id', $account->getId());
/** @var Ess_M2ePro_Model_Order $order */
foreach ($orders->getItems() as $order) {
$order->deleteProcessings();
$order->deleteProcessingLocks();

$this->assertSuccess($order->deleteInstance(), 'Order');
}

/** @var Ess_M2ePro_Model_Amazon_Account $amazonAccount */
$amazonAccount = $account->getChildObject();

$amazonAccount->deleteInventorySku();
$amazonAccount->deleteProcessingListSku();

$itemCollection = $this->_activeRecordFactory->getObjectCollection('Amazon_Item');
$itemCollection->addFieldToFilter('account_id', $amazonAccount->getId());
/** @var Ess_M2ePro_Model_Amazon_Item $item */
foreach ($itemCollection->getItems() as $item) {
$item->deleteProcessings();
$item->deleteProcessingLocks();

$this->assertSuccess($item->deleteInstance(), 'Item');
}

if ($amazonAccount->isRepricing()) {
$amazonAccountRepricing = $amazonAccount->getRepricing();

$amazonAccountRepricing->deleteProcessings();
$amazonAccountRepricing->deleteProcessingLocks();

$this->assertSuccess($amazonAccountRepricing->$amazonAccountRepricing(), 'Account Repricing');
}

Mage::helper('M2ePro/Data_Cache_Permanent')->removeTagValues('account');

$account->deleteProcessings();
$account->deleteProcessingLocks();

$this->assertSuccess($account->deleteInstance(), 'Account');
}

/**
* @throws \Ess_M2ePro_Model_Exception
*/
private function assertSuccess($value, $label)
{
if ($value === false) {
throw new Ess_M2ePro_Model_Exception('Unable to delete ' . $label);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public function validate()
return false;
}

if (!$this->getAmazonListingProduct()->isAfnChannel() &&
(!$this->getListingProduct()->isListed() || !$this->getListingProduct()->isRevisable())
if (!$this->getAmazonListingProduct()->isAfnChannel()
&& ($this->isChangerUser() && !$this->getListingProduct()->isBlocked())
&& (!$this->getListingProduct()->isListed() || !$this->getListingProduct()->isRevisable())
) {
$this->addMessage('Item is not Listed or not available');
return false;
Expand Down Expand Up @@ -109,4 +110,4 @@ protected function validateParentListingProduct()
}

//########################################
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ protected function getParams()
return $this->_params;
}

protected function isChangerUser()
{
$params = $this->getParams();
if (!array_key_exists('status_changer', $params)) {
return false;
}

return (int)$params['status_changer'] === Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER;
}

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

/**
Expand Down Expand Up @@ -232,6 +242,10 @@ protected function validateSku()

protected function validateBlocked()
{
if ($this->isChangerUser()) {
return true;
}

if ($this->getListingProduct()->isBlocked()) {
$this->addMessage(
'The Action can not be executed as the Item was Closed, Incomplete or Blocked on Amazon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function performActions()

$listingProduct->setActionConfigurator($configurator);

/** @var Ess_M2ePro_Model_Ebay_Connector_Item_Dispatcher $dispatcher */
$dispatcher = Mage::getModel('M2ePro/Ebay_Connector_Item_Dispatcher');
$dispatcher->process($scheduledAction->getActionType(), array($listingProduct), $params);

Expand Down
48 changes: 0 additions & 48 deletions app/code/community/Ess/M2ePro/Model/Ebay/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,54 +82,6 @@ public function _construct()

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

public function deleteInstance()
{
if ($this->isLocked()) {
return false;
}

Mage::getSingleton('core/resource')->getConnection('core_write')
->delete(
Mage::helper('M2ePro/Module_Database_Structure')
->getTableNameWithPrefix('m2epro_ebay_account_store_category'),
array('account_id = ?' => $this->getId())
);

$storeCategoryTemplates = $this->_activeRecordFactory->getObjectCollection('Ebay_Template_StoreCategory');
$storeCategoryTemplates->addFieldToFilter('account_id', $this->getId());
foreach ($storeCategoryTemplates->getItems() as $storeCategoryTemplate) {
/** @var Ess_M2ePro_Model_Ebay_Template_StoreCategory $storeCategoryTemplate */
$storeCategoryTemplate->deleteInstance();
}

$feedbacks = $this->_activeRecordFactory->getObjectCollection('Ebay_Feedback');
$feedbacks->addFieldToFilter('account_id', $this->getId());
foreach ($feedbacks->getItems() as $feedback) {
/** @var Ess_M2ePro_Model_Ebay_Feedback $feedback */
$feedback->deleteInstance();
}

$feedbackTemplates = $this->_activeRecordFactory->getObjectCollection('Ebay_Feedback_Template');
$feedbackTemplates->addFieldToFilter('account_id', $this->getId());
foreach ($feedbackTemplates->getItems() as $feedbackTemplate) {
/** @var Ess_M2ePro_Model_Ebay_Feedback_Template $feedbackTemplate */
$feedbackTemplate->deleteInstance();
}

$itemCollection = $this->_activeRecordFactory->getObjectCollection('Ebay_Item');
$itemCollection->addFieldToFilter('account_id', $this->getId());
foreach ($itemCollection->getItems() as $item) {
/** @var Ess_M2ePro_Model_Ebay_Item $item */
$item->deleteInstance();
}

$this->delete();

return true;
}

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

/**
* @return bool
*/
Expand Down
Loading

0 comments on commit e489112

Please sign in to comment.