Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.10' into 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Oct 8, 2016
2 parents 3705531 + 876a619 commit c4e3207
Show file tree
Hide file tree
Showing 40 changed files with 1,173 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\DependencyInjection;
namespace Oro\Bridge\CrmCall\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\DependencyInjection;
namespace Oro\Bridge\CrmCall\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
Expand All @@ -20,7 +20,7 @@ class OroCRMCallBridgeExtension extends Extension
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\Migrations\Data\ORM;
namespace Oro\Bridge\CrmCall\Migrations\Data\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\Migrations\Schema;
namespace Oro\Bridge\CrmCall\Migrations\Schema;

use Doctrine\DBAL\Schema\Schema;

Expand All @@ -13,7 +13,7 @@
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtension;
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtensionAwareInterface;

use Oro\CRMCallBridgeBundle\Migrations\Schema\v1_0\OroCRMCallBridgeBundle;
use Oro\Bridge\CrmCall\Migrations\Schema\v1_0\OroCRMCallBridgeBundle;

class OroCRMCallBridgeBundleInstaller implements
Installation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\Migrations\Schema\v1_0;
namespace Oro\Bridge\CrmCall\Migrations\Schema\v1_0;

use Doctrine\DBAL\Schema\Schema;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle;
namespace Oro\Bridge\CrmCall;

use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMCallBridgeBundle\Provider;
namespace Oro\Bridge\CrmCall\Provider;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bundles:
#Should be loaded after OroCRMCaseBundle, OroCRMCallBundle, OroCRMMagentoBundle, OroCRMContactUsBundle,
#because of migration priority
- { name: Oro\CRMCallBridgeBundle\OroCRMCallBridgeBundle, priority: 110 }
- { name: Oro\Bridge\CrmCall\OroCRMCallBridgeBundle, priority: 110 }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
oro_crm_call_bridge.call_activity_direction.provider:
class: Oro\CRMCallBridgeBundle\Provider\CallDirectionProvider
class: Oro\Bridge\CrmCall\Provider\CallDirectionProvider
arguments:
- '@oro_activity.manager'
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Oro\CRMCallBridgeBundle\Tests\Unit\Provider;
namespace Oro\Bridge\CrmCall\Tests\Unit\Provider;

use Oro\CRMCallBridgeBundle\Provider\CallDirectionProvider;
use Oro\Bridge\CrmCall\Provider\CallDirectionProvider;
use OroCRM\Bundle\CallBundle\Entity\Call;
use OroCRM\Bundle\CallBundle\Entity\CallDirection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMTaskBundle\Migrations\Data\Demo\ORM;
namespace Oro\Bridge\CrmTask\Migrations\Data\Demo\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMTaskBundle\Migrations\Data\Demo\ORM;
namespace Oro\Bridge\CrmTask\Migrations\Data\Demo\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Oro\CRMTaskBundle\Migrations\Schema;
namespace Oro\Bridge\CrmTask\Migrations\Schema;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtension;
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtensionAwareInterface;
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
use Oro\CRMTaskBundle\Migrations\Schema\v1_0\OroCRMTaskBundle as CRMTaskBundle_v1_0;
use Oro\Bridge\CrmTask\Migrations\Schema\v1_0\OroCRMTaskBundle as CRMTaskBundle_v1_0;

class OroCRMTaskBundleInstaller implements
Installation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMTaskBundle\Migrations\Schema\v1_0;
namespace Oro\Bridge\CrmTask\Migrations\Schema\v1_0;

use Doctrine\DBAL\Schema\Schema;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMTaskBundle;
namespace Oro\Bridge\CrmTask;

use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down
4 changes: 4 additions & 0 deletions src/Oro/Bridge/CrmTask/Resources/config/oro/bundles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bundles:
#Should be loaded after OroCRMAccountBundle, OroCRMSalesBundle, OroCRMMagentoBundle, OroCRMCaseBundle,
#OroCRMTaskBundle, OroCRMContactBundle because of migration priority
- { name: Oro\Bridge\CrmTask\OroCRMTaskBridgeBundle, priority: 110 }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oro\CRMTaskBundle\Tests\Selenium;
namespace Oro\Bridge\CrmTask\Tests\Selenium;

use Oro\Bundle\TestFrameworkBundle\Test\Selenium2TestCase;
use OroCRM\Bundle\TaskBundle\Tests\Selenium\Pages\Task;
Expand Down
2 changes: 0 additions & 2 deletions src/Oro/CRMTaskBundle/Resources/config/oro/bundles.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends 'OroUIBundle:actions:view.html.twig' %}

{% oro_title_set({params : {"%account.name%": resource_granted('VIEW', entity, 'name')
{% set hasGrantedNameView = resource_granted('VIEW', entity, 'name') %}

{% oro_title_set({params : {"%account.name%": hasGrantedNameView
? entity.name|default('N/A')
: 'view %fieldName% not granted'|trans({'%fieldName%': 'orocrm.account.name.label'|trans}) }})
%}
Expand Down Expand Up @@ -29,7 +31,8 @@
'entity': entity,
'indexPath': path('orocrm_account_index'),
'indexLabel': 'orocrm.account.entity_plural_label'|trans,
'entityTitle': resource_granted('VIEW', entity, 'name')
'rawEntityTitle': not hasGrantedNameView,
'entityTitle': hasGrantedNameView
? entity.name|default('N/A')
: UI.renderDisabledLabel('view %fieldName% not granted'|trans({'%fieldName%': 'orocrm.account.name.label'|trans}))
} %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
data-page-component-module="oronote/js/app/components/notes-component"
data-page-component-options="{{ options|json_encode }}"></div>

{% include 'OroCRMCaseBundle:Comment:js/list.js.twig' with {'id': 'template-comment-list'} %}
{% include 'OroCRMCaseBundle:Comment:js/view.js.twig' with {'id': 'template-comment-item'} %}
{% include 'OroCRMCaseBundle:Comment:js/list.html.twig' with {'id': 'template-comment-list'} %}
{% include 'OroCRMCaseBundle:Comment:js/view.html.twig' with {'id': 'template-comment-item'} %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class GuestCustomerDataConverter extends AbstractTreeDataConverter
];

/**
* @param array $orderData
* Extract customer data from Order or Cart entity data
*
* @param array $entityData
* @return array
*/
public static function extractCustomersValues(array $orderData)
public static function extractCustomersValues(array $entityData)
{
$customerData = array_intersect_key($orderData, self::$conversionRules);
$customerData = array_intersect_key($entityData, self::$conversionRules);

if (!empty($orderData['store']['originId'])) {
$customerData['store_id'] = $orderData['store']['originId'];
if (!empty($entityData['store']['originId'])) {
$customerData['store_id'] = $entityData['store']['originId'];
}

return $customerData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Doctrine\Common\Collections\ArrayCollection;

use Oro\Bundle\AddressBundle\Entity\Region;
use Oro\Bundle\IntegrationBundle\Entity\Channel;

use OroCRM\Bundle\MagentoBundle\Entity\Cart;
use OroCRM\Bundle\MagentoBundle\Entity\CartAddress;
use OroCRM\Bundle\MagentoBundle\Entity\CartStatus;
use OroCRM\Bundle\MagentoBundle\Entity\Customer;
use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
use OroCRM\Bundle\MagentoBundle\ImportExport\Converter\GuestCustomerDataConverter;
use OroCRM\Bundle\MagentoBundle\Provider\Reader\ContextCustomerReader;
Expand Down Expand Up @@ -70,18 +72,24 @@ protected function isProcessingAllowed(Cart $cart)
$isProcessingAllowed = true;

if ($cart->getCustomer()) {
$customer = $this->findExistingEntity($cart->getCustomer());

$customer = $this->findExistingCustomer($cart);
$customerOriginId = $cart->getCustomer()->getOriginId();
if (!$customer && $customerOriginId) {
$this->appendDataToContext(ContextCustomerReader::CONTEXT_POST_PROCESS_CUSTOMERS, $customerOriginId);

$isProcessingAllowed = false;
}

if (!$customer && $cart->getIsGuest()) {
/** @var MagentoSoapTransport $transport */
/**
* If registered customer add items to cart in Magento
* but after customer was deleted in Magento before customer and cart were synced
* Cart will not have connection to the customer
* Customer for such Carts should be processed as guest if Guest Customer synchronization is allowed
*/
if (!$customer && !$customerOriginId) {
/** @var Channel $channel */
$channel = $this->databaseHelper->findOneByIdentity($cart->getChannel());
/** @var MagentoSoapTransport $transport */
$transport = $channel->getTransport();
if ($transport->getGuestCustomerSync()) {
$this->appendDataToContext(
Expand All @@ -97,6 +105,30 @@ protected function isProcessingAllowed(Cart $cart)
return $isProcessingAllowed;
}

/**
* Get existing registered customer or existing guest customer
* If customer not found by Identifier
* find existing customer using entity data for entities containing customer like Order and Cart
*
* @param Cart $entity
*
* @return null|Customer
*/
protected function findExistingCustomer($entity)
{
$existingEntity = null;
$customer = $entity->getCustomer();

if ($customer->getId() || $customer->getOriginId()) {
$existingEntity = parent::findExistingEntity($customer);
}
if (!$existingEntity) {
$existingEntity = $this->findExistingCustomerByContext($entity);
}

return $existingEntity;
}

/**
* @param Cart $entity
*
Expand Down Expand Up @@ -140,7 +172,7 @@ protected function updateRemovedCartItems(Cart $entity)
if ((int)$entity->getItemsQty() === 0) {
foreach ($entity->getCartItems() as $cartItem) {
if (!$cartItem->isRemoved()) {
$cartItem->setUpdatedAt(new \DateTime('now'), new \DateTimeZone('UTC'));
$cartItem->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
$cartItem->setRemoved(true);
}
}
Expand All @@ -151,7 +183,7 @@ protected function updateRemovedCartItems(Cart $entity)
foreach ($existingCartItems as $existingCartItem) {
if (!$newCartItems->contains($existingCartItem)) {
if (!$existingCartItem->isRemoved()) {
$existingCartItem->setUpdatedAt(new \DateTime('now'), new \DateTimeZone('UTC'));
$existingCartItem->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
$existingCartItem->setRemoved(true);
}
}
Expand Down Expand Up @@ -272,25 +304,33 @@ protected function findExistingEntity($entity, array $searchContext = [])
$existingEntity = null;

if ($entity instanceof Region) {
/** @var \OroCRM\Bundle\MagentoBundle\Entity\Region $magentoRegion */
$magentoRegion = $this->databaseHelper->findOneBy(
'OroCRM\Bundle\MagentoBundle\Entity\Region',
[
'regionId' => $entity->getCode()
]
);
if ($magentoRegion) {
$existingEntity = $this->databaseHelper->findOneBy(
'Oro\Bundle\AddressBundle\Entity\Region',
[
'combinedCode' => $magentoRegion->getCombinedCode()
]
);
}
/** @var \OroCRM\Bundle\MagentoBundle\Entity\Region $existingEntity */
$existingEntity = $this->findRegionEntity($entity);
} elseif ($entity instanceof Customer && !$entity->getOriginId() && $this->existingEntity) {
/**
* Get existing customer entity
* As guest customer entity not exist in Magento as separate entity and saved in order
* find guest by customer email
*/
$existingEntity = $this->findExistingCustomerByContext($this->existingEntity);
} else {
$existingEntity = parent::findExistingEntity($entity, $searchContext);
}

return $existingEntity;
}

/**
* Add cart customer email to customer search context
*
* {@inheritdoc}
*/
protected function getEntityCustomerSearchContext($cart)
{
/** @var Cart $cart */
$searchContext = parent::getEntityCustomerSearchContext($cart);
$searchContext['email'] = $cart->getEmail();

return $searchContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,41 +136,13 @@ protected function findExistingEntity($entity, array $searchContext = [])
}
}
} elseif ($entity instanceof Region) {
$existingEntity = $this->findRegionEntity($entity);

/** @var \OroCRM\Bundle\MagentoBundle\Entity\Region $existingEntity */
$existingEntity = $this->findRegionEntity($entity, $entity->getCombinedCode());
} else {
/** @var Customer $existingEntity */
$existingEntity = parent::findExistingEntity($entity, $searchContext);
}

return $existingEntity;
}

/**
* @param Region $entity
*
* @return null|object
*/
protected function findRegionEntity($entity)
{
$existingEntity = null;

/** @var \OroCRM\Bundle\MagentoBundle\Entity\Region $magentoRegion */
$magentoRegion = $this->databaseHelper->findOneBy(
'OroCRM\Bundle\MagentoBundle\Entity\Region',
[
'regionId' => $entity->getCombinedCode()
]
);
if ($magentoRegion) {
$existingEntity = $this->databaseHelper->findOneBy(
'Oro\Bundle\AddressBundle\Entity\Region',
[
'combinedCode' => $magentoRegion->getCombinedCode()
]
);
}

return $existingEntity;
}
}

0 comments on commit c4e3207

Please sign in to comment.