-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1405 from bakaphp/product-category-multi-update
[1.x] Product category multi update
- Loading branch information
Showing
9 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Domains/Inventory/Products/Actions/AddCategoryAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanvas\Inventory\Products\Actions; | ||
|
||
use Kanvas\Inventory\Categories\Models\Categories; | ||
use Kanvas\Inventory\Products\Models\Products; | ||
use Kanvas\Inventory\Products\Models\ProductsCategories; | ||
|
||
class AddCategoryAction | ||
{ | ||
public function __construct( | ||
protected Products $product, | ||
protected Categories $category | ||
) { | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
ProductsCategories::firstOrCreate( | ||
[ | ||
'categories_id' => $this->category->getId(), | ||
'products_id' => $this->product->getId(), | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\GraphQL\Inventory; | ||
|
||
use Tests\TestCase; | ||
|
||
class ProductCategoryTest extends TestCase | ||
{ | ||
public function testAddProductCategoryTest(): void | ||
{ | ||
$dataRegion = [ | ||
'name' => 'Test Region', | ||
'slug' => 'test-region', | ||
'short_slug' => 'test-region', | ||
'is_default' => 1, | ||
'currency_id' => 1, | ||
]; | ||
$response = $this->graphQL(' | ||
mutation($data: RegionInput!) { | ||
createRegion(input: $data) | ||
{ | ||
id | ||
name | ||
slug | ||
short_slug | ||
currency_id | ||
is_default | ||
} | ||
}', ['data' => $dataRegion]) | ||
->assertJson([ | ||
'data' => ['createRegion' => $dataRegion] | ||
]); | ||
$idRegion = $response->json()['data']['createRegion']['id']; | ||
$data = [ | ||
'regions_id' => $idRegion, | ||
'name' => 'Test Warehouse', | ||
'location' => 'Test Location', | ||
'is_default' => true, | ||
'is_published' => true, | ||
]; | ||
|
||
$response = $this->graphQL(' | ||
mutation($data: WarehouseInput!) { | ||
createWarehouse(input: $data) | ||
{ | ||
id | ||
regions_id | ||
name | ||
location | ||
is_default | ||
is_published | ||
} | ||
}', ['data' => $data])->assertJson([ | ||
'data' => ['createWarehouse' => $data] | ||
]); | ||
|
||
$categoryData = [ | ||
'name' => fake()->name, | ||
'code' => fake()->name, | ||
'position' => 1, | ||
'is_published' => true, | ||
'weight' => 0 | ||
]; | ||
$categoryResponse = $this->graphQL(' | ||
mutation($data: CategoryInput!) { | ||
createCategory(input: $data) | ||
{ | ||
id | ||
name, | ||
code, | ||
position, | ||
is_published | ||
weight | ||
} | ||
}', ['data' => $categoryData])->assertJson([ | ||
'data' => ['createCategory' => $categoryData] | ||
]); | ||
$idCategory = $categoryResponse->json()['data']['createCategory']['id']; | ||
|
||
$data = [ | ||
'name' => fake()->name, | ||
'sku' => fake()->time, | ||
'description' => fake()->text, | ||
'categories' => [ | ||
[ | ||
'id' => $idCategory | ||
] | ||
] | ||
]; | ||
|
||
$response = $this->graphQL(' | ||
mutation($data: ProductInput!) { | ||
createProduct(input: $data) | ||
{ | ||
id | ||
name | ||
description | ||
categories{ | ||
id | ||
} | ||
} | ||
}', ['data' => $data]); | ||
|
||
unset($data['sku']); | ||
$response->assertJson([ | ||
'data' => ['createProduct' => $data], | ||
]); | ||
} | ||
} |