Skip to content

Commit 75a7b9b

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1077 from magento-tsg/2.1.8-develop-pr14
[TSG] Backporting for 2.1 (pr14) (2.1.8)
2 parents b8b698b + 7a03b97 commit 75a7b9b

File tree

20 files changed

+622
-57
lines changed

20 files changed

+622
-57
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Sales\Model\ResourceModel\Order\Payment;
77

8-
use Magento\Sales\Api\Data\OrderPaymentInterface;
98
use Magento\Sales\Api\Data\OrderPaymentSearchResultInterface;
109
use Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection;
1110

@@ -68,42 +67,16 @@ protected function _construct()
6867
}
6968

7069
/**
71-
* Unserialize additional_information in each item
70+
* Unserialize additional_information in each item.
7271
*
7372
* @return $this
7473
*/
7574
protected function _afterLoad()
7675
{
7776
foreach ($this->_items as $item) {
7877
$this->getResource()->unserializeFields($item);
79-
if (!empty($item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) {
80-
$additionalInfo = $this->convertAdditionalInfo(
81-
$item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION)
82-
);
83-
$item->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo);
84-
}
8578
}
86-
return parent::_afterLoad();
87-
}
8879

89-
/**
90-
* Convert multidimensional additional information array to single
91-
*
92-
* @param array $info
93-
* @return array
94-
*/
95-
private function convertAdditionalInfo($info)
96-
{
97-
$result = [];
98-
foreach ($info as $key => $item) {
99-
if (is_array($item)) {
100-
$result += $this->convertAdditionalInfo($item);
101-
unset($info[$key]);
102-
} else {
103-
$result[$key] = $item;
104-
}
105-
}
106-
107-
return $result;
80+
return parent::_afterLoad();
10881
}
10982
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Observer;
8+
9+
use Magento\Framework\App\Area;
10+
use Magento\Framework\App\State;
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\Event\ObserverInterface;
13+
use Magento\Sales\Api\Data\OrderPaymentInterface;
14+
use Magento\Sales\Model\ResourceModel\Order\Payment\Collection;
15+
16+
/**
17+
* Class ConvertAdditionalInfo convert additional info from multidimensional array into single one for API calls.
18+
*/
19+
class ConvertAdditionalInfoObserver implements ObserverInterface
20+
{
21+
/**
22+
* Application state for identifying API calls.
23+
*
24+
* @var State
25+
*/
26+
private $state;
27+
28+
/**
29+
* ConvertAdditionalInfoObserver constructor.
30+
* @param State $state
31+
*/
32+
public function __construct(State $state)
33+
{
34+
$this->state = $state;
35+
}
36+
37+
/**
38+
* Convert additional info from multidimensional array into single one for API calls.
39+
*
40+
* @param Observer $observer
41+
* @return void
42+
*/
43+
public function execute(\Magento\Framework\Event\Observer $observer)
44+
{
45+
/** @var Collection $paymentCollection */
46+
$paymentCollection = $observer->getData('order_payment_collection');
47+
$areaCode = $this->state->getAreaCode();
48+
if ($areaCode == Area::AREA_WEBAPI_REST || $areaCode == Area::AREA_WEBAPI_SOAP) {
49+
foreach ($paymentCollection as $payment) {
50+
if (!empty($payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) {
51+
$additionalInfo = $this->convertAdditionalInfo(
52+
$payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION)
53+
);
54+
$payment->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo);
55+
}
56+
}
57+
}
58+
}
59+
60+
/**
61+
* Convert multidimensional additional information array to single.
62+
*
63+
* @param array $info
64+
* @return array
65+
*/
66+
private function convertAdditionalInfo($info)
67+
{
68+
$result = [];
69+
foreach ($info as $key => $item) {
70+
if (is_array($item)) {
71+
$result += $this->convertAdditionalInfo($item);
72+
unset($info[$key]);
73+
} else {
74+
$result[$key] = $item;
75+
}
76+
}
77+
78+
return $result;
79+
}
80+
}

