Skip to content

Commit f709d2a

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-46014
2 parents d97ebe5 + 4712b83 commit f709d2a

File tree

85 files changed

+2350
-1979
lines changed

Some content is hidden

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

85 files changed

+2350
-1979
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
99
use Magento\Customer\Api\GroupManagementInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Quote\Api\CartManagementInterface;
1012

1113
/**
1214
* Adminhtml quote session
@@ -79,6 +81,11 @@ class Quote extends \Magento\Framework\Session\SessionManager
7981
*/
8082
protected $quoteFactory;
8183

84+
/**
85+
* @var \Magento\Quote\Api\CartManagementInterface;
86+
*/
87+
private $cartManagement;
88+
8289
/**
8390
* @param \Magento\Framework\App\Request\Http $request
8491
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
@@ -143,15 +150,15 @@ public function __construct(
143150
*/
144151
public function getQuote()
145152
{
153+
$cartManagement = $this->getCartManagement();
154+
146155
if ($this->_quote === null) {
147-
$this->_quote = $this->quoteFactory->create();
148156
if ($this->getStoreId()) {
149157
if (!$this->getQuoteId()) {
150-
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId())
151-
->setIsActive(false)
152-
->setStoreId($this->getStoreId());
153-
$this->quoteRepository->save($this->_quote);
154-
$this->setQuoteId($this->_quote->getId());
158+
$this->setQuoteId($cartManagement->createEmptyCart());
159+
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
160+
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
161+
$this->_quote->setIsActive(false);
155162
} else {
156163
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
157164
$this->_quote->setStoreId($this->getStoreId());
@@ -169,6 +176,18 @@ public function getQuote()
169176
return $this->_quote;
170177
}
171178

179+
/**
180+
* @return CartManagementInterface
181+
* @deprecated
182+
*/
183+
private function getCartManagement()
184+
{
185+
if ($this->cartManagement === null) {
186+
$this->cartManagement = ObjectManager::getInstance()->get(CartManagementInterface::class);
187+
}
188+
return $this->cartManagement;
189+
}
190+
172191
/**
173192
* Retrieve store model object
174193
*

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
9292
*/
9393
protected $quoteFactoryMock;
9494

95+
/**
96+
* @var \PHPUnit_Framework_MockObject_MockObject
97+
*/
98+
protected $cartManagementMock;
99+
95100
/**
96101
* Set up
97102
*
@@ -197,9 +202,16 @@ protected function setUp()
197202
);
198203

199204
$this->quoteFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteFactory', ['create'], [], '', false);
205+
$this->cartManagementMock = $this->getMock(
206+
\Magento\Quote\Api\CartManagementInterface::class,
207+
[],
208+
[],
209+
'',
210+
false
211+
);
200212

201213
$this->quote = $this->getMock(
202-
'Magento\Backend\Model\Session\Quote',
214+
\Magento\Backend\Model\Session\Quote::class,
203215
['getStoreId', 'getQuoteId', 'setQuoteId', 'hasCustomerId', 'getCustomerId'],
204216
[
205217
'request' => $this->requestMock,
@@ -217,10 +229,12 @@ protected function setUp()
217229
'storeManager' => $this->storeManagerMock,
218230
'groupManagement' => $this->groupManagementMock,
219231
'quoteFactory' => $this->quoteFactoryMock
220-
],
221-
'',
222-
true
232+
]
223233
);
234+
235+
$this->prepareObjectManager([
236+
[\Magento\Quote\Api\CartManagementInterface::class, $this->cartManagementMock]
237+
]);
224238
}
225239

226240
/**
@@ -235,6 +249,8 @@ public function testGetQuoteWithoutQuoteId()
235249
$customerId = 66;
236250
$customerGroupId = 77;
237251

252+
$this->cartManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($quoteId);
253+
238254
$this->quote->expects($this->any())
239255
->method('getQuoteId')
240256
->will($this->returnValue(null));
@@ -271,7 +287,6 @@ public function testGetQuoteWithoutQuoteId()
271287
'setStoreId',
272288
'setCustomerGroupId',
273289
'setIsActive',
274-
'getId',
275290
'assignCustomer',
276291
'setIgnoreOldQty',
277292
'setIsSuperMode',
@@ -281,9 +296,7 @@ public function testGetQuoteWithoutQuoteId()
281296
'',
282297
false
283298
);
284-
$quoteMock->expects($this->once())
285-
->method('setStoreId')
286-
->with($storeId);
299+
$this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock);
287300
$quoteMock->expects($this->once())
288301
->method('setCustomerGroupId')
289302
->with($customerGroupId)
@@ -292,9 +305,6 @@ public function testGetQuoteWithoutQuoteId()
292305
->method('setIsActive')
293306
->with(false)
294307
->will($this->returnSelf());
295-
$quoteMock->expects($this->once())
296-
->method('getId')
297-
->will($this->returnValue($quoteId));
298308
$quoteMock->expects($this->once())
299309
->method('assignCustomer')
300310
->with($dataCustomerMock);
@@ -305,13 +315,6 @@ public function testGetQuoteWithoutQuoteId()
305315
->method('setIsSuperMode')
306316
->with(true);
307317

308-
$this->quoteFactoryMock->expects($this->once())
309-
->method('create')
310-
->will($this->returnValue($quoteMock));
311-
$this->quoteRepositoryMock->expects($this->once())
312-
->method('save')
313-
->with($quoteMock);
314-
315318
$this->assertEquals($quoteMock, $this->quote->getQuote());
316319
}
317320

@@ -380,9 +383,6 @@ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expected
380383
->method('getCustomerId')
381384
->will($this->returnValue($quoteCustomerId));
382385

383-
$this->quoteFactoryMock->expects($this->once())
384-
->method('create')
385-
->will($this->returnValue($quoteMock));
386386
$this->quoteRepositoryMock->expects($this->once())
387387
->method('get')
388388
->with($quoteId)
@@ -401,4 +401,19 @@ public function getQuoteDataProvider()
401401
'customer ids same' => [66, 66, 'never'],
402402
];
403403
}
404+
405+
/**
406+
* @param array $map
407+
* @deprecated
408+
*/
409+
private function prepareObjectManager($map)
410+
{
411+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
412+
$objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf();
413+
$objectManagerMock->expects($this->any())->method('get')->will($this->returnValueMap($map));
414+
$reflectionClass = new \ReflectionClass('Magento\Framework\App\ObjectManager');
415+
$reflectionProperty = $reflectionClass->getProperty('_instance');
416+
$reflectionProperty->setAccessible(true);
417+
$reflectionProperty->setValue($objectManagerMock);
418+
}
404419
}

app/code/Magento/Backend/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<argument name="storage" xsi:type="object">Magento\Backend\Model\Session\Quote\Storage</argument>
150150
</arguments>
151151
</type>
152-
<type name="Magento\Framework\Console\CommandList">
152+
<type name="Magento\Framework\Console\CommandListInterface">
153153
<arguments>
154154
<argument name="commands" xsi:type="array">
155155
<item name="cacheEnableCommand" xsi:type="object">Magento\Backend\Console\Command\CacheEnableCommand</item>

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
@@ -180,7 +180,7 @@ define([
180180
};
181181
});
182182

