/**
  * @param $catalog
  * @param StoreEntity $shopifyStore
  * @return array|null|object|CatalogEntity
  * @throws NoResultException
  */
 public function getCatalog($catalog, StoreEntity $shopifyStore)
 {
     //Might not be needed this
     if ($catalog == CatalogEntity::$ALL) {
         $catalogs = $this->catalogRepository->findBy(['storeId' => $shopifyStore->getStoreId()]);
     } else {
         $catalogs = $this->catalogRepository->findBy(['storeId' => $shopifyStore->getStoreId(), 'catalogName' => $catalog]);
     }
     if (!$catalogs) {
         throw new NoResultException('No catalogs found');
     }
     return $catalogs;
 }
 /**
  * @param ProductCatalogEntity $productCatalog
  * @param StoreEntity $store
  */
 public function addProductsToCollection(ProductCatalogEntity $productCatalog, StoreEntity $store)
 {
     /** @var CatalogEntity $catalog */
     $catalog = $this->catalogRepository->findOneBy(['storeId' => $store->getStoreId(), 'catalogName' => $productCatalog->getCatalog()]);
     if (!$catalog) {
         throw new \InvalidArgumentException(sprintf('Cannot find catalog %s', $productCatalog->getCatalog()));
     }
     //Process is to delete the collection and then recreate it as we cannot remove products
     //from a collection that easy.
     $this->shopifyClient->deleteCollection($store, $catalog);
     $this->catalogRepository->save($catalog);
     $this->shopifyClient->createCollection($store, $catalog);
     $this->catalogRepository->save($catalog);
     $products = [];
     foreach ($productCatalog->getProducts() as $product) {
         /** @var SkuToProductEntity $existingProduct */
         $existingProduct = $this->skuToProductRepo->findOneBy(['sku' => $product->getSku(), 'storeId' => $store->getStoreId(), 'catalog' => $productCatalog->getCatalog()]);
         if ($existingProduct) {
             $products[] = ['product_id' => $existingProduct->getShopifyProductId()];
         }
     }
     $this->shopifyClient->addProductsToCollection($store, $products, $catalog);
 }