/**
  * @param StoreEntity $store
  */
 public function checkHandlingFeeProductAndCreateIt(StoreEntity $store)
 {
     try {
         if ($store->getShopifyHandlingFeeProductId()) {
             $this->shopifyClient->checkHandlingFeeProduct($store);
         } else {
             $erpProduct = ErpProductEntity::createHandlingFeeProduct();
             $product = $this->shopifyClient->saveProduct($store, $erpProduct);
             $store->setShopifyHandlingFeeProductId($product->getVariantId());
             $this->storeRepository->save($store);
         }
     } catch (NoShopifyProductFound $e) {
         //Add the handling fee product
         $erpProduct = ErpProductEntity::createHandlingFeeProduct();
         $product = $this->shopifyClient->saveProduct($store, $erpProduct);
         $store->setShopifyHandlingFeeProductId($product->getVariantId());
         $this->storeRepository->save($store);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param StoreEntity $store
  * @param CatalogEntity $catalog
  * @param ErpProductEntity $product
  */
 public function getProductExtraInformation(StoreEntity $store, CatalogEntity $catalog, ErpProductEntity $product)
 {
     $request = $this->client->createRequest('GET', sprintf('%s/catalogs/%s/%s/all', $store->getErpUrl(), $catalog->getCatalogName(), $product->getSku()), ['auth' => [$store->getErpUsername(), $store->getErpPassword()]]);
     $response = $this->sendRequest($request)->xml();
     ErpProductEntity::updateProduct($product, $response);
 }
 /**
  * @param StoreEntity $store
  * @param ErpProductEntity $erpProduct
  * @param SkuToProductEntity $skuToProductEntity
  * @return mixed
  * @throws NoShopifyProductFound
  */
 public function updateProduct(StoreEntity $store, ErpProductEntity $erpProduct, SkuToProductEntity $skuToProductEntity)
 {
     if (empty($skuToProductEntity->getVariantId())) {
         throw new \InvalidArgumentException(sprintf('Product needs a variant id before it can be updated: %s', $skuToProductEntity->getSku()));
     }
     $this->setSettings($store);
     $productData = ['id' => $skuToProductEntity->getShopifyProductId(), 'title' => $erpProduct->getTitle(), 'product_type' => $erpProduct->getCategory(), 'body_html' => $erpProduct->getFullDesription(), 'variants' => [['id' => $skuToProductEntity->getVariantId(), 'price' => $erpProduct->getPrice(), 'sku' => $erpProduct->getSku(), 'inventory_management' => $erpProduct->getStockManagement(), 'inventory_policy' => $erpProduct->getInventoryPolicy(), 'inventory_quantity' => $erpProduct->getQty()]]];
     try {
         $response = $this->client->updateProduct(['id' => $skuToProductEntity->getShopifyProductId(), 'product' => $productData]);
     } catch (CommandClientException $e) {
         //if 404, Collection has already been deleted via shopify, lets carry on
         if ($e->getResponse()->getStatusCode() == '404') {
             throw new NoShopifyProductFound(sprintf('Product Id: %s cannot be found within shopify', $skuToProductEntity->getShopifyProductId()));
         }
     }
     return $response;
 }