/** * Check if synchronize process is finished and generate notification message * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function checkSynchronizationOperations(\Magento\Framework\Event\Observer $observer) { $this->_flag->loadSelf(); if ($this->_flag->isExpired()) { $this->_notifier->addMajor(__('Google Shopping operation has expired.'), __('One or more google shopping synchronization operations failed because of timeout.')); $this->_flag->unlock(); } return $this; }
/** * Remove Google Content items. * * @param int[]|ItemCollection $items * @return $this * @throws \Exception|\Zend_Gdata_App_CaptchaRequiredException */ public function deleteItems($items) { $totalDeleted = 0; $itemsCollection = $this->_getItemsCollection($items); $errors = array(); if ($itemsCollection) { if (count($itemsCollection) < 1) { return $this; } foreach ($itemsCollection as $item) { if ($this->_flag && $this->_flag->isExpired()) { break; } try { $item->deleteItem()->delete(); // The item was removed successfully $totalDeleted++; } catch (\Zend_Gdata_App_CaptchaRequiredException $e) { throw $e; } catch (\Zend_Gdata_App_Exception $e) { $this->_addGeneralError(); $errors[] = $this->_gleShoppingData->parseGdataExceptionMessage($e->getMessage(), $item->getProduct()); } catch (\Exception $e) { $this->_logger->logException($e); $errors[] = __('The item "%1" hasn\'t been deleted.', $item->getProduct()->getName()); } } } else { return $this; } if ($totalDeleted > 0) { $this->_getNotifier()->addNotice(__('Google Shopping item removal process succeded'), __('Total of %1 items(s) have been removed from Google Shopping.', $totalDeleted)); } if (count($errors)) { $this->_getNotifier()->addMajor(__('Errors happened while deleting items from Google Shopping'), $errors); } return $this; }
/** * Remove Google Content items. * * @param int[]|ItemCollection $items * @return $this * @throws \Exception|\Zend_Gdata_App_CaptchaRequiredException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function deleteItems($items) { $totalDeleted = 0; $itemsCollection = $this->_getItemsCollection($items); $errors = []; if ($itemsCollection) { if (count($itemsCollection) < 1) { return $this; } foreach ($itemsCollection as $item) { if ($this->_flag && $this->_flag->isExpired()) { break; } try { $item->deleteItem()->delete(); // The item was removed successfully $totalDeleted++; } catch (\Zend_Gdata_App_CaptchaRequiredException $e) { throw $e; } catch (\Zend_Gdata_App_Exception $e) { $this->_addGeneralError(); $errors[] = $this->_gleShoppingData->parseGdataExceptionMessage($e->getMessage(), $item->getProduct()); } catch (\Exception $e) { $this->_logger->critical($e); $errors[] = __('We can\'t update item "%1" right now.', $item->getProduct()->getName()); } } } else { return $this; } if ($totalDeleted > 0) { $this->_notifier->addNotice(__('The Google Shopping item removal process succeeded.'), __('You removed %1 items(s) from Google Shopping.', $totalDeleted)); } if (count($errors)) { $this->_notifier->addMajor(__('Something went wrong while deleting items from Google Shopping.'), $errors); } return $this; }