183-
$option.text(template(toTemplate));
183+
$option.html(template(toTemplate));
184184
});
185185
});
186186
},

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
103103
* @param array $entityIds the entity ids limitation
104104
* @param int $attributeId the attribute id limitation
105105
* @return $this
106+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
106107
*/
107108
protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
108109
{
@@ -125,31 +126,37 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
125126
['s' => $this->getTable('store')],
126127
['store_id', 'website_id']
127128
)->joinLeft(
128-
['d' => $this->getTable('catalog_product_entity_int')],
129-
'd.store_id = 0 OR d.store_id = s.store_id',
130-
['attribute_id', 'value']
129+
['dd' => $this->getTable('catalog_product_entity_int')],
130+
'dd.store_id = 0',
131+
['attribute_id']
131132
)->joinLeft(
132-
['d2' => $this->getTable('catalog_product_entity_int')],
133+
['ds' => $this->getTable('catalog_product_entity_int')],
134+
"ds.store_id = s.store_id AND ds.attribute_id = dd.attribute_id AND " .
135+
"ds.{$productIdField} = dd.{$productIdField}",
136+
['value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)')]
137+
)->joinLeft(
138+
['d2d' => $this->getTable('catalog_product_entity_int')],
133139
sprintf(
134-
"d.{$productIdField} = d2.{$productIdField}"
135-
. ' AND d2.attribute_id = %s AND d2.value = %s AND d.store_id = d2.store_id',
136-
$this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId(),
137-
ProductStatus::STATUS_ENABLED
140+
"d2d.store_id = 0 AND d2d.{$productIdField} = dd.{$productIdField} AND d2d.attribute_id = %s",
141+
$this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId()
138142
),
139143
[]
144+
)->joinLeft(
145+
['d2s' => $this->getTable('catalog_product_entity_int')],
146+
"d2s.store_id = s.store_id AND d2s.attribute_id = d2d.attribute_id AND " .
147+
"d2s.{$productIdField} = d2d.{$productIdField}",
148+
[]
140149
)->joinLeft(
141150
['cpe' => $this->getTable('catalog_product_entity')],
142-
"cpe.{$productIdField} = d.{$productIdField}",
151+
"cpe.{$productIdField} = dd.{$productIdField}",
143152
array_unique([$productIdField, 'entity_id'])
144153
)->where(
145154
's.store_id != 0'
146155
)->where(
147-
'd.value IS NOT NULL'
156+
'(ds.value IS NOT NULL OR dd.value IS NOT NULL)'
148157
)->where(
149-
'd2.value IS NOT NULL'
150-
)->group([
151-
's.store_id', 's.website_id', 'cpe.entity_id', 'd.attribute_id', 'd.value',
152-
]);
158+
(new \Zend_Db_Expr('COALESCE(d2s.value, d2d.value)')) . ' = ' . ProductStatus::STATUS_ENABLED
159+
)->distinct(true);
153160

