customizable customer building
This commit is contained in:
parent
3814d0f612
commit
77aac323e2
3 changed files with 74 additions and 1 deletions
|
@ -15,6 +15,7 @@ use Intaro\RetailCrm\Component\Builder\Exception\BuilderException;
|
|||
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
|
||||
use Intaro\RetailCrm\Component\Events;
|
||||
use Intaro\RetailCrm\Model\Api\Address;
|
||||
use Intaro\RetailCrm\Model\Api\Contragent;
|
||||
use Intaro\RetailCrm\Model\Api\Customer;
|
||||
|
@ -160,6 +161,8 @@ class CustomerBuilder implements BuilderInterface
|
|||
*/
|
||||
public function getResult()
|
||||
{
|
||||
Events::push(Events::CUSTOMER_BUILDER_GET_RESULT, ['customer' => $this->customer]);
|
||||
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
|
|
36
intaro.retailcrm/lib/component/events.php
Normal file
36
intaro.retailcrm/lib/component/events.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
|
||||
use Bitrix\Main\Event;
|
||||
|
||||
/**
|
||||
* Class Events
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component
|
||||
*/
|
||||
class Events
|
||||
{
|
||||
public const CUSTOMER_BUILDER_GET_RESULT = 'OnRetailcrmApiCustomerBuilderGetResult';
|
||||
|
||||
/**
|
||||
* Push event
|
||||
*
|
||||
* @param string $eventType
|
||||
* @param array $eventParams
|
||||
*/
|
||||
public static function push(string $eventType, array $eventParams): void
|
||||
{
|
||||
$event = new Event(Constants::MODULE_ID, $eventType, $eventParams);
|
||||
$event->send();
|
||||
}
|
||||
}
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
namespace Tests\Intaro\RetailCrm\Component\Builder\Api;
|
||||
|
||||
use Bitrix\Main\Event;
|
||||
use Bitrix\Main\EventManager;
|
||||
use Bitrix\Main\Type\DateTime;
|
||||
use Intaro\RetailCrm\Component\Builder\Api\CustomerBuilder;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Constants;
|
||||
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
|
||||
use Intaro\RetailCrm\Component\Events;
|
||||
use Intaro\RetailCrm\Model\Api\Address;
|
||||
use Intaro\RetailCrm\Model\Api\Customer;
|
||||
use Intaro\RetailCrm\Model\Bitrix\User;
|
||||
|
@ -53,13 +57,43 @@ class CustomerBuilderTest extends TestCase
|
|||
$this->assertCount(2, $result->phones);
|
||||
$this->assertEquals($entity->getPersonalPhone(), $result->phones[0]->number);
|
||||
$this->assertEquals($entity->getWorkPhone(), $result->phones[1]->number);
|
||||
$this->assertThat($result->address, new IsType(Address::class));
|
||||
$this->assertTrue($result->address instanceof Address);
|
||||
$this->assertEquals($entity->getPersonalCity(), $result->address->city);
|
||||
$this->assertEquals($entity->getPersonalStreet(), $result->address->text);
|
||||
$this->assertEquals($entity->getPersonalZip(), $result->address->index);
|
||||
$this->assertEquals($_COOKIE['_rc'], $result->browserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Intaro\RetailCrm\Component\Builder\Exception\BuilderException
|
||||
* @var User $entity
|
||||
* @dataProvider userData
|
||||
*/
|
||||
public function testCustomizedBuild($entity): void
|
||||
{
|
||||
$this->assertTrue($entity instanceof User);
|
||||
|
||||
$_COOKIE['_rc'] = 'rcCookie';
|
||||
|
||||
EventManager::getInstance()->addEventHandler(
|
||||
Constants::MODULE_ID,
|
||||
Events::CUSTOMER_BUILDER_GET_RESULT,
|
||||
static function (Event $event) {
|
||||
$event->getParameter('customer')->externalId = 'replaced';
|
||||
}
|
||||
);
|
||||
|
||||
$builder = new CustomerBuilder();
|
||||
$result = $builder
|
||||
->setPersonTypeId('individual')
|
||||
->setUser($entity)
|
||||
->build()
|
||||
->getResult();
|
||||
|
||||
$this->assertTrue($result instanceof Customer);
|
||||
$this->assertEquals('replaced', $result->externalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Intaro\RetailCrm\Model\Bitrix\User[][]
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue