Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
orocrmdeployer committed Apr 16, 2018
2 parents 90377ca + 83866b1 commit 795707b
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 52 deletions.
8 changes: 3 additions & 5 deletions src/Oro/Bridge/CalendarCRM/README.md
@@ -1,7 +1,5 @@
CalendarCRM
===========
# OroCalendarCRMBridgeBundle

What is CalendarCRM?
------------
OroCalendarCRMBridgeBundle is a bridge that integrates features of the [OroCalendarBundle](https://github.com/oroinc/OroCalendarBundle) into OroCRM applications.

CalendarCRM is a bridge that integrates certain CRM related features of the OroCalendarBundle into CRM applications.
The bundle enables the Calendar Events [activity](https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/ActivityBundle) for the Contact, Case, Account, Magento Customer, Order, Lead, Opportunity, B2bCustomer entities, and enables users to create Calendar Events from the pages of these entities with the appropriate prefilled event context.
5 changes: 5 additions & 0 deletions src/Oro/Bridge/CallCRM/README.md
@@ -0,0 +1,5 @@
# OroCallCRMBridgeBundle

OroCallCRMBridgeBundle enables Calls contact [activity](https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/ActivityBundle) for Account, Calendar, Case, ContactUs Request, Magento Customer, Magento Order, Magento Cart, Sales Lead, Sales Opportunity, B2bCustomer entities.

The bundle enables Oro application users to log Call events from the pages of these entities.
3 changes: 3 additions & 0 deletions src/Oro/Bridge/CustomerPortalCRM/README.md
@@ -0,0 +1,3 @@
# OroCustomerPortalCRMBridgeBundle

OroCustomerPortalCRMBridgeBundle integrates OroCRM features with OroCommerce user roles and enables Oro application users with the ROLE_ACCOUNT_MANAGER role to manage all application Account and Contact entity records.
9 changes: 3 additions & 6 deletions src/Oro/Bridge/MarketingCRM/README.md
@@ -1,8 +1,5 @@
MarketingCRM
===========
# OroMarketingCRMBridgeBundle

What is MarketingCRM?
------------
OroMarketingCRMBridgeBundle is aimed at integrating features of marketing package into OroCRM applications.

MarketingCRM is a bridge that integrates certain CRM related features of the marketing package
(CampaignBundle, MarketingListBundle, TrackingBundle) into CRM applications.
The bundle adds widgets with the statistics of customer visits to the Account and Customer view pages, if the tracking [feature](https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/FeatureToggleBundle) is enabled in Oro application.
3 changes: 3 additions & 0 deletions src/Oro/Bridge/TaskCRM/README.md
@@ -0,0 +1,3 @@
# OroTaskCRMBridgeBundle

OroTaskCRMBridgeBundle enables the task [activity](https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/ActivityBundle) for Account, Contact, Sales Lead, Sales Opportunity, Sales B2BCustomer, Case, Magento Customer, Magento Order entities. The bundle enables users to create Tasks from the view pages of these entities with correct prefilled context.
Expand Up @@ -3,19 +3,19 @@
namespace Oro\Bundle\ContactBundle\Tests\Functional\DataFixtures;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Oro\Bundle\OrganizationBundle\Entity\Manager\OrganizationManager;
use Oro\Bundle\SecurityBundle\Acl\Persistence\AclManager;
use Oro\Bundle\TestFrameworkBundle\Tests\Functional\DataFixtures\LoadOrganization;
use Oro\Bundle\UserBundle\Entity\Role;
use Oro\Bundle\UserBundle\Entity\UserManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadUserData extends AbstractFixture implements ContainerAwareInterface
class LoadUserData extends AbstractFixture implements ContainerAwareInterface, DependentFixtureInterface
{
const USER_NAME = 'user';
const USER_PASSWORD = 'password';
const USER_ORGANIZATION = 1;
const USER_NAME = 'user';
const USER_PASSWORD = 'password';

/**
* @var ContainerInterface
Expand All @@ -40,6 +40,14 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

/**
* {@inheritdoc}
*/
public function getDependencies()
{
return [LoadOrganization::class];
}

/**
* Load roles
*
Expand Down Expand Up @@ -73,11 +81,7 @@ public function load(ObjectManager $manager)
$userManager = $this->container->get('oro_user.manager');

$user = $userManager->createUser();

/** @var OrganizationManager $organizationManager */
$organizationManager = $this->container->get('oro_organization.organization_manager');
$organization = $organizationManager->getOrganizationRepo()->getOrganizationById(self::USER_ORGANIZATION);

$organization = $this->getReference('organization');
$user->setUsername(self::USER_NAME)
->setPlainPassword(self::USER_PASSWORD)
->setFirstName('User')
Expand Down
82 changes: 54 additions & 28 deletions src/Oro/Bundle/MagentoBundle/Provider/Customer/AccountProvider.php
Expand Up @@ -2,36 +2,44 @@

namespace Oro\Bundle\MagentoBundle\Provider\Customer;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Oro\Bundle\AccountBundle\Entity\Account;
use Oro\Bundle\ImportExportBundle\Strategy\Import\NewEntitiesHelper;
use Oro\Bundle\MagentoBundle\Entity\Customer;
use Oro\Bundle\MagentoBundle\Service\AutomaticDiscovery;
use Oro\Bundle\SalesBundle\Provider\Customer\AccountCreation\AccountProviderInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class AccountProvider implements AccountProviderInterface, ContainerAwareInterface
/**
* Provides Account instance based on the Customer entity.
*/
class AccountProvider implements AccountProviderInterface
{
/** @var ContainerInterface */
protected $container;
/** @var NewEntitiesHelper */
protected $newEntitiesHelper;

/** @var AutomaticDiscovery */
protected $automaticDiscovery;

/** @var NewEntitiesHelper */
protected $newEntitiesHelper;
/** @var ManagerRegistry */
protected $registry;

public function __construct(NewEntitiesHelper $newEntitiesHelper)
{
$this->newEntitiesHelper = $newEntitiesHelper;
}
/** @var int */
private $accountNameLength;

/**
* {@inheritdoc}
* @param NewEntitiesHelper $newEntitiesHelper
* @param AutomaticDiscovery $automaticDiscovery
* @param ManagerRegistry $registry
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
public function __construct(
NewEntitiesHelper $newEntitiesHelper,
AutomaticDiscovery $automaticDiscovery,
ManagerRegistry $registry
) {
$this->newEntitiesHelper = $newEntitiesHelper;
$this->automaticDiscovery = $automaticDiscovery;
$this->registry = $registry;
}

/**
Expand All @@ -49,8 +57,7 @@ public function getAccount($targetCustomer)
} else {
// try to find similar customer and get its account
/** @var Customer|null $similar */
$automaticDiscovery = $this->getAutomaticDiscovery();
$similar = $automaticDiscovery->discoverSimilar($targetCustomer);
$similar = $this->automaticDiscovery->discoverSimilar($targetCustomer);

if (null !== $similar) {
if ($similar->getAccount()) {
Expand Down Expand Up @@ -83,13 +90,11 @@ public function getAccount($targetCustomer)
*/
protected function createAccount($targetCustomer)
{
$accountName = !$targetCustomer->getFirstName() && !$targetCustomer->getLastName()
? 'N/A'
: sprintf('%s %s', $targetCustomer->getFirstName(), $targetCustomer->getLastName());
$account = new Account();
$account->setName($this->getAccountName($targetCustomer))
->setOwner($targetCustomer->getOwner())
->setOrganization($targetCustomer->getOrganization());

$account = (new Account())->setName($accountName);
$account->setOwner($targetCustomer->getOwner());
$account->setOrganization($targetCustomer->getOrganization());
$contact = $targetCustomer->getContact();
if ($contact) {
$account->setDefaultContact($contact);
Expand All @@ -99,14 +104,35 @@ protected function createAccount($targetCustomer)
}

/**
* @return AutomaticDiscovery
* @param Customer $targetCustomer
* @return string
*/
protected function getAutomaticDiscovery()
private function getAccountName(Customer $targetCustomer)
{
if (null === $this->automaticDiscovery) {
$this->automaticDiscovery = $this->container->get('oro_magento.service.automatic_discovery');
$accountName = 'N/A';
if ($targetCustomer->getFirstName() || $targetCustomer->getLastName()) {
$accountName = sprintf('%s %s', $targetCustomer->getFirstName(), $targetCustomer->getLastName());
$accountName = substr(trim($accountName), 0, $this->getAccountNameLength());
}

return $accountName;
}

/**
* @return int|null
*/
private function getAccountNameLength()
{
if ($this->accountNameLength === null) {
$manager = $this->registry->getManagerForClass(Account::class);

/** @var ClassMetadataInfo $metadata */
$metadata = $manager->getClassMetadata(Account::class);
$nameMetadata = $metadata->getFieldMapping('name');

$this->accountNameLength = (int)$nameMetadata['length'];
}

return $this->automaticDiscovery;
return $this->accountNameLength;
}
}
6 changes: 3 additions & 3 deletions src/Oro/Bundle/MagentoBundle/Resources/config/services.yml
Expand Up @@ -1142,11 +1142,11 @@ services:
class: Oro\Bundle\MagentoBundle\Provider\Customer\AccountProvider
arguments:
- '@oro_magento.provider.customer.account.new_entities_helper'
- '@oro_magento.service.automatic_discovery'
- '@doctrine'
public: false
calls:
- [setContainer, ["@service_container"]]
tags:
- { name: oro_sales.provider.customer.account_creation, priority: 10 }
- { name: oro_sales.provider.customer.account_creation, priority: 10 }

oro_magento.provider.customer.account.new_entities_helper:
class: Oro\Bundle\ImportExportBundle\Strategy\Import\NewEntitiesHelper
Expand Down
@@ -0,0 +1,104 @@
<?php

namespace Oro\Bundle\MagentoBundle\Tests\Unit\Provider\Customer;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Oro\Bundle\AccountBundle\Entity\Account;
use Oro\Bundle\ImportExportBundle\Strategy\Import\NewEntitiesHelper;
use Oro\Bundle\MagentoBundle\Entity\Customer;
use Oro\Bundle\MagentoBundle\Provider\Customer\AccountProvider;
use Oro\Bundle\MagentoBundle\Service\AutomaticDiscovery;

class AccountProviderTest extends \PHPUnit_Framework_TestCase
{
/** @var AutomaticDiscovery|\PHPUnit_Framework_MockObject_MockObject */
private $automaticDiscovery;

/** @var NewEntitiesHelper|\PHPUnit_Framework_MockObject_MockObject */
private $newEntitiesHelper;

/** @var AccountProvider */
private $provider;

protected function setUp()
{
$this->automaticDiscovery = $this->createMock(AutomaticDiscovery::class);
$this->newEntitiesHelper = $this->createMock(NewEntitiesHelper::class);

$this->provider = new AccountProvider(
$this->newEntitiesHelper,
$this->automaticDiscovery,
$this->getDoctrineMock()
);
}

public function testGetAccountForUnsupportedCustomer()
{
$targetCustomer = new \stdClass();

$this->assertNull($this->provider->getAccount($targetCustomer));
}

public function testGetAccountForCustomerWithAccount()
{
$account = new Account();

$targetCustomer = new Customer();
$targetCustomer->setAccount($account);

$this->assertSame($account, $this->provider->getAccount($targetCustomer));
}

public function testGetAccount()
{
$targetCustomer = new Customer();
$targetCustomer->setFirstName('Too long first name for Account');
$targetCustomer->setLastName('Too long last name for Account');

$account = $this->provider->getAccount($targetCustomer);

$this->assertInstanceOf(Account::class, $account);
$this->assertEquals('Too long first name for Account Too long l', $account->getName());
}

public function testGetAccountNameComposition()
{
$targetCustomer = new Customer();
$targetCustomer->setFirstName('First Name');
$targetCustomer->setLastName('');

$this->assertEquals('First Name', $this->provider->getAccount($targetCustomer)->getName());

$targetCustomer->setFirstName('');
$targetCustomer->setLastName(' Last Name ');
$this->assertEquals('Last Name', $this->provider->getAccount($targetCustomer)->getName());
}

/**
* @return ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject
*/
private function getDoctrineMock()
{
$metadata = $this->createMock(ClassMetadataInfo::class);
$metadata->expects($this->any())
->method('getFieldMapping')
->with('name')
->willReturn(['length' => 42]);

$manager = $this->createMock(ObjectManager::class);
$manager->expects($this->any())
->method('getClassMetadata')
->with(Account::class)
->willReturn($metadata);

$registry = $this->createMock(ManagerRegistry::class);
$registry->expects($this->any())
->method('getManagerForClass')
->with(Account::class)
->willReturn($manager);

return $registry;
}
}

0 comments on commit 795707b

Please sign in to comment.