public function testFilters() { // add only last id filter $this->filter->addLastIdFilter(1); $filters = $this->getAppliedFilters($this->filter); $this->assertCount(1, $filters['complex_filter']); $this->assertNotEmpty($filters['complex_filter'][0]); // add date filter in initial mode $this->filter->addDateFilter('created_at', 'to', new \DateTime()); $filters = $this->getAppliedFilters($this->filter); $this->assertCount(2, $filters['complex_filter']); $this->assertNotEmpty($filters['complex_filter'][1]); $this->assertContains('created_at', $filters['complex_filter'][1]); $this->assertEquals('to', $filters['complex_filter'][1]['value']['key']); $this->filter->addDateFilter('updated_at', 'from', new \DateTime()); $filters = $this->getAppliedFilters($this->filter); $this->assertCount(3, $filters['complex_filter']); // still should be two filters $this->assertContains('updated_at', $filters['complex_filter'][2]); $this->assertEquals('from', $filters['complex_filter'][2]['value']['key']); // add website filter $this->filter->addWebsiteFilter([1]); $filters = $this->getAppliedFilters($this->filter); $this->assertCount(4, $filters['complex_filter']); $this->assertContains('website_id', $filters['complex_filter'][3]); // add store filter $this->filter->addStoreFilter([1]); $filters = $this->getAppliedFilters($this->filter); $this->assertCount(5, $filters['complex_filter']); $this->assertContains('store_id', $filters['complex_filter'][4]); }
/** * @param \DateTime $date * @param array $websiteIds * @param array $storeIds * @param string $format * * @return array */ protected function getBatchFilter(\DateTime $date, array $websiteIds = [], array $storeIds = [], $format = 'Y-m-d H:i:s') { if ($this->websiteId !== StoresSoapIterator::ALL_WEBSITES) { if (!empty($websiteIds)) { $this->filter->addWebsiteFilter($websiteIds); } if (!empty($storeIds)) { $this->filter->addStoreFilter($storeIds); } } $initMode = $this->mode == self::IMPORT_MODE_INITIAL; if ($initMode) { $dateField = 'created_at'; $dateKey = 'to'; } else { $dateField = 'updated_at'; $dateKey = 'from'; } $this->filter->addDateFilter($dateField, $dateKey, $date, $format); $lastId = $this->getLastId(); if (!is_null($lastId) && $initMode) { $this->filter->addLastIdFilter($lastId, $this->getIdFieldName()); } $this->logAppliedFilters($this->filter); return $this->filter->getAppliedFilters(); }
/** * @param array $websiteIds * @param array $storeIds */ protected function applyWebsiteFilters(array $websiteIds, array $storeIds) { if ($this->websiteId !== StoresSoapIterator::ALL_WEBSITES) { if (!empty($websiteIds)) { $this->filter->addWebsiteFilter($websiteIds); } if (!empty($storeIds)) { $this->filter->addStoreFilter($storeIds); } } }
/** * @param array $ids */ protected function loadEntities(array $ids) { if (!$ids) { return; } $filters = new BatchFilterBag(); $filters->addComplexFilter('in', ['key' => $this->getIdFieldName(), 'value' => ['key' => 'in', 'value' => implode(',', $ids)]]); if (null !== $this->websiteId && $this->websiteId !== StoresSoapIterator::ALL_WEBSITES) { $filters->addStoreFilter($this->getStoresByWebsiteId($this->websiteId)); } $filters = $filters->getAppliedFilters(); $filters['pager'] = ['page' => $this->getCurrentPage(), 'pageSize' => $this->pageSize]; $this->loadByFilters($filters); }
/** * 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); }
/** * @param BatchFilterBag $filter */ protected function applyStoreFilter(BatchFilterBag $filter) { if ($this->websiteId && $this->websiteId !== StoresSoapIterator::ALL_WEBSITES) { $filter->addStoreFilter($this->getStoresByWebsiteId($this->websiteId)); } }