Example #1
0
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     if (array_key_exists('paymentDetails', $data)) {
         $data['paymentDetails'] = $this->importHelper->denormalizePaymentDetails($data['paymentDetails']);
     }
     /** @var Order $order */
     $order = parent::denormalize($data, $class, $format, $context);
     $integration = $this->importHelper->getIntegrationFromContext($context);
     $order->setChannel($integration);
     $order->setDataChannel($this->channelImportHelper->getChannel($integration));
     if ($order->getStore()) {
         $order->getStore()->setChannel($integration);
     }
     return $order;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     /** @var Customer $resultObject */
     $resultObject = new $class();
     if (!is_array($data)) {
         return $resultObject;
     }
     $mappedData = [];
     foreach ($data as $key => $value) {
         $fieldKey = isset($this->importFieldsMap[$key]) ? $this->importFieldsMap[$key] : $key;
         $mappedData[$fieldKey] = $value;
     }
     if (!empty($mappedData['birthday'])) {
         $mappedData['birthday'] = substr($mappedData['birthday'], 0, 10);
     }
     if (isset($mappedData['gender']) && !empty($mappedData['gender'])) {
         $gender = strtolower($mappedData['gender']);
         if (in_array($gender, [Gender::FEMALE, Gender::MALE])) {
             $mappedData['gender'] = $gender;
         } else {
             $mappedData['gender'] = null;
         }
     }
     $integration = $this->getIntegrationFromContext($context);
     $resultObject->setChannel($integration);
     $resultObject->setDataChannel($this->channelImportHelper->getChannel($integration));
     $this->setScalarFieldsValues($resultObject, $mappedData);
     $this->setObjectFieldsValues($resultObject, $mappedData, $format, $context);
     return $resultObject;
 }
Example #3
0
 /**
  * @dataProvider getChannelDataProvider
  *
  * @param int            $integrationId
  * @param int|null|false $expected
  * @param bool           $optional
  */
 public function testGetChannel($integrationId, $expected, $optional = false)
 {
     $integration = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel');
     $integration->expects($this->any())->method('getId')->will($this->returnValue($integrationId));
     if (false === $expected) {
         $this->setExpectedException('\\LogicException', 'Unable to find channel for given integration');
     }
     $existingIntegrationId = self::TEST_INTEGRATION_ID_WITH_CHANNEL;
     $existingChannelId = self::TEST_CHANNEL_ID;
     $this->getDriverConnectionMock($this->em)->expects($this->once())->method('query')->will($this->returnCallback(function () use($integrationId, $expected, $existingIntegrationId, $existingChannelId) {
         return $this->createFetchStatementMock([['id0' => $existingChannelId, 'id1' => $existingIntegrationId]]);
     }));
     $result1 = $this->helper->getChannel($integration, $optional);
     $result2 = $this->helper->getChannel($integration, $optional);
     $this->assertSame(is_object($result1) ? $result1->getId() : $result1, $expected);
     $this->assertSame($result1, $result2, 'Ensure query executed once');
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 protected function afterProcessEntity($entity)
 {
     if ($entity instanceof ChannelAwareInterface && $entity instanceof IntegrationAwareInterface && $entity->getChannel()) {
         $dataChannel = $this->channelHelper->getChannel($entity->getChannel());
         if ($dataChannel) {
             $entity->setDataChannel($dataChannel);
         }
     }
     return parent::afterProcessEntity($entity);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     if (array_key_exists('paymentDetails', $data)) {
         $data['paymentDetails'] = $this->importHelper->denormalizePaymentDetails($data['paymentDetails']);
     }
     /** @var Cart $cart */
     $cart = parent::denormalize($data, $class, $format, $context);
     $integration = $this->importHelper->getIntegrationFromContext($context);
     $cart->setChannel($integration);
     $cart->setDataChannel($this->channelImportHelper->getChannel($integration));
     if ($cart->getStore()) {
         $cart->getStore()->setChannel($integration);
     }
     if (!empty($data['email'])) {
         $cart->getCustomer()->setEmail($data['email']);
     }
     $this->updateStatus($cart, $data);
     return $cart;
 }