check if already synced with local products
@param array $products
@param int $syncDomainsCount
@return array
484161
private function markProductsAsSynced($products, $syncDomainsCount)
    {

        $syncProducts = $this->SyncProduct->findAllSyncProducts($this->AppAuth->getManufacturerId());

        foreach ($products as $product) {
            $syncCount = 0;
            $preparedSyncProducts = [];

            foreach ($syncProducts as $syncProduct) {
                if ($syncProduct->dash_separated_local_product_id === $product->id_product) {
                    $syncCount++;
                    $preparedSyncProducts[] = [
                        'domain' => $syncProduct->sync_domain->domain,
                        'name' => 'Name wird nach Login angezeigt...',
                        'remoteProductId' => $syncProduct->dash_separated_remote_product_id
                    ];
                }
            }

            if ($syncCount > 0) {
                $product->prepared_sync_products = $preparedSyncProducts;
            }
        }

        return $products;
    }
1055301
public static function shakeFor(Collection $products) : Collection
	{
		$suggestions = new static($key = 'all');

		$suggestions->products = $products;

		$suggestions->excluding($products);

		return $suggestions->suggestFor($key);
	}
548353
public function setProducts(array $products)
    {
        $this->products = array_values(array_filter($products, function ($product): bool {
            return $product instanceof Product;
        }));
        return $this;
    }
579153
public static function countLogData($syncid, $type = 'all')
	{
		$db = Factory::getDBO();

		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from('#__jfusion_sync_details')
			->where('syncid = ' . $db->quote($syncid));

		if ($type != 'all') {
			$query->where('action = ' . $db->quote($type));
		}
		$db->setQuery($query);
		return (int)$db->loadResult();
	}
882157
protected function has_changes( array $changes, $attributes = null ) {
		if ( empty( $attributes ) ) {
			return count( $changes ) > 0;
		}

		foreach ( (array) $attributes as $attribute ) {
			if ( array_key_exists( $attribute, $changes ) ) {
				return true;
			}
		}

		return false;
	}
27182
private function isDomainMatch($imageHost, array $sourceDomains)
    {
        if (null === $imageHost) {
            return empty($sourceDomains) || in_array(null, $sourceDomains);
        }

        if (in_array($imageHost, $sourceDomains)) {
            return true;
        }

        // check sub domain
        $imageDomainParts = explode('.', $imageHost, 2);
        if (isset($imageDomainParts[1]) && in_array($imageDomainParts[1], $sourceDomains)) {
            return true;
        }

        return false;
    }
800304
protected function hasOneOrManyDeepFromRelations(array $relations)
    {
        if (is_array($relations[0])) {
            $relations = $relations[0];
        }

        $related = null;
        $through = [];
        $foreignKeys = [];
        $localKeys = [];

        foreach ($relations as $i => $relation) {
            $method = $this->hasOneOrManyDeepRelationMethod($relation);

            [$through, $foreignKeys, $localKeys] = $this->$method($relation, $through, $foreignKeys, $localKeys);

            if ($i === count($relations) - 1) {
                $related = get_class($relation->getRelated());
            } else {
                $through[] = get_class($relation->getRelated());
            }
        }

        return [$related, $through, $foreignKeys, $localKeys];
    }
1189492
public function updateCustomer(StripeLocalCustomer $localCustomer, $syncSources): bool
    {
        // Get the stripe object
        $stripeCustomer = $this->retrieveCustomer($localCustomer);

        // The retrieving failed: return false
        if (false === $stripeCustomer) {
            return false;
        }

        // Update the stripe object with info set in the local object
        $this->customerSyncer->syncStripeFromLocal($stripeCustomer, $localCustomer);

        // Save the customer object
        $stripeCustomer = $this->callStripeObject($stripeCustomer, 'save');

        // If the update failed, return false
        if (false === $stripeCustomer) {
            return false;
        }

        // Set the data returned by Stripe in the LocalCustomer object
        $this->customerSyncer->syncLocalFromStripe($localCustomer, $stripeCustomer);

        if (true === $syncSources) {
            $this->customerSyncer->syncLocalSources($localCustomer, $stripeCustomer);
        }

        return true;
    }
460623
public function set($product_id, array $products)
    {
        $this->delete(array('product_id' => $product_id));

        $added = $count = 0;
        foreach ($products as $product) {

            $count++;

            $data = array(
                'product_id' => $product_id,
                'item_product_id' => $product['product_id']
            );

            if ($this->add($data)) {
                $added++;
            }
        }

        return $count && $added == $count;
    }
