コード例 #1
0
 /**
  * @param StoreEntity $store
  * @param $catalog
  * @param bool|false $extra
  * @return ProductCatalogEntity
  */
 public function getProducts(StoreEntity $store, CatalogEntity $catalog, $extra = false)
 {
     $request = $this->client->createRequest('GET', sprintf('%s/catalogs/%s', $store->getErpUrl(), $catalog->getCatalogName()), ['auth' => [$store->getErpUsername(), $store->getErpPassword()]]);
     $response = $this->sendRequest($request)->xml();
     $productCatalog = ProductCatalogEntity::createFromXMLResponse($response);
     if ($extra) {
         foreach ($productCatalog->getProducts() as $product) {
             $this->getProductExtraInformation($store, $catalog, $product);
         }
     }
     return $productCatalog;
 }
コード例 #2
0
 /**
  * @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);
 }