Skip to content

Commit 3db86df

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-44270-fatal-memory-allocation
2 parents bc2818b + e7105f2 commit 3db86df

File tree

8 files changed

+285
-106
lines changed

8 files changed

+285
-106
lines changed

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/radio.phtml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
<?php if ($block->showSingle()): ?>
2323
<?php /* @escapeNotVerified */ echo $block->getSelectionTitlePrice($_selections[0]) ?>
2424
<input type="hidden"
25-
class="bundle-option-<?php /* @escapeNotVerified */ echo $_option->getId() ?> product bundle option"
26-
name="bundle_option[<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
27-
value="<?php /* @escapeNotVerified */ echo $_selections[0]->getSelectionId() ?>" />
25+
class="bundle-option-<?php echo (int)$_option->getId() ?> product bundle option"
26+
name="bundle_option[<?php echo (int)$_option->getId() ?>]"
27+
value="<?php echo (int)$_selections[0]->getSelectionId() ?>"
28+
id="bundle-option-<?php echo (int)$_option->getId() ?>-<?php echo (int)$_selections[0]->getSelectionId() ?>"
29+
checked="checked"
30+
/>
2831
<?php else:?>
2932
<?php if (!$_option->getRequired()): ?>
3033
<div class="field choice">

app/code/Magento/Catalog/Model/Product/Link.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class Link extends \Magento\Framework\Model\AbstractModel
4949
*/
5050
protected $_linkCollectionFactory;
5151

52-
/**
53-
* @var \Magento\CatalogInventory\Helper\Stock
54-
*/
55-
protected $stockHelper;
56-
5752
/**
5853
* @var \Magento\Catalog\Model\Product\Link\SaveHandler
5954
*/
@@ -64,7 +59,6 @@ class Link extends \Magento\Framework\Model\AbstractModel
6459
* @param \Magento\Framework\Registry $registry
6560
* @param \Magento\Catalog\Model\ResourceModel\Product\Link\CollectionFactory $linkCollectionFactory
6661
* @param \Magento\Catalog\Model\ResourceModel\Product\Link\Product\CollectionFactory $productCollectionFactory
67-
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
6862
* @param \Magento\Catalog\Model\Product\Link\SaveHandler $saveProductLinks
6963
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
7064
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
@@ -75,15 +69,13 @@ public function __construct(
7569
\Magento\Framework\Registry $registry,
7670
\Magento\Catalog\Model\ResourceModel\Product\Link\CollectionFactory $linkCollectionFactory,
7771
\Magento\Catalog\Model\ResourceModel\Product\Link\Product\CollectionFactory $productCollectionFactory,
78-
\Magento\CatalogInventory\Helper\Stock $stockHelper,
7972
\Magento\Catalog\Model\Product\Link\SaveHandler $saveProductLinks,
8073
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
8174
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
8275
array $data = []
8376
) {
8477
$this->_linkCollectionFactory = $linkCollectionFactory;
8578
$this->_productCollectionFactory = $productCollectionFactory;
86-
$this->stockHelper = $stockHelper;
8779
$this->saveProductLinks = $saveProductLinks;
8880
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
8981
}
@@ -144,7 +136,6 @@ public function getAttributeTypeTable($type)
144136
public function getProductCollection()
145137
{
146138
$collection = $this->_productCollectionFactory->create()->setLinkModel($this);
147-
$this->stockHelper->addInStockFilterToCollection($collection);
148139
return $collection;
149140
}
150141

app/code/Magento/Catalog/Test/Unit/Model/Product/LinkTest.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase
2020
protected $resource;
2121

2222
/**
23-
* @var \Magento\CatalogInventory\Helper\Stock|\PHPUnit_Framework_MockObject_MockObject
23+
* @var \Magento\Catalog\Model\Product\Link\SaveHandler|\PHPUnit_Framework_MockObject_MockObject
2424
*/
25-
protected $stockHelperMock;
25+
protected $saveProductLinksMock;
2626

