forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature Sylius#14724 As an Admin, I want to modify taxons of a produc…
…t (everwhatever) This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Related tickets | [jira]( https://sylius.atlassian.net/browse/SYL-2215) | | License | MIT | <!-- - Bug fixes must be submitted against the 1.11 or 1.12 branch - Features and deprecations must be submitted against the 1.13 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- a1b8d59 As an Admin, I want to modify taxons of a product e9247b7 after cr
- Loading branch information
Showing
18 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
features/product/managing_products/modifying_taxons_assigned_to_an_existing_product.feature
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,23 @@ | ||
@managing_products | ||
Feature: Modifying taxons assigned to an exisiting product | ||
In order to specify in which taxon a product is available | ||
As an Administrator | ||
I want to be able to change taxon of a product | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And the store classifies its products as "Clothes" and "T-Shirts" | ||
And the store has a "Shirt" configurable product | ||
And the store has a "T-Shirt" configurable product | ||
And the product "T-Shirt" belongs to taxon "Clothes" | ||
And I am logged in as an administrator | ||
|
||
@ui @api | ||
Scenario: Modifying taxons assigned to a product | ||
When I change that the "T-Shirt" product belongs to the "T-Shirts" taxon | ||
Then the product "T-Shirt" should have the "T-Shirts" taxon | ||
|
||
@ui @api | ||
Scenario: Adding taxons to product | ||
When I add "Clothes" taxon to the "Shirt" product | ||
Then the product "Shirt" should have the "Clothes" taxon |
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
50 changes: 50 additions & 0 deletions
50
src/Sylius/Behat/Context/Api/Admin/ManagingProductTaxonsContext.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,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Behat\Context\Api\Admin; | ||
|
||
use ApiPlatform\Core\Api\IriConverterInterface; | ||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Context\Api\Resources; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\Component\Core\Model\TaxonInterface; | ||
|
||
final class ManagingProductTaxonsContext implements Context | ||
{ | ||
public function __construct(private ApiClientInterface $client, private IriConverterInterface $iriConverter) | ||
{ | ||
} | ||
|
||
/** | ||
* @When I change that the :product product belongs to the :taxon taxon | ||
*/ | ||
public function iChangeThatTheProductBelongsToTheTaxon(ProductInterface $product, TaxonInterface $taxon): void | ||
{ | ||
$this->client->buildUpdateRequest(Resources::PRODUCT_TAXONS, (string) $product->getProductTaxons()->current()->getId()); | ||
$this->client->updateRequestData(['taxon' => $this->iriConverter->getIriFromItem($taxon)]); | ||
$this->client->update(); | ||
} | ||
|
||
/** | ||
* @When I assign the :taxon taxon to the :product product | ||
* @When I add :taxon taxon to the :product product | ||
*/ | ||
public function iAddTaxonToTheProduct(TaxonInterface $taxon, ProductInterface $product): void | ||
{ | ||
$this->client->buildCreateRequest(Resources::PRODUCT_TAXONS); | ||
$this->client->addRequestData('taxon', $this->iriConverter->getIriFromItem($taxon)); | ||
$this->client->addRequestData('product', $this->iriConverter->getIriFromItem($product)); | ||
$this->client->create(); | ||
} | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
src/Sylius/Bundle/ApiBundle/DataPersister/ProductTaxonDataPersister.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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\DataPersister; | ||
|
||
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; | ||
use Sylius\Component\Core\Event\ProductUpdated; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\Component\Core\Model\ProductTaxonInterface; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
/** @experimental */ | ||
final class ProductTaxonDataPersister implements ContextAwareDataPersisterInterface | ||
{ | ||
public function __construct( | ||
private ContextAwareDataPersisterInterface $decoratedDataPersister, | ||
private MessageBusInterface $eventBus, | ||
) { | ||
} | ||
|
||
public function supports($data, array $context = []): bool | ||
{ | ||
return $data instanceof ProductTaxonInterface; | ||
} | ||
|
||
public function persist($data, array $context = []) | ||
{ | ||
/** @var ProductInterface $product */ | ||
$product = $data->getProduct(); | ||
$product->addProductTaxon($data); | ||
|
||
$this->decoratedDataPersister->persist($data, $context); | ||
|
||
$this->eventBus->dispatch(new ProductUpdated($product->getCode())); | ||
} | ||
|
||
public function remove($data, array $context = []) | ||
{ | ||
return $this->decoratedDataPersister->remove($data, $context); | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
src/Sylius/Bundle/ApiBundle/spec/DataPersister/ProductTaxonDataPersisterSpec.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,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Bundle\ApiBundle\DataPersister; | ||
|
||
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Event\ProductUpdated; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\Component\Core\Model\ProductTaxonInterface; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
class ProductTaxonDataPersisterSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
ContextAwareDataPersisterInterface $decoratedDataPersister, | ||
MessageBusInterface $eventBus, | ||
): void { | ||
$this->beConstructedWith($decoratedDataPersister, $eventBus); | ||
} | ||
|
||
function it_supports_only_product_taxon_entity(ProductTaxonInterface $productTaxon, ProductInterface $product): void | ||
{ | ||
$this->supports($productTaxon)->shouldReturn(true); | ||
$this->supports($product)->shouldReturn(false); | ||
} | ||
|
||
function it_uses_decorated_data_persister_to_remove_product_taxon( | ||
ContextAwareDataPersisterInterface $decoratedDataPersister, | ||
ProductTaxonInterface $productTaxon, | ||
): void { | ||
$decoratedDataPersister->remove($productTaxon, [])->shouldBeCalled(); | ||
|
||
$this->remove($productTaxon, []); | ||
} | ||
|
||
function it_uses_decorated_data_persister_to_persist_product_taxon_and_product( | ||
ContextAwareDataPersisterInterface $decoratedDataPersister, | ||
ProductTaxonInterface $productTaxon, | ||
ProductInterface $product, | ||
MessageBusInterface $eventBus, | ||
): void { | ||
$productTaxon->getProduct()->willReturn($product); | ||
$product->getCode()->willReturn('t_shirt'); | ||
$message = new ProductUpdated('t_shirt'); | ||
|
||
$product->addProductTaxon($productTaxon)->shouldBeCalled(); | ||
$decoratedDataPersister->persist($productTaxon, [])->shouldBeCalled(); | ||
$eventBus->dispatch($message)->willReturn(new Envelope($message))->shouldBeCalled(); | ||
|
||
$this->persist($productTaxon, []); | ||
} | ||
} |