Skip to content

Commit 83782e8

Browse files
author
Oleksii Korshenko
authored
Merge pull request #136 from magento-south/BUGS
[South] Bugfixing
2 parents 0d59cf4 + 60fc34b commit 83782e8

File tree

50 files changed

+4400
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4400
-475
lines changed

app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* "Reset to Defaults" button renderer
1515
*
16+
* @deprecated
1617
* @author Magento Core Team <core@magentocommerce.com>
1718
*/
1819
class Reset extends \Magento\Config\Block\System\Config\Form\Field

app/code/Magento/Backend/Test/Unit/Block/Page/System/Config/Robots/ResetTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
namespace Magento\Backend\Test\Unit\Block\Page\System\Config\Robots;
1111

12+
/**
13+
* Class ResetTest
14+
* @deprecated
15+
* @package Magento\Backend\Test\Unit\Block\Page\System\Config\Robots
16+
*/
1217
class ResetTest extends \PHPUnit_Framework_TestCase
1318
{
1419
/**

app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getValue()
124124
$value = $product->getData('final_price') * ($selectionPriceValue / 100);
125125
} else {
126126
// calculate price for selection type fixed
127-
$value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity;
127+
$value = $this->priceCurrency->convert($selectionPriceValue);
128128
}
129129
}
130130
if (!$this->useRegularPrice) {

app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,67 @@ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice)
313313
$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
314314
}
315315

316+
/**
317+
* test for method getValue with type Fixed and selectionPriceType is empty or zero
318+
*
319+
* @param bool $useRegularPrice
320+
* @dataProvider useRegularPriceDataProvider
321+
*/
322+
public function testFixedPriceWithMultipleQty($useRegularPrice)
323+
{
324+
$qty = 2;
325+
326+
$selectionPrice = new \Magento\Bundle\Pricing\Price\BundleSelectionPrice(
327+
$this->productMock,
328+
$qty,
329+
$this->calculatorMock,
330+
$this->priceCurrencyMock,
331+
$this->bundleMock,
332+
$this->eventManagerMock,
333+
$this->discountCalculatorMock,
334+
$useRegularPrice
335+
);
336+
337+
$this->setupSelectionPrice($useRegularPrice);
338+
$regularPrice = 100.125;
339+
$discountedPrice = 70.453;
340+
$convertedValue = 100.247;
341+
$actualPrice = $useRegularPrice ? $convertedValue : $discountedPrice;
342+
$expectedPrice = $useRegularPrice ? round($convertedValue, 2) : round($discountedPrice, 2);
343+
344+
$this->bundleMock->expects($this->once())
345+
->method('getPriceType')
346+
->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED));
347+
$this->productMock->expects($this->once())
348+
->method('getSelectionPriceType')
349+
->will($this->returnValue(false));
350+
$this->productMock->expects($this->any())
351+
->method('getSelectionPriceValue')
352+
->will($this->returnValue($regularPrice));
353+
354+
$this->priceCurrencyMock->expects($this->once())
355+
->method('convert')
356+
->with($regularPrice)
357+
->will($this->returnValue($convertedValue));
358+
359+
if (!$useRegularPrice) {
360+
$this->discountCalculatorMock->expects($this->once())
361+
->method('calculateDiscount')
362+
->with(
363+
$this->equalTo($this->bundleMock),
364+
$this->equalTo($convertedValue)
365+
)
366+
->will($this->returnValue($discountedPrice));
367+
}
368+
369+
$this->priceCurrencyMock->expects($this->once())
370+
->method('round')
371+
->with($actualPrice)
372+
->will($this->returnValue($expectedPrice));
373+
374+
$this->assertEquals($expectedPrice, $selectionPrice->getValue());
375+
}
376+
316377
public function useRegularPriceDataProvider()
317378
{
318379
return [

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ define([
5555
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
5656
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
5757
}
58-
this._applyQtyFix();
5958
this._applyOptionNodeFix(options);
6059

6160
options.on('change', this._onBundleOptionChanged.bind(this));
@@ -113,6 +112,7 @@ define([
113112
* Helper to fix backend behavior:
114113
* - if default qty large than 1 then backend multiply price in config
115114
*
115+
* @deprecated
116116
* @private
117117
*/
118118
_applyQtyFix: function applyQtyFix() {

app/code/Magento/Config/view/adminhtml/templates/page/system/config/robots/reset.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
/**
10+
* @deprecated
1011
* @var $block \Magento\Backend\Block\Page\System\Config\Robots\Reset
1112
* @var $jsonHelper \Magento\Framework\Json\Helper\Data
1213
*/

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
namespace Magento\Customer\Controller\Account;
88

99
use Magento\Customer\Model\AuthenticationInterface;
10+
use Magento\Customer\Model\Customer\Mapper;
1011
use Magento\Customer\Model\EmailNotificationInterface;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Data\Form\FormKey\Validator;
1315
use Magento\Customer\Api\AccountManagementInterface;
1416
use Magento\Customer\Api\CustomerRepositoryInterface;
@@ -68,6 +70,11 @@ class EditPost extends \Magento\Customer\Controller\AbstractAccount
6870
*/
6971
private $authentication;
7072

73+
/**
74+
* @var Mapper
75+
*/
76+
private $customerMapper;
77+
7178
/**
7279
* @param Context $context
7380
* @param Session $customerSession
@@ -101,7 +108,7 @@ private function getAuthentication()
101108
{
102109

103110
if (!($this->authentication instanceof AuthenticationInterface)) {
104-
return \Magento\Framework\App\ObjectManager::getInstance()->get(
111+
return ObjectManager::getInstance()->get(
105112
\Magento\Customer\Model\AuthenticationInterface::class
106113
);
107114
} else {
@@ -118,7 +125,7 @@ private function getAuthentication()
118125
private function getEmailNotification()
119126
{
120127
if (!($this->emailNotification instanceof EmailNotificationInterface)) {
121-
return \Magento\Framework\App\ObjectManager::getInstance()->get(
128+
return ObjectManager::getInstance()->get(
122129
EmailNotificationInterface::class
123130
);
124131
} else {
@@ -196,7 +203,7 @@ public function execute()
196203
private function getScopeConfig()
197204
{
198205
if (!($this->scopeConfig instanceof \Magento\Framework\App\Config\ScopeConfigInterface)) {
199-
return \Magento\Framework\App\ObjectManager::getInstance()->get(
206+
return ObjectManager::getInstance()->get(
200207
\Magento\Framework\App\Config\ScopeConfigInterface::class
201208
);
202209
} else {
@@ -241,7 +248,12 @@ private function populateNewCustomerDataObject(
241248
\Magento\Framework\App\RequestInterface $inputData,
242249
\Magento\Customer\Api\Data\CustomerInterface $currentCustomerData
243250
) {
244-
$customerDto = $this->customerExtractor->extract(self::FORM_DATA_EXTRACTOR_CODE, $inputData);
251+
$attributeValues = $this->getCustomerMapper()->toFlatArray($currentCustomerData);
252+
$customerDto = $this->customerExtractor->extract(
253+
self::FORM_DATA_EXTRACTOR_CODE,
254+
$inputData,
255+
$attributeValues
256+
);
245257
$customerDto->setId($currentCustomerData->getId());
246258
if (!$customerDto->getAddresses()) {
247259
$customerDto->setAddresses($currentCustomerData->getAddresses());
@@ -299,4 +311,19 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn
299311
}
300312
}
301313
}
314+
315+
/**
316+
* Get Customer Mapper instance
317+
*
318+
* @return Mapper
319+
*
320+
* @deprecated
321+
*/
322+
private function getCustomerMapper()
323+
{
324+
if ($this->customerMapper === null) {
325+
$this->customerMapper = ObjectManager::getInstance()->get('Magento\Customer\Model\Customer\Mapper');
326+
}
327+
return $this->customerMapper;
328+
}
302329
}

app/code/Magento/Customer/Controller/Address/FormPost.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1010
use Magento\Customer\Api\Data\RegionInterface;
1111
use Magento\Customer\Api\Data\RegionInterfaceFactory;
12+
use Magento\Customer\Model\Address\Mapper;
1213
use Magento\Customer\Model\Metadata\FormFactory;
1314
use Magento\Customer\Model\Session;
1415
use Magento\Directory\Helper\Data as HelperData;
1516
use Magento\Directory\Model\RegionFactory;
1617
use Magento\Framework\Api\DataObjectHelper;
1718
use Magento\Framework\App\Action\Context;
19+
use Magento\Framework\App\ObjectManager;
1820
use Magento\Framework\Controller\Result\ForwardFactory;
1921
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
2022
use Magento\Framework\Exception\InputException;
@@ -36,6 +38,11 @@ class FormPost extends \Magento\Customer\Controller\Address
3638
*/
3739
protected $helperData;
3840

41+
/**
42+
* @var Mapper
43+
*/
44+
private $customerAddressMapper;
45+
3946
/**
4047
* @param Context $context
4148
* @param Session $customerSession
@@ -127,12 +134,7 @@ protected function getExistingAddressData()
127134
if ($existingAddress->getCustomerId() !== $this->_getSession()->getCustomerId()) {
128135
throw new \Exception();
129136
}
130-
$existingAddressData = $this->_dataProcessor->buildOutputDataArray(
131-
$existingAddress,
132-
'\Magento\Customer\Api\Data\AddressInterface'
133-
);
134-
$existingAddressData['region_code'] = $existingAddress->getRegion()->getRegionCode();
135-
$existingAddressData['region'] = $existingAddress->getRegion()->getRegion();
137+
$existingAddressData = $this->getCustomerAddressMapper()->toFlatArray($existingAddress);
136138
}
137139
return $existingAddressData;
138140
}
@@ -212,4 +214,19 @@ public function execute()
212214

213215
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->error($url));
214216
}
217+
218+
/**
219+
* Get Customer Address Mapper instance
220+
*
221+
* @return Mapper
222+
*
223+
* @deprecated
224+
*/
225+
private function getCustomerAddressMapper()
226+
{
227+
if ($this->customerAddressMapper === null) {
228+
$this->customerAddressMapper = ObjectManager::getInstance()->get('Magento\Customer\Model\Address\Mapper');
229+
}
230+
return $this->customerAddressMapper;
231+
}
215232
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Controller\Adminhtml\File\Address;
7+
8+
use Magento\Backend\App\Action;
9+
use Magento\Backend\App\Action\Context;
10+
use Magento\Customer\Api\AddressMetadataInterface;
11+
use Magento\Customer\Model\FileUploader;
12+
use Magento\Customer\Model\FileUploaderFactory;
13+
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Psr\Log\LoggerInterface;
16+
17+
class Upload extends Action
18+
{
19+
/**
20+
* Authorization level of a basic admin session
21+
*
22+
* @see _isAllowed()
23+
*/
24+
const ADMIN_RESOURCE = 'Magento_Customer::manage';
25+
26+
/**
27+
* @var FileUploaderFactory
28+
*/
29+
private $fileUploaderFactory;
30+
31+
/**
32+
* @var AddressMetadataInterface
33+
*/
34+
private $addressMetadataService;
35+
36+
/**
37+
* @var LoggerInterface
38+
*/
39+
private $logger;
40+
41+
/**
42+
* @param Context $context
43+
* @param FileUploaderFactory $fileUploaderFactory
44+
* @param AddressMetadataInterface $addressMetadataService
45+
* @param LoggerInterface $logger
46+
*/
47+
public function __construct(
48+
Context $context,
49+
FileUploaderFactory $fileUploaderFactory,
50+
AddressMetadataInterface $addressMetadataService,
51+
LoggerInterface $logger
52+
) {
53+
$this->fileUploaderFactory = $fileUploaderFactory;
54+
$this->addressMetadataService = $addressMetadataService;
55+
$this->logger = $logger;
56+
parent::__construct($context);
57+
}
58+
59+
/**
60+
* @inheritDoc
61+
*/
62+
public function execute()
63+
{
64+
try {
65+
if (empty($_FILES)) {
66+
throw new \Exception('$_FILES array is empty.');
67+
}
68+
69+
// Must be executed before any operations with $_FILES!
70+
$this->convertFilesArray();
71+
72+
$attributeCode = key($_FILES['address']['name']);
73+
$attributeMetadata = $this->addressMetadataService->getAttributeMetadata($attributeCode);
74+
75+
/** @var FileUploader $fileUploader */
76+
$fileUploader = $this->fileUploaderFactory->create([
77+
'attributeMetadata' => $attributeMetadata,
78+
'entityTypeCode' => AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
79+
'scope' => 'address',
80+
]);
81+
82+
$errors = $fileUploader->validate();
83+
if (true !== $errors) {
84+
$errorMessage = implode('</br>', $errors);
85+
throw new LocalizedException(__($errorMessage));
86+
}
87+
88+
$result = $fileUploader->upload();
89+
} catch (LocalizedException $e) {
90+
$result = [
91+
'error' => $e->getMessage(),
92+
'errorcode' => $e->getCode(),
93+
];
94+
} catch (\Exception $e) {
95+
$this->logger->critical($e);
96+
$result = [
97+
'error' => __('Something went wrong while saving file.'),
98+
'errorcode' => $e->getCode(),
99+
];
100+
}
101+
102+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
103+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
104+
$resultJson->setData($result);
105+
return $resultJson;
106+
}
107+
108+
/**
109+
* Update global $_FILES array. Convert data to standard form
110+
*
111+
* NOTE: This conversion is required to use \Magento\Framework\File\Uploader::_setUploadFileId($fileId) method.
112+
*
113+
* @return void
114+
*/
115+
private function convertFilesArray()
116+
{
117+
foreach($_FILES['address'] as $itemKey => $item) {
118+
foreach ($item as $value) {
119+
if (is_array($value)) {
120+
$_FILES['address'][$itemKey] = [
121+
key($value) => current($value),
122+
];
123+
}
124+
}
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)