Skip to content

Commit 7c71dc8

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop-pr4' into 2.3-develop-pr2
2 parents 1c3bc69 + 88fed05 commit 7c71dc8

File tree

19 files changed

+320
-827
lines changed

19 files changed

+320
-827
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Block\DataProviders;
9+
10+
use Magento\Framework\Escaper;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Customer\Api\AddressMetadataInterface;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
16+
/**
17+
* Provides address attribute data into template.
18+
*/
19+
class AddressAttributeData implements ArgumentInterface
20+
{
21+
/**
22+
* @var AddressMetadataInterface
23+
*/
24+
private $addressMetadata;
25+
26+
/**
27+
* @var Escaper
28+
*/
29+
private $escaper;
30+
31+
/**
32+
* @param AddressMetadataInterface $addressMetadata
33+
* @param Escaper $escaper
34+
*/
35+
public function __construct(
36+
AddressMetadataInterface $addressMetadata,
37+
Escaper $escaper
38+
) {
39+
40+
$this->addressMetadata = $addressMetadata;
41+
$this->escaper = $escaper;
42+
}
43+
44+
/**
45+
* Returns frontend label for attribute.
46+
*
47+
* @param string $attributeCode
48+
* @return string
49+
* @throws LocalizedException
50+
*/
51+
public function getFrontendLabel(string $attributeCode): string
52+
{
53+
try {
54+
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
55+
$frontendLabel = $attribute->getFrontendLabel();
56+
} catch (NoSuchEntityException $e) {
57+
$frontendLabel = '';
58+
}
59+
60+
return $this->escaper->escapeHtml(__($frontendLabel));
61+
}
62+
}

app/code/Magento/Customer/view/frontend/layout/customer_account_create.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
</referenceBlock>
1313
<referenceContainer name="content">
1414
<block class="Magento\Customer\Block\Form\Register" name="customer_form_register" template="Magento_Customer::form/register.phtml">
15+
<arguments>
16+
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
17+
</arguments>
1518
<container name="form.additional.info" as="form_additional_info"/>
1619
<container name="customer.form.register.fields.before" as="form_fields_before" label="Form Fields Before" htmlTag="div" htmlClass="customer-form-before"/>
1720
</block>

app/code/Magento/Customer/view/frontend/layout/customer_address_form.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
</arguments>
1818
</referenceBlock>
1919
<referenceContainer name="content">
20-
<block class="Magento\Customer\Block\Address\Edit" name="customer_address_edit" template="Magento_Customer::address/edit.phtml" cacheable="false"/>
20+
<block class="Magento\Customer\Block\Address\Edit" name="customer_address_edit" template="Magento_Customer::address/edit.phtml" cacheable="false">
21+
<arguments>
22+
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
23+
</arguments>
24+
</block>
2125
</referenceContainer>
2226
</body>
2327
</page>

app/code/Magento/Customer/view/frontend/templates/address/edit.phtml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
<?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>
4343
<div class="field street required">
4444
<label for="street_1" class="label">
45-
<span><?= $block->escapeHtml(__('Street Address')) ?></span>
45+
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?></span>
4646
</label>
4747
<div class="control">
4848
<input type="text"
4949
name="street[]"
5050
value="<?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?>"
51-
title="<?= $block->escapeHtmlAttr(__('Street Address')) ?>"
51+
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?>"
5252
id="street_1"
5353
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>"/>
5454
<div class="nested">
@@ -74,20 +74,20 @@
7474
<?php if ($this->helper('Magento\Customer\Helper\Address')->isVatAttributeVisible()) : ?>
7575
<div class="field taxvat">
7676
<label class="label" for="vat_id">
77-
<span><?= $block->escapeHtml(__('VAT Number')) ?></span>
77+
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?></span>
7878
</label>
7979
<div class="control">
8080
<input type="text"
8181
name="vat_id"
8282
value="<?= $block->escapeHtmlAttr($block->getAddress()->getVatId()) ?>"
83-
title="<?= $block->escapeHtmlAttr(__('VAT Number')) ?>"
83+
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?>"
8484
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('vat_id')) ?>"
8585
id="vat_id">
8686
</div>
8787
</div>
8888
<?php endif; ?>
8989
<div class="field city required">
90-
<label class="label" for="city"><span><?= $block->escapeHtml(__('City')) ?></span></label>
90+
<label class="label" for="city"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('city') ?></span></label>
9191
<div class="control">
9292
<input type="text"
9393
name="city"
@@ -99,37 +99,37 @@
9999
</div>
100100
<div class="field region required">
101101
<label class="label" for="region_id">
102-
<span><?= $block->escapeHtml(__('State/Province')) ?></span>
102+
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?></span>
103103
</label>
104104
<div class="control">
105105
<select id="region_id" name="region_id"
106-
title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>"
106+
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
107107
class="validate-select" <?= /* @noEscape */ !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>>
108108
<option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
109109
</select>
110110
<input type="text"
111111
id="region"
112112
name="region"
113113
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
114-
title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>"
114+
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
115115
class="input-text validate-not-number-first <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
116116
</div>
117117
</div>
118118
<div class="field zip required">
119119
<label class="label" for="zip">
120-
<span><?= $block->escapeHtml(__('Zip/Postal Code')) ?></span>
120+
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?></span>
121121
</label>
122122
<div class="control">
123123
<input type="text"
124124
name="postcode"
125125
value="<?= $block->escapeHtmlAttr($block->getAddress()->getPostcode()) ?>"
126-
title="<?= $block->escapeHtmlAttr(__('Zip/Postal Code')) ?>"
126+
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>"
127127
id="zip"
128128
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
129129
</div>
130130
</div>
131131
<div class="field country required">
132-
<label class="label" for="country"><span><?= $block->escapeHtml(__('Country')) ?></span></label>
132+
<label class="label" for="country"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('country_id') ?></span></label>
133133
<div class="control">
134134
<?= $block->getCountryHtmlSelect() ?>
135135
</div>

