Skip to content

Commit 6c3de62

Browse files
committed
Merge remote-tracking branch 'remotes/dev/1.7' into 1.7
2 parents 579e975 + 6897c38 commit 6c3de62

File tree

7 files changed

+79
-52
lines changed

7 files changed

+79
-52
lines changed

Diff for: src/OroCRM/Bundle/MagentoBundle/Entity/IntegrationEntityTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait IntegrationEntityTrait
2626
* @param Integration $integration
2727
* @return $this
2828
*/
29-
public function setChannel(Integration $integration = null)
29+
public function setChannel(Integration $integration)
3030
{
3131
$this->channel = $integration;
3232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\MagentoBundle\ImportExport\Converter;
4+
5+
use Oro\Bundle\IntegrationBundle\ImportExport\DataConverter\AbstractTreeDataConverter;
6+
7+
class GuestCustomerDataConverter extends AbstractTreeDataConverter
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
protected function getHeaderConversionRules()
13+
{
14+
return [
15+
'customerEmail' => 'email',
16+
'firstname' => 'firstName',
17+
'lastname' => 'lastName',
18+
'prefix' => 'namePrefix',
19+
'suffix' => 'nameSuffix',
20+
'middlename' => 'middleName',
21+
'created_at' => 'createdAt',
22+
'updated_at' => 'updatedAt',
23+
'store_id' => 'store:originId',
24+
'created_in' => 'createdIn'
25+
];
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
32+
{
33+
if ($this->context && $this->context->hasOption('channel')) {
34+
$importedRecord['store:channel:id'] = $this->context->getOption('channel');
35+
$importedRecord['website:channel:id'] = $this->context->getOption('channel');
36+
$importedRecord['group:channel:id'] = $this->context->getOption('channel');
37+
}
38+
39+
$importedRecord = parent::convertToImportFormat($importedRecord, $skipNullValues);
40+
$importedRecord = AttributesConverterHelper::addUnknownAttributes($importedRecord, $this->context);
41+
42+
$importedRecord['confirmed'] = false;
43+
$importedRecord['guest'] = true;
44+
45+
return $importedRecord;
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
protected function getBackendHeader()
52+
{
53+
return array_values($this->getHeaderConversionRules());
54+
}
55+
}

Diff for: src/OroCRM/Bundle/MagentoBundle/ImportExport/Strategy/CustomerStrategy.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ protected function findExistingEntity($entity, array $searchContext = [])
9595
$existingEntity = $this->databaseHelper->findOneBy(
9696
'OroCRM\Bundle\MagentoBundle\Entity\Customer',
9797
[
98-
'email' => $entity->getEmail()
98+
'email' => $entity->getEmail(),
99+
'channel' => $entity->getChannel()
99100
]
100101
);
101102
if ($existingEntity && $existingEntity->getId()) {

Diff for: src/OroCRM/Bundle/MagentoBundle/ImportExport/Strategy/GuestCustomerStrategy.php

+17-47
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function process($entity)
1313
{
1414
$this->assertEnvironment($entity);
1515

16-
if ($this->checkExistingCustomer()) {
16+
if ($this->checkExistingCustomer($entity)) {
1717
return null;
1818
}
1919

@@ -29,19 +29,22 @@ public function process($entity)
2929
}
3030

3131
/**
32+
* @param Customer $entity
33+
*
3234
* @return Customer
3335
*/
34-
protected function checkExistingCustomer()
36+
protected function checkExistingCustomer(Customer $entity)
3537
{
36-
$itemData = $this->context->getValue('itemData');
37-
if (!array_key_exists('customerEmail', $itemData)) {
38+
if (!$entity->getEmail()) {
3839
return null;
3940
}
4041

41-
$email = $itemData['customerEmail'];
4242
$existingCustomer = $this->databaseHelper->findOneBy(
4343
'OroCRM\Bundle\MagentoBundle\Entity\Customer',
44-
['email' => $email]
44+
[
45+
'email' => $entity->getEmail(),
46+
'channel' => $entity->getChannel()
47+
]
4548
);
4649

4750
return $existingCustomer;
@@ -62,63 +65,30 @@ protected function afterProcessEntity($entity)
6265
*/
6366
protected function processChangeAttributes(Customer $entity)
6467
{
65-
$itemData = $this->context->getValue('itemData');
66-
$entity->setGuest(true);
67-
$entity->setConfirmed(false);
6868
foreach ($entity->getAddresses() as $address) {
6969
$address->setOriginId(null);
7070
}
7171

72-
$em = $this->databaseHelper->getRegistry()->getManager();
73-
if (!empty($itemData['store']['channel']['id'])) {
74-
$this->setGroup($entity, $itemData, $em);
75-
$this->setWebsite($entity, $itemData, $em);
76-
}
77-
78-
!empty($itemData['customerEmail']) && $entity->setEmail($itemData['customerEmail']);
79-
if (!empty($itemData['addresses'])) {
80-
$address = array_pop($itemData['addresses']);
81-
!empty($address['firstName']) && !$entity->getFirstName() && $entity->setFirstName($address['firstName']);
82-
!empty($address['lastName']) && !$entity->getLastName() && $entity->setLastName($address['lastName']);
83-
}
72+
$entity->setWebsite($entity->getStore()->getWebsite());
73+
$entity->setCreatedIn($entity->getStore()->getName());
74+
$this->setDefaultGroup($entity);
8475
}
8576

8677
/**
8778
* @param Customer $entity
88-
* @param $itemData
89-
* @param $em
9079
*/
91-
protected function setGroup(Customer $entity, $itemData, $em)
80+
protected function setDefaultGroup(Customer $entity)
9281
{
93-
if (array_key_exists('customer_group_id', $itemData) && !$entity->getGroup()) {
82+
$em = $this->databaseHelper->getRegistry()->getManager();
83+
if (!$entity->getGroup() && $entity->getWebsite()->getDefaultGroupId()) {
9484
$group = $em->getRepository('OroCRMMagentoBundle:CustomerGroup')
9585
->findOneBy(
9686
[
97-
'originId' => $itemData['customer_group_id'],
98-
'channel' => $itemData['store']['channel']['id']
87+
'originId' => $entity->getWebsite()->getDefaultGroupId(),
88+
'channel' => $entity->getChannel()
9989
]
10090
);
10191
$entity->setGroup($group);
10292
}
10393
}
104-
105-
/**
106-
* @param Customer $entity
107-
* @param $itemData
108-
* @param $em
109-
*/
110-
protected function setWebsite(Customer $entity, $itemData, $em)
111-
{
112-
if (!empty($itemData['store']['originId'])) {
113-
$store = $em->getRepository('OroCRMMagentoBundle:Store')
114-
->findOneBy(
115-
[
116-
'originId' => $itemData['store']['originId'],
117-
'channel' => $itemData['store']['channel']['id']
118-
]
119-
);
120-
$entity->setWebsite($store->getWebsite());
121-
$entity->setCreatedIn($store->getName());
122-
}
123-
}
12494
}

Diff for: src/OroCRM/Bundle/MagentoBundle/ImportExport/Strategy/OrderStrategy.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ protected function processCustomer(Order $order, Customer $customer = null)
6868
$customer = $this->databaseHelper->findOneBy(
6969
'OroCRM\Bundle\MagentoBundle\Entity\Customer',
7070
[
71-
'email' => $order->getCustomerEmail()
71+
'email' => $order->getCustomerEmail(),
72+
'channel' => $order->getChannel()
7273
]
7374
);
7475
}

Diff for: src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/v1_31/AddCustomerAttributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Oro\Bundle\MigrationBundle\Migration\Migration;
88
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
99

10-
class AddCustomerAttributes implements Migration
10+
class AddCustomerPassword implements Migration
1111
{
1212
/**
1313
* {@inheritdoc}

Diff for: src/OroCRM/Bundle/MagentoBundle/Resources/config/importexport.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ services:
361361
orocrm_magento.importexport.processor.import_guest_customer:
362362
parent: oro_integration.importexport.processor.import
363363
calls:
364-
- [setDataConverter, [@oro_importexport.data_converter.default]]
364+
- [setDataConverter, [@orocrm_magento.importexport.data_converter.guest_customer]]
365365
- [setStrategy, [@orocrm_magento.import.strategy.guest_customer.add_or_update]]
366366
- [setEntityName, [%orocrm_magento.entity.customer.class%]]
367367
tags:

0 commit comments

Comments
 (0)