Skip to content

Commit 25b6600

Browse files
authored
Merge pull request #257 from magento-south/MAGETWO-24139
Stories: * MAGETWO-24139: Resolve TODO's related to Customer Service or create stories to resolve them * MAGETWO-56007: Initialize default values in customer custom attributes metadata * MAGETWO-56008: Moving getStoreByWebsite to Store Module
2 parents 6e64d1c + 7a71c1c commit 25b6600

File tree

14 files changed

+437
-31
lines changed

14 files changed

+437
-31
lines changed

app/code/Magento/Customer/Model/Address/AbstractAddress.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ public function getRegionId()
393393
if (!$regionId) {
394394
if (is_numeric($region)) {
395395
$this->setData('region_id', $region);
396-
//@TODO method unsRegion() is neither defined in abstract model nor in it's children
397396
$this->unsRegion();
398397
} else {
399398
$regionModel = $this->_createRegionInstance()->loadByCode(
@@ -629,4 +628,13 @@ protected function _createCountryInstance()
629628
{
630629
return $this->_countryFactory->create();
631630
}
631+
632+
/**
633+
* Unset Region from address
634+
* @return $this
635+
*/
636+
public function unsRegion()
637+
{
638+
return $this->unsetData("region");
639+
}
632640
}

app/code/Magento/Customer/Model/AttributeMetadataConverter.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Customer\Api\Data\OptionInterfaceFactory;
99
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
1010
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
11+
use Magento\Eav\Api\Data\AttributeDefaultValueInterface;
1112

1213
/**
1314
* Converter for AttributeMetadata
@@ -93,7 +94,13 @@ public function createMetadataAttribute($attribute)
9394
$validationRules[] = $validationRule;
9495
}
9596

96-
return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())
97+
$attributeMetaData = $this->attributeMetadataFactory->create();
98+
99+
if ($attributeMetaData instanceof AttributeDefaultValueInterface) {
100+
$attributeMetaData->setDefaultValue($attribute->getDefaultValue());
101+
}
102+
103+
return $attributeMetaData->setAttributeCode($attribute->getAttributeCode())
97104
->setFrontendInput($attribute->getFrontendInput())
98105
->setInputFilter((string)$attribute->getInputFilter())
99106
->setStoreLabel($attribute->getStoreLabel())

app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\Exception\LocalizedException;
99

1010
/**
11+
* @deprecated
1112
* Customer password attribute backend
1213
*/
1314
class Password extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
@@ -62,6 +63,7 @@ public function beforeSave($object)
6263
}
6364

6465
/**
66+
* @deprecated
6567
* @param \Magento\Framework\DataObject $object
6668
* @return bool
6769
*/

app/code/Magento/Customer/Model/Data/AttributeMetadata.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* Customer attribute metadata class.
1313
*/
1414
class AttributeMetadata extends \Magento\Framework\Api\AbstractSimpleObject implements
15-
\Magento\Customer\Api\Data\AttributeMetadataInterface
15+
\Magento\Customer\Api\Data\AttributeMetadataInterface,
16+
\Magento\Eav\Api\Data\AttributeDefaultValueInterface
1617
{
1718
/**
1819
* {@inheritdoc}
@@ -400,4 +401,20 @@ public function setIsSearchableInGrid($isSearchableInGrid)
400401
{
401402
return $this->setData(self::IS_SEARCHABLE_IN_GRID, $isSearchableInGrid);
402403
}
404+
405+
/**
406+
* @inheritdoc
407+
*/
408+
public function getDefaultValue()
409+
{
410+
return $this->_get(self::DEFAULT_VALUE);
411+
}
412+
413+
/**
414+
* @inheritdoc
415+
*/
416+
public function setDefaultValue($defaultValue)
417+
{
418+
return $this->setData(self::DEFAULT_VALUE, $defaultValue);
419+
}
403420
}

app/code/Magento/Customer/Model/EmailNotification.php

+18-27
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ class EmailNotification implements EmailNotificationInterface
4343
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template';
4444

4545
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template';
46+
47+
/**
48+
* self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled
49+
* and password is set
50+
* self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled
51+
* and password is not set
52+
* self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled
53+
* and password is set
54+
* self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link
55+
*/
56+
const TEMPLATE_TYPES = [
57+
self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
58+
self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE,
59+
self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
60+
self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
61+
];
62+
4663
/**#@-*/
4764

4865
/**
@@ -339,7 +356,7 @@ public function newAccount(
339356
$storeId = 0,
340357
$sendemailStoreId = null
341358
) {
342-
$types = $this->getTemplateTypes();
359+
$types = self::TEMPLATE_TYPES;
343360

344361
if (!isset($types[$type])) {
345362
throw new LocalizedException(__('Please correct the transactional account email type.'));
@@ -361,30 +378,4 @@ public function newAccount(
361378
$storeId
362379
);
363380
}
364-
365-
/**
366-
* Get template types
367-
*
368-
* @return array
369-
* @todo: consider eliminating method
370-
*/
371-
private function getTemplateTypes()
372-
{
373-
/**
374-
* self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled
375-
* and password is set
376-
* self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled
377-
* and password is not set
378-
* self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled
379-
* and password is set
380-
* self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link
381-
*/
382-
$types = [
383-
self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
384-
self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE,
385-
self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
386-
self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
387-
];
388-
return $types;
389-
}
390381
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model;
7+
8+
use Magento\Customer\Api\Data\OptionInterfaceFactory;
9+
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
10+
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
11+
use Magento\Customer\Model\AttributeMetadataConverter;
12+
13+
/**
14+
* Class AttributeMetadataConverterTest
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
* @package Magento\Customer\Test\Unit\Model
17+
*/
18+
class AttributeMetadatConverterTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var OptionInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $optionFactory;
24+
25+
/**
26+
* @var ValidationRuleInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $validationRuleFactory;
29+
30+
/**
31+
* @var AttributeMetadataInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $attributeMetadataFactory;
34+
35+
/**
36+
* @var \Magento\Framework\Api\DataObjectHelper | \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $dataObjectHelper;
39+
40+
/** @var AttributeMetadataConverter */
41+
private $model;
42+
43+
/** @var \Magento\Customer\Model\Attribute | \PHPUnit_Framework_MockObject_MockObject */
44+
private $attribute;
45+
46+
public function setUp()
47+
{
48+
$this->optionFactory = $this->getMockBuilder(OptionInterfaceFactory::class)
49+
->setMethods(['create'])
50+
->disableOriginalConstructor()
51+
->getMock();
52+
$this->validationRuleFactory = $this->getMockBuilder(ValidationRuleInterfaceFactory::class)
53+
->setMethods(['create'])
54+
->disableOriginalConstructor()
55+
->getMock();
56+
$this->attributeMetadataFactory = $this->getMockBuilder(AttributeMetadataInterfaceFactory::class)
57+
->setMethods(['create'])
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$this->dataObjectHelper = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class)
61+
->disableOriginalConstructor()
62+
->getMock();
63+
$this->attribute = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
64+
->disableOriginalConstructor()
65+
->getMock();
66+
67+
$this->model = new AttributeMetadataConverter(
68+
$this->optionFactory,
69+
$this->validationRuleFactory,
70+
$this->attributeMetadataFactory,
71+
$this->dataObjectHelper
72+
);
73+
}
74+
75+
/**
76+
* @return array
77+
*/
78+
private function prepareValidateRules()
79+
{
80+
return [
81+
'one' => 'numeric',
82+
'two' => 'alphanumeric'
83+
];
84+
}
85+
86+
/**
87+
* @return array
88+
*/
89+
private function prepareOptions()
90+
{
91+
return [
92+
[
93+
'label' => 'few_values',
94+
'value' => [
95+
[1], [2]
96+
]
97+
],
98+
[
99+
'label' => 'one_value',
100+
'value' => 1
101+
]
102+
];
103+
}
104+
105+
public function testCreateAttributeMetadataTestWithSource()
106+
{
107+
$validatedRules = $this->prepareValidateRules();
108+
$options = $this->prepareOptions();
109+
$optionDataObjectForSimpleValue1 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class)
110+
->disableOriginalConstructor()
111+
->getMock();
112+
$optionDataObjectForSimpleValue2 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class)
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$optionObject1 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class);
116+
$optionObject2 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class);
117+
$this->optionFactory->expects($this->exactly(4))
118+
->method('create')
119+
->will(
120+
$this->onConsecutiveCalls(
121+
$optionDataObjectForSimpleValue2,
122+
$optionObject1,
123+
$optionObject2,
124+
$optionDataObjectForSimpleValue1
125+
)
126+
);
127+
$source = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class)
128+
->disableOriginalConstructor()
129+
->getMock();
130+
$source->expects($this->once())
131+
->method('getAllOptions')
132+
->willReturn($options);
133+
$this->attribute->expects($this->once())
134+
->method('usesSource')
135+
->willReturn(true);
136+
$this->attribute->expects($this->once())
137+
->method('getSource')
138+
->willReturn($source);
139+
$optionDataObjectForSimpleValue1->expects($this->once())
140+
->method('setValue')
141+
->with(1);
142+
$optionDataObjectForSimpleValue2->expects($this->once())
143+
->method('setLabel')
144+
->with('few_values');
145+
$optionDataObjectForSimpleValue1->expects($this->once())
146+
->method('setLabel')
147+
->with('one_value');
148+
$this->dataObjectHelper->expects($this->exactly(2))
149+
->method('populateWithArray')
150+
->withConsecutive(
151+
[$optionObject1, ['1'], \Magento\Customer\Api\Data\OptionInterface::class],
152+
[$optionObject2, ['2'], \Magento\Customer\Api\Data\OptionInterface::class]
153+
);
154+
$validationRule1 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class);
155+
$validationRule2 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class);
156+
$this->validationRuleFactory->expects($this->exactly(2))
157+
->method('create')
158+
->will($this->onConsecutiveCalls($validationRule1, $validationRule2));
159+
$validationRule1->expects($this->once())
160+
->method('setValue')
161+
->with('numeric');
162+
$validationRule1->expects($this->once())
163+
->method('setName')
164+
->with('one')
165+
->willReturnSelf();
166+
$validationRule2->expects($this->once())
167+
->method('setValue')
168+
->with('alphanumeric');
169+
$validationRule2->expects($this->once())
170+
->method('setName')
171+
->with('two')
172+
->willReturnSelf();
173+
$attributeMetaData = $this->getMockBuilder(\Magento\Customer\Model\Data\AttributeMetadata::class)
174+
->disableOriginalConstructor()
175+
->enableProxyingToOriginalMethods()
176+
->getMock();
177+
$this->attribute->expects($this->once())
178+
->method('getValidateRules')
179+
->willReturn($validatedRules);
180+
$this->attributeMetadataFactory->expects($this->once())
181+
->method('create')
182+
->willReturn($attributeMetaData);
183+
$frontend = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::class)
184+
->disableOriginalConstructor()
185+
->getMock();
186+
$this->attribute->expects($this->once())
187+
->method('getFrontend')
188+
->willReturn($frontend);
189+
$optionDataObjectForSimpleValue2->expects($this->once())
190+
->method('setOptions')
191+
->with([$optionObject1, $optionObject2]);
192+
$this->model->createMetadataAttribute($this->attribute);
193+
}
194+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Eav\Api\Data;
8+
9+
/**
10+
* Interface AttributeDefaultValueInterface
11+
* Allows to manage attribute default value through interface
12+
* @api
13+
* @package Magento\Eav\Api\Data
14+
*/
15+
interface AttributeDefaultValueInterface
16+
{
17+
const DEFAULT_VALUE = "default_value";
18+
19+
/**
20+
* @param string $defaultValue
21+
* @return \Magento\Framework\Api\MetadataObjectInterface
22+
*/
23+
public function setDefaultValue($defaultValue);
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getDefaultValue();
29+
}

app/code/Magento/Quote/Model/Quote.php

+1
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ public function beforeSave()
841841
* Loading quote data by customer
842842
*
843843
* @param \Magento\Customer\Model\Customer|int $customer
844+
* @deprecated
844845
* @return $this
845846
*/
846847
public function loadByCustomer($customer)

0 commit comments

Comments
 (0)