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); }
/** * Create attribute model * * @param string $name * @return \Magento\GoogleShopping\Model\Attribute\DefaultAttribute */ public function createAttribute($name) { $modelName = 'Magento\\GoogleShopping\\Model\\Attribute\\' . $this->_string->upperCaseWords($this->_googleShoppingHelper->normalizeName($name)); try { /** @var \Magento\GoogleShopping\Model\Attribute\DefaultAttribute $attributeModel */ $attributeModel = $this->_objectManager->create($modelName); if (!$attributeModel) { $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute'); } } catch (\Exception $e) { $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute'); } $attributeModel->setName($name); return $attributeModel; }
/** * Retrieve item query for Google Content * * @param \Magento\GoogleShopping\Model\Item $item * @return \Magento\Framework\Gdata\Gshopping\ItemQuery */ protected function _buildItemQuery($item) { $storeId = $item->getStoreId(); $service = $this->getService($storeId); $countryInfo = $this->getConfig()->getTargetCountryInfo($storeId); $itemId = $this->_gsData->buildContentProductId($item->getProductId(), $item->getStoreId()); $query = $service->newItemQuery()->setId($itemId)->setTargetCountry($this->getConfig()->getTargetCountry($storeId))->setLanguage($countryInfo['language']); return $query; }
/** * Remove attributes which were removed from mapping. * * @param Entry $entry * @param string[] $existAttributes * @return Entry */ protected function _removeNonexistentAttributes($entry, $existAttributes) { // attributes which can't be removed $ignoredAttributes = ["id", "image_link", "content_language", "target_country", "expiration_date", "adult"]; $contentAttributes = $entry->getContentAttributes(); foreach ($contentAttributes as $contentAttribute) { $name = $this->_googleShoppingHelper->normalizeName($contentAttribute->getName()); if (!in_array($name, $ignoredAttributes) && !in_array($existAttributes, $existAttributes)) { $entry->removeContentAttribute($name); } } return $entry; }
/** * 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; }