From e48911219f297819da351a4a195dea471ca57b70 Mon Sep 17 00:00:00 2001
From: M2E Pro
';
- $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 M2E Accounts.';
- $text = Mage::helper('M2ePro')->__($text, Mage::helper('M2ePro/Module_Support')->getAccountsUrl());
+
+ $text = Mage::helper('M2ePro')->__(
+ <<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 not be affected.
Please confirm if you would like to delete the account.
+Note: once the account is no longer connected to your M2E Pro, please remember to delete it from +M2E Accounts
+HTML + , + Mage::helper('M2ePro/Module_Support')->getAccountsUrl() + ); $translations = Mage::helper('M2ePro')->jsonEncode( array( diff --git a/app/code/community/Ess/M2ePro/Model/Account.php b/app/code/community/Ess/M2ePro/Model/Account.php index 2fc8da156..9f4fbdb41 100644 --- a/app/code/community/Ess/M2ePro/Model/Account.php +++ b/app/code/community/Ess/M2ePro/Model/Account.php @@ -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() diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Account.php b/app/code/community/Ess/M2ePro/Model/Amazon/Account.php index 0dea6f455..713071f81 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Account.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Account.php @@ -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 */ @@ -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) diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Account/DeleteManager.php b/app/code/community/Ess/M2ePro/Model/Amazon/Account/DeleteManager.php new file mode 100644 index 000000000..23500f163 --- /dev/null +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Account/DeleteManager.php @@ -0,0 +1,102 @@ +_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); + } + } +} diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Revise/Validator.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Revise/Validator.php index 365e665ea..f8c6bcd39 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Revise/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Revise/Validator.php @@ -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; @@ -109,4 +110,4 @@ protected function validateParentListingProduct() } //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Validator.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Validator.php index 9f8023853..8d34f646a 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Type/Validator.php @@ -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; + } + // --------------------------------------- /** @@ -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. diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php index 8dcc52fef..be21bcb64 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php @@ -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); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Account.php b/app/code/community/Ess/M2ePro/Model/Ebay/Account.php index 2c9f3c7ac..5c52bdd56 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Account.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Account.php @@ -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 */ diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Account/DeleteManager.php b/app/code/community/Ess/M2ePro/Model/Ebay/Account/DeleteManager.php new file mode 100644 index 000000000..ce738c18e --- /dev/null +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Account/DeleteManager.php @@ -0,0 +1,125 @@ +_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_Ebay_Account $ebayAccount */ + $ebayAccount = $account->getChildObject(); + + Mage::getSingleton('core/resource')->getConnection('core_write') + ->delete( + Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_account_store_category'), + array('account_id = ?' => $ebayAccount->getId()) + ); + + $storeCategoryTemplates = $this->_activeRecordFactory->getObjectCollection('Ebay_Template_StoreCategory'); + $storeCategoryTemplates->addFieldToFilter('account_id', $ebayAccount->getId()); + /** @var Ess_M2ePro_Model_Ebay_Template_StoreCategory $storeCategoryTemplate */ + foreach ($storeCategoryTemplates->getItems() as $storeCategoryTemplate) { + $storeCategoryTemplate->deleteProcessings(); + $storeCategoryTemplate->deleteProcessingLocks(); + + $this->assertSuccess($storeCategoryTemplate->deleteInstance(), 'Store Category Template'); + } + + $feedbacks = $this->_activeRecordFactory->getObjectCollection('Ebay_Feedback'); + $feedbacks->addFieldToFilter('account_id', $ebayAccount->getId()); + /** @var Ess_M2ePro_Model_Ebay_Feedback $feedback */ + foreach ($feedbacks->getItems() as $feedback) { + $feedback->deleteProcessings(); + $feedback->deleteProcessingLocks(); + + $this->assertSuccess($feedback->deleteInstance(), 'Feedback'); + } + + $itemCollection = $this->_activeRecordFactory->getObjectCollection('Ebay_Item'); + $itemCollection->addFieldToFilter('account_id', $ebayAccount->getId()); + /** @var Ess_M2ePro_Model_Ebay_Item $item */ + foreach ($itemCollection->getItems() as $item) { + $item->deleteProcessings(); + $item->deleteProcessingLocks(); + + $this->assertSuccess($item->deleteInstance(), 'Item'); + } + + $shippingTemplateCollection = $this->_activeRecordFactory->getObjectCollection('Ebay_Template_Shipping') + ->applyLinkedAccountFilter($ebayAccount->getId()); + /** @var Ess_M2ePro_Model_Ebay_Template_Shipping $item */ + foreach ($shippingTemplateCollection->getItems() as $item) { + $item->deleteShippingRateTables($account); + $item->save(); + } + + 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); + } + } +} diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Dispatcher.php b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Dispatcher.php index 8776888e2..b69c055ce 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Dispatcher.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Dispatcher.php @@ -94,6 +94,7 @@ protected function processAccountsMarketplaces( protected function processProducts(array $products, $action, $isRealTime = false, array $params = array()) { + /** @var Ess_M2ePro_Model_Ebay_Connector_Dispatcher $dispatcher */ $dispatcher = Mage::getModel('M2ePro/Ebay_Connector_Dispatcher'); $connectorName = 'Ebay_Connector_Item_'.$this->getActionNick($action).'_Requester'; diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php index 2caa0ca5f..64f8a059b 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php @@ -130,7 +130,9 @@ protected function initializeVariations() $needSave = true; } - $needSave && $variation->save(); + if ($needSave) { + $variation->save(); + } } } diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Validator.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Validator.php index c3f0d592a..43b04a11d 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Validator.php @@ -335,49 +335,65 @@ protected function validateIsVariationProductWithoutVariations() protected function validateVariationsOptions() { - $totalVariationsCount = 0; - $totalDeletedVariationsCount = 0; - $uniqueAttributesValues = array(); - - foreach ($this->getEbayListingProduct()->getVariations(true) as $variation) { - /** @var Ess_M2ePro_Model_Listing_Product_Variation $variation */ - /** @var Ess_M2ePro_Model_Ebay_Listing_Product_Variation $ebayVariation */ - - $ebayVariation = $variation->getChildObject(); - - foreach ($variation->getOptions(true) as $option) { - /** @var Ess_M2ePro_Model_Listing_Product_Variation_Option $option */ + /** @var Ess_M2ePro_Helper_Component_Ebay $ebayComponentHelper */ + $ebayComponentHelper = \Mage::helper('M2ePro/Component_Ebay'); + /** @var Ess_M2ePro_Model_Listing_Product_Variation $listingProduct */ + $listingProduct = $ebayComponentHelper->getModel('Listing_Product_Variation'); + + /** @var Ess_M2ePro_Model_Resource_Listing_Product_Variation_Option $variationOptionResource */ + $variationOptionResource = \Mage::getResourceModel('M2ePro/Listing_Product_Variation_Option'); + + /** @var Ess_M2ePro_Model_Resource_Listing_Product_Variation_Collection $collection */ + $collection = $listingProduct->getResourceCollection(); + $collection->getSelect()->reset(\Zend_Db_Select::COLUMNS); + $collection->getSelect()->columns(array( + 'count_deleted' => new \Zend_Db_Expr('SUM(IF(second_table.`delete`, 1, 0))'), + )); + $collection->getSelect()->joinLeft( + array('vo' => $variationOptionResource->getMainTable()), + 'vo.listing_product_variation_id = main_table.id', + array( + 'attribute_name' => 'vo.attribute', + 'count_options' => new \Zend_Db_Expr('COUNT(DISTINCT IF(second_table.`delete`, NULL, vo.`option`))') + ) + ); + $collection->getSelect()->group('vo.attribute'); + $collection->getSelect()->where( + 'main_table.listing_product_id = ?', + $this->getListingProduct()->getId() + ); - $uniqueAttributesValues[$option->getAttribute()][$option->getOption()] = true; + $data = $collection->getData(); - // Max 5 pair attribute-option: - // Color: Blue, Size: XL, ... - if (count($uniqueAttributesValues) > 5) { - $this->addMessage( - 'Variations of this Magento Product are out of the eBay Variational Item limits. + // Max 5 pair attribute-option: + // Color: Blue, Size: XL, ... + if (count($data) > 5) { + $this->addMessage( + 'Variations of this Magento Product are out of the eBay Variational Item limits. Its number of Variational Attributes is more than 5. That is why, this Product cannot be updated on eBay. Please, decrease the number of Attributes to solve this issue.' - ); - return false; - } + ); + return false; + } - // Maximum 60 options by one attribute: - // Color: Red, Blue, Green, ... - if (count($uniqueAttributesValues[$option->getAttribute()]) > 60) { - $this->addMessage( - 'Variations of this Magento Product are out of the eBay Variational Item limits. + $totalVariationsCount = 1; + $totalDeletedVariationsCount = 0; + foreach ($data as $item) { + $totalVariationsCount *= $item['count_options']; + $totalDeletedVariationsCount += $item['count_deleted']; + // Maximum 60 options by one attribute: + // Color: Red, Blue, Green, ... + if ($item['count_options'] > 60) { + $this->addMessage( + 'Variations of this Magento Product are out of the eBay Variational Item limits. Its number of Options for some Variational Attribute(s) is more than 60. That is why, this Product cannot be updated on eBay. Please, decrease the number of Options to solve this issue.' - ); - return false; - } + ); + return false; } - $totalVariationsCount++; - $ebayVariation->isDelete() && $totalDeletedVariationsCount++; - // Not more that 250 possible variations if ($totalVariationsCount > 250) { $this->addMessage( diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Shipping.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Shipping.php index 5b26511e6..ef0413008 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Shipping.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Shipping.php @@ -804,6 +804,30 @@ public function getInternationalShippingServices() return $returns; } + /** + * @param \Ess_M2ePro_Model_Account $account + * @return void + * @throws \Ess_M2ePro_Model_Exception_Logic + */ + public function deleteShippingRateTables(Ess_M2ePro_Model_Account $account) + { + $this->deleteShippingRateTable($account->getId(), 'local_shipping_rate_table'); + $this->deleteShippingRateTable($account->getId(), 'international_shipping_rate_table'); + } + + /** + * @param int|string $accountId + * @param string $settingsField + * @return void + * @throws \Ess_M2ePro_Model_Exception_Logic + */ + private function deleteShippingRateTable($accountId, $settingsField) + { + $rateTables = $this->getSettings($settingsField); + unset($rateTables[$accountId]); + $this->setSettings($settingsField, $rateTables); + } + //######################################## public function save() diff --git a/app/code/community/Ess/M2ePro/Model/Listing.php b/app/code/community/Ess/M2ePro/Model/Listing.php index 4d6dcd2e5..83839f271 100644 --- a/app/code/community/Ess/M2ePro/Model/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Listing.php @@ -943,6 +943,21 @@ public function removeDeletedProduct($product) // --------------------------------------- } + /** + * @return void + * @throws \Ess_M2ePro_Model_Exception_Logic + */ + public function deleteListingProductsForce() + { + $listingProducts = $this->getProducts(true); + + /**@var Ess_M2ePro_Model_Listing_Product $listingProduct */ + foreach ($listingProducts as $listingProduct) { + $listingProduct->canBeForceDeleted(true); + $listingProduct->deleteInstance(); + } + } + //######################################## public function save() diff --git a/app/code/community/Ess/M2ePro/Model/Listing/Product.php b/app/code/community/Ess/M2ePro/Model/Listing/Product.php index 56136e2c4..42b95f970 100644 --- a/app/code/community/Ess/M2ePro/Model/Listing/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Listing/Product.php @@ -264,15 +264,22 @@ public function getMarketplace() */ public function getVariations($asObjects = false, array $filters = array()) { + /** @var Ess_M2ePro_Helper_Data_Cache_Runtime $runtimeCache */ + $runtimeCache = Mage::helper('M2ePro/Data_Cache_Runtime'); + /** @var Ess_M2ePro_Helper_Data $dataHelper */ + $dataHelper = Mage::helper('M2ePro'); + /** @var Ess_M2ePro_Helper_Component $componentHelper */ + $componentHelper = Mage::helper('M2ePro/Component'); + $storageKey = "listing_product_{$this->getId()}_variations_" . - sha1((string)$asObjects . Mage::helper('M2ePro')->jsonEncode($filters)); + sha1((string)$asObjects . $dataHelper->jsonEncode($filters)); - if ($cacheData = Mage::helper('M2ePro/Data_Cache_Runtime')->getValue($storageKey)) { + if ($cacheData = $runtimeCache->getValue($storageKey)) { return $cacheData; } /** @var Ess_M2ePro_Model_Resource_ActiveRecord_CollectionAbstract $collection */ - $collection = Mage::helper('M2ePro/Component')->getComponentCollection( + $collection = $componentHelper->getComponentCollection( $this->getComponentMode(), 'Listing_Product_Variation' ); @@ -294,7 +301,7 @@ public function getVariations($asObjects = false, array $filters = array()) $result = $result['items']; } - Mage::helper('M2ePro/Data_Cache_Runtime')->setValue( + $runtimeCache->setValue( $storageKey, $result, array( diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Template/Shipping/Collection.php b/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Template/Shipping/Collection.php index 548486b84..04151efe5 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Template/Shipping/Collection.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Template/Shipping/Collection.php @@ -9,13 +9,19 @@ class Ess_M2ePro_Model_Resource_Ebay_Template_Shipping_Collection extends Ess_M2ePro_Model_Resource_Collection_Abstract { - //######################################## - public function _construct() { parent::_construct(); $this->_init('M2ePro/Ebay_Template_Shipping'); } - //######################################## + public function applyLinkedAccountFilter($accountId) + { + $this + ->getSelect() + ->where('local_shipping_rate_table LIKE ?', "%\"$accountId\":%") + ->orWhere('international_shipping_rate_table LIKE ?', "%\"$accountId\":%"); + + return $this; + } } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Account.php b/app/code/community/Ess/M2ePro/Model/Walmart/Account.php index 0ff434436..a6941e13d 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Account.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Account.php @@ -79,27 +79,6 @@ public function _construct() //######################################## - public function deleteInstance() - { - if ($this->isLocked()) { - return false; - } - - $itemCollection = $this->_activeRecordFactory->getObjectCollection('Walmart_Item'); - $itemCollection->addFieldToFilter('account_id', $this->getId()); - foreach ($itemCollection->getItems() as $item) { - $item->deleteInstance(); - } - - $this->_marketplaceModel = null; - - $this->delete(); - - return true; - } - - //######################################## - /** * @return Ess_M2ePro_Model_Marketplace */ @@ -889,6 +868,24 @@ public function getOtherCarriers() return $this->getSettings('other_carriers'); } + public function deleteInventoryWpid() + { + $inventorySkuCollection = $this->_activeRecordFactory->getObjectCollection('Walmart_Inventory_Wpid'); + $inventorySkuCollection->addFieldToFilter('account_id', $this->getId()); + foreach ($inventorySkuCollection->getItems() as $item) { + $item->deleteInstance(); + } + } + + public function deleteProcessingList() + { + $inventorySkuCollection = $this->_activeRecordFactory->getObjectCollection('Walmart_Listing_Product_Action_ProcessingList'); + $inventorySkuCollection->addFieldToFilter('account_id', $this->getId()); + foreach ($inventorySkuCollection->getItems() as $item) { + $item->deleteInstance(); + } + } + //######################################## public function save() diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Account/DeleteManager.php b/app/code/community/Ess/M2ePro/Model/Walmart/Account/DeleteManager.php new file mode 100644 index 000000000..cb8ffeec3 --- /dev/null +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Account/DeleteManager.php @@ -0,0 +1,93 @@ +_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_Walmart_Account $walmartAccount */ + $walmartAccount = $account->getChildObject(); + + $walmartAccount->deleteInventoryWpid(); + $walmartAccount->deleteProcessingList(); + + $itemCollection = $this->_activeRecordFactory->getObjectCollection('Walmart_Item'); + $itemCollection->addFieldToFilter('account_id', $walmartAccount->getId()); + /** @var Ess_M2ePro_Model_Walmart_Item $item */ + foreach ($itemCollection->getItems() as $item) { + $item->deleteProcessings(); + $item->deleteProcessingLocks(); + + $this->assertSuccess($item->deleteInstance(), 'Item'); + } + + 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); + } + } +} diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Revise/Validator.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Revise/Validator.php index 43009a925..e75f3808f 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Revise/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Revise/Validator.php @@ -52,7 +52,9 @@ public function validate() return false; } - if (!$this->getListingProduct()->isListed() || !$this->getListingProduct()->isRevisable()) { + if (($this->isChangerUser() && !$this->getListingProduct()->isBlocked()) + && (!$this->getListingProduct()->isListed() || !$this->getListingProduct()->isRevisable()) + ) { $this->addMessage('Item is not Listed or not available'); return false; } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php index 458a86ab1..6987a4702 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php @@ -51,6 +51,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; + } + // --------------------------------------- /** @@ -249,6 +259,10 @@ protected function validateMissedOnChannelBlocked() protected function validateGeneralBlocked() { + if ($this->isChangerUser()) { + return true; + } + if ($this->getListingProduct()->isBlocked() && !$this->getWalmartListingProduct()->isMissedOnChannel() && !$this->getWalmartListingProduct()->isOnlinePriceInvalid() diff --git a/app/code/community/Ess/M2ePro/composer.json b/app/code/community/Ess/M2ePro/composer.json index 01686d01c..ee0225852 100644 --- a/app/code/community/Ess/M2ePro/composer.json +++ b/app/code/community/Ess/M2ePro/composer.json @@ -2,7 +2,7 @@ "name": "m2epro/magento1-extension", "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": "magento-module", - "version": "6.39.2", + "version": "6.41.0", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/", diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/AccountController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/AccountController.php index a2d492181..6c38a966e 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/AccountController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/AccountController.php @@ -596,32 +596,24 @@ public function deleteAction() return; } - $deleted = $locked = 0; - foreach ($accounts as $account) { + $deleted = 0; + try { /** @var Ess_M2ePro_Model_Account $account */ - - if ($account->isLocked(true)) { - $locked++; - continue; + foreach ($accounts as $account) { + /** @var Ess_M2ePro_Model_Amazon_Account_DeleteManager $deleteManager */ + $deleteManager = Mage::getModel('M2ePro/Amazon_Account_DeleteManager'); + $deleteManager->process($account); + $deleted++; } - $account->deleteProcessings(); - $account->deleteProcessingLocks(); - $account->deleteInstance(); - - $deleted++; + $deleted && $this->_getSession()->addSuccess( + Mage::helper('M2ePro')->__('%amount% account(s) were deleted.', $deleted) + ); + } catch (\Exception $exception) { + $this->_getSession()->addError(Mage::helper('M2ePro')->__($exception->getMessage())); } - $deleted && $this->_getSession()->addSuccess( - Mage::helper('M2ePro')->__('%amount% record(s) were deleted.', $deleted) - ); - $locked && $this->_getSession()->addError( - Mage::helper('M2ePro')->__( - '%amount% record(s) are used in M2E Pro Listing(s). Account must not be in use to be deleted.', $locked - ) - ); - $this->_redirect('*/*/index'); } diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php index 25da7c738..da8f2cd28 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php @@ -275,35 +275,39 @@ public function deleteAction() $ids = $this->getRequestIds(); if (empty($ids)) { - $this->_getSession()->addError(Mage::helper('M2ePro')->__('Please select Account(s) to remove.')); + $this->_getSession()->addError(Mage::helper('M2ePro')->__('Please select account(s) to remove.')); $this->_redirect('*/*/index'); return; } - $deleted = $locked = 0; - foreach ($ids as $id) { + /** @var Ess_M2ePro_Model_Resource_Account_Collection $accountCollection */ + $accountCollection = Mage::getModel('M2ePro/Account')->getCollection(); + $accountCollection->addFieldToFilter('id', array('in' => $ids)); - /** @var $account Ess_M2ePro_Model_Account */ - $account = Mage::getModel('M2ePro/Account')->loadInstance($id); + $accounts = $accountCollection->getItems(); - if ($account->isLocked(true)) { - $locked++; - continue; - } - - $account->deleteProcessings(); - $account->deleteProcessingLocks(); - $account->deleteInstance(); - - $deleted++; + if (empty($accounts)) { + $this->_redirect('*/*/index'); + return; } - $tempString = Mage::helper('M2ePro')->__('%amount% record(s) were deleted.', $deleted); - $deleted && $this->_getSession()->addSuccess($tempString); + $deleted = 0; - $tempString = Mage::helper('M2ePro')->__('%amount% record(s) are used in M2E Pro Listing(s).', $locked) . ' '; - $tempString .= Mage::helper('M2ePro')->__('Account must not be in use to be deleted.'); - $locked && $this->_getSession()->addError($tempString); + try { + /** @var Ess_M2ePro_Model_Account $account */ + foreach ($accounts as $account) { + /** @var Ess_M2ePro_Model_Ebay_Account_DeleteManager $deleteManager */ + $deleteManager = Mage::getModel('M2ePro/Ebay_Account_DeleteManager'); + $deleteManager->process($account); + $deleted++; + } + + $deleted && $this->_getSession()->addSuccess( + Mage::helper('M2ePro')->__('%amount% account(s) were deleted.', $deleted) + ); + } catch (\Exception $exception) { + $this->_getSession()->addError(Mage::helper('M2ePro')->__($exception->getMessage())); + } $this->_redirect('*/*/index'); } diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/ListingController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/ListingController.php index f752d7f9a..e7509aa92 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/ListingController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/ListingController.php @@ -1217,6 +1217,7 @@ protected function runConnector($listingsProducts, $action, array $params, $logs $params['status_changer'] = Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER; $params['is_realtime'] = true; + /** @var Ess_M2ePro_Model_Ebay_Connector_Item_Dispatcher $dispatcherObject */ $dispatcherObject = Mage::getModel('M2ePro/Ebay_Connector_Item_Dispatcher'); $result = (int)$dispatcherObject->process($action, $listingsProductsIds, $params); diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/AccountController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/AccountController.php index c3fcd6d26..9be77610c 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/AccountController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/AccountController.php @@ -147,7 +147,6 @@ public function deleteAction() if (empty($ids)) { $this->_getSession()->addError(Mage::helper('M2ePro')->__('Please select account(s) to remove.')); $this->_redirect('*/*/index'); - return; } @@ -159,34 +158,27 @@ public function deleteAction() if (empty($accounts)) { $this->_redirect('*/*/index'); - return; } - $deleted = $locked = 0; - foreach ($accounts as $account) { - - /** @var $account Ess_M2ePro_Model_Account */ + $deleted = 0; - if ($account->isLocked(true)) { - $locked++; - continue; + try { + /** @var Ess_M2ePro_Model_Account $account */ + foreach ($accounts as $account) { + /** @var Ess_M2ePro_Model_Walmart_Account_DeleteManager $deleteManager */ + $deleteManager = Mage::getModel('M2ePro/Walmart_Account_DeleteManager'); + $deleteManager->process($account); + $deleted++; } - $account->deleteProcessings(); - $account->deleteProcessingLocks(); - $account->deleteInstance(); - - $deleted++; + $deleted && $this->_getSession()->addSuccess( + Mage::helper('M2ePro')->__('%amount% account(s) were deleted.', $deleted) + ); + } catch (\Exception $exception) { + $this->_getSession()->addError(Mage::helper('M2ePro')->__($exception->getMessage())); } - $tempString = Mage::helper('M2ePro')->__('%amount% record(s) were deleted.', $deleted); - $deleted && $this->_getSession()->addSuccess($tempString); - - $tempString = Mage::helper('M2ePro')->__('%amount% record(s) are used in M2E Pro Listing(s).', $locked) . ' '; - $tempString .= Mage::helper('M2ePro')->__('Account must not be in use to be deleted.'); - $locked && $this->_getSession()->addError($tempString); - $this->_redirect('*/*/index'); } diff --git a/app/code/community/Ess/M2ePro/etc/config.xml b/app/code/community/Ess/M2ePro/etc/config.xml index d9de8f2a1..4e5e65106 100644 --- a/app/code/community/Ess/M2ePro/etc/config.xml +++ b/app/code/community/Ess/M2ePro/etc/config.xml @@ -2,7 +2,7 @@Please confirm if you would like to delete the account.
+Note: once the account is no longer connected to your M2E Pro, please remember to delete it from +M2E Accounts
+HTML + , + Mage::helper('M2ePro/Module_Support')->getAccountsUrl() + ) )); ?>); M2ePro.formData.id = 'getRequest()->getParam('id'); ?>'; diff --git a/app/design/adminhtml/default/default/template/M2ePro/ebay/account/tabs/general.phtml b/app/design/adminhtml/default/default/template/M2ePro/ebay/account/tabs/general.phtml index 6f816ef57..8e2cc68a1 100644 --- a/app/design/adminhtml/default/default/template/M2ePro/ebay/account/tabs/general.phtml +++ b/app/design/adminhtml/default/default/template/M2ePro/ebay/account/tabs/general.phtml @@ -87,10 +87,18 @@ if ($isEdit) { 'No Customer entry is found for specified ID.' => Mage::helper('M2ePro')->__('No Customer entry is found for specified ID.'), 'If Yes is chosen, you must select at least one Attribute for Product Linking.' => Mage::helper('M2ePro')->__('If Yes is chosen, you must select at least one Attribute for Product Linking.'), 'You should create at least one Response Template.' => Mage::helper('M2ePro')->__('You should create at least one Response Template.'), - 'on_delete_account_message' => Mage::helper('M2ePro')->__(' - If you confirm the deletion of your Account, it will be removed from the M2E Pro instance only, your Subscription and Billing for this Channel Account won`t be affected.Please confirm if you would like to delete the account.
+Note: once the account is no longer connected to your M2E Pro, please remember to delete it from +M2E Accounts
+HTML + , + Mage::helper('M2ePro/Module_Support')->getAccountsUrl() + ) )); ?>); M2ePro.formData.id = 'getRequest()->getParam('id'); ?>'; diff --git a/app/design/adminhtml/default/default/template/M2ePro/walmart/account/tabs/general.phtml b/app/design/adminhtml/default/default/template/M2ePro/walmart/account/tabs/general.phtml index 0cf224f1f..56a572935 100644 --- a/app/design/adminhtml/default/default/template/M2ePro/walmart/account/tabs/general.phtml +++ b/app/design/adminhtml/default/default/template/M2ePro/walmart/account/tabs/general.phtml @@ -68,13 +68,20 @@ )); ?>); M2ePro.translator.add( Mage::helper('M2ePro')->__('Be attentive! By Deleting Account you delete all information on it from M2E Pro Server. This will cause inappropriate work of all Accounts\' copies.'), 'Please enter correct value.' => Mage::helper('M2ePro')->__('Please enter correct value.'), 'Coefficient is not valid.' => Mage::helper('M2ePro')->__('Coefficient is not valid.'), - 'on_delete_account_message' => Mage::helper('M2ePro')->__(' - If you confirm the deletion of your Account, it will be removed from the M2E Pro instance only, your Subscription and Billing for this Channel Account won`t be affected.Please confirm if you would like to delete the account.
+Note: once the account is no longer connected to your M2E Pro, please remember to delete it from +M2E Accounts
+HTML + , + Mage::helper('M2ePro/Module_Support')->getAccountsUrl() + ) )); ?>); M2ePro.formData.id = 'getRequest()->getParam('id'); ?>'; diff --git a/composer.json b/composer.json index 01686d01c..ee0225852 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "m2epro/magento1-extension", "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": "magento-module", - "version": "6.39.2", + "version": "6.41.0", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/",