コード例 #1
0
 /**
  * prepare stubs
  */
 public function setUp()
 {
     parent::setUp();
     $this->_httpApi = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Api\\HttpApi')->disableOriginalConstructor()->getMock();
     $this->_observerStub = $this->getModelMock('ebayenterprise_order/observer');
     $this->_itemSelection = $this->getHelperMock('ebayenterprise_order/item_selection', ['selectFrom']);
     $this->_payloadFactory = new PayloadFactory();
     $this->_request = $this->_payloadFactory->buildPayload('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Order\\OrderCreateRequest');
     $this->_requestStub = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Order\\IOrderCreateRequest');
     $this->_replyStub = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Order\\IOrderCreateReply');
     $this->_coreHelperStub = $this->getHelperMock('eb2ccore/data', ['generateRequestId', 'getConfigModel']);
     $coreConfig = $this->buildCoreConfigRegistry(['clientCustomerIdPrefix' => $this->_clientCustomerIdPrefix, 'language_code' => 'en-us', 'clientCustomerIdLength' => 0]);
     $this->_coreHelperStub->expects($this->any())->method('getConfigModel')->will($this->returnValue($coreConfig));
     $this->_config = $this->buildCoreConfigRegistry(['levelOfService' => $this->_expectedLevelOfService, 'orderType' => $this->_expectedOrderType, 'requestIdPrefix' => $this->_expectedRequestIdPrefix, 'apiCreateOperation' => 'create', 'apiService' => 'orders', 'genderMap' => ['Female' => 'F', 'Male' => 'M', 'SomeOtherGender' => 'Invalid']]);
     $this->_orderHelperStub = $this->getHelperMock('ebayenterprise_order', ['prefixCustomerId']);
     // Mock the customer id prefixing method to return the customer id
     // prefixed with the constant client customer id prefix.
     $clientCustomerIdPrefix = $this->_clientCustomerIdPrefix;
     $this->_orderHelperStub->method('prefixCustomerId')->will($this->returnCallback(function ($id) use($clientCustomerIdPrefix) {
         return $clientCustomerIdPrefix . $id;
     }));
     $this->_customer = Mage::getModel('customer/customer', ['increment_id' => '12345123456789']);
     $this->_order = Mage::getModel('sales/order', ['created_at' => '2014-07-28 16:22:46', 'customer' => $this->_customer, 'customer_dob' => '2014-07-28 16:22:46', 'customer_email' => '*****@*****.**', 'customer_firstname' => 'fname', 'customer_lastname' => 'lname', 'customer_middlename' => 'mname', 'customer_prefix' => 'mr', 'customer_id' => '123456789', 'customer_taxvat' => 'taxid', 'increment_id' => '12345123456789']);
     $this->_item1 = $this->getModelMock('sales/order_item', []);
     $this->_item2 = $this->getModelMock('sales/order_item', []);
     $this->_billAddress = Mage::getModel('sales/order_address', ['address_type' => Mage_Customer_Model_Address_Abstract::TYPE_BILLING, 'entity_id' => $this->_billAddressId]);
     $this->_shipAddress = Mage::getModel('sales/order_address', ['address_type' => Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING, 'entity_id' => $this->_shipAddressId]);
     // Mock log context to prevent session interactions while building out log data.
     $this->_logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']);
     $this->_logContext->method('getMetaData')->will($this->returnValue([]));
     // prevent magento events from actually triggering
     Mage::app()->disableEvents();
 }
コード例 #2
0
 /**
  * Scenario: Mask StoredValue* Payload XML sensitive data
  * Given an XML Payload containing sensitive data.
  * When the mask XML nodes is applied.
  * Then all sensitive data are masked in XML Payload.
  *
  * @param string
  * @param string
  * @param array
  * @param string
  * @dataProvider providerMaskXmlNodes
  */
 public function testMaskXmlNodes($xml, $mask, array $expressionList, $prefix)
 {
     /** @var DOMDocument */
     $doc = $this->coreHelper->getNewDomDocument();
     $doc->loadXML($xml);
     /** @var DOMXPath */
     $xpath = $this->getXPath($doc, $prefix);
     foreach ($expressionList as $expression) {
         // Proving that the value of the nodes are not masked prior to calling
         // the method ebayenterprise_giftcard/giftcard::maskXmlNodes() on the
         // XML Payload.
         $this->assertNotSame($mask, $xpath->evaluate($expression));
     }
     /** @var DOMDocument */
     $maskDoc = $this->coreHelper->getNewDomDocument();
     // Masking the node values in the XML Payload
     $maskDoc->loadXML($this->mask->maskXmlNodes($xml));
     /** @var DOMXPath */
     $maskXPath = $this->getXPath($maskDoc, $prefix);
     foreach ($expressionList as $expression) {
         // Proving that the value of the nodes are now masked after calling
         // the method ebayenterprise_giftcard/giftcard::maskXmlNodes() on the
         // XML Payload.
         $this->assertSame($mask, $maskXPath->evaluate($expression));
     }
 }
