/**
  * @param CatalogEntity $catalogEntity
  * @param StoreEntity $storeEntity
  * @param ProductCatalogEntity $productCatalogEntity
  */
 public function collectProductsFromShopifyAndImport(CatalogEntity $catalogEntity, StoreEntity $storeEntity, ProductCatalogEntity $productCatalogEntity)
 {
     $totalProducts = $this->shopifyClient->getProductCountByCollection($storeEntity, $catalogEntity->getShopifyCollectionId());
     if ($totalProducts == 0) {
         return;
     }
     $totalPages = ceil($totalProducts / $this->shopifyProductLimit);
     $products = [];
     for ($currentPage = 1; $currentPage <= $totalPages; $currentPage++) {
         $this->shopifyClient->getProductsByCollection($storeEntity, $catalogEntity, $this->shopifyProductLimit, $currentPage, $products);
     }
     //Check to see if the products are in the database
     /** @var ShopifyProductEntity $shopifyProduct */
     foreach ($products as $shopifyProduct) {
         /** @var SkuToProductEntity $existingProduct */
         $existingProduct = $this->skuToProductRepo->findOneBy(['shopifyProductId' => $shopifyProduct->getId(), 'storeId' => $storeEntity->getStoreId(), 'catalog' => $catalogEntity->getCatalogName()]);
         if (!$existingProduct) {
             /** @var ErpProductEntity $product */
             foreach ($productCatalogEntity->getProducts() as $product) {
                 if ($product->getSku() == $shopifyProduct->getSku()) {
                     $skuToProduct = new SkuToProductEntity($product, $shopifyProduct, $storeEntity, $productCatalogEntity);
                     $this->skuToProductRepo->save($skuToProduct);
                 }
             }
         }
     }
     $this->removeMissingShopifyProducts($storeEntity, $catalogEntity, $products);
 }
 /**
  * @param StoreEntity $store
  * @param CatalogEntity $catalog
  */
 public function deleteCollection(StoreEntity $store, CatalogEntity $catalog)
 {
     //Collection has already been deleted
     if (is_null($catalog->getShopifyCollectionId())) {
         return;
     }
     $this->setSettings($store);
     try {
         $this->client->deleteCustomCollection(['id' => $catalog->getShopifyCollectionId()]);
         $catalog->setShopifyCollectionId(null);
     } catch (CommandClientException $e) {
         //if 404, Collection has already been deleted via shopify, lets carry on
         if ($e->getResponse()->getStatusCode() != '404') {
             throw $e;
         }
     }
 }