Пример #1
0
 public function testParseGdataExceptionMessageWithProduct()
 {
     $message = "some message\n\nother message";
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getName', 'getStoreId'], [], '', false);
     $product->expects($this->any())->method('getName')->will($this->returnValue("product name"));
     $storeId = 1;
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManagerInterface->expects($this->any())->method('getStore')->with($storeId)->will($this->returnValue($store));
     $store->expects($this->any())->method('getName')->will($this->returnValue('store name'));
     $result = $this->data->parseGdataExceptionMessage($message, $product);
     $this->assertEquals("some message for product 'product name' (in 'store name' store). " . "other message for product 'product name' (in 'store name' store)", $result);
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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;
 }