Skip to content

Commit afad728

Browse files
author
Alex Akimov
committed
Merge remote-tracking branch 'mainline/develop' into checkout
2 parents fc4a5c3 + 357e3a1 commit afad728

File tree

42 files changed

+1008
-519
lines changed

Some content is hidden

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

42 files changed

+1008
-519
lines changed

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,12 @@ public function getSelectionsByIds($selectionIds, $product)
883883
->addFilterByRequiredOptions()
884884
->setSelectionIdsFilter($selectionIds);
885885

886+
if (count($usedSelections->getItems()) !== count($selectionIds)) {
887+
throw new \Magento\Framework\Exception\LocalizedException(
888+
__('The options you selected are not available.')
889+
);
890+
}
891+
886892
if (!$this->_catalogData->isPriceGlobal() && $storeId) {
887893
$websiteId = $this->_storeManager->getStore($storeId)
888894
->getWebsiteId();

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,8 @@ public function testGetSelectionsByIds()
19001900
'setPositionOrder',
19011901
'addFilterByRequiredOptions',
19021902
'setSelectionIdsFilter',
1903-
'joinPrices'
1903+
'joinPrices',
1904+
'getItems'
19041905
]
19051906
)
19061907
->disableOriginalConstructor()
@@ -1969,6 +1970,10 @@ public function testGetSelectionsByIds()
19691970
->method('setSelectionIdsFilter')
19701971
->with($selectionIds)
19711972
->will($this->returnSelf());
1973+
$usedSelectionsMock->expects($this->once())
1974+
->method('getItems')
1975+
->willReturn($usedSelectionsIds);
1976+
19721977
$usedSelectionsMock->expects($this->once())
19731978
->method('joinPrices')
19741979
->with($websiteId)
@@ -1981,6 +1986,96 @@ public function testGetSelectionsByIds()
19811986
$this->model->getSelectionsByIds($selectionIds, $productMock);
19821987
}
19831988

