-
Notifications
You must be signed in to change notification settings - Fork 38
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 #31 from Glancu/feature/product-bundle-edit-product
Feature: edit product bundle product
- Loading branch information
Showing
7 changed files
with
78 additions
and
17 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
39 changes: 39 additions & 0 deletions
39
spec/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerSpec.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,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusProductBundlePlugin\EventListener; | ||
|
||
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface; | ||
use BitBag\SyliusProductBundlePlugin\Entity\ProductInterface; | ||
use BitBag\SyliusProductBundlePlugin\EventListener\AddProductToProductBundleWhenEditNormalProductEventListener; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
|
||
final class AddProductToProductBundleWhenEditNormalProductEventListenerSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(AddProductToProductBundleWhenEditNormalProductEventListener::class); | ||
} | ||
|
||
public function it_should_add_product_to_product_bundle_if_not_exist_on_pre_create_and_update_event( | ||
ResourceControllerEvent $resourceControllerEvent, | ||
ProductInterface $product, | ||
ProductBundleInterface $productBundle | ||
): void { | ||
$resourceControllerEvent->getSubject()->willReturn($product); | ||
|
||
$product->getProductBundle()->shouldBeCalled(); | ||
|
||
$product->getProductBundle()->willReturn($productBundle); | ||
|
||
$this->addProductToProductBundle($resourceControllerEvent); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/EventListener/AddProductToProductBundleWhenEditNormalProductEventListener.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,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusProductBundlePlugin\EventListener; | ||
|
||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use Tests\BitBag\SyliusProductBundlePlugin\Entity\Product; | ||
|
||
final class AddProductToProductBundleWhenEditNormalProductEventListener | ||
{ | ||
public function addProductToProductBundle(ResourceControllerEvent $resourceControllerEvent): void | ||
{ | ||
/** @var Product $product */ | ||
$product = $resourceControllerEvent->getSubject(); | ||
if (null !== $product->getProductBundle() && null === $product->getProductBundle()->getProduct()) { | ||
$product->getProductBundle()->setProduct($product); | ||
} | ||
} | ||
} |
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="bitbag_sylius_product_bundle_plugin.request_listener.add_product_to_product_bundle_when_edit_normal_product" class="BitBag\SyliusProductBundlePlugin\EventListener\AddProductToProductBundleWhenEditNormalProductEventListener"> | ||
<tag name="kernel.event_listener" event="sylius.product.pre_update" method="addProductToProductBundle" /> | ||
<tag name="kernel.event_listener" event="sylius.product.pre_create" method="addProductToProductBundle" /> | ||
</service> | ||
</services> | ||
</container> |