2727
/**
2828
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -73,7 +73,7 @@ protected function setUp()
7373
]
7474
);
7575

76-
$this->stockHelperMock = $this->getMockBuilder('Magento\CatalogInventory\Helper\Stock')
76+
$this->saveProductLinksMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Link\SaveHandler')
7777
->disableOriginalConstructor()
7878
->getMock();
7979

@@ -84,7 +84,7 @@ protected function setUp()
8484
'linkCollectionFactory' => $linkCollectionFactory,
8585
'productCollectionFactory' => $productCollectionFactory,
8686
'resource' => $this->resource,
87-
'stockHelper' => $this->stockHelperMock
87+
'saveProductLinks' => $this->saveProductLinksMock
8888
]
8989
);
9090
}
@@ -127,10 +127,6 @@ public function testGetAttributeTypeTable()
127127

128128
public function testGetProductCollection()
129129
{
130-
$this->stockHelperMock
131-
->expects($this->once())
132-
->method('addInStockFilterToCollection')
133-
->with($this->productCollection);
134130
$this->assertInstanceOf(
135131
'Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection',
136132
$this->model->getProductCollection()
@@ -159,23 +155,13 @@ public function testGetAttributes()
159155

160156
public function testSaveProductRelations()
161157
{
162-
$data = [1];
163-
$typeId = 1;
164-
$this->model->setData('link_type_id', $typeId);
165-
$product = $this->getMockBuilder(
166-
'Magento\Catalog\Model\Product'
167-
)->disableOriginalConstructor()->setMethods(
168-
['getRelatedLinkData', 'getUpSellLinkData', 'getCrossSellLinkData', '__wakeup']
169-
)->getMock();
170-
$product->expects($this->any())->method('getRelatedLinkData')->will($this->returnValue($data));
171-
$product->expects($this->any())->method('getUpSellLinkData')->will($this->returnValue($data));
172-
$product->expects($this->any())->method('getCrossSellLinkData')->will($this->returnValue($data));
173-
$map = [
174-
[$product, $data, Link::LINK_TYPE_RELATED, $this->resource],
175-
[$product, $data, Link::LINK_TYPE_UPSELL, $this->resource],
176-
[$product, $data, Link::LINK_TYPE_CROSSSELL, $this->resource],
177-
];
178-
$this->resource->expects($this->any())->method('saveProductLinks')->will($this->returnValueMap($map));
158+
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
159+
->disableOriginalConstructor()
160+
->getMock();
161+
$this->saveProductLinksMock
162+
->expects($this->once())
163+
->method('execute')
164+
->with(\Magento\Catalog\Api\Data\ProductInterface::class, $product);
179165
$this->model->saveProductRelations($product);
180166
}
181167
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: akasian
5+
* Date: 11/17/15
6+
* Time: 12:29 PM
7+
*/
8+
9+
namespace Magento\CatalogInventory\Model\Plugin;
10+
11+
use Magento\Catalog\Model\Product\Link;
12+
use Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection;
13+
use Magento\CatalogInventory\Helper\Stock;
14+
use Magento\CatalogInventory\Model\Configuration;
15+
16+
class ProductLinks
17+
{
18+
/**
19+
* @var Configuration
20+
*/
21+
private $configuration;
22+
23+
/**
24+
* @var Stock
25+
*/
26+
private $stockHelper;
27+
28+
/**
29+
* ProductLinks constructor.
30+
*
31+
* @param Configuration $configuration
32+
* @param Stock $stockHelper
33+
*/
34+
public function __construct(Configuration $configuration, Stock $stockHelper)
35+
{
36+
$this->configuration = $configuration;
37+
$this->stockHelper = $stockHelper;
38+
}
39+
40+
/**
41+
* @param Link $subject
42+
* @param Collection $collection
43+
* @return Collection
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterGetProductCollection(Link $subject, Collection $collection)
47+
{
48+
if ($this->configuration->isShowOutOfStock() != 1) {
49+
$this->stockHelper->addInStockFilterToCollection($collection);
50+
}
51+
return $collection;
52+
}
53+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Test\Unit\Model\Plugin;
7+
8+
class ProductLinksTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\CatalogInventory\Model\Plugin\ProductLinks
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \Magento\CatalogInventory\Model\Configuration|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $configMock;
19+
20+
/**
21+
* @var \Magento\CatalogInventory\Helper\Stock|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $stockHelperMock;
24+
25+
public function setUp()
26+
{
27+
$this->configMock = $this->getMock(
28+
'Magento\CatalogInventory\Model\Configuration',
29+
[],
30+
[],
31+
'',
32+
false
33+
);
34+
$this->stockHelperMock = $this->getMock(
35+
'\Magento\CatalogInventory\Helper\Stock',
36+
[],
37+
[],
38+
'',
39+
false
40+
);
41+
42+
$this->model = new \Magento\CatalogInventory\Model\Plugin\ProductLinks(
43+
$this->configMock,
44+
$this->stockHelperMock
45+
);
46+
}
47+
48+
/**
49+
* @dataProvider stockStatusDataProvider
50+
*/
51+
public function testAfterGetProductCollectionShow($status, $callCount)
52+
{
53+
list($collectionMock, $subjectMock) = $this->buildMocks();
54+
$this->configMock->expects($this->once())->method('isShowOutOfStock')->will($this->returnValue($status));
55+
$this->stockHelperMock
56+
->expects($this->exactly($callCount))
57+
->method('addInStockFilterToCollection')
58+
->with($collectionMock);
59+
60+
61+
$this->assertEquals($collectionMock, $this->model->afterGetProductCollection($subjectMock, $collectionMock));
62+
}
63+
64+
private function buildMocks()
65+
{
66+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection $collectionMock */
67+
$collectionMock = $this->getMock(
68+
'Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection',
69+
[],
70+
[],
71+
'',
72+
false
73+
);
74+
75+
/** @var \Magento\Catalog\Model\Product\Link $subjectMock */
76+
$subjectMock = $this->getMock('Magento\Catalog\Model\Product\Link', [], [], '', false);
77+
return [$collectionMock, $subjectMock];
78+
}
79+
80+
/**
81+
* @return array
82+
*/
83+
public function stockStatusDataProvider()
84+
{
85+
return [
86+
[0, 1],
87+
[1, 0],
88+
];
89+
}
90+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Catalog\Model\Product\Link">
10+
<plugin name="isInStockFilter" type="Magento\CatalogInventory\Model\Plugin\ProductLinks" />
11+
</type>
12+
</config>

0 commit comments

Comments
 (0)