コード例 #3
0
 /**
  * Test that a properly configured SDK API is created for making
  * the tax request.
  */
 public function testGetSdkApi()
 {
     // Allow the core helper to provide the correct API object
     // if given the appropriate configuration values for the
     // API service and operation.
     $this->_coreHelper->expects($this->any())->method('getSdkApi')->with($this->identicalTo($this->_apiService), $this->identicalTo($this->_apiOperation))->will($this->returnValue($this->_api));
     $this->assertSame($this->_api, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_sdkHelper, '_getSdkApi'));
 }
コード例 #4
0
 public function testGetTenderTypeLookupApi()
 {
     $service = 'payments';
     $operation = 'tendertype/lookup';
     $tenderTypeHelper = $this->getHelperMockBuilder('ebayenterprise_giftcard/tendertype')->setMethods(null)->setConstructorArgs([$this->constructorArgs])->getMock();
     $this->api = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi')->getMockForAbstractClass();
     $this->coreHelper->expects($this->once())->method('getSdkApi')->with($this->identicalTo($service), $this->identicalTo($operation), $this->identicalTo([]), $this->identicalTo($this->apiLogger))->will($this->returnValue($this->api));
     $this->assertSame($this->api, EcomDev_Utils_Reflection::invokeRestrictedMethod($tenderTypeHelper, 'getTenderTypeLookupApi'));
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 /**
  * Extracting the response data using the configuration
  * callback methods.
  *
  * @return array
  */
 protected function _extractData(IOrderDetailResponse $detail)
 {
     $data = [];
     foreach ($this->_config->mapDetailResponse as $key => $callback) {
         if ($callback['type'] !== 'disabled') {
             $getter = $callback['getter'];
             $callback['parameters'] = [$detail, $getter];
             $data[$key] = $this->_coreHelper->invokeCallback($callback);
         }
     }
     return $data;
 }
コード例 #7
0
 /**
  * Mask the StoredValue request XML message of any sensitive data - PAN, PIN.
  *
  * @param  string
  * @return string
  */
 public function maskXmlNodes($xml)
 {
     /** @var DOMDocument */
     $doc = $this->coreHelper->getNewDomDocument();
     $doc->loadXML($xml);
     /** @var DOMElement */
     $element = $doc->documentElement;
     /** @var DOMXPath */
     $xpath = $this->coreHelper->getNewDomXPath($doc);
     $xpath->registerNamespace('x', $element->namespaceURI);
     $this->maskPin($doc, $xpath)->maskPan($doc, $xpath);
     return $doc->saveXML();
 }
コード例 #8
0
 public function setUp()
 {
     parent::setUp();
     // Prevent log context from needing session while gather context data for logging.
     $this->logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']);
     $this->logContext->method('getMetaData')->will($this->returnValue([]));
     $this->api = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi');
     $this->configModel = $this->buildCoreConfigRegistry(['apiService' => 'inventory', 'apiOperation' => 'allocate']);
     $this->helper = $this->getHelperMock('ebayenterprise_inventory');
     $this->helper->method('getConfigModel')->will($this->returnValue($this->configModel));
     $this->coreHelper = $this->getHelperMock('eb2ccore', ['getSdkApi']);
     $this->coreHelper->method('getSdkApi')->will($this->returnValue($this->api));
 }
コード例 #9
0
 /**
  * extract the SalesClass from DOMNOdeList object and map to a known Magento 'backorder' value
  * @param DOMNodeList $nodes
  * @param Mage_Catalog_Model_Product $product
  * @return null
  */
 public function extractStockData(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     /** @var string */
     $value = $this->coreHelper->extractNodeVal($nodes);
     /** @var int */
     $productId = (int) $product->getId();
     /** @var array */
     $stockData = $this->buildStockData($productId, $value);
     if (!$productId) {
         $product->setNewProductStockData($stockData);
         return null;
     }
     $this->saveStockItem($stockData, $productId);
     return null;
 }
コード例 #10
0
 /**
  * Get the last timestamp captured from a test message and return a new DateTime
  * object for the timestamp. If no last test message exists or is not a parseable
  * date time, will return null.
  * @return DateTime|null
  */
 protected function _getLastTimestamp()
 {
     $lastTimestamp = $this->getValue();
     $timestamp = null;
     try {
         // If the value isn't set, don't create a new DateTime. new DateTime(null)
         // gives a DateTime for the current time, which is not desirable here.
         $timestamp = $lastTimestamp ? $this->_coreHelper->getNewDateTime($lastTimestamp) : null;
     } catch (Exception $e) {
         $logData = ['last_timestamp' => $lastTimestamp];
         $logMessage = 'Invalid timestamp for last AMQP test message timestamp: {last_timestamp}.';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $e));
     }
     return $timestamp;
 }
コード例 #11
0
 /**
  * build the xml node base on the image data given and the DOMDocument object given
  * @param EbayEnterprise_Dom_Document
  * @param array $imageData
  * @return self
  */
 protected function _buildXmlNodes(EbayEnterprise_Dom_Document $doc, array $imageData)
 {
     $itemImages = $this->_coreHelper->getDomElement($doc);
     foreach ($imageData as $data) {
         $this->_buildImagesNodes($itemImages->createChild('Item', null, ['id' => $data['id']]), $data['image_data']);
     }
     return $this;
 }
コード例 #12
0
 /**
  * Load the XML file into a new DOMDocument.
  *
  * @param string
  * @return DOMDocument
  * @throws EbayEnterprise_Eb2cCore_Exception_InvalidXml If file files to be loaded into a DOMDocument.
  */
 protected function loadDoc($fileName)
 {
     $doc = $this->coreHelper->getNewDomDocument();
     if ($doc->load($fileName)) {
         return $doc;
     }
     // If file could not be loaded into a DOMDocument, treat the XML as invalid.
     throw Mage::exception('EbayEnterprise_Eb2cCore_Exception_InvalidXml', "Could not load {$fileName} in DOMDocument.");
 }
コード例 #13
0
 /**
  * Prepare an API instance for a balance request - fill out and set the
  * request payload with gift card data.
  * @param  Api\IBidirectionalApi $api
  * @return self
  */
 protected function _prepareApiForVoid(Api\IBidirectionalApi $api)
 {
     $this->setRedeemVoidRequestId($this->_coreHelper->generateRequestId(self::VOID_REQUST_ID_PREFIX));
     $payload = $api->getRequestBody();
     $payload->setRequestId($this->getRedeemVoidRequestId())->setPin($this->getPin())->setAmount($this->getAmountRedeemed())->setCurrencyCode($this->getRedeemCurrencyCode());
     $this->_setPayloadPaymentContext($payload);
     $api->setRequestBody($payload);
     return $this;
 }
コード例 #14
0
 /**
  * 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;
 }
コード例 #15
0
 /**
  * Resubmit an order.
  *
  * @param Mage_Sales_Model_Order
  * @return void
  */
 protected function resubmit(Mage_Sales_Model_Order $order)
 {
     if (!$order->hasEb2cOrderCreateRequest()) {
         $this->logger->warning('Unable to resubmit "{order_id}". Please see documentation for possible solutions.', $this->logContext->getMetaData(['order_id' => $order->getIncrementId()]));
         return;
     }
     $api = $this->coreHelper->getSdkApi($this->orderCfg->apiService, $this->orderCfg->apiCreateOperation);
     $createArgs = ['api' => $api, 'config' => $this->orderCfg, 'is_payload_prebuilt' => true, 'order' => $order, 'payload' => $api->getRequestBody()];
     $this->getOrderCreateModel($createArgs)->send();
 }
