filter = new InventoryFilterType(); $request->filter->productActive = NumericBoolean::TRUE; $request->filter->sites = ['moysklad', 'aliexpress']; $mock = static::createApiMockBuilder('store/inventories'); $mock->matchMethod(RequestMethod::GET) ->matchQuery(self::encodeFormArray($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->inventories($request); self::assertModelEqualsToResponse($json, $response); } public function testInventoriesUpload(): void { $json = <<<'EOF' { "success": true, "processedOffersCount": 1 } EOF; $offer = new Offer(); $offer->xmlId = '1'; $offer->stores = [new Inventory('main12', 15, 15)]; $request = new InventoriesUploadRequest(); $request->offers = [$offer]; $request->site = 'aliexpress'; $mock = static::createApiMockBuilder('store/inventories/upload'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->inventoriesUpload($request); self::assertModelEqualsToResponse($json, $response); } public function testPricesUpload(): void { $json = <<<'EOF' { "success": true, "processedOffersCount": 1, "notFoundOffers": [] } EOF; $price = new PriceUploadInput(); $price->site = 'aliexpress'; $price->xmlId = '1'; $price->prices = [new PriceUploadPricesInput('base', 100)]; $mock = static::createApiMockBuilder('store/prices/upload'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm(new PricesUploadRequest([$price]))) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->pricesUpload(new PricesUploadRequest([$price])); self::assertModelEqualsToResponse($json, $response); } public function testProductGroups(): void { $json = <<<'EOF' { "success": true, "pagination": { "limit": 20, "totalCount": 7, "currentPage": 1, "totalPageCount": 1 }, "productGroup": [ { "site": "aliexpress", "id": 4326, "name": "Test Category", "externalId": "1", "active": true }, { "site": "moysklad", "id": 3676, "name": "warehouseRoot", "externalId": "warehouseRoot", "active": true }, { "site": "moysklad", "id": 3677, "name": "Вторая группа", "externalId": "2group", "active": true }, { "parentId": 3677, "site": "moysklad", "id": 3679, "name": "Входящая в группу", "externalId": "2-1Group", "active": true }, { "parentId": 3679, "site": "moysklad", "id": 3680, "name": "test", "externalId": "test", "active": true }, { "site": "moysklad", "id": 3724, "name": "Услуги", "externalId": "fFkaMR23j9nCbAMnkG2T20", "active": true }, { "site": "moysklad", "id": 3678, "name": "Фрукты", "externalId": "extFruits", "active": true } ] } EOF; $request = new ProductGroupsRequest(); $request->filter = new ProductGroupFilterType(); $request->filter->sites = ['moysklad', 'aliexpress']; $request->filter->active = NumericBoolean::TRUE; $mock = static::createApiMockBuilder('store/product-groups'); $mock->matchMethod(RequestMethod::GET) ->matchQuery(self::encodeFormArray($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productGroups($request); self::assertModelEqualsToResponse($json, $response); } public function testProducts(): void { $json = <<<'EOF' { "success": true, "pagination": { "limit": 20, "totalCount": 1, "currentPage": 1, "totalPageCount": 1 }, "products": [ { "minPrice": 624, "maxPrice": 624, "id": 828272, "article": "38311", "type": "product", "name": "Test Product", "url": "https://example.com", "imageUrl": "https://example.com/image.jpg", "description": "Test Description", "groups": [ { "id": 4050, "externalId": "368" }, { "id": 4154, "externalId": "391" }, { "id": 4279, "externalId": "394" } ], "externalId": "38311", "manufacturer": "Test", "offers": [ { "name": "Test #1", "price": 624, "images": [ "https://example.com/image.jpg" ], "id": 1941833, "externalId": "38311", "xmlId": "38311", "article": "38311", "prices": [ { "priceType": "base", "price": 624, "ordering": 991 } ], "purchasePrice": 272.64, "vatRate": "none", "properties": { "ves": "33", "brend": "Test", "image": "https://example.com/image.jpg", "ves_g": "33", "artikul": "38311" }, "quantity": 0, "weight": 33, "active": true, "unit": { "code": "pc", "name": "Штука", "sym": "шт." } } ], "active": true, "quantity": 0, "markable": false } ] } EOF; $request = new ProductsRequest(); $request->filter = new ProductFilterType(); $request->filter->active = NumericBoolean::TRUE; $request->filter->priceType = 'base'; $request->filter->maxPrice = '10000'; $request->filter->name = 'Test Product'; $mock = static::createApiMockBuilder('store/products'); $mock->matchMethod(RequestMethod::GET) ->matchQuery(self::encodeFormArray($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->products($request); self::assertModelEqualsToResponse($json, $response); } public function testProductsSinceUpdated(): void { $json = <<<'EOF' { "success": true, "pagination": { "limit": 20, "totalCount": 1, "currentPage": 1, "totalPageCount": 1 }, "products": [ { "updatedAt": "2019-12-01 00:00:00", "minPrice": 624, "maxPrice": 624, "id": 828272, "article": "38311", "name": "Test Product", "url": "https://example.com", "imageUrl": "https://example.com/image.jpg", "description": "Test Description", "groups": [ { "id": 4050, "externalId": "368" }, { "id": 4154, "externalId": "391" }, { "id": 4279, "externalId": "394" } ], "externalId": "38311", "manufacturer": "Test", "offers": [ { "name": "Test #1", "price": 624, "images": [ "https://example.com/image.jpg" ], "id": 1941833, "externalId": "38311", "xmlId": "38311", "article": "38311", "prices": [ { "priceType": "base", "price": 624, "ordering": 991 } ], "purchasePrice": 272.64, "vatRate": "none", "properties": { "ves": "33", "brend": "Test", "image": "https://example.com/image.jpg", "ves_g": "33", "artikul": "38311" }, "quantity": 0, "weight": 33, "active": true, "unit": { "code": "pc", "name": "Штука", "sym": "шт." } } ], "active": true, "quantity": 0, "markable": false } ] } EOF; $request = new ProductsRequest(); $request->filter = new ProductFilterType(); $request->filter->active = NumericBoolean::TRUE; $request->filter->priceType = 'base'; $request->filter->maxPrice = '10000'; $request->filter->name = 'Test Product'; $request->filter->sinceId = 828272; $request->filter->sinceUpdatedAt = DateTimeTransformer::create('2020-01-01 00:00:00'); $mock = static::createApiMockBuilder('store/products'); $mock->matchMethod(RequestMethod::GET) ->matchQuery(self::encodeFormArray($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->products($request); self::assertModelEqualsToResponse($json, $response); } public function testProductProperties(): void { $json = <<<'EOF' { "success": true, "pagination": { "limit": 20, "totalCount": 1, "currentPage": 1, "totalPageCount": 1 }, "properties": [ { "sites": [ "e-mapper", "sendpulse", "glavpunkt", "retailcrm-services-peshkariki", "vk-com", "moysklad", "eftestshop-ru" ], "groups": [ { "id": 3676, "name": "warehouseRoot" }, { "id": 3679, "name": "Входящая в группу" }, { "id": 3680, "name": "test" }, { "id": 3724, "name": "Услуги" } ], "code": "code", "name": "Код", "isNumeric": false, "visible": true, "variative": true } ] } EOF; $request = new ProductPropertiesRequest(); $request->filter = new ProductPropertiesFilterType(); $request->filter->sites = ['moysklad', 'aliexpress']; $request->filter->visible = NumericBoolean::TRUE; $request->filter->variative = NumericBoolean::TRUE; $mock = static::createApiMockBuilder('store/products/properties'); $mock->matchMethod(RequestMethod::GET) ->matchQuery(self::encodeFormArray($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productsProperties($request); self::assertModelEqualsToResponse($json, $response); } public function testProductBatchEdit(): void { $json = <<<'EOF' { "success": true } EOF; $productInput = new ProductEditInput(); $productInput->name = 'testName'; $productInput->description = 'testDescription'; $productInput->active = true; $productInput->id = 10; $productInput->url = 'testUrl'; $productInput->article = 'testArticle'; $productInput->catalogId = 10; $productInput->externalId = 'testExternalId'; $productInput->manufacturer = 'testManufacturer'; $productInput->markable = true; $productInput->novelty = true; $productInput->popular = true; $productInput->recommended = true; $productInput->site = 'testSite'; $productInput->stock = true; $productEditGroupInput = new ProductEditGroupInput(); $productEditGroupInput->externalId = 'testExternalId'; $productEditGroupInput->id = 10; $productInput->groups[] = $productEditGroupInput; $request = new ProductBatchEditRequest([$productInput]); $mock = static::createApiMockBuilder('store/products/batch/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productBatchEdit($request); self::assertModelEqualsToResponse($json, $response); } public function testProductBatchCreate(): void { $json = <<<'EOF' { "success": true, "processedProductsCount": 1, "addedProducts": [ 100 ] } EOF; $productInput = new ProductCreateInput(); $productInput->name = 'testName4'; $productInput->description = 'testDescription'; $productInput->active = true; $productInput->url = 'url'; $productInput->article = 'testArticle'; $productInput->catalogId = 110; $productInput->externalId = 'testExternalId4'; $productInput->manufacturer = 'testManufacturer'; $productInput->markable = true; $productInput->novelty = true; $productInput->popular = true; $productInput->recommended = true; $productInput->stock = true; $productInput->type = 'product'; $productEditGroupInput = new ProductEditGroupInput(); $productEditGroupInput->id = 9717; $productInput->groups[] = $productEditGroupInput; $request = new ProductsBatchCreateRequest([$productInput]); $mock = static::createApiMockBuilder('store/products/batch/create'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productsBatchCreate($request); self::assertModelEqualsToResponse($json, $response); } public function testProductGroupsCreate(): void { $json = <<<'EOF' { "success": true, "id": 9740 } EOF; $productGroup = new SerializedProductGroup(); $productGroup->parentId = 100; $productGroup->name = 'TestGroup'; $productGroup->description = 'Test group of products'; $productGroup->externalId = 'xxx-001'; $productGroup->active = true; $productGroup->site = 'gray_sale_2'; $request = new ProductGroupsCreateRequest($productGroup); $mock = static::createApiMockBuilder('store/product-groups/create'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productGroupsCreate($request); self::assertModelEqualsToResponse($json, $response); } public function testProductGroupsEdit(): void { $json = <<<'EOF' { "success": true, "id": 9740 } EOF; $productGroup = new SerializedProductGroup(); $productGroup->name = 'TestGroup edit'; $productGroup->description = 'Test group of products edit'; $productGroup->externalId = 'xxx-001-edit'; $productGroup->active = true; $request = new ProductGroupsEditRequest($productGroup, 'id', 'gray_sale_2'); $mock = static::createApiMockBuilder('store/product-groups/9740/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(self::encodeForm($request)) ->reply(200) ->withBody($json); $client = TestClientFactory::createClient($mock->getClient()); $response = $client->store->productGroupsEdit(9740, $request); self::assertModelEqualsToResponse($json, $response); } }