app/code/Magento/Sales/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@
5151
<event name="store_add">
5252
<observer name="magento_sequence" instance="Magento\SalesSequence\Observer\SequenceCreatorObserver" />
5353
</event>
54+
<event name="sales_order_payment_collection_load_after">
55+
<observer name="convert_additional_info" instance="Magento\Sales\Observer\ConvertAdditionalInfoObserver" />
56+
</event>
5457
</config>

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,40 @@
88

99
class Generate extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
1010
{
11+
/**
12+
* @var \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory
13+
*/
14+
private $generationSpecFactory;
15+
16+
/**
17+
* @var \Magento\SalesRule\Model\Service\CouponManagementService
18+
*/
19+
private $couponManagementService;
20+
21+
/**
22+
* Generate constructor.
23+
* @param \Magento\Backend\App\Action\Context $context
24+
* @param \Magento\Framework\Registry $coreRegistry
25+
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
26+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
27+
* @param \Magento\SalesRule\Model\Service\CouponManagementService|null $couponManagementService
28+
* @param \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory|null $generationSpecFactory
29+
*/
30+
public function __construct(
31+
\Magento\Backend\App\Action\Context $context,
32+
\Magento\Framework\Registry $coreRegistry,
33+
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
34+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
35+
\Magento\SalesRule\Model\Service\CouponManagementService $couponManagementService = null,
36+
\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory = null
37+
) {
38+
parent::__construct($context, $coreRegistry, $fileFactory, $dateFilter);
39+
$this->generationSpecFactory = $generationSpecFactory ?:
40+
$this->_objectManager->get(\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory::class);
41+
$this->couponManagementService = $couponManagementService ?:
42+
$this->_objectManager->get(\Magento\SalesRule\Model\Service\CouponManagementService::class);
43+
}
44+
1145
/**
1246
* Generate Coupons action
1347
*
@@ -17,6 +51,7 @@ public function execute()
1751
{
1852
if (!$this->getRequest()->isAjax()) {
1953
$this->_forward('noroute');
54+
2055
return;
2156
}
2257
$result = [];
@@ -35,18 +70,15 @@ public function execute()
3570
$data = $inputFilter->getUnescaped();
3671
}
3772

38-
/** @var $generator \Magento\SalesRule\Model\Coupon\Massgenerator */
39-
$generator = $this->_objectManager->get('Magento\SalesRule\Model\Coupon\Massgenerator');
40-
if (!$generator->validateData($data)) {
41-
$result['error'] = __('Invalid data provided');
42-
} else {
43-
$generator->setData($data);
44-
$generator->generatePool();
45-
$generated = $generator->getGeneratedCount();
46-
$this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated));
47-
$this->_view->getLayout()->initMessages();
48-
$result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml();
49-
}
73+
$data = $this->convertCouponSpecData($data);
74+
$couponSpec = $this->generationSpecFactory->create(['data' => $data]);
75+
$couponCodes = $this->couponManagementService->generate($couponSpec);
76+
$generated = count($couponCodes);
77+
$this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated));
78+
$this->_view->getLayout()->initMessages();
79+
$result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml();
80+
} catch (\Magento\Framework\Exception\InputException $inputException) {
81+
$result['error'] = __('Invalid data provided');
5082
} catch (\Magento\Framework\Exception\LocalizedException $e) {
5183
$result['error'] = $e->getMessage();
5284
} catch (\Exception $e) {
@@ -60,4 +92,18 @@ public function execute()
6092
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
6193
);
6294
}
95+
96+
/**
97+
* We should map old values to new one
98+
* We need to do this, as new service with another key names was added
99+
*
100+
* @param array $data
101+
* @return array
102+
*/
103+
private function convertCouponSpecData(array $data)
104+
{
105+
$data['quantity'] = $data['qty'];
106+
107+
return $data;
108+
}
63109
}

app/code/Magento/SalesRule/Model/Service/CouponManagementService.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\SalesRule\Model\Service;
77