1171584
public static function getStatus($syncid) {
		if (!empty($syncid)) {
			$db = Factory::getDBO();

			$query = $db->getQuery(true)
				->select('active')
				->from('#__jfusion_sync')
				->where('syncid = ' . $db->quote($syncid));

			$db->setQuery($query);
			return (int)$db->loadResult();
		}
		return 0;
	}
335924
public function countFilterBySiteIds(array $siteIds)
    {
        $qa = $this->createAggregationQuery();
        $qa->match($this->getReferenceFilter('groups', $this->generateFilterSiteId($siteIds)));

        return $this->countDocumentAggregateQuery($qa);
    }
857734
public static function initData($syncid, $action)
	{
		if ($syncid) {
			//clear sync in progress catch in case we manually stopped the sync so that the sync will continue
			self::changeStatus($syncid, 0);
		}

		$syncdata = new Registry();

		$syncdata->set('completed', false);
		$syncdata->set('sync_errors', 0);
		$syncdata->set('total_to_sync', 0);
		$syncdata->set('synced_users', 0);
		$syncdata->set('userbatch', 1);
		$syncdata->set('user_offset', 0);
		$syncdata->set('syncid', $syncid);
		$syncdata->set('action', $action);

		return $syncdata;
	}
772707
public function syncAll(array $options = [])
    {
        $this->logger->info('Synchronizing categories');
        $this->recursiveSync(0);

        $cache = [];

        $this->logger->info('Synchronizing parent/child relationships');

        // when all categories has been saved we iterate through them to update their parent/child relationship
        // @todo this should probably be moved to the updater
        foreach ($this->repository->iterate(['update' => true]) as $category) {
            foreach ($category->getParentIdList() as $parentNumber) {
                if (isset($cache[$parentNumber])) {
                    $parent = $this->repository->getReference($cache[$parentNumber]);
                } else {
                    // @todo if an existing relationship that has been deleted in Dandomain then it isn't updated here
                    $parent = $this->repository->findOneByNumber($parentNumber);
                    $cache[$parentNumber] = $parent->getId();
                }

                if ($parent) {
                    $category->addParentCategory($parent);
                }
            }
        }
    }
1214945
public function rebuildStoreIndex($storeId, $productIds = null)
    {
        $productId = 0;

        // Magento is only sending children ids here. Ensure to reindex also the parents product ids, if any.
        if (!empty($productIds)) {
            $productIds = array_unique(array_merge($productIds, $this->resourceModel->getRelationsByChild($productIds)));
        }

        do {
            $products = $this->getSearchableProducts($storeId, $productIds, $productId);

            foreach ($products as $productData) {
                $productId = (int) $productData['entity_id'];
                $productData['has_options']      = (bool) $productData['has_options'];
                $productData['required_options'] = (bool) $productData['required_options'];
                yield $productId => $productData;
            }
        } while (!empty($products));
    }
43594
public function syncAll(array $options = [])
    {
        $pageSize = 100;
        $pages = \GuzzleHttp\json_decode((string) $this->api->productTag->getProductTagPageCount($pageSize));

        for ($page = 1; $page <= $pages; ++$page) {
            $tags = $this->api->productTag->getProductTagPage($page, $pageSize);
            foreach ($tags as $tag) {
                $entity = $this->tagUpdater->updateFromApiResponse(DandomainFoundation\objectToArray($tag));
                $this->repository->save($entity);
            }
        }
    }
791058
public function syncAll(array $options = [])
    {
        // @todo fix site repository
        $siteIds = [26];
        $currency = 'DKK';

        foreach ($siteIds as $siteId) {
            $shippingMethods = \GuzzleHttp\json_decode((string) $this->api->settings->getShippingMethods($siteId)->getBody());

            foreach ($shippingMethods as $shippingMethod) {
                $entity = $this->shippingMethodUpdater->updateFromApiResponse(DandomainFoundation\objectToArray($shippingMethod), $currency);
                $this->repository->save($entity);
            }
        }
    }
1081481
protected function getFieldsCompare(array $products)
    {
        $labels = array();

        foreach ($products as $product) {
            if (!empty($product['field_value_labels'])) {
                foreach ($product['field_value_labels'] as $type => $fields) {
                    foreach (array_keys($fields) as $field_id) {
                        $labels[$type][$field_id] = $product['fields'][$type][$field_id]['title'];
                    }
                }
            }
        }

        return $labels;
    }