コード例 #16
0
 /**
  * If the "ExtendedAttributes/AllowGiftMessage" node exist then we proceed
  * to set the product attribute "use_config_gift_message_available" to false
  * and return the boolean value of the "ExtendedAttributes/AllowGiftMessage" node.
  * Otherwise, if the "ExtendedAttributes/AllowGiftMessage" node doesn't exists
  * we simply return null in order to let the default value be set on the attribute.
  *
  * @param  DOMNodeList
  * @param  Mage_Catalog_Model_Product
  * @return int | null
  */
 public function extractAllowGiftMessage(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     if ($nodes->length) {
         $product->setUseConfigGiftMessageAvailable(0);
         // Explicitly casting the extracted boolean value as an integer value because
         // Magento only work with integer value 0 or 1 representing boolean value in the database.
         return (int) $this->coreHelper->parseBool($nodes->length ? $nodes->item(0)->nodeValue : null);
     }
     return null;
 }
コード例 #17
0
 /**
  * Build a collection of order item from this particular ship group
  *
  * @param bool
  * @return Varien_Data_Collection
  */
 protected function _buildItemsCollection($includeHidden)
 {
     $items = $this->_coreHelper->getNewVarienDataCollection();
     foreach ($this->getOrderItems() as $itemId) {
         $item = $this->_order->getItemsCollection()->getItemByColumnValue('ref_id', $itemId);
         if ($item && ($includeHidden || !$item->getIsHiddenGift())) {
             $items->addItem($item);
         }
     }
     return $items;
 }
コード例 #18
0
 /**
  * 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);
 }
コード例 #19
0
 /**
  * Retry order create requests on unsubmitted orders.
  * Run this on cron.
  *
  * @return void
  */
 public function handleEbayEnterpriseOrderCreateRetryJob()
 {
     $orders = $this->getUnsubmittedOrders();
     $this->logger->debug('Found {order_retry_count} order(s) to be resubmitted.', $this->logContext->getMetaData(__CLASS__, ['order_retry_count' => $orders->getSize()]));
     $api = $this->coreHelper->getSdkApi($this->orderCfg->apiService, $this->orderCfg->apiCreateOperation);
     $createArgs = ['api' => $api, 'config' => $this->orderCfg, 'payload' => $api->getRequestBody(), 'is_payload_prebuilt' => true];
     foreach ($orders as $order) {
         $this->resubmit($order, $createArgs);
     }
     $this->logger->debug('Order retry complete.', $this->logContext->getMetaData(__CLASS__));
 }
コード例 #20
0
 /**
  * Extracting the response data using the configuration
  * callback methods.
  *
  * @param  IPayload
  * @param  array
  * @return array
  */
 protected function _extractData(IPayload $payload, array $map)
 {
     $data = [];
     foreach ($map as $key => $callback) {
         if ($callback['type'] !== 'disabled') {
             $getter = $callback['getter'];
             $callback['parameters'] = [$payload, $getter];
             $data[$key] = $this->_coreHelper->invokeCallback($callback);
         }
     }
     return $data;
 }
コード例 #21
0
 /**
  * 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;
 }
コード例 #22
0
 /**
  * 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;
 }
コード例 #23
0
 /**
  * Account for shipping discounts not attached to an item.
  * Combine all shipping discounts into one.
  *
  * @see self::handleSalesConvertQuoteAddressToOrderAddress
  * @see Mage_SalesRule_Model_Validator::processShippingAmount
  * @param Varien_Event_Observer
  * @return void
  */
 public function handleSalesQuoteCollectTotalsAfter(Varien_Event_Observer $observer)
 {
     $event = $observer->getEvent();
     /** @var Mage_Sales_Model_Quote $quote */
     $quote = $event->getQuote();
     /** @var Mage_Sales_Model_Resource_Quote_Address_Collection */
     $addresses = $quote->getAddressesCollection();
     foreach ($addresses as $address) {
         $appliedRuleIds = $address->getAppliedRuleIds();
         if (is_array($appliedRuleIds)) {
             $appliedRuleIds = implode(',', $appliedRuleIds);
         }
         $data = (array) $address->getEbayEnterpriseOrderDiscountData();
         $data[$appliedRuleIds] = ['id' => $appliedRuleIds, 'amount' => $address->getBaseShippingDiscountAmount(), 'description' => $this->helper->__('Shipping Discount')];
         $address->setEbayEnterpriseOrderDiscountData($data);
     }
 }
