/** * @param array $item * @param Customer $entity */ protected function writeExistingItem(array $item, Customer $entity) { $customerId = $item[self::CUSTOMER_ID_KEY]; try { $remoteData = $this->transport->getCustomerInfo($customerId); $item = $this->getStrategy()->merge($this->getEntityChangeSet(), $item, $remoteData, $this->getTwoWaySyncStrategy()); $this->stepExecution->getJobExecution()->getExecutionContext()->put(self::CONTEXT_CUSTOMER_POST_PROCESS, [$item]); $result = $this->transport->updateCustomer($customerId, $item); if ($result) { $this->stateHandler->markCustomerSynced($entity); $this->logger->info(sprintf('Customer with id %s successfully updated with data %s', $customerId, json_encode($item))); $entity->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); } else { $this->logger->error(sprintf('Customer with id %s was not updated', $customerId)); } } catch (TransportException $e) { if ($e->getFaultCode() == self::FAULT_CODE_NOT_EXISTS) { $this->stateHandler->markCustomerRemoved($entity); } $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } catch (\Exception $e) { $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } }
/** * @param array $item */ protected function writeExistingItem(array $item) { $customerAddressId = $item[self::CUSTOMER_ADDRESS_ID_KEY]; /** @var Address $entity */ $entity = $this->getEntity(); try { $remoteData = $this->transport->getCustomerAddressInfo($customerAddressId); $remoteData[self::CUSTOMER_ID_KEY] = $entity->getOwner()->getOriginId(); $item = $this->getStrategy()->merge($this->getEntityChangeSet(), $item, $remoteData, $this->getTwoWaySyncStrategy(), ['is_default_shipping', 'is_default_billing']); $this->stepExecution->getJobExecution()->getExecutionContext()->put(self::CONTEXT_CUSTOMER_ADDRESS_POST_PROCESS, [$item]); $result = $this->transport->updateCustomerAddress($customerAddressId, $item); if ($result) { $this->stateHandler->markAddressSynced($entity); $this->logger->info(sprintf('Customer address with id %s successfully updated with data %s', $customerAddressId, json_encode($item))); } else { $this->logger->error(sprintf('Customer address with id %s was not updated', $customerAddressId)); } } catch (TransportException $e) { if ($e->getFaultCode() == self::FAULT_CODE_NOT_EXISTS) { $this->stateHandler->markAddressRemoved($entity); } $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } catch (\Exception $e) { $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } }
/** * @param Address $entity */ protected function scheduleAddressSyncToMagento(Address $entity) { $this->stateHandler->markAddressForSync($entity); $this->saveEntity($entity); }