app/code/Magento/Customer/view/frontend/templates/form/register.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
<?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>
6666

6767
<div class="field street required">
68-
<label for="street_1" class="label"><span><?= $block->escapeHtml(__('Street Address')) ?></span></label>
68+
<label for="street_1" class="label"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?></span></label>
6969
<div class="control">
70-
<input type="text" name="street[]" value="<?= $block->escapeHtmlAttr($block->getFormData()->getStreet(0)) ?>" title="<?= $block->escapeHtmlAttr(__('Street Address')) ?>" id="street_1" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
70+
<input type="text" name="street[]" value="<?= $block->escapeHtmlAttr($block->getFormData()->getStreet(0)) ?>" title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?>" id="street_1" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
7171
<div class="nested">
7272
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
7373
<?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?>
@@ -85,31 +85,31 @@
8585
</div>
8686

8787
<div class="field required">
88-
<label for="city" class="label"><span><?= $block->escapeHtml(__('City')) ?></span></label>
88+
<label for="city" class="label"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('city') ?></span></label>
8989
<div class="control">
90-
<input type="text" name="city" value="<?= $block->escapeHtmlAttr($block->getFormData()->getCity()) ?>" title="<?= $block->escapeHtmlAttr(__('City')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city')) ?>" id="city">
90+
<input type="text" name="city" value="<?= $block->escapeHtmlAttr($block->getFormData()->getCity()) ?>" title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('city') ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city')) ?>" id="city">
9191
</div>
9292
</div>
9393

9494
<div class="field region required">
95-
<label for="region_id" class="label"><span><?= $block->escapeHtml(__('State/Province')) ?></span></label>
95+
<label for="region_id" class="label"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?></span></label>
9696
<div class="control">
97-
<select id="region_id" name="region_id" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="validate-select" style="display:none;">
97+
<select id="region_id" name="region_id" title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>" class="validate-select" style="display:none;">
9898
<option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
9999
</select>
100-
<input type="text" id="region" name="region" value="<?= $block->escapeHtml($block->getRegion()) ?>" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>" style="display:none;">
100+
<input type="text" id="region" name="region" value="<?= $block->escapeHtml($block->getRegion()) ?>" title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>" style="display:none;">
101101
</div>
102102
</div>
103103

104104
<div class="field zip required">
105-
<label for="zip" class="label"><span><?= $block->escapeHtml(__('Zip/Postal Code')) ?></span></label>
105+
<label for="zip" class="label"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?></span></label>
106106
<div class="control">
107-
<input type="text" name="postcode" value="<?= $block->escapeHtmlAttr($block->getFormData()->getPostcode()) ?>" title="<?= $block->escapeHtmlAttr(__('Zip/Postal Code')) ?>" id="zip" class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
107+
<input type="text" name="postcode" value="<?= $block->escapeHtmlAttr($block->getFormData()->getPostcode()) ?>" title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>" id="zip" class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
108108
</div>
109109
</div>
110110

111111
<div class="field country required">
112-
<label for="country" class="label"><span><?= $block->escapeHtml(__('Country')) ?></span></label>
112+
<label for="country" class="label"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('country_id') ?></span></label>
113113
<div class="control">
114114
<?= $block->getCountryHtmlSelect() ?>
115115
</div>

app/code/Magento/Directory/Model/Currency/Import/FixerIo.php

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
*/
66
namespace Magento\Directory\Model\Currency\Import;
77

