/** * @param StoreEntity $store * @param ErpProductEntity $erpProduct * @return ShopifyProductEntity */ public function saveProduct(StoreEntity $store, ErpProductEntity $erpProduct) { $this->setSettings($store); $image = new \StdClass(); $image->src = $erpProduct->getImage(); $productData = ['published' => true, 'title' => $erpProduct->getTitle(), 'product_type' => $erpProduct->getCategory(), 'body_html' => $erpProduct->getFullDesription(), 'images' => [$image], 'variants' => [['price' => $erpProduct->getPrice(), 'sku' => $erpProduct->getSku(), 'inventory_management' => $erpProduct->getStockManagement(), 'inventory_policy' => $erpProduct->getInventoryPolicy(), 'inventory_quantity' => $erpProduct->getQty(), 'fulfillment_service' => $erpProduct->getFulFilmentService()]]]; $response = $this->client->createProduct(['product' => $productData]); $product = ShopifyProductEntity::createFromProductCreationResponse($response); return $product; }
/** * @depends testProductDelete */ public function testProductPagination() { for ($i = 0; $i <= 9; $i++) { $this->client->createProduct(['title' => 'test product ' . $i]); } $counter = 0; foreach ($this->client->getResourcePager('products', 5) as $product) { $this->assertNotEmpty($product); $this->assertObjectHasAttribute('title', $product); $this->assertEquals('test product ' . $counter, $product->title); $counter++; } $this->assertEquals(10, $this->client->getProductsCount(), 'There should be 10 products in the system.'); $opts['query']['limit'] = 5; foreach ($this->client->getProducts($opts) as $product) { $this->assertObjectHasAttribute('id', $product); $this->client->deleteProduct($product->id); } $this->assertEquals(0, $this->client->getProductsCount(), 'Not all products were deleted.'); }