/**
  * @param Customer $value
  * @return array
  */
 protected function getRemoteCustomers($value)
 {
     $this->transport->init($value->getChannel()->getTransport());
     $filter = new BatchFilterBag();
     $filter->addComplexFilter('email', ['key' => 'email', 'value' => ['key' => 'eq', 'value' => $value->getEmail()]]);
     $filter->addComplexFilter('store_id', ['key' => 'store_id', 'value' => ['key' => 'eq', 'value' => $value->getStore()->getOriginId()]]);
     $filters = $filter->getAppliedFilters();
     $customers = $this->transport->call(SoapTransport::ACTION_CUSTOMER_LIST, $filters);
     return (array) $customers;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     $this->channel = $this->contextMediator->getChannel($context);
     $this->transport = $this->contextMediator->getInitializedTransport($this->channel, true);
     // info was loaded from index action
     if ($this->transport->isSupportedExtensionVersion()) {
         return;
     }
     $entitiesIds = (array) $this->stepExecution->getJobExecution()->getExecutionContext()->get($this->contextKey);
     if (!$entitiesIds) {
         return;
     }
     sort($entitiesIds);
     $this->ids = array_unique(array_filter($entitiesIds));
 }
 /**
  * @dataProvider readItemDatesDataProvider
  *
  * @param string  $dateInContext
  * @param string  $dateInItem
  * @param string  $expectedDate
  * @param boolean $hasData
  * @param string  $dateInIterator
  */
 public function testRead($dateInContext, $dateInItem, $expectedDate, $hasData = true, $dateInIterator = null)
 {
     $iteratorMock = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Iterator\\UpdatedLoaderInterface');
     $connector = $this->getConnector($this->transportMock, $this->stepExecutionMock);
     $this->transportMock->expects($this->at(0))->method($this->getIteratorGetterMethodName())->will($this->returnValue($iteratorMock));
     $connector->setStepExecution($this->stepExecutionMock);
     $context = $this->stepExecutionMock->getExecutionContext();
     $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInContext]);
     $testValue = ['created_at' => '01.01.2200 14:15:08', 'updatedAt' => $dateInItem];
     if ($hasData) {
         $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInContext]);
         $iteratorMock->expects($this->once())->method('rewind');
         $iteratorMock->expects($this->once())->method('next');
         $iteratorMock->expects($this->any())->method('valid')->will($this->onConsecutiveCalls(true, false));
         $iteratorMock->expects($this->once())->method('current')->will($this->returnValue($testValue));
         $this->assertEquals($testValue, $connector->read());
     } else {
         $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInIterator]);
         $iteratorMock->expects($this->once())->method('rewind');
         $iteratorMock->expects($this->never())->method('next');
         $iteratorMock->expects($this->any())->method('valid')->will($this->returnValue(false));
         $iteratorMock->expects($this->never())->method('current')->will($this->returnValue(null));
         $iteratorMock->expects($this->at(0))->method('getStartDate')->will($this->returnValue(new \Datetime($dateInIterator)));
         $iteratorMock->expects($this->at(1))->method('getStartDate')->will($this->returnValue($dateInIterator));
     }
     $this->assertNull($connector->read());
     $connectorData = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY);
     $this->assertArrayHasKey('lastSyncItemDate', $connectorData);
     if ($hasData) {
         $this->assertSame($expectedDate, $connectorData['lastSyncItemDate']);
     } else {
         $this->assertSame($dateInIterator, $connectorData['lastSyncItemDate']);
     }
 }
Example #4
0
 /**
  * Process search for removal carts in CRM and mark them as "expired"
  *
  * @param array $ids
  */
 protected function processBatch($ids)
 {
     $filterBag = new BatchFilterBag();
     $filterBag->addStoreFilter($this->stores);
     $filterBag->addComplexFilter('entity_id', ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => implode(',', array_keys($ids))]]);
     $filters = $filterBag->getAppliedFilters();
     $filters['pager'] = ['page' => 1, 'pageSize' => $this->batchSize];
     $result = $this->transport->call(SoapTransport::ACTION_ORO_CART_LIST, $filters);
     $result = WSIUtils::processCollectionResponse($result);
     $resultIds = array_map(function (&$item) {
         return (int) $item->entity_id;
     }, $result);
     $resultIds = array_flip($resultIds);
     $removedIds = array_values(array_diff_key($ids, $resultIds));
     $this->em->getRepository('OroCRMMagentoBundle:Cart')->markExpired($removedIds);
 }
Example #5
0
 /**
  * @param MagentoTransportInterface $transport
  * @param int                       $websiteId
  *
  * @return array
  */
 protected function getSores(MagentoTransportInterface $transport, $websiteId)
 {
     $stores = [];
     foreach ($transport->getStores() as $store) {
         if ($store['website_id'] == $websiteId || $websiteId === StoresSoapIterator::ALL_WEBSITES) {
             $stores[] = $store['store_id'];
         }
     }
     return $stores;
 }