1989+
/**
1990+
* @expectedException \Magento\Framework\Exception\LocalizedException
1991+
* @expectedExceptionMessage The options you selected are not available.
1992+
*
1993+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1994+
*/
1995+
public function testGetSelectionsByIdsException()
1996+
{
1997+
$selectionIds = [1, 2, 3];
1998+
$usedSelectionsIds = [4, 5];
1999+
$storeId = 2;
2000+
$storeFilter = 'store_filter';
2001+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
2002+
->disableOriginalConstructor()
2003+
->getMock();
2004+
$usedSelectionsMock = $this->getMockBuilder('Magento\Bundle\Model\Resource\Selection\Collection')
2005+
->setMethods(
2006+
[
2007+
'addAttributeToSelect',
2008+
'setFlag',
2009+
'addStoreFilter',
2010+
'setStoreId',
2011+
'setPositionOrder',
2012+
'addFilterByRequiredOptions',
2013+
'setSelectionIdsFilter',
2014+
'joinPrices',
2015+
'getItems'
2016+
]
2017+
)
2018+
->disableOriginalConstructor()
2019+
->getMock();
2020+
$productGetMap = [
2021+
['_cache_instance_used_selections', null, null],
2022+
['_cache_instance_used_selections_ids', null, $usedSelectionsIds],
2023+
['_cache_instance_store_filter', null, $storeFilter],
2024+
];
2025+
$productMock->expects($this->any())
2026+
->method('getData')
2027+
->will($this->returnValueMap($productGetMap));
2028+
$productSetMap = [
2029+
['_cache_instance_used_selections', $usedSelectionsMock, $productMock],
2030+
['_cache_instance_used_selections_ids', $selectionIds, $productMock],
2031+
];
2032+
$productMock->expects($this->any())
2033+
->method('setData')
2034+
->will($this->returnValueMap($productSetMap));
2035+
$productMock->expects($this->once())
2036+
->method('getStoreId')
2037+
->will($this->returnValue($storeId));
2038+
2039+
$this->bundleCollection->expects($this->once())
2040+
->method('create')
2041+
->will($this->returnValue($usedSelectionsMock));
2042+
2043+
$usedSelectionsMock->expects($this->once())
2044+
->method('addAttributeToSelect')
2045+
->with('*')
2046+
->will($this->returnSelf());
2047+
$flagMap = [
2048+
['require_stock_items', true, $usedSelectionsMock],
2049+
['product_children', true, $usedSelectionsMock],
2050+
];
2051+
$usedSelectionsMock->expects($this->any())
2052+
->method('setFlag')
2053+
->will($this->returnValueMap($flagMap));
2054+
$usedSelectionsMock->expects($this->once())
2055+
->method('addStoreFilter')
2056+
->with($storeFilter)
2057+
->will($this->returnSelf());
2058+
$usedSelectionsMock->expects($this->once())
2059+
->method('setStoreId')
2060+
->with($storeId)
2061+
->will($this->returnSelf());
2062+
$usedSelectionsMock->expects($this->once())
2063+
->method('setPositionOrder')
2064+
->will($this->returnSelf());
2065+
$usedSelectionsMock->expects($this->once())
2066+
->method('addFilterByRequiredOptions')
2067+
->will($this->returnSelf());
2068+
$usedSelectionsMock->expects($this->once())
2069+
->method('setSelectionIdsFilter')
2070+
->with($selectionIds)
2071+
->will($this->returnSelf());
2072+
$usedSelectionsMock->expects($this->once())
2073+
->method('getItems')
2074+
->willReturn($usedSelectionsIds);
2075+
2076+
2077+
$this->model->getSelectionsByIds($selectionIds, $productMock);
2078+
}
19842079
/**
19852080
* @return void
19862081
*/

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

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,53 @@
1717
class Url extends \Magento\Framework\DataObject
1818
{
1919
/**
20-
* Static URL instance
20+
* URL instance
2121
*
22-
* @var \Magento\Framework\UrlInterface
22+
* @var \Magento\Framework\UrlFactory
2323
*/
24-
protected $_url;
24+
protected $urlFactory;
2525

2626
/**
2727
* @var \Magento\Framework\Filter\FilterManager
2828
*/
2929
protected $filter;
3030

31-
/**
32-
* Catalog category
33-
*
34-
* @var \Magento\Catalog\Helper\Category
35-
*/
36-
protected $_catalogCategory = null;
37-
3831
/**
3932
* Store manager
4033
*
4134
* @var \Magento\Store\Model\StoreManagerInterface
4235
*/
43-
protected $_storeManager;
36+
protected $storeManager;
4437

4538
/**
4639
* @var \Magento\Framework\Session\SidResolverInterface
4740
*/
48-
protected $_sidResolver;
49-
50-
/** @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator */
51-
protected $productUrlPathGenerator;
41+
protected $sidResolver;
5242

5343
/** @var UrlFinderInterface */
5444
protected $urlFinder;
5545

5646
/**
57-
* @param \Magento\Framework\UrlInterface $url
47+
* @param \Magento\Framework\UrlFactory $urlFactory
5848
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
59-
* @param \Magento\Catalog\Helper\Category $catalogCategory
6049
* @param \Magento\Framework\Filter\FilterManager $filter
6150
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
62-
* @param \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator $productUrlPathGenerator
6351
* @param UrlFinderInterface $urlFinder
6452
* @param array $data
6553
*/
6654
public function __construct(
67-
\Magento\Framework\UrlInterface $url,
55+
\Magento\Framework\UrlFactory $urlFactory,
6856
\Magento\Store\Model\StoreManagerInterface $storeManager,
69-
\Magento\Catalog\Helper\Category $catalogCategory,
7057
\Magento\Framework\Filter\FilterManager $filter,
7158
\Magento\Framework\Session\SidResolverInterface $sidResolver,
72-
\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator $productUrlPathGenerator,
7359
UrlFinderInterface $urlFinder,
7460
array $data = []
7561
) {
7662
parent::__construct($data);
77-
$this->_url = $url;
78-
$this->_storeManager = $storeManager;
79-
$this->_catalogCategory = $catalogCategory;
63+
$this->urlFactory = $urlFactory;
64+
$this->storeManager = $storeManager;
8065
$this->filter = $filter;
81-
$this->_sidResolver = $sidResolver;
82-
$this->productUrlPathGenerator = $productUrlPathGenerator;
66+
$this->sidResolver = $sidResolver;
8367
$this->urlFinder = $urlFinder;
8468
}
8569

@@ -88,23 +72,9 @@ public function __construct(
8872
*
8973
* @return \Magento\Framework\UrlInterface
9074
*/
91-
public function getUrlInstance()
92-
{
93-
return $this->_url;
94-
}
95-
96-
/**
97-
* 'no_selection' shouldn't be a valid image attribute value
98-
*
99-
* @param string $image
100-
* @return string
101-
*/
102-
protected function _validImage($image)
75+
private function getUrlInstance()
10376
{
104-
if ($image == 'no_selection') {
105-
$image = null;
106-
}
107-
return $image;
77+
return $this->urlFactory->create();
10878
}
10979

11080
/**
@@ -130,7 +100,7 @@ public function getUrlInStore(\Magento\Catalog\Model\Product $product, $params =
130100
public function getProductUrl($product, $useSid = null)
131101
{
132102
if ($useSid === null) {
133-
$useSid = $this->_sidResolver->getUseSessionInUrl();
103+
$useSid = $this->sidResolver->getUseSessionInUrl();
134104
}
135105

136106
$params = [];
@@ -167,12 +137,11 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
167137
$routeParams = $params;
168138

169139
$storeId = $product->getStoreId();
170-
if (isset($params['_ignore_category'])) {
171-
unset($params['_ignore_category']);
172-
$categoryId = null;
173-
} else {
174-
$categoryId = $product->getCategoryId() &&
175-
!$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
140+
141+
$categoryId = null;
142+
143+
if (!isset($params['_ignore_category']) && $product->getCategoryId() && !$product->getDoNotUseCategoryId()) {
144+
$categoryId = $product->getCategoryId();
176145
}
177146

178147
if ($product->hasUrlDataObject()) {
@@ -200,10 +169,10 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
200169
}
201170

202171
if (isset($routeParams['_scope'])) {
203-
$storeId = $this->_storeManager->getStore($routeParams['_scope'])->getId();
172+
$storeId = $this->storeManager->getStore($routeParams['_scope'])->getId();
204173
}
205174

206-
if ($storeId != $this->_storeManager->getStore()->getId()) {
175+
if ($storeId != $this->storeManager->getStore()->getId()) {
207176
$routeParams['_scope_to_url'] = true;
208177
}
209178

app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* @method \Magento\Catalog\Model\Resource\Eav\Attribute getFrontendInputRenderer()
2121
* @method string setFrontendInputRenderer(string $value)
2222
* @method int setIsGlobal(int $value)
23-
* @method \Magento\Catalog\Model\Resource\Eav\Attribute getSearchWeight()
23+
* @method int getSearchWeight()
2424
* @method int setSearchWeight(int $value)
25-
* @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsUsedForPriceRules()
25+
* @method bool getIsUsedForPriceRules()
2626
* @method int setIsUsedForPriceRules(int $value)
2727
* @method \Magento\Eav\Api\Data\AttributeExtensionInterface getExtensionAttributes()
2828
*

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ protected function setUp()
5151
'Magento\UrlRewrite\Model\UrlFinderInterface'
5252
)->disableOriginalConstructor()->getMock();
5353

54-
$this->catalogCategory = $this->getMockBuilder(
55-
'Magento\Catalog\Helper\Category'
56-
)->disableOriginalConstructor()->setMethods(
57-
['getCategoryUrlPath']
58-
)->getMock();
59-
6054
$this->url = $this->getMockBuilder(
6155
'Magento\Framework\Url'
6256
)->disableOriginalConstructor()->setMethods(
@@ -70,14 +64,20 @@ protected function setUp()
7064
$storeManager = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface');
7165
$storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
7266

67+
$urlFactory = $this->getMockBuilder('\Magento\Framework\UrlFactory')
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$urlFactory->method('create')
71+
->willReturn($this->url);
72+
7373
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7474
$this->model = $objectManager->getObject(
7575
'Magento\Catalog\Model\Product\Url',
7676
[
7777
'filter' => $this->filter,
7878
'catalogCategory' => $this->catalogCategory,
7979
'storeManager' => $storeManager,
80-
'url' => $this->url,
80+
'urlFactory' => $urlFactory,
8181
'sidResolver' => $this->sidResolver,
8282
]
8383
);

0 commit comments

Comments
 (0)