public function testProductPut() { $product = ['title' => 'test product going to update']; $product = $this->client->createProduct($product); $update_product = ['title' => 'test product has been UPDATED']; $product = $this->client->updateProduct($product->id, $update_product); $this->assertFalse($this->client->hasErrors(), 'Client has errors'); $this->assertEquals('test product has been UPDATED', $product->title, 'Product title is not updated'); }
/** * @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; }