Skip to content

Commit a8c49c4

Browse files
Merge branch 'MAGETWO-91760-rebase' into EPAM-PR-10
2 parents 8f38ed2 + 836681b commit a8c49c4

File tree

4 files changed

+167
-72
lines changed

4 files changed

+167
-72
lines changed

app/code/Magento/Checkout/Model/DefaultConfigProvider.php

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Customer\Model\Context as CustomerContext;
1414
use Magento\Customer\Model\Session as CustomerSession;
1515
use Magento\Customer\Model\Url as CustomerUrlManager;
16+
use Magento\Eav\Api\AttributeOptionManagementInterface;
1617
use Magento\Framework\App\Config\ScopeConfigInterface;
1718
use Magento\Framework\App\Http\Context as HttpContext;
1819
use Magento\Framework\App\ObjectManager;
@@ -26,11 +27,18 @@
2627
use Magento\Store\Model\ScopeInterface;
2728

2829
/**
30+
* Default Config Provider
31+
*
2932
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3033
* @SuppressWarnings(PHPMD.TooManyFields)
3134
*/
3235
class DefaultConfigProvider implements ConfigProviderInterface
3336
{
37+
/**
38+
* @var AttributeOptionManagementInterface
39+
*/
40+
private $attributeOptionManager;
41+
3442
/**
3543
* @var CheckoutHelper
3644
*/
@@ -194,6 +202,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
194202
* @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
195203
* @param UrlInterface $urlBuilder
196204
* @param AddressMetadataInterface $addressMetadata
205+
* @param AttributeOptionManagementInterface $attributeOptionManager
197206
* @codeCoverageIgnore
198207
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
199208
*/
@@ -224,7 +233,8 @@ public function __construct(
224233
\Magento\Store\Model\StoreManagerInterface $storeManager,
225234
\Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
226235
UrlInterface $urlBuilder,
227-
AddressMetadataInterface $addressMetadata = null
236+
AddressMetadataInterface $addressMetadata = null,
237+
AttributeOptionManagementInterface $attributeOptionManager = null
228238
) {
229239
$this->checkoutHelper = $checkoutHelper;
230240
$this->checkoutSession = $checkoutSession;
@@ -253,10 +263,15 @@ public function __construct(
253263
$this->paymentMethodManagement = $paymentMethodManagement;
254264
$this->urlBuilder = $urlBuilder;
255265
$this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class);
266+
$this->attributeOptionManager = $attributeOptionManager ??
267+
ObjectManager::getInstance()->get(AttributeOptionManagementInterface::class);
256268
}
257269

258270
/**
259-
* {@inheritdoc}
271+
* Return configuration array
272+
*
273+
* @return array|mixed
274+
* @throws \Magento\Framework\Exception\NoSuchEntityException
260275
*/
261276
public function getConfig()
262277
{
@@ -359,7 +374,7 @@ private function filterNotVisibleAttributes(array $attributes)
359374
}
360375
}
361376

362-
return $attributes;
377+
return $this->setLabelsToAttributes($attributes);
363378
}
364379

365380
/**
@@ -581,6 +596,7 @@ protected function getStaticBaseUrl()
581596

582597
/**
583598
* Return quote totals data
599+
*
584600
* @return array
585601
*/
586602
private function getTotalsData()
@@ -612,6 +628,7 @@ private function getTotalsData()
612628

613629
/**
614630
* Returns active carriers codes
631+
*
615632
* @return array
616633
*/
617634
private function getActiveCarriers()
@@ -625,6 +642,7 @@ private function getActiveCarriers()
625642

626643
/**
627644
* Returns origin country code
645+
*
628646
* @return string
629647
*/
630648
private function getOriginCountryCode()
@@ -638,7 +656,9 @@ private function getOriginCountryCode()
638656