8+
use Magento\Store\Model\ScopeInterface;
9+
810
/**
911
* Currency rate import model (From http://fixer.io/)
1012
*/
11-
class FixerIo extends \Magento\Directory\Model\Currency\Import\AbstractImport
13+
class FixerIo extends AbstractImport
1214
{
1315
/**
1416
* @var string
1517
*/
16-
const CURRENCY_CONVERTER_URL = 'http://api.fixer.io/latest?base={{CURRENCY_FROM}}&symbols={{CURRENCY_TO}}';
18+
const CURRENCY_CONVERTER_URL = 'http://data.fixer.io/api/latest?access_key={{ACCESS_KEY}}'
19+
. '&base={{CURRENCY_FROM}}&symbols={{CURRENCY_TO}}';
1720

1821
/**
1922
* Http Client Factory
@@ -47,7 +50,7 @@ public function __construct(
4750
}
4851

4952
/**
50-
* {@inheritdoc}
53+
* @inheritdoc
5154
*/
5255
public function fetchRates()
5356
{
@@ -65,6 +68,13 @@ public function fetchRates()
6568
return $data;
6669
}
6770

71+
/**
72+
* @inheritdoc
73+
*/
74+
protected function _convert($currencyFrom, $currencyTo)
75+
{
76+
}
77+
6878
/**
6979
* Return currencies convert rates in batch mode
7080
*
@@ -73,11 +83,21 @@ public function fetchRates()
7383
* @param array $currenciesTo
7484
* @return array
7585
*/
76-
private function convertBatch($data, $currencyFrom, $currenciesTo)
86+
private function convertBatch(array $data, string $currencyFrom, array $currenciesTo): array
7787
{
88+
$accessKey = $this->scopeConfig->getValue('currency/fixerio/api_key', ScopeInterface::SCOPE_STORE);
89+
if (empty($accessKey)) {
90+
$this->_messages[] = __('No API Key was specified or an invalid API Key was specified.');
91+
$data[$currencyFrom] = $this->makeEmptyResponse($currenciesTo);
92+
return $data;
93+
}
94+
7895
$currenciesStr = implode(',', $currenciesTo);
79-
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL);
80-
$url = str_replace('{{CURRENCY_TO}}', $currenciesStr, $url);
96+
$url = str_replace(
97+
['{{ACCESS_KEY}}', '{{CURRENCY_FROM}}', '{{CURRENCY_TO}}'],
98+
[$accessKey, $currencyFrom, $currenciesStr],
99+
self::CURRENCY_CONVERTER_URL
100+
);
81101

82102
set_time_limit(0);
83103
try {
@@ -86,6 +106,11 @@ private function convertBatch($data, $currencyFrom, $currenciesTo)
86106
ini_restore('max_execution_time');
87107
}
88108

109+
if (!$this->validateResponse($response, $currencyFrom)) {
110+
$data[$currencyFrom] = $this->makeEmptyResponse($currenciesTo);
111+
return $data;
112+
}
113+
89114
foreach ($currenciesTo as $currencyTo) {
90115
if ($currencyFrom == $currencyTo) {
91116
$data[$currencyFrom][$currencyTo] = $this->_numberFormat(1);
@@ -110,25 +135,24 @@ private function convertBatch($data, $currencyFrom, $currenciesTo)
110135
* @param int $retry
111136
* @return array
112137
*/
113-
private function getServiceResponse($url, $retry = 0)
138+
private function getServiceResponse(string $url, int $retry = 0): array
114139
{
115140
/** @var \Magento\Framework\HTTP\ZendClient $httpClient */
116141
$httpClient = $this->httpClientFactory->create();
117142
$response = [];
118143

119144
try {
120-
$jsonResponse = $httpClient->setUri(
121-
$url
122-
)->setConfig(
123-
[
124-
'timeout' => $this->scopeConfig->getValue(
125-
'currency/fixerio/timeout',
126-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
127-
),
128-
]
129-
)->request(
130-
'GET'
131-
)->getBody();
145+
$jsonResponse = $httpClient->setUri($url)
146+
->setConfig(
147+
[
148+
'timeout' => $this->scopeConfig->getValue(
149+
'currency/fixerio/timeout',
150+
ScopeInterface::SCOPE_STORE
151+
),
152+
]
153+
)
154+
->request('GET')
155+
->getBody();
132156

133157
$response = json_decode($jsonResponse, true);
134158
} catch (\Exception $e) {
@@ -140,9 +164,38 @@ private function getServiceResponse($url, $retry = 0)
140164
}
141165

142166
/**
143-
* {@inheritdoc}
167+
* Validates rates response.
168+
*
169+
* @param array $response
170+
* @param string $baseCurrency
171+
* @return bool
144172
*/
145-
protected function _convert($currencyFrom, $currencyTo)
173+
private function validateResponse(array $response, string $baseCurrency): bool
174+
{
175+
if ($response['success']) {
176+
return true;
177+
}
178+
179+
$errorCodes = [
180+
101 => __('No API Key was specified or an invalid API Key was specified.'),
181+
102 => __('The account this API request is coming from is inactive.'),
182+
105 => __('The "%1" is not allowed as base currency for your subscription plan.', $baseCurrency),
183+
201 => __('An invalid base currency has been entered.'),
184+
];
185+
186+
$this->_messages[] = $errorCodes[$response['error']['code']] ?? __('Currency rates can\'t be retrieved.');
187+
188+
return false;
189+
}
190+
191+
/**
192+
* Creates array for provided currencies with empty rates.
193+
*
194+
* @param array $currenciesTo
195+
* @return array
196+
*/
197+
private function makeEmptyResponse(array $currenciesTo): array
146198
{
199+
return array_fill_keys($currenciesTo, null);
147200
}
148201
}

0 commit comments

Comments
 (0)