public function testAccumulateByMapFromAndToAreArrays()
 {
     $from['value'] = 'from_value';
     $map[false] = 'value';
     $to['key'] = 'to_value';
     $default['new_key'] = 'value';
     $expected['key'] = 'to_value';
     $expected['value'] = 'from_value';
     $expected['new_key'] = 'value';
     $this->assertEquals($expected, $this->mapper->accumulateByMap($from, $to, $map, $default));
 }
 /**
  * Import $this public data from a private response array
  *
  * @param array $privateResponseMap
  * @param array $response
  * @return void
  */
 protected function _importFromResponse(array $privateResponseMap, array $response)
 {
     $map = [];
     foreach ($privateResponseMap as $key) {
         if (isset($this->_globalMap[$key])) {
             $map[$key] = $this->_globalMap[$key];
         }
         if (isset($response[$key]) && isset($this->_importFromRequestFilters[$key])) {
             $callback = $this->_importFromRequestFilters[$key];
             $response[$key] = call_user_func([$this, $callback], $response[$key], $key, $map[$key]);
         }
     }
     \Magento\Framework\DataObject\Mapper::accumulateByMap($response, [$this, 'setDataUsingMethod'], $map);
 }
Exemple #3
0
 /**
  * Prepare request data basing on provided addresses
  *
  * @param array $to
  * @return array
  */
 protected function _importAddresses(array $to)
 {
     $billingAddress = $this->getBillingAddress() ? $this->getBillingAddress() : $this->getAddress();
     $shippingAddress = $this->getAddress();
     $to = \Magento\Framework\DataObject\Mapper::accumulateByMap($billingAddress, $to, array_merge(array_flip($this->_billingAddressMap), $this->_billingAddressMapRequest));
     $regionCode = $this->_lookupRegionCodeFromAddress($billingAddress);
     if ($regionCode) {
         $to['STATE'] = $regionCode;
     }
     if (!$this->getSuppressShipping()) {
         $to = \Magento\Framework\DataObject\Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap));
         $regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress);
         if ($regionCode) {
             $to['SHIPTOSTATE'] = $regionCode;
         }
         $this->_importStreetFromAddress($shippingAddress, $to, 'SHIPTOSTREET', 'SHIPTOSTREET2');
         $this->_importStreetFromAddress($billingAddress, $to, 'STREET', 'STREET2');
         $to['SHIPTONAME'] = $shippingAddress->getName();
     }
     return $to;
 }
Exemple #4
0
 /**
  * Grab data from payment and map it into target
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param array|\Magento\Framework\DataObject|callback $to
  * @param array|null $map
  * @return array|\Magento\Framework\DataObject
  */
 public function &exportFromPayment(\Magento\Payment\Model\InfoInterface $payment, $to, array $map = null)
 {
     $fullMap = array_merge($this->_paymentMap, $this->_systemMap);
     \Magento\Framework\DataObject\Mapper::accumulateByMap([$payment, 'getAdditionalInformation'], $to, $map ? $map : array_flip($fullMap));
     return $to;
 }