コード例 #24
0
 /**
  * Test that the helper callback method ebayenterprise_catalog/map::extractCustomAttributes()
  * when invoked will be given as its first parameter an object of type DOMNodeList, and as its second parameter
  * an object of type catalog/product. Then, we expect the proper custom attribute to be extracted
  * and added to the passed-in product object.
  *
  * @param string
  * @param Mage_Catalog_Model_Product
  * @dataProvider providerExtractCustomAttributes
  */
 public function testExtractCustomAttributes($feedFile, Mage_Catalog_Model_Product $product)
 {
     $this->_doc->loadXML(file_get_contents($feedFile));
     /** @var DOMXPath $xpath */
     $xpath = $this->_coreHelper->getNewDomXPath($this->_doc);
     /** @var DOMNodeList $nodes */
     $nodes = $xpath->query('//CustomAttributes/Attribute');
     /** @var EbayEnterprise_Catalog_Helper_Map $map */
     $map = Mage::helper('ebayenterprise_catalog/map');
     // Proving that product object has no value
     $this->assertEmpty($product->getData());
     // Proving that when the method ebayenterprise_catalog/map::extractCustomAttributes()
     // invoked it will always return null
     $this->assertNull($map->extractCustomAttributes($nodes, $product));
     // Proving that after calling the method ebayenterprise_catalog/map::extractCustomAttributes()
     // the empty passed in product object will now contains data
     $this->assertNotEmpty($product->getData());
 }
コード例 #25
0
 /**
  * Account for discounts in order create request.
  *
  * @see self::handleSalesConvertQuoteItemToOrderItem
  * @see Mage_SalesRule_Model_Validator::process
  * @see Order-Datatypes-Common-1.0.xsd:PromoDiscountSet
  * @param Varien_Event_Observer
  * @return void
  */
 public function handleSalesRuleValidatorProcess(Varien_Event_Observer $observer)
 {
     /** @var Varien_Event $event */
     $event = $observer->getEvent();
     /** @var Mage_SalesRule_Model_Rule $rule */
     $rule = $event->getRule();
     /** @var Mage_Sales_Model_Quote $quote */
     $quote = $event->getQuote();
     /** @var Mage_Core_Model_Store $store */
     $store = $quote->getStore();
     /** @var Mage_Sales_Model_Quote_Item $item */
     $item = $event->getItem();
     $data = (array) $item->getEbayEnterpriseOrderDiscountData();
     $ruleId = $rule->getId();
     // Use the rule id to prevent duplicates.
     $data[$ruleId] = ['amount' => $event->getResult()->getBaseDiscountAmount(), 'applied_count' => $event->getQty(), 'code' => $this->helper->getQuoteCouponCode($quote, $rule), 'description' => $rule->getStoreLabel($store) ?: $rule->getName(), 'effect_type' => $rule->getSimpleAction(), 'id' => $ruleId];
     $item->setEbayEnterpriseOrderDiscountData($data);
 }
コード例 #26
0
 /**
  * Perform the web request for address validation and return the response
  * @param Mage_Customer_Model_Address_Abstract $address
  * @return EbayEnterprise_Address_Model_Validation_Response|null
  */
 protected function _makeRequestForAddress(Mage_Customer_Model_Address_Abstract $address)
 {
     $config = $this->_helper->getConfigModel();
     $api = $this->_coreHelper->getSdkApi($config->apiService, $config->apiOperation);
     try {
         $this->_prepareApiForAddressRequest($address, $api);
         $api->send();
         return $this->_getValidationResponse($api);
     } catch (NetworkError $e) {
         $logMessage = 'Address validation service returned empty response.';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__));
     } catch (Exception $e) {
         $logMessage = 'Unexpected exception from SDK.';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     return null;
 }
