Skip to content

Commit dac614a

Browse files
author
Stanislav Idolov
committed
Merge remote-tracking branch 'mainline/develop' into bugs
2 parents 8102ba4 + 4e14f2e commit dac614a

File tree

45 files changed

+938
-310
lines changed

Some content is hidden

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

45 files changed

+938
-310
lines changed

app/code/Magento/Checkout/Controller/Cart/CouponPost.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,17 @@ public function execute()
9090

9191
if ($codeLength) {
9292
$escaper = $this->_objectManager->get(\Magento\Framework\Escaper::class);
93+
$coupon = $this->couponFactory->create();
94+
$coupon->load($couponCode, 'code');
9395
if (!$itemsCount) {
94-
if ($isCodeLengthValid) {
95-
$coupon = $this->couponFactory->create();
96-
$coupon->load($couponCode, 'code');
97-
if ($coupon->getId()) {
98-
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
99-
$this->messageManager->addSuccess(
100-
__(
101-
'You used coupon code "%1".',
102-
$escaper->escapeHtml($couponCode)
103-
)
104-
);
105-
} else {
106-
$this->messageManager->addError(
107-
__(
108-
'The coupon code "%1" is not valid.',
109-
$escaper->escapeHtml($couponCode)
110-
)
111-
);
112-
}
96+
if ($isCodeLengthValid && $coupon->getId()) {
97+
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
98+
$this->messageManager->addSuccess(
99+
__(
100+
'You used coupon code "%1".',
101+
$escaper->escapeHtml($couponCode)
102+
)
103+
);
113104
} else {
114105
$this->messageManager->addError(
115106
__(
@@ -119,7 +110,7 @@ public function execute()
119110
);
120111
}
121112
} else {
122-
if ($isCodeLengthValid && $couponCode == $cartQuote->getCouponCode()) {
113+
if ($isCodeLengthValid && $coupon->getId() && $couponCode == $cartQuote->getCouponCode()) {
123114
$this->messageManager->addSuccess(
124115
__(
125116
'You used coupon code "%1".',

app/code/Magento/Checkout/Test/Unit/Controller/Cart/CouponPostTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class CouponPostTest extends \PHPUnit_Framework_TestCase
6969
*/
7070
protected $quoteRepository;
7171

72+
/**
73+
* @var \PHPUnit_Framework_MockObject_MockObject
74+
*/
75+
private $redirect;
76+
77+
/**
78+
* @var \PHPUnit_Framework_MockObject_MockObject
79+
*/
80+
private $redirectFactory;
81+
7282
/**
7383
* @return void
7484
*/
@@ -204,6 +214,12 @@ public function testExecuteWithGoodCouponAndItems()
204214
->method('getCouponCode')
205215
->willReturn('OLDCODE');
206216

217+
$coupon = $this->getMock(\Magento\SalesRule\Model\Coupon::class, [], [], '', false);
218+
$this->couponFactory->expects($this->once())
219+
->method('create')
220+
->willReturn($coupon);
221+
$coupon->expects($this->once())->method('load')->willReturnSelf();
222+
$coupon->expects($this->once())->method('getId')->willReturn(1);
207223
$this->quote->expects($this->any())
208224
->method('getItemsCount')
209225
->willReturn(1);

app/code/Magento/ConfigurableProduct/view/frontend/templates/product/view/type/options/configurable.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ $_attributes = $block->decorateArray($block->getAllowAttributes());
3535
"#product_addtocart_form": {
3636
"configurable": {
3737
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>,
38-
"onlyMainImg": <?php /* @escapeNotVerified */ echo $block->getVar('change_only_base_image', 'Magento_ConfigurableProduct') ?: 'false'; ?>
38+
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
39+
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
3940
}
4041
}
4142
}

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ define([
2929
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
3030
mediaGalleryInitial: null,
3131
slyOldPriceSelector: '.sly-old-price',
32-
onlyMainImg: false
32+
33+
/**
34+
* Defines the mechanism of how images of a gallery should be
35+
* updated when user switches between configurations of a product.
36+
*
37+
* As for now value of this option can be either 'replace' or 'prepend'.
38+
*
39+
* @type {String}
40+
*/
41+
gallerySwitchStrategy: 'replace'
3342
},
3443

3544
/**
@@ -85,10 +94,10 @@ define([
8594

8695
this.inputSimpleProduct = this.element.find(options.selectSimpleProduct);
8796

88-
gallery.on('gallery:loaded', function () {
89-
var galleryObject = gallery.data('gallery');
90-
options.mediaGalleryInitial = galleryObject.returnCurrentImages();
91-
});
97+
gallery.data('gallery') ?
98+
this._onGalleryLoaded(gallery) :
99+
gallery.on('gallery:loaded', this._onGalleryLoaded.bind(this, gallery));
100+
92101
},
93102

94103
/**
@@ -259,46 +268,33 @@ define([
259268
*/
260269
_changeProductImage: function () {
261270
var images,
262-
initialImages = $.extend(true, [], this.options.mediaGalleryInitial),
271+
initialImages = this.options.mediaGalleryInitial,
263272
galleryObject = $(this.options.mediaGallerySelector).data('gallery');
264273

265-
if (this.options.spConfig.images[this.simpleProduct]) {
266-
images = $.extend(true, [], this.options.spConfig.images[this.simpleProduct]);
274+
if (!galleryObject) {
275+
return;
267276
}
268277

269-
function updateGallery(imagesArr) {
270-
var imgToUpdate,
271-
mainImg;
278+
images = this.options.spConfig.images[this.simpleProduct];
272279

273-
mainImg = imagesArr.filter(function (img) {
274-
return img.isMain;
275-
});
280+
if (images) {
281+
if (this.options.gallerySwitchStrategy === 'prepend') {
282+
images = images.concat(initialImages);
283+
}
276284

277-
imgToUpdate = mainImg.length ? mainImg[0] : imagesArr[0];
278-
galleryObject.updateDataByIndex(0, imgToUpdate);
279-
galleryObject.seek(1);
280-
}
285+
images = $.extend(true, [], images);
281286

282-
if (galleryObject) {
283-
if (images) {
284-
images.map(function (img) {
285-
img.type = 'image';
286-
});
287+
images.forEach(function (img) {
288+
img.type = 'image';
289+
});
287290

288-
if (this.options.onlyMainImg) {
289-
updateGallery(images);
290-
} else {
291-
galleryObject.updateData(images)
292-
}
293-
} else {
294-
if (this.options.onlyMainImg) {
295-
updateGallery(initialImages);
296-
} else {
297-
galleryObject.updateData(this.options.mediaGalleryInitial);
298-
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
299-
}
300-
}
291+
galleryObject.updateData(images);
292+
} else {
293+
galleryObject.updateData(initialImages);
294+
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
301295
}
296+
297+
galleryObject.first();
302298
},
303299

304300
/**
@@ -506,8 +502,18 @@ define([
506502
} else {
507503
$(this.options.slyOldPriceSelector).hide();
508504
}
509-
}
505+
},
510506

507+
/**
508+
* Callback which fired after gallery gets initialized.
509+
*
510+
* @param {HTMLElement} element - DOM element associated with gallery.
511+
*/
512+
_onGalleryLoaded: function (element) {
513+
var galleryObject = element.data('gallery');
514+
515+
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
516+
}
511517
});
512518

513519
return $.mage.configurable;

app/code/Magento/Eav/Model/AttributeManagement.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
*/
77
namespace Magento\Eav\Model;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Exception\InputException;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\Exception\StateException;
1213

14+
/**
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
1317
class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterface
1418
{
1519
/**
@@ -19,6 +23,7 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
1923

2024
/**
2125
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
26+
* @deprecated please use instead \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
2227
*/
2328
protected $attributeCollection;
2429

@@ -47,6 +52,11 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
4752
*/
4853
protected $attributeResource;
4954

55+
/**
56+
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
57+
*/
58+
private $attributeCollectionFactory;
59+
5060
/**
5161
* @param \Magento\Eav\Api\AttributeSetRepositoryInterface $setRepository
5262
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection
@@ -154,11 +164,26 @@ public function getAttributes($entityType, $attributeSetId)
154164
if (!$attributeSet->getAttributeSetId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
155165
throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
156166
}
157-
158-
$attributeCollection = $this->attributeCollection
159-
->setAttributeSetFilter($attributeSet->getAttributeSetId())
160-
->load();
167+
/** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection */
168+
$attributeCollection = $this->getCollectionFactory()->create();
169+
$attributeCollection->setAttributeSetFilter($attributeSet->getAttributeSetId())->load();
161170

162171
return $attributeCollection->getItems();
163172
}
173+
174+
/**
175+
* Retrieve collection factory
176+
*
177+
* @deprecated
178+
* @return \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
179+
*/
180+
private function getCollectionFactory()
181+
{
182+
if ($this->attributeCollectionFactory === null) {
183+
$this->attributeCollectionFactory = ObjectManager::getInstance()->create(
184+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory::class
185+
);
186+
}
187+
return $this->attributeCollectionFactory;
188+
}
164189
}

app/code/Magento/Eav/Test/Unit/Model/AttributeManagementTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ public function testGetAttributes()
371371
$entityType = 'type';
372372
$attributeSetId = 148;
373373

374+
$attributeCollectionFactoryMock = $this->getMock(
375+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory::class,
376+
['create'],
377+
[],
378+
'',
379+
false
380+
);
381+
$attributeCollectionFactoryMock->expects($this->once())
382+
->method('create')
383+
->willReturn($this->attributeCollectionMock);
384+
385+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
386+
$objectManager->setBackwardCompatibleProperty(
387+
$this->model,
388+
'attributeCollectionFactory',
389+
$attributeCollectionFactoryMock
390+
);
391+
374392
$attributeSetMock = $this->getMock(\Magento\Eav\Api\Data\AttributeSetInterface::class, [], [], '', false);
375393
$this->setRepositoryMock->expects($this->once())
376394
->method('get')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ public function getAuthorizationTransaction()
12891289
*/
12901290
public function isCaptureFinal($amountToCapture)
12911291
{
1292-
$total = $this->getOrder()->getTotalDue();
1292+
$total = $this->getOrder()->getBaseTotalDue();
12931293
return $this->formatAmount($total, true) == $this->formatAmount($amountToCapture, true);
12941294
}
12951295

app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ public function testIsCaptureFinal()
15481548
$partialAmount = 12.00;
15491549

15501550
$this->orderMock->expects(static::exactly(2))
1551-
->method('getTotalDue')
1551+
->method('getBaseTotalDue')
15521552
->willReturn($amount);
15531553

15541554
static::assertFalse($this->payment->isCaptureFinal($partialAmount));

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class Data
6363
*/
6464
protected $imageHelper;
6565

66+
/**
67+
* Product metadata pool
68+
*
69+
* @var \Magento\Framework\EntityManager\MetadataPool
70+
*/
71+
private $metadataPool;
72+
6673
/**
6774
* Data key which should populated to Attribute entity from "additional_data" field
6875
*
@@ -196,7 +203,13 @@ public function loadVariationByFallback(Product $parentProduct, array $attribute
196203
}
197204

198205
$productCollection = $this->productCollectionFactory->create();
199-
$this->addFilterByParent($productCollection, $parentProduct->getId());
206+
207+
$productLinkedFiled = $this->getMetadataPool()
208+
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
209+
->getLinkField();
210+
$parentId = $parentProduct->getData($productLinkedFiled);
211+
212+
$this->addFilterByParent($productCollection, $parentId);
200213

201214
$configurableAttributes = $this->getAttributesFromConfigurable($parentProduct);
202215
$allAttributesArray = [];
@@ -491,4 +504,19 @@ public function isTextSwatch(Attribute $attribute)
491504
}
492505
return $attribute->getData(Swatch::SWATCH_INPUT_TYPE_KEY) == Swatch::SWATCH_INPUT_TYPE_TEXT;
493506
}
507+
508+
/**
509+
* Get product metadata pool.
510+
*
511+
* @return \Magento\Framework\EntityManager\MetadataPool
512+
* @deprecared
513+
*/
514+
protected function getMetadataPool()
515+
{
516+
if (!$this->metadataPool) {
517+
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
518+
->get(\Magento\Framework\EntityManager\MetadataPool::class);
519+
}
520+
return $this->metadataPool;
521+
}
494522
}

0 commit comments

Comments
 (0)