639657
/**
640658
* Returns array of payment methods
641-
* @return array
659+
*
660+
* @return array $paymentMethods
661+
* @throws \Magento\Framework\Exception\NoSuchEntityException
642662
*/
643663
private function getPaymentMethods()
644664
{
@@ -654,4 +674,59 @@ private function getPaymentMethods()
654674
}
655675
return $paymentMethods;
656676
}
677+
678+
/**
679+
* Set Labels to custom Attributes
680+
*
681+
* @param array $customAttributes
682+
* @return array $customAttributes
683+
* @throws \Magento\Framework\Exception\InputException
684+
* @throws \Magento\Framework\Exception\StateException
685+
*/
686+
private function setLabelsToAttributes(array $customAttributes) : array
687+
{
688+
if (!empty($customAttributes)) {
689+
foreach ($customAttributes as $customAttributeCode => $customAttribute) {
690+
$attributeOptionLabels = $this->getAttributeLabels($customAttribute, $customAttributeCode);
691+
if (!empty($attributeOptionLabels)) {
692+
$customAttributes[$customAttributeCode]['label'] = implode(', ', $attributeOptionLabels);
693+
}
694+
}
695+
}
696+
697+
return $customAttributes;
698+
}
699+
700+
/**
701+
* Get Labels by CustomAttribute and CustomAttributeCode
702+
*
703+
* @param array $customAttribute
704+
* @param string|integer $customAttributeCode
705+
* @return array $attributeOptionLabels
706+
* @throws \Magento\Framework\Exception\InputException
707+
* @throws \Magento\Framework\Exception\StateException
708+
*/
709+
private function getAttributeLabels(array $customAttribute, string $customAttributeCode) : array
710+
{
711+
$attributeOptionLabels = [];
712+
713+
if (!empty($customAttribute['value'])) {
714+
$customAttributeValues = explode(',', $customAttribute['value']);
715+
$attributeOptions = $this->attributeOptionManager->getItems(
716+
\Magento\Customer\Model\Indexer\Address\AttributeProvider::ENTITY,
717+
$customAttributeCode
718+
);
719+
720+
if (!empty($attributeOptions)) {
721+
foreach ($attributeOptions as $attributeOption) {
722+
$attributeOptionValue = $attributeOption->getValue();
723+
if (in_array($attributeOptionValue, $customAttributeValues)) {
724+
$attributeOptionLabels[] = $attributeOption->getLabel() ?? $attributeOptionValue;
725+
}
726+
}
727+
}
728+
}
729+
730+
return $attributeOptionLabels;
731+
}
657732
}

app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,37 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<div class="billing-address-details" data-bind="if: isAddressDetailsVisible() && currentBillingAddress()">
8-
<!-- ko text: currentBillingAddress().prefix --><!-- /ko --> <!-- ko text: currentBillingAddress().firstname --><!-- /ko --> <!-- ko text: currentBillingAddress().middlename --><!-- /ko -->
9-
<!-- ko text: currentBillingAddress().lastname --><!-- /ko --> <!-- ko text: currentBillingAddress().suffix --><!-- /ko --><br/>
10-
<!-- ko text: _.values(currentBillingAddress().street).join(", ") --><!-- /ko --><br/>
11-
<!-- ko text: currentBillingAddress().city --><!-- /ko -->, <span data-bind="html: currentBillingAddress().region"></span> <!-- ko text: currentBillingAddress().postcode --><!-- /ko --><br/>
12-
<!-- ko text: getCountryName(currentBillingAddress().countryId) --><!-- /ko --><br/>
13-
<!-- ko if: (currentBillingAddress().telephone) -->
14-
<a data-bind="text: currentBillingAddress().telephone, attr: {'href': 'tel:' + currentBillingAddress().telephone}"></a>
15-
<!-- /ko --><br/>
16-
<!-- ko foreach: { data: currentBillingAddress().customAttributes, as: 'element' } -->
17-
<!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
18-
<!-- ko if: (typeof element[attribute] === "object") -->
19-
<!-- ko text: element[attribute].value --><!-- /ko -->
20-
<!-- /ko -->
21-
<!-- ko if: (typeof element[attribute] === "string") -->
22-
<!-- ko text: element[attribute] --><!-- /ko -->
23-
<!-- /ko --><br/>
24-
<!-- /ko -->
25-
<!-- /ko -->
26-
<button type="button"
7+
<div if="isAddressDetailsVisible() && currentBillingAddress()" class="billing-address-details">
8+
<text args="currentBillingAddress().prefix"/> <text args="currentBillingAddress().firstname"/> <text args="currentBillingAddress().middlename"/>
9+
<text args="currentBillingAddress().lastname"/> <text args="currentBillingAddress().suffix"/><br/>
10+
<text args="_.values(currentBillingAddress().street).join(', ')"/><br/>
11+
<text args="currentBillingAddress().city "/>, <span html="currentBillingAddress().region"></span> <text args="currentBillingAddress().postcode"/><br/>
12+
<text args="getCountryName(currentBillingAddress().countryId)"/><br/>
13+
<a if="currentBillingAddress().telephone" attr="'href': 'tel:' + currentBillingAddress().telephone" text="currentBillingAddress().telephone"></a><br/>
14+
15+
<each args="data: currentBillingAddress().customAttributes, as: 'element'">
16+
<each args="data: Object.keys(element), as: 'attribute'">
17+
<if args="typeof element[attribute] === 'object'">
18+
<if args="element[attribute].label">
19+
<text args="element[attribute].label"/>
20+
</if>
21+
<ifnot args="element[attribute].label">
22+
<if args="element[attribute].value">
23+
<text args="element[attribute].value"/>
24+
</if>
25+
</ifnot>
26+
<if args="typeof element[attribute] === 'string'">
27+
<text args="element[attribute]"/>
28+
</if>
29+
</if><br/>
30+
</each>
31+
</each>
32+
33+
<button visible="!isAddressSameAsShipping()"
34+
type="button"
2735
class="action action-edit-address"
28-
data-bind="visible: !isAddressSameAsShipping(), click: editAddress">
29-
<span data-bind="i18n: 'Edit'"></span>
36+
click="editAddress">
37+
<span translate="'Edit'"></span>
3038
</button>
3139
</div>
40+