コード例 #27
0
 /**
  * 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;
 }
コード例 #28
0
 /**
  * get all exported files and a list of acknowledgment files imported
  * loop through all the exported files and check if each exported files has an imported acknowledgment file
  * in the list of acknowledgment files, if the file is in the list of
  * acknowledgment file, then simply move the exported to export_archive and the acknowledgment file to import_archive
  * otherwise the exported file has no acknowledgment therefore, check the created time of
  * exported file if is greater than the configurable elapse time simply move it back to
  * out-box to be exported again, however if the elapse time is less than the configurable
  * simply ignore the file
  * @return self
  */
 public function process()
 {
     $exportedList = $this->_listFilesByCfgKey(self::CFG_EXPORTED_FEED_DIR);
     if (!empty($exportedList)) {
         $importedList = $this->_getImportedAckFiles();
         foreach ($exportedList as $exported) {
             $ack = $this->_getAck($exported, $importedList);
             if (!is_null($ack)) {
                 $this->_mvTo($exported, self::CFG_EXPORT_ARCHIVE)->_mvTo($ack, self::CFG_IMPORT_ARCHIVE);
             } elseif ($this->_isTimedOut($exported)) {
                 // create the error directory since it's not automatically created
                 // when processing the feeds
                 $this->_coreHelper->createDir($this->_buildPath(self::CFG_ERROR_DIRECTORY));
                 $this->_mvTo($exported, self::CFG_ERROR_DIRECTORY);
                 $this->_logger->critical('{file_name} was not acknowledged by Product Hub', $this->_context->getMetaData(__CLASS__, ['file_name' => $exported]));
             }
         }
     }
     return $this;
 }
コード例 #29
0
 /**
  * Create the DOMDocument representing the feed. Should initialize (add root
  * node and message header) the DOMDocument, build out and append fragments
  * for each item to be included, and validate the resulting DOM.
  */
 public function testCreateDomFromFeedData()
 {
     $itemNode = 'Item';
     $isValidate = 'true';
     $this->_doc->loadXML('<root></root>');
     $itemFragment = $this->_doc->createDocumentFragment();
     $itemFragment->appendChild($this->_doc->createElement('Item'));
     $pimProduct = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->getMock();
     $this->replaceByMock('helper', 'eb2ccore', $this->_coreHelper);
     $this->_coreHelper->expects($this->once())->method('parseBool')->with($this->identicalTo($isValidate))->will($this->returnValue(true));
     $this->_pimProductCollection->expects($this->once())->method('getItems')->will($this->returnValue(array($pimProduct)));
     $pim = $this->getModelMockBuilder('ebayenterprise_catalog/pim')->disableOriginalConstructor()->setMethods(array('_buildItemNode', '_startDocument', '_validateDocument', '_getFeedConfig'))->getMock();
     $pim->expects($this->once())->method('_startDocument')->will($this->returnSelf());
     $pim->expects($this->once())->method('_buildItemNode')->with($this->identicalTo($pimProduct), $this->identicalTo($itemNode))->will($this->returnValue($itemFragment));
     $pim->expects($this->once())->method('_validateDocument')->will($this->returnSelf());
     $pim->expects($this->once())->method('_getFeedConfig')->will($this->returnValue($this->_feedTypeConfig));
     EcomDev_Utils_Reflection::setRestrictedPropertyValue($pim, '_doc', $this->_doc);
     $this->assertSame($this->_doc, EcomDev_Utils_Reflection::invokeRestrictedMethod($pim, '_createDomFromFeedData', array($this->_pimProductCollection, $this->_feedTypeConfig)));
     $this->assertSame('<root><Item></Item></root>', $this->_doc->C14N());
 }
コード例 #30
0
 /**
  * Scenario: Extract size option
  * Given an XML NodeList object containing size data.
  * When the callback extracts the size option.
  * Then The size option id is returned.
  */
 public function testExtractSizeValue()
 {
     /** @var int $optionId */
     $optionId = 89;
     /** @var DOMDocument $doc */
     $doc = $this->coreHelper->getNewDomDocument();
     $doc->loadXML('<root>
             <Size>
                 <Code>77</Code>
                 <Description xml:lang="en-us">Small</Description>
             </Size>
         </root>');
     /** @var DOMXPath $xpath */
     $xpath = $this->coreHelper->getNewDomXPath($doc);
     /** @var DOMNodeList $nodeList */
     $nodeList = $xpath->query('Size', $doc->documentElement);
     /** @var Mock_EbayEnterprise_Catalog_Helper_Map_Attribute $mapAttribute */
     $mapAttribute = $this->getHelperMock('ebayenterprise_catalog/map_attribute', ['_setOptionValues']);
     $mapAttribute->expects($this->once())->method('_setOptionValues')->with($this->identicalTo('size'), $this->identicalTo('77'), $this->identicalTo(['en-us' => 'Small']))->will($this->returnValue($optionId));
     $this->assertSame($optionId, $mapAttribute->extractSizeValue($nodeList));
 }