示例#1
0
 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);
         }
     }
 }
示例#4
0
 /**
  * @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->addWebsiteFilter([$this->websiteId]);
     }
     $this->loadByFilters($filters->getAppliedFilters());
 }