app/code/Magento/Checkout/view/frontend/web/template/shipping-address/address-renderer/default.html

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,38 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<div class="shipping-address-item" data-bind="css: isSelected() ? 'selected-item' : 'not-selected-item'">
8-
<!-- ko text: address().prefix --><!-- /ko --> <!-- ko text: address().firstname --><!-- /ko --> <!-- ko text: address().middlename --><!-- /ko -->
9-
<!-- ko text: address().lastname --><!-- /ko --> <!-- ko text: address().suffix --><!-- /ko --><br/>
10-
<!-- ko text: _.values(address().street).join(", ") --><!-- /ko --><br/>
11-
<!-- ko text: address().city --><!-- /ko -->, <span data-bind="html: address().region"></span> <!-- ko text: address().postcode --><!-- /ko --><br/>
12-
<!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>
13-
<!-- ko if: (address().telephone) -->
14-
<a data-bind="text: address().telephone, attr: {'href': 'tel:' + address().telephone}"></a>
15-
<!-- /ko --><br/>
16-
<!-- ko foreach: { data: address().customAttributes, as: 'element' } -->
17-
<!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
18-
<!-- ko if: (typeof element[attribute] === "object") -->
19-
<!-- ko text: element[attribute].value --><!-- /ko -->
20-
<!-- /ko -->
21-
<!-- ko if: (typeof element[attribute] === "string") -->
22-
<!-- ko text: element[attribute] --><!-- /ko -->
23-
<!-- /ko --><br/>
24-
<!-- /ko -->
25-
<!-- /ko -->
26-
<!-- ko if: (address().isEditable()) -->
27-
<button type="button"
7+
<div class="shipping-address-item" css="'selected-item' : isSelected() , 'not-selected-item':!isSelected()">
8+
<text args="address().prefix"/> <text args="address().firstname"/> <text args="address().middlename"/>
9+
<text args="address().lastname"/> <text args="address().suffix"/><br/>
10+
<text args="_.values(address().street).join(', ')"/><br/>
11+
<text args="address().city "/>, <span html="address().region"></span> <text args="address().postcode"/><br/>
12+
<text args="getCountryName(address().countryId)"/><br/>
13+
<a if="address().telephone" attr="'href': 'tel:' + address().telephone" text="address().telephone"></a><br/>
14+
15+
<each args="data: address().customAttributes, as: 'element'">
16+
<each args="data: Object.keys(element), as: 'attribute'">
17+
<if args="typeof element[attribute] === 'object'">
18+
<if args="element[attribute].label">
19+
<text args="element[attribute].label"/>
20+
</if>
21+
<ifnot args="element[attribute].label">
22+
<if args="element[attribute].value">
23+
<text args="element[attribute].value"/>
24+
</if>
25+
</ifnot>
26+
<if args="typeof element[attribute] === 'string'">
27+
<text args="element[attribute]"/>
28+
</if>
29+
</if><br/>
30+
</each>
31+
</each>
32+
33+
<button visible="address().isEditable()" type="button"
2834
class="action edit-address-link"
29-
data-bind="click: editAddress, visible: address().isEditable()">
30-
<span data-bind="i18n: 'Edit'"></span>
35+
click="editAddress">
36+
<span translate="'Edit'"></span>
3137
</button>
32-
<!-- /ko -->
33-
<button type="button" data-bind="click: selectAddress" class="action action-select-shipping-item">
34-
<span data-bind="i18n: 'Ship Here'"></span>
38+
<button type="button" click="selectAddress" class="action action-select-shipping-item">
39+
<span translate="'Ship Here'"></span>
3540
</button>
3641
</div>

app/code/Magento/Checkout/view/frontend/web/template/shipping-information/address-renderer/default.html

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<!-- ko if: (visible()) -->
8-
<!-- ko text: address().prefix --><!-- /ko --> <!-- ko text: address().firstname --><!-- /ko --> <!-- ko text: address().middlename --><!-- /ko -->
9-
<!-- ko text: address().lastname --><!-- /ko --> <!-- ko text: address().suffix --><!-- /ko --><br/>
10-
<!-- ko text: _.values(address().street).join(", ") --><!-- /ko --><br/>
11-
<!-- ko text: address().city --><!-- /ko -->, <span data-bind="html: address().region"></span> <!-- ko text: address().postcode --><!-- /ko --><br/>
12-
<!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>
13-
<!-- ko if: (address().telephone) -->
14-
<a data-bind="text: address().telephone, attr: {'href': 'tel:' + address().telephone}"></a>
15-
<!-- /ko --><br/>
16-
<!-- ko foreach: { data: address().customAttributes, as: 'element' } -->
17-
<!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
18-
<!-- ko if: (typeof element[attribute] === "object") -->
19-
<!-- ko text: element[attribute].value --><!-- /ko -->
20-
<!-- /ko -->
21-
<!-- ko if: (typeof element[attribute] === "string") -->
22-
<!-- ko text: element[attribute] --><!-- /ko -->
23-
<!-- /ko --><br/>
24-
<!-- /ko -->
25-
<!-- /ko -->
26-
<!-- /ko -->
7+
<if args="visible()">
8+
<text args="address().prefix"/> <text args="address().firstname"/> <text args="address().middlename"/>
9+
<text args="address().lastname"/> <text args="address().suffix"/><br/>
10+
<text args="_.values(address().street).join(', ')"/><br/>
11+
<text args="address().city "/>, <span html="address().region"></span> <text args="address().postcode"/><br/>
12+
<text args="getCountryName(address().countryId)"/><br/>
13+
<a if="address().telephone" attr="'href': 'tel:' + address().telephone" text="address().telephone"></a><br/>
14+
15+
<each args="data: address().customAttributes, as: 'element'">
16+
<each args="data: Object.keys(element), as: 'attribute'">
17+
<if args="typeof element[attribute] === 'object'">
18+
<if args="element[attribute].label">
19+
<text args="element[attribute].label"/>
20+
</if>
21+
<ifnot args="element[attribute].label">
22+
<if args="element[attribute].value">
23+
<text args="element[attribute].value"/>
24+
</if>
25+
</ifnot>
26+
<if args="typeof element[attribute] === 'string'">
27+
<text args="element[attribute]"/>
28+
</if>
29+
</if><br/>
30+
</each>
31+
</each>
32+
</if>

0 commit comments

Comments
 (0)