8-
use Magento\SalesRule\Model\Coupon;
9-
108
/**
119
* Coupon management service class
1210
*

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ define([
213213
],
214214
"mobileUK": [
215215
function(value) {
216-
return value.length > 9 && value.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
216+
return value.length > 9 && value.match(/^((0|\+44)7\d{3}\s?\d{6})$/);
217217
},
218218
$.mage.__('Please specify a valid mobile number')
219219
],

app/code/Magento/Ui/view/base/web/js/timeline/timeline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ define([
104104
* @returns {Boolean}
105105
*/
106106
isActive: function (record) {
107-
return record.status === 1;
107+
return Number(record.status) === 1;
108108
},
109109

110110
/**
@@ -115,7 +115,7 @@ define([
115115
* @returns {Boolean}
116116
*/
117117
isUpcoming: function (record) {
118-
return record.status === 2;
118+
return Number(record.status) === 2;
119119
},
120120

121121
/**

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,47 @@
1010
use Magento\Mtf\Client\Locator;
1111

1212
/**
13-
* Class DiscountCodes
14-
* Discount codes block
13+
* Discount codes block.
1514
*/
1615
class DiscountCodes extends Form
1716
{
1817
/**
19-
* Form wrapper selector
18+
* Message after coupon applying.
19+
*
20+
* @var string
21+
*/
22+
protected $couponApplyingMessage = './/div[contains(@class,"messages")]//div[contains(@class,"message")]';
23+
24+
/**
25+
* Form wrapper selector.
2026
*
2127
* @var string
2228
*/
2329
protected $formWrapper = '.content';
2430

2531
/**
26-
* Open discount codes form selector
32+
* Open discount codes form selector.
2733
*
2834
* @var string
2935
*/
3036
protected $openForm = '.payment-option-title';
3137

3238
/**
33-
* Fill discount code input selector
39+
* Fill discount code input selector.
3440
*
3541
* @var string
3642
*/
3743
protected $couponCode = '#discount-code';
3844

3945
/**
40-
* Click apply button selector
46+
* Click apply button selector.
4147
*
4248
* @var string
4349
*/
4450
protected $applyButton = '.action.action-apply';
4551

4652
/**
47-
* Enter discount code and click apply button
53+
* Enter discount code and click apply button.
4854
*
4955
* @param string $code
5056
* @return void
@@ -55,4 +61,14 @@ public function applyCouponCode($code)
5561
$this->_rootElement->find($this->couponCode, Locator::SELECTOR_CSS)->setValue($code);
5662
$this->_rootElement->find($this->applyButton, Locator::SELECTOR_CSS)->click();
5763
}
64+
65+
/**
66+
* Get message after coupon applying.
67+
*
68+
* @return string
69+
*/
70+
public function getCouponApplyingMessage()
71+
{
72+
return $this->_rootElement->find($this->couponApplyingMessage, Locator::SELECTOR_XPATH)->getText();
73+
}
5874
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab;
88

99
use Magento\Mtf\Block\Block;
10+
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\PaymentInfoBlock;
1011

1112
/**
1213
* Order information tab block.
@@ -20,6 +21,13 @@ class Info extends Block
2021
*/
2122
protected $orderStatus = '#order_status';
2223

24+
/**
25+
* Selector for 'Payment Information' block.
26+
*
27+
* @var string
28+
*/
29+
private $paymentInfoBlockSelector = '.order-payment-method';
30+
2331
/**
2432
* Get order status from info block
2533
*
@@ -29,4 +37,17 @@ public function getOrderStatus()
2937
{
3038
return $this->_rootElement->find($this->orderStatus)->getText();
3139
}
40+
41+
/**
42+
* Returns Payment Information block.
43+
*
44+
* @return PaymentInfoBlock
45+
*/
46+
public function getPaymentInfoBlock()
47+
{
48+
return $this->blockFactory->create(
49+
PaymentInfoBlock::class,
50+
['element' => $this->_rootElement->find($this->paymentInfoBlockSelector)]
51+
);
52+
}
3253
}

0 commit comments

Comments
 (0)