/**
  * Make a request to the token validation service using the token set in
  * "magic" data. Should return the response message from the service.
  * @return string
  */
 public function makeRequest()
 {
     // if there's no token, don't attempt to validate it
     if (!$this->getToken()) {
         $logMessage = 'No token to make request for';
         $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__));
         return '';
     }
     $response = Mage::getModel('eb2ccore/api')->setStatusHandlerPath(static::API_STATUS_HANDLER)->request($this->_buildRequest(), Mage::helper('eb2ccsr')->getConfigModel()->xsdFileTokenValidation, $this->_getApiUri());
     return $response;
 }
 /**
  * Go through all products that need to be cleaned and clean them.
  * @return $this object
  */
 public function cleanAllProducts()
 {
     // Get all products that need cleaning - due to loose comparison of column
     // values by the collection, any products that do not include an 'is_clean'
     // column will be included.
     $productsToClean = $this->_products->getItemsByColumnValue('is_clean', false);
     $logData = ['total_products' => count($productsToClean)];
     $logMessage = 'Cleaning {total_products} products.';
     $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     foreach ($productsToClean as $product) {
         $this->cleanProduct($product);
     }
     // save all the products that may have been modified while cleaning products
     $this->_helper->saveCollectionStubIndexer($this->_products);
     return $this;
 }
 /**
  * Save an EAV collection, disabling the indexer if the collection is
  * larger than a configured size.
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract
  * @return self
  */
 public function saveCollectionStubIndexer(Mage_Eav_Model_Entity_Collection_Abstract $collection)
 {
     $config = $this->getConfigModel();
     $stubIndexer = $config->maxPartialReindexSkus < $collection->getSize();
     if ($stubIndexer) {
         // Stub the indexer so no indexing can take place during massive saves.
         $indexerKey = '_singleton/index/indexer';
         $oldIndexer = $this->reregister($indexerKey, $this->indexerStub);
     }
     $failureCount = 0;
     $logData = ['product_count' => $collection->getSize()];
     $logMessage = 'Saving {product_count} products with stubbed indexer.';
     $this->logger->info($logMessage, $this->context->getMetaData(__CLASS__, $logData));
     $failMessage = 'Failed to save product with sku {sku}.';
     foreach ($collection as $item) {
         try {
             $item->save();
         } catch (Exception $e) {
             $failureCount++;
             $failLogData = ['sku' => $item->getSku(), 'exception' => $e];
             $this->logger->logException($e, $this->context->getMetaData(__CLASS__, $failLogData))->error($failMessage, $this->context->getMetaData(__CLASS__, $failLogData));
         }
     }
     $logMessage = 'Finished saving {product_count} products with {failure_count} failures.';
     $logData['failure_count'] = $failureCount;
     $this->logger->info($logMessage, $this->context->getMetaData(__CLASS__, $logData));
     if ($stubIndexer) {
         $this->reregister($indexerKey, $oldIndexer);
     }
     return $this;
 }
 /**
  * Dispacth an event in Magento with the payload and store scope it was received in.
  * @param IOrderEvent $payload
  * @param Mage_Core_Model_Store $store
  * @return self
  */
 protected function _dispatchPayload(IOrderEvent $payload, Mage_Core_Model_Store $store)
 {
     $eventName = $this->_eventPrefix . '_' . $this->_coreHelper->underscoreWords($payload->getEventType());
     $logData = ['event_name' => $eventName];
     $logMessage = 'Dispatching event "{event_name}" for payload.';
     $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     Mage::dispatchEvent($eventName, array('payload' => $payload, 'store' => $store));
     return $this;
 }
 /**
  * Log the different requests consistently.
  *
  * @param string $type 'do authorization', 'do express', 'do void', 'get express', 'set express'
  * @param string $body the serialized xml body
  * @param string $direction 'request' or 'response'
  */
 protected function logApiCall($type, $body, $direction)
 {
     $logData = ['type' => $type, 'direction' => $direction];
     $logMessage = 'Processing PayPal {type} {direction}';
     $this->logger->info($logMessage, $this->logContext->getMetaData(__CLASS__, $logData));
     $logData = ['rom_request_body' => $body];
     $logMessage = 'Request Data';
     $this->logger->debug($logMessage, $this->logContext->getMetaData(__CLASS__, $logData));
 }
 /**
  * undo the the allocation
  *
  * @return self
  */
 public function undoAllocation()
 {
     $result = $this->getInventorySession()->getAllocationResult();
     if ($result) {
         $reservation = $result->getReservation();
         $this->logger->info('Undo item allocation "{reservation_id}"', $this->logContext->getMetaData(__CLASS__, ['reservation_id' => $reservation->getId()]));
         $this->createDeallocator()->rollback($reservation);
     }
     $this->getInventorySession()->unsAllocationResult();
     return $this;
 }
 /**
  * Call the API.
  *
  * @param DOMDocument $doc The document to send in the request body
  * @param string $xsdName The basename of the xsd file to validate $doc (The dirname is in config.xml)
  * @param string $uri The uri to send the request to
  * @param int $timeout The amount of time in seconds after which the connection is terminated
  * @param string $adapter The classname of a Zend_Http_Client_Adapter
  * @param Zend_Http_Client $client
  * @param string $apiKey Alternate API Key to use
  * @return string The response from the server
  */
 public function request(DOMDocument $doc, $xsdName, $uri, $timeout = self::DEFAULT_TIMEOUT, $adapter = self::DEFAULT_ADAPTER, Zend_Http_Client $client = null, $apiKey = null)
 {
     if (!$apiKey) {
         $apiKey = Mage::helper('eb2ccore')->getConfigModel()->apiKey;
     }
     $xmlStr = $doc->C14N();
     $logData = array_merge(['rom_request_body' => $xmlStr], $this->_logAppContext);
     $logMessage = 'Validating request.';
     $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     $this->schemaValidate($doc, $xsdName);
     $client = $this->_setupClient($client, $apiKey, $uri, $xmlStr, $adapter, $timeout);
     $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext);
     $logMessage = 'Sending request.';
     $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     try {
         $response = $client->request(self::DEFAULT_METHOD);
         return $this->_processResponse($response, $uri);
     } catch (Zend_Http_Client_Exception $e) {
         return $this->_processException($e, $uri);
     }
 }
 /**
  * Clear out user and session data when validation fails. Dispatch an event,
  * set session messages and unset user data before returning the empty
  * user object.
  * @param  Mage_Admin_Model_User $user
  * @param  Mage_Core_Controller_Request_Http $request
  * @param  Mage_Core_Exception $authException
  * @return null
  * @codeCoverageIgnore All side-effects taken from Magento auth/login process
  */
 protected function _failValidation(Mage_Admin_Model_User $user, Mage_Core_Controller_Request_Http $request = null, Mage_Core_Exception $authException)
 {
     $logMessage = 'Failed to authenticate using token.';
     $this->logger->info($logMessage, $this->context->getMetaData(__CLASS__));
     // This may be problematic due to the missing user password. It is never
     // given while doing the token auth so we don't have one to pass. So far
     // it doesn't seem to be causing any issues but may have some impact on the
     // Mage_Enterprise_Pci_Model_Observer::adminAuthenticate method.
     Mage::dispatchEvent('admin_user_authenticate_after', array('username' => $user->getUsername(), 'password' => '', 'user' => $user, 'result' => false));
     Mage::dispatchEvent('admin_session_user_login_failed', array('user_name' => $user->getUsername(), 'exception' => $authException));
     if ($request && !$request->getParam('messageSent')) {
         Mage::getSingleton('adminhtml/session')->addError($authException->getMessage());
         $request->setParam('messageSent', true);
     }
     $user->unsetData();
     $this->_postAuthCheckRedirect(Mage::helper('adminhtml')->getUrl('*'));
 }
 /**
  * generate the outgoing product feed.
  * @param  array  $productIds     list of product id's to include in the feed.
  * @param  array  $feedTypeConfig configuration data for the current feed.
  * @param  array  $stores         list of stores to use as context for getting values.
  * @return array  array of full filepath where the feed files was saved.
  */
 public function buildFeed()
 {
     $logData = ['total_entity_ids' => count($this->_batch->getProductIds())];
     $logMessage = 'About to export {total_entity_ids} entity ids.';
     $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     $feedFilePath = '';
     $feedDataSet = $this->_createFeedDataSet();
     if ($feedDataSet->count()) {
         $feedFilePath = $this->_getFeedFilePath();
         $feedDoc = $this->_createDomFromFeedData($feedDataSet);
         $feedDoc->save($feedFilePath);
     } else {
         $skuLength = EbayEnterprise_Catalog_Helper_Pim::MAX_SKU_LENGTH;
         $filename = basename($feedFilePath);
         $logData = ['filename' => $filename, 'sku_length' => $skuLength];
         $logMessage = 'Could not generate {filename} because of missing required product data or the sku exceeded {sku_length} characters';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     }
     return $feedFilePath;
 }
 /**
  * load a product collection base on a given set of product data and apply
  * the product data to the collection and then save
  * product data is expected to have known SKU in order to load the collection
  * @param  DOMDocument $itemDataDoc
  * @param  int $storeId
  * @param  array $cfgData
  * @param  EbayEnterprise_Catalog_Interface_Import_Items $items
  * @return self
  */
 protected function _importExtractedData(DOMDocument $itemDataDoc, $storeId, array $cfgData, EbayEnterprise_Catalog_Interface_Import_Items $items)
 {
     $feedXPath = $this->_coreHelper->getNewDomXPath($itemDataDoc);
     $skusToUpdate = $this->_getSkusToUpdate($feedXPath, $cfgData);
     if (count($skusToUpdate)) {
         $collection = $items->buildCollection($skusToUpdate);
         if ($cfgData['feed_type'] === 'product') {
             $collection->setStore($storeId);
         }
         foreach ($feedXPath->query($cfgData['base_item_xpath']) as $itemNode) {
             $this->_updateItem($feedXPath, $itemNode, $collection, $storeId, $cfgData, $items);
         }
         $logData = ['total_products' => $collection->getSize(), 'feed_type' => $cfgData['feed_type']];
         $logMessage = 'saving collection of {total_products} {feed_type}';
         $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         // keep track of skus we've processed for the website
         $this->_importedSkus = array_unique(array_merge($this->_importedSkus, $skusToUpdate));
         $this->_helper->saveCollectionStubIndexer($collection);
     }
     return $this;
 }
 /**
  * Log the different requests consistently.
  *
  * @param string $type 'balance', 'redeem', 'void'
  * @param string $body the serialized xml body
  * @param string $direction 'request' or 'response'
  */
 protected function _logApiCall($type, $direction)
 {
     $logData = ['type' => $type, 'direction' => $direction];
     $logMessage = 'Processing gift card {type} {direction}.';
     $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
 }