vendor/pimcore/customer-management-framework-bundle/src/Event/CustomerMergerEventListener.php line 40

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace CustomerManagementFrameworkBundle\Event;
  15. use CustomerManagementFrameworkBundle\CustomerSaveManager\CustomerSaveManagerInterface;
  16. class CustomerMergerEventListener
  17. {
  18.     /**
  19.      * @var CustomerSaveManagerInterface
  20.      */
  21.     private $customerSaveManager;
  22.     public function __construct(CustomerSaveManagerInterface $customerSaveManager)
  23.     {
  24.         $this->customerSaveManager $customerSaveManager;
  25.     }
  26.     public function onPreMerge(\Symfony\Component\EventDispatcher\GenericEvent $e)
  27.     {
  28.         $this->customerSaveManager
  29.             ->getSaveOptions()
  30.             ->disableOnSaveSegmentBuilders()
  31.             ->disableValidator();
  32.     }
  33.     public function onPostMerge(\Symfony\Component\EventDispatcher\GenericEvent $e)
  34.     {
  35.         $sourceCustomer \Pimcore::getContainer()->get('cmf.customer_provider')->getById($e->getArgument('sourceId'));
  36.         $targetCustomer \Pimcore::getContainer()->get('cmf.customer_provider')->getById($e->getArgument('targetId'));
  37.         if ($sourceCustomer && $targetCustomer) {
  38.             \Pimcore::getContainer()->get('cmf.customer_merger')->mergeCustomers($sourceCustomer$targetCustomerfalse);
  39.         }
  40.         $this->customerSaveManager->setSaveOptions(
  41.             $this->customerSaveManager->getDefaultSaveOptions()
  42.         );
  43.     }
  44. }