/**
  * cache the self::_configMap known class constant and map them
  * to their configuration value
  * @param string $cfgKey the key of the configMap array
  * @return string | null a string value if the key is in the configMap otherwise null
  */
 protected function _getConfigMapValue($cfgKey)
 {
     if (empty($this->_configMap)) {
         $cfg = $this->_coreHelper->getConfigModel();
         $this->_configMap = [self::CFG_EXPORT_ARCHIVE => $cfg->feedExportArchive, self::CFG_IMPORT_ARCHIVE => $cfg->feedImportArchive, self::CFG_EXPORT_OUTBOX => $cfg->feedOutboxDirectory, self::CFG_IMPORTED_ACK_DIR => $cfg->feedAckInbox, self::CFG_EXPORTED_FEED_DIR => $cfg->feedSentDirectory, self::CFG_WAIT_TIME_LIMIT => $cfg->ackResendTimeLimit, self::CFG_ERROR_DIRECTORY => $cfg->feedAckErrorDirectory];
     }
     return isset($this->_configMap[$cfgKey]) ? $this->_configMap[$cfgKey] : null;
 }
 /**
  * Get a new AMQP SDK API object. Hostname, username and password may be
  * provided to override configuration settings (useful for testing AMQP
  * credentials).
  * @param string $queueName
  * @param mixed $store Any valid store identifier. Default to null (current store)
  * @param string $hostname If empty will use value in config
  * @param string $username If empty will use value in config
  * @param string $password If empty will use value in config
  * @return Api\IAmqpApi
  * @codeCoverageIgnore Minimal logic worth testing, just calling constructors with config values
  */
 public function getSdkAmqp($queueName, $store = null, $hostname = null, $username = null, $password = null)
 {
     $coreConfig = $this->_coreHelper->getConfigModel($store);
     $queueName = $this->_processQueueName($queueName, $coreConfig);
     $config = $this->getConfigModel($store);
     $hostname = $hostname ?: $config->hostname;
     $username = $username ?: $config->username;
     $password = $password ?: $config->password;
     $amqpConfig = new Api\AmqpConfig($config->connectionType, $config->numberOfMessagesToProcess, $hostname, $config->port, $username, $password, $config->vhost, is_array($config->connectionContext) ? $config->connectionContext : [], $config->connectionInsistFlag, $config->connectionLoginMethod, $config->connectionLocale, $config->connectionTimeout, $config->connectionReadWriteTimeout, $queueName, $config->queuePassiveFlag, $config->queueDurableFlag, $config->queueExclusiveFlag, $config->queueAutoDeleteFlag, $config->queueNowaitFlag, $this->_logger);
     return new Api\AmqpApi($amqpConfig, [], $this->_logger);
 }
 /**
  * Get the API test message by making a test request, using AdVal with a
  * hard-coded address, and using the response to determine if the configuration
  * is correct or not. Appropriate response messages for API response types
  * handled by custom API status handlers.
  * @param  string $storeId
  * @param  string $apiKey
  * @param  string $hostname
  * @return string
  */
 public function testApiConnection($storeId, $apiKey, $hostname)
 {
     try {
         $this->_validateApiSettings($storeId, $apiKey, $hostname);
     } catch (EbayEnterprise_Eb2cCore_Exception_Api_Configuration $e) {
         return ['message' => $e->getMessage(), 'success' => false];
     }
     // need to manually build the URI as the eb2ccore/helper method doesn't
     // allow specifying the store id and doesn't really make sense for it to
     $coreConfig = $this->_helper->getConfigModel();
     $uri = $this->_getApiUri($hostname, $storeId, $coreConfig->apiMajorVersion, $coreConfig->apiMinorVersion);
     $xsd = self::AD_VAL_XSD;
     $adValRequest = $this->_buildTestRequest();
     /** @var EbayEnterprise_Eb2cCore_Model_Api $api */
     $api = Mage::getModel('eb2ccore/api');
     $api->setStatusHandlerPath(self::API_HANDLER_PATH);
     $response = $api->request($adValRequest, $xsd, $uri, $api::DEFAULT_TIMEOUT, $api::DEFAULT_ADAPTER, null, $apiKey);
     return $response;
 }
 /**
  * Return config values that may vary by website/store for the given
  * website.
  * @param  Mage_Core_Model_Website $website
  * @return array Config values for store id, AMQP username and AMQP password
  */
 public function getWebsiteLevelAmqpConfigurations(Mage_Core_Model_Website $website)
 {
     $storeIdPath = $this->_coreConfigMap->getPathForKey(self::STORE_ID_CONFIG_KEY);
     $usernamePath = $this->_amqpConfigMap->getPathForKey(self::USERNAME_CONFIG_KEY);
     $passwordPath = $this->_amqpConfigMap->getPathForKey(self::PASSWORD_CONFIG_KEY);
     $defaultCoreConfig = $this->_coreHelper->getConfigModel(Mage::app()->getStore(0));
     $defaultAmqpConfig = $this->_helper->getConfigModel(Mage::app()->getStore(0));
     // get website level config values, falling back to any not available to the
     // website with default store config values
     return array('store_id' => $website->getConfig($storeIdPath) ?: $defaultCoreConfig->storeId, 'username' => $website->getConfig($usernamePath) ?: $defaultAmqpConfig->username, 'password' => $this->_mageHelper->decrypt($website->getConfig($passwordPath)) ?: $defaultAmqpConfig->password);
 }
 /**
  * get the locale code for the order
  *
  * @return string
  */
 protected function _getLocale()
 {
     $languageCode = $this->_coreHelper->getConfigModel()->setStore($this->_order->getStore())->languageCode;
     $splitCode = explode('-', $languageCode);
     if (!empty($splitCode[0]) && !empty($splitCode[1])) {
         $result = strtolower($splitCode[0]) . '_' . strtoupper($splitCode[1]);
     } else {
         $logData = ['order_id' => $this->_order->getIncrementId(), 'language_code' => $languageCode];
         $this->_logger->critical("The store for order '{order_id}' is configured with an invalid language code: '{language_code}'", $this->_logContext->getMetaData(__CLASS__, $logData));
         $result = '';
     }
     return $result;
 }
 /**
  * Remove a client order id prefix from the increment id. As the prefix on the
  * increment id may have been any of the configured order id prefixes, need
  * to check through all possible prefixes configured to find the one to remove.
  * @param  string
  * @return string
  */
 public function removeOrderIncrementPrefix($incrementId)
 {
     $stores = $this->_getAllStores();
     foreach ($stores as $store) {
         $prefix = $this->_coreHelper->getConfigModel($store->getId())->clientOrderIdPrefix;
         // if the configured prefix matches the start of the increment id, strip
         // off the prefix from the increment
         if (strpos($incrementId, $prefix) === 0) {
             return substr($incrementId, strlen($prefix));
         }
     }
     // must return a string
     return (string) $incrementId;
 }
 /**
  * This should produce a serialized array of product links to be handled by
  * the product cleaner. Arrays should consist of
  *
  * @param DOMNodeList $nodes DOM nodes extracted from the feed
  * @return string Serialized array
  */
 public function extractProductLinks(DOMNodeList $nodes)
 {
     $links = array();
     foreach ($nodes as $linkNode) {
         $attrs = $linkNode->attributes;
         try {
             $linkType = $this->_convertToMagentoLinkType($attrs->getNamedItem('link_type')->nodeValue);
         } catch (Mage_Core_Exception $e) {
             // If the link_type in the feed dosn't match a known link type, do not
             // include it and move on to the next link.
             continue;
         }
         $links[] = array('link_type' => $linkType, 'operation_type' => $attrs->getNamedItem('operation_type')->nodeValue, 'link_to_unique_id' => Mage::helper('ebayenterprise_catalog')->normalizeSku(trim($linkNode->nodeValue), $this->coreHelper->getConfigModel()->catalogId));
     }
     return serialize($links);
 }
 /**
  * Update a single product with data from the feed. Should check for the
  * product to already exist in the collection and when it does, update the
  * product in the collection. When the product doesn't exist yet, it should
  * create a new product, set the extracted data on it and add it to the
  * collection.
  *
  * @param DOMXPath $feedXPath
  * @param DOMNode $itemNode
  * @param Varien_Data_Collection $itemCollection
  * @param int $storeId
  * @param array $cfgData
  * @param EbayEnterprise_Catalog_Interface_Import_Items $items
  * @return self
  */
 protected function _updateItem(DOMXPath $feedXPath, DOMNode $itemNode, Varien_Data_Collection $itemCollection, $storeId, array $cfgData, EbayEnterprise_Catalog_Interface_Import_Items $items)
 {
     $extractor = Mage::getSingleton('ebayenterprise_catalog/feed_extractor');
     $sku = $this->_helper->normalizeSku($extractor->extractSku($feedXPath, $itemNode, $cfgData['extractor_sku_xpath']), $this->_coreHelper->getConfigModel()->catalogId);
     $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
     $item = $itemCollection->getItemById($sku);
     if (is_null($item)) {
         $item = $items->createNewItem($sku);
         $item->setWebsiteIds(array($websiteId));
         $itemCollection->addItem($item);
     } elseif ($cfgData['feed_type'] === 'product') {
         $item->setUrlKey(false);
     }
     $item->setStoreId($storeId);
     $webSiteIds = array_unique(array_merge($item->getWebsiteIds(), array($websiteId)));
     $item->setWebsiteIds($webSiteIds);
     $item->addData($extractor->extractItem($feedXPath, $itemNode, $item, $cfgData));
     return $this;
 }
 /**
  * Prefix the order with the Client Order Id Prefix configured for the
  * current scope.
  * @return string
  */
 public function getPrefix()
 {
     return $this->_coreHelper->getConfigModel($this->_getStoreId())->clientOrderIdPrefix;
 }
 /**
  * load the preliminary data into EbayEnterprise_Dom_Document object and then return
  * a EbayEnterprise_Dom_Document object
  * @param int $storeId
  * @return EbayEnterprise_Dom_Document
  */
 protected function _loadDom($storeId)
 {
     $doc = $this->_coreHelper->getNewDomDocument();
     $doc->loadXml(sprintf(self::XML_TEMPLATE, self::ROOT_NODE, $this->_getCurrentHostName($storeId), $this->_coreHelper->getConfigModel()->clientId, Mage::getModel('core/date')->date('c'), $this->_catalogHelper->generateMessageHeader($this->_config->imageFeedEventType), $this->_coreHelper->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)));
     return $doc;
 }
 /**
  * Get the path to the XSD schema file to use to validate the DOMDocument
  * used to check an xml:lang.
  *
  * @return string
  */
 protected function _getLanguageCodeValidationSchemaFile()
 {
     $cfg = $this->_coreHelper->getConfigModel();
     return Mage::getBaseDir() . DS . $cfg->apiXsdPath . DS . self::LANGUAGE_CODE_SCHEMA;
 }