Created
September 4, 2017 14:11
-
-
Save dnahrebecki/f53587811a3c52d2b5eccc25c3eb5ceb to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Oro\Bundle\CustomerBundle\Api\Processor\Create; | |
use Oro\Bundle\CustomerBundle\Entity\CustomerUser; | |
use Oro\Bundle\CustomerBundle\Entity\CustomerUserManager; | |
use Oro\Component\ChainProcessor\ContextInterface; | |
use Oro\Component\ChainProcessor\ProcessorInterface; | |
use Oro\Bundle\ApiBundle\Processor\Create\CreateContext; | |
class SaveIncludedCustomerUser implements ProcessorInterface | |
{ | |
/** | |
* @var CustomerUserManager | |
*/ | |
protected $userManager; | |
/** | |
* @param CustomerUserManager $userManager | |
*/ | |
public function __construct(CustomerUserManager $userManager) | |
{ | |
$this->userManager = $userManager; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function process(ContextInterface $context) | |
{ | |
/** @var CreateContext $context */ | |
$includedEntities = $context->getIncludedEntities(); | |
if (null === $includedEntities) { | |
// the Context does not have included entities | |
return; | |
} | |
foreach ($includedEntities as $entity) { | |
if ($entity instanceof CustomerUser) { | |
$this->userManager->updateUser($entity); | |
} | |
} | |
} | |
} |
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
# file Oro/Bundle/CustomerBundle/Resources/config/services_api.yml | |
oro_customer_user.api.create.save_included_entity: | |
class: Oro\Bundle\CustomerBundle\Api\Processor\Create\SaveIncludedCustomerUser | |
arguments: | |
- '@oro_customer_user.manager' | |
tags: | |
- { name: oro.api.processor, action: create, group: save_data, priority: 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment