Skip to content

Commit bb499f5

Browse files
Merge pull request #34 from magmodules/release/1.14.0
Release/1.14.0
2 parents 674a2ca + d1f41eb commit bb499f5

File tree

4 files changed

+110
-7
lines changed

4 files changed

+110
-7
lines changed

Service/WebApi/Order.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
8585
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
8686

8787
foreach ($collection as $order) {
88-
$data[] = [
88+
$orderData = [
8989
"id" => $order->getId(),
9090
"currency" => $order->getOrderCurrencyCode(),
9191
"number" => $order->getIncrementId(),
@@ -99,6 +99,29 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
9999
"created_at" => $order->getCreatedAt(),
100100
"shopping_cart_id" => $order->getQuoteId()
101101
];
102+
if ($shipAddress = $order->getShippingAddress()) {
103+
$shipData = $shipAddress->getData();
104+
unset($shipData['entity_id'],
105+
$shipData['parent_id'],
106+
$shipData['quote_address_id'],
107+
$shipData['customer_address_id']
108+
);
109+
$orderData['shipping_address'] = array_filter($shipData, function ($value) {
110+
return !is_null($value);
111+
});
112+
}
113+
if ($billAddress = $order->getBillingAddress()) {
114+
$billData = $billAddress->getData();
115+
unset($billData['entity_id'],
116+
$billData['parent_id'],
117+
$billData['quote_address_id'],
118+
$billData['customer_address_id']
119+
);
120+
$orderData['billing_address'] = array_filter($billData, function ($value) {
121+
return !is_null($value);
122+
});
123+
}
124+
$data[] = $orderData;
102125
}
103126

104127
return $data;

Service/WebApi/Profiles.php

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Api\CustomerRepositoryInterface;
1212
use Magento\Customer\Api\Data\CustomerInterface;
1313
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource;
14+
use Magento\Eav\Api\AttributeRepositoryInterface;
1415
use Magento\Framework\Api\SearchCriteriaBuilder;
1516
use Magento\Framework\Api\SearchCriteriaInterface;
1617
use Magento\Framework\Exception\LocalizedException;
@@ -61,8 +62,18 @@ class Profiles
6162
* @var LogRepository
6263
*/
6364
private $logRepository;
64-
65+
/**
66+
* @var GroupCollectionFactory
67+
*/
6568
private $groupCollectionFactory;
69+
/**
70+
* @var AttributeRepositoryInterface
71+
*/
72+
private $attributeRepository;
73+
/**
74+
* @var array
75+
*/
76+
private $attributeSourceMap = [];
6677

6778
/**
6879
* Profiles constructor.
@@ -73,6 +84,9 @@ class Profiles
7384
* @param SearchCriteriaBuilder $searchCriteriaBuilder
7485
* @param CustomerResource $customerResource
7586
* @param AddressRepository $addressRepository
87+
* @param LogRepository $logRepository
88+
* @param GroupCollectionFactory $groupCollectionFactory
89+
* @param AttributeRepositoryInterface $attributeRepository
7690
*/
7791
public function __construct(
7892
Subscriber $subscriber,
@@ -82,7 +96,8 @@ public function __construct(
8296
CustomerResource $customerResource,
8397
AddressRepository $addressRepository,
8498
LogRepository $logRepository,
85-
GroupCollectionFactory $groupCollectionFactory
99+
GroupCollectionFactory $groupCollectionFactory,
100+
AttributeRepositoryInterface $attributeRepository
86101
) {
87102
$this->subscriber = $subscriber;
88103
$this->storeManager = $storeManager;
@@ -92,6 +107,7 @@ public function __construct(
92107
$this->addressRepository = $addressRepository;
93108
$this->logRepository = $logRepository;
94109
$this->groupCollectionFactory = $groupCollectionFactory;
110+
$this->attributeRepository = $attributeRepository;
95111
}
96112

97113
/**
@@ -123,7 +139,8 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
123139

124140
$customAttributes = $customer->getCustomAttributes();
125141
foreach ($customAttributes as $attributeCode => $attribute) {
126-
$mainData['eav_' . $attributeCode] = $attribute->getValue();
142+
$type = $this->getAttributeType($attributeCode);
143+
$mainData['eav_' . $attributeCode] = $this->getAttributeValue($attribute, $type);
127144
}
128145

129146
if ($billingId = $customer->getDefaultBilling()) {
@@ -237,4 +254,67 @@ private function getCustomersGroups(): array
237254
}
238255
return $customerGroups;
239256
}
240-
}
257+
258+
/**
259+
* @param $attribute
260+
* @return string
261+
* @throws \Magento\Framework\Exception\NoSuchEntityException
262+
*/
263+
private function getAttributeType($attribute): string
264+
{
265+
return $this->attributeRepository->get('customer', $attribute)
266+
->getFrontendInput();
267+
}
268+
269+
/**
270+
* @param $attribute
271+
* @return mixed|string
272+
*/
273+
private function getAttributeValue($attribute, $type)
274+
{
275+
$value = '';
276+
if (!$attribute || !$type) {
277+
return $value;
278+
}
279+
if ($type == 'select' || $type == 'multiselect') {
280+
try {
281+
$attributeCode = $attribute->getAttributeCode();
282+
$attributeSource = $this->getAttributeSource($attributeCode);
283+
$attributeValue = $attribute->getValue();
284+
285+
if ($type == 'multiselect') {
286+
$value = [];
287+
$values = explode(',', $attributeValue);
288+
foreach ($values as $singleValue) {
289+
$label = $attributeSource->getOptionText($singleValue);
290+
if ($label) {
291+
$value[] = $label;
292+
}
293+
}
294+
$value = implode(', ', $value);
295+
} else {
296+
$value = $attributeSource->getOptionText($attributeValue);
297+
}
298+
} catch (\Exception $e) {
299+
$value = 'Error retrieving value';
300+
}
301+
} else {
302+
$value = $attribute->getValue();
303+
}
304+
return $value;
305+
}
306+
307+
/**
308+
* @param $attributeCode
309+
* @return mixed
310+
* @throws \Magento\Framework\Exception\NoSuchEntityException
311+
*/
312+
private function getAttributeSource($attributeCode)
313+
{
314+
if (!isset($this->attributeSourceMap[$attributeCode])) {
315+
$this->attributeSourceMap[$attributeCode] =
316+
$this->attributeRepository->get('customer', $attributeCode)->getSource();
317+
}
318+
return $this->attributeSourceMap[$attributeCode];
319+
}
320+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magmodules/magento2-reloadify",
33
"description": "Reloadify extension for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.13.0",
5+
"version": "1.14.0",
66
"license": [
77
"BSD-2-Clause"
88
],

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<default>
1111
<magmodules_reloadify>
1212
<general>
13-
<version>v1.13.0</version>
13+
<version>v1.14.0</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
</general>

0 commit comments

Comments
 (0)