154161
if ($entityIds !== null) {
155162
$subSelect->where('cpe.entity_id IN(?)', $entityIds);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AbstractModifier.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;
77

88
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
9-
use Magento\Framework\Stdlib\ArrayManager;
9+
use Magento\Framework\Pricing\PriceCurrencyInterface;
1010

1111
/**
1212
* Class AbstractModifier
@@ -195,13 +195,24 @@ protected function getGroupCodeByField(array $meta, $field)
195195
}
196196

197197
/**
198-
* Format number to have only two decimals after delimiter
198+
* Format price to have only two decimals after delimiter
199199
*
200200
* @param mixed $value
201201
* @return string
202202
*/
203-
protected function formatFloat($value)
203+
protected function formatPrice($value)
204204
{
205-
return $value !== null ? number_format((float)$value, 2, '.', '') : '';
205+
return $value !== null ? number_format((float)$value, PriceCurrencyInterface::DEFAULT_PRECISION, '.', '') : '';
206+
}
207+
208+
/**
209+
* Strip excessive decimal digits from weight number
210+
*
211+
* @param mixed $value
212+
* @return string
213+
*/
214+
protected function formatWeight($value)
215+
{
216+
return (float)$value;
206217
}
207218
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public function modifyData(array $data)
156156

157157
/** @var \Magento\Catalog\Model\Product\Option $option */
158158
foreach ($productOptions as $index => $option) {
159-
$options[$index] = $this->formatFloatByPath(static::FIELD_PRICE_NAME, $option->getData());
159+
$options[$index] = $this->formatPriceByPath(static::FIELD_PRICE_NAME, $option->getData());
160160
$values = $option->getValues() ?: [];
161161

162162
/** @var \Magento\Catalog\Model\Product\Option $value */
163163
foreach ($values as $value) {
164-
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatFloatByPath(
164+
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatPriceByPath(
165165
static::FIELD_PRICE_NAME,
166166
$value->getData()
167167
);
@@ -188,12 +188,12 @@ public function modifyData(array $data)
188188
* @param array $data
189189
* @return array
190190
*/
191-
protected function formatFloatByPath($path, array $data)
191+
protected function formatPriceByPath($path, array $data)
192192
{
193193
$value = $this->arrayManager->get($path, $data);
194194

195195
if (is_numeric($value)) {
196-
$data = $this->arrayManager->replace($path, $data, $this->formatFloat($value));
196+
$data = $this->arrayManager->replace($path, $data, $this->formatPrice($value));
197197
}
198198

199199
return $data;

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function modifyData(array $data)
354354
foreach ($attributes as $attribute) {
355355
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
356356
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
357-
$attributeValue = $this->formatFloat($attributeValue);
357+
$attributeValue = $this->formatPrice($attributeValue);
358358
}
359359
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
360360
}

0 commit comments

Comments
 (0)