Skip to content

Commit a02f2b8

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-56675
2 parents c723d36 + b56df96 commit a02f2b8

File tree

81 files changed

+2153
-109
lines changed

Some content is hidden

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

81 files changed

+2153
-109
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ define([
295295
case 'hidden':
296296
optionHash = 'bundle-option-' + optionName + '##' + optionValue;
297297
optionQty = optionConfig[optionValue].qty || 0;
298+
canQtyCustomize = optionConfig[optionValue].customQty === '1';
299+
qtyField = element.data('qtyField');
300+
qtyField.data('option', element);
301+
toggleQtyField(qtyField, optionQty, optionId, optionValue, canQtyCustomize);
298302
tempChanges = utils.deepClone(optionConfig[optionValue].prices);
299303
tempChanges = applyTierPrice(tempChanges, optionQty, optionConfig);
300304
tempChanges = applyQty(tempChanges, optionQty);

app/code/Magento/Catalog/Block/Product/AbstractProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __construct(\Magento\Catalog\Block\Product\Context $context, arr
124124
*/
125125
public function getAddToCartUrl($product, $additional = [])
126126
{
127-
if ($product->getTypeInstance()->hasRequiredOptions($product)) {
127+
if (!$product->getTypeInstance()->isPossibleBuyFromList($product)) {
128128
if (!isset($additional['_escape'])) {
129129
$additional['_escape'] = true;
130130
}

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,4 +1092,15 @@ public function getAssociatedProducts($product)
10921092
{
10931093
return [];
10941094
}
1095+
1096+
/**
1097+
* Check if product can be potentially buyed from the category page or some other list
1098+
*
1099+
* @param \Magento\Catalog\Model\Product $product
1100+
* @return bool
1101+
*/
1102+
public function isPossibleBuyFromList($product)
1103+
{
1104+
return !$this->hasRequiredOptions($product);
1105+
}
10951106
}

app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public function testGetAddToCartPostParams()
154154
];
155155

156156
$this->typeInstanceMock->expects($this->once())
157-
->method('hasRequiredOptions')
157+
->method('isPossibleBuyFromList')
158158
->with($this->equalTo($this->productMock))
159-
->will($this->returnValue(false));
159+
->will($this->returnValue(true));
160160
$this->cartHelperMock->expects($this->any())
161161
->method('getAddUrl')
162162
->with($this->equalTo($this->productMock), $this->equalTo([]))

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ define([
8484
}
8585

8686
if (res.backUrl) {
87+
var eventData = {
88+
'form': form,
89+
'redirectParameters': []
90+
}
91+
// trigger global event, so other modules will be able add parameters to redirect url
92+
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
93+
if (eventData.redirectParameters.length > 0) {
94+
var parameters = res.backUrl.split('#');
95+
parameters.push(eventData.redirectParameters.join('&'));
96+
res.backUrl = parameters.join('#');
97+
}
8798
window.location = res.backUrl;
8899
return;
89100
}

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/Model/Product/Type/Configurable.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,4 +1287,19 @@ private function getCatalogConfig()
12871287
}
12881288
return $this->catalogConfig;
12891289
}
1290+
1291+
/**
1292+
* @inheritdoc
1293+
*/
1294+
public function isPossibleBuyFromList($product)
1295+
{
1296+
$isAllCustomOptionsDisplayed = true;
1297+
foreach ($this->getConfigurableAttributes($product) as $attribute) {
1298+
$eavAttribute = $attribute->getProductAttribute();
1299+
1300+
$isAllCustomOptionsDisplayed = ($isAllCustomOptionsDisplayed && $eavAttribute->getUsedInProductListing());
1301+
}
1302+
1303+
return $isAllCustomOptionsDisplayed;
1304+
}
12901305
}

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')

0 commit comments

Comments
 (0)