Skip to content

Commit 4128189

Browse files
committed
Merge remote-tracking branch 'origin/develop' into PR-5
2 parents 980ba76 + 4197d0e commit 4128189

File tree

68 files changed

+779
-234
lines changed

Some content is hidden

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

68 files changed

+779
-234
lines changed

app/code/Magento/Backend/Block/Widget/Button/Item.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace Magento\Backend\Block\Widget\Button;
88

99
/**
10-
* @method string getButtonKey
11-
* @method string getRegion
12-
* @method string getName
13-
* @method int getLevel
14-
* @method int getSortOrder
15-
* @method string getTitle
10+
* @method string getButtonKey()
11+
* @method string getRegion()
12+
* @method string getName()
13+
* @method int getLevel()
14+
* @method int getSortOrder()
15+
* @method string getTitle()
1616
*/
1717
class Item extends \Magento\Framework\DataObject
1818
{

app/code/Magento/Backend/Block/Widget/Button/Toolbar/Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\Backend\Block\Widget\Button\ContextInterface;
1010

1111
/**
12-
* @method \Magento\Backend\Block\Widget\Button\Item getButtonItem
13-
* @method ContextInterface getContext
12+
* @method \Magento\Backend\Block\Widget\Button\Item getButtonItem()
13+
* @method ContextInterface getContext()
1414
* @method ContextInterface setContext(ContextInterface $context)
1515
*/
1616
class Container extends \Magento\Framework\View\Element\AbstractBlock

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ public function getTotalBundleItemsPrice($product, $qty = null)
118118
{
119119
$price = 0.0;
120120
if ($product->hasCustomOptions()) {
121-
$customOption = $product->getCustomOption('bundle_selection_ids');
122-
if ($customOption) {
123-
$selectionIds = unserialize($customOption->getValue());
121+
$selectionIds = $this->getBundleSelectionIds($product);
122+
if ($selectionIds) {
124123
$selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds, $product);
125124
$selections->addTierPriceData();
126125
$this->_eventManager->dispatch(
@@ -145,6 +144,24 @@ public function getTotalBundleItemsPrice($product, $qty = null)
145144
return $price;
146145
}
147146

147+
/**
148+
* Retrieve array of bundle selection IDs
149+
*
150+
* @param \Magento\Catalog\Model\Product $product
151+
* @return array
152+
*/
153+
protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
154+
{
155+
$customOption = $product->getCustomOption('bundle_selection_ids');
156+
if ($customOption) {
157+
$selectionIds = unserialize($customOption->getValue());
158+
if (!empty($selectionIds) && is_array($selectionIds)) {
159+
return $selectionIds;
160+
}
161+
}
162+
return [];
163+
}
164+
148165
/**
149166
* Get product final price
150167
*

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

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,121 @@ public function calculateSpecialPrice()
146146
[10, 100, 1, true, 10],
147147
];
148148
}
149+
150+
public function testGetTotalBundleItemsPriceWithNoCustomOptions()
151+
{
152+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
153+
->disableOriginalConstructor()
154+
->getMock();
155+
156+
$productMock->expects($this->once())
157+
->method('hasCustomOptions')
158+
->willReturn(false);
159+
160+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
161+
}
162+
163+
/**
164+
* @param string|null $value
165+
* @dataProvider dataProviderWithEmptyOptions
166+
*/
167+
public function testGetTotalBundleItemsPriceWithEmptyOptions($value)
168+
{
169+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
170+
->setMethods(['getValue'])
171+
->disableOriginalConstructor()
172+
->getMock();
173+
174+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
175+
->disableOriginalConstructor()
176+
->getMock();
177+
178+
$productMock->expects($this->once())
179+
->method('hasCustomOptions')
180+
->willReturn(true);
181+
$productMock->expects($this->once())
182+
->method('getCustomOption')
183+
->with('bundle_selection_ids')
184+
->willReturn($dataObjectMock);
185+
186+
$dataObjectMock->expects($this->once())
187+
->method('getValue')
188+
->willReturn($value);
189+
190+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
191+
}
192+
193+
/**
194+
* @return array
195+
*/
196+
public function dataProviderWithEmptyOptions()
197+
{
198+
return [
199+
['a:0:{}'],
200+
[''],
201+
[null],
202+
];
203+
}
204+
205+
public function testGetTotalBundleItemsPriceWithNoItems()
206+
{
207+
$storeId = 1;
208+
209+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
210+
->setMethods(['getValue'])
211+
->disableOriginalConstructor()
212+
->getMock();
213+
214+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
215+
->disableOriginalConstructor()
216+
->getMock();
217+
218+
$productTypeMock = $this->getMockBuilder('Magento\Bundle\Model\Product\Type')
219+
->disableOriginalConstructor()
220+
->getMock();
221+
222+
$selectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection')
223+
->disableOriginalConstructor()
224+
->getMock();
225+
226+
$productMock->expects($this->once())
227+
->method('hasCustomOptions')
228+
->willReturn(true);
229+
$productMock->expects($this->once())
230+
->method('getCustomOption')
231+
->with('bundle_selection_ids')
232+
->willReturn($dataObjectMock);
233+
$productMock->expects($this->once())
234+
->method('getTypeInstance')
235+
->willReturn($productTypeMock);
236+
$productMock->expects($this->once())
237+
->method('getStoreId')
238+
->willReturn($storeId);
239+
240+
$dataObjectMock->expects($this->once())
241+
->method('getValue')
242+
->willReturn('a:1:{i:0;s:1:"1";}');
243+
244+
$productTypeMock->expects($this->once())
245+
->method('getSelectionsByIds')
246+
->with([1], $productMock)
247+
->willReturn($selectionsMock);
248+
249+
$selectionsMock->expects($this->once())
250+
->method('addTierPriceData')
251+
->willReturnSelf();
252+
$selectionsMock->expects($this->once())
253+
->method('getItems')
254+
->willReturn([]);
255+
256+
$this->eventManagerMock->expects($this->once())
257+
->method('dispatch')
258+
->with(
259+
'prepare_catalog_product_collection_prices',
260+
['collection' => $selectionsMock, 'store_id' => $storeId]
261+
)
262+
->willReturnSelf();
263+
264+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
265+
}
149266
}

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ class Advanced extends Generic
3131
*/
3232
protected $_yesNo;
3333

34+
/**
35+
* @var array
36+
*/
37+
protected $disableScopeChangeList;
38+
3439
/**
3540
* @param \Magento\Backend\Block\Template\Context $context
3641
* @param \Magento\Framework\Registry $registry
3742
* @param \Magento\Framework\Data\FormFactory $formFactory
3843
* @param Yesno $yesNo
3944
* @param Data $eavData
45+
* @param array $disableScopeChangeList
4046
* @param array $data
4147
*/
4248
public function __construct(
@@ -45,10 +51,12 @@ public function __construct(
4551
\Magento\Framework\Data\FormFactory $formFactory,
4652
Yesno $yesNo,
4753
Data $eavData,
54+
array $disableScopeChangeList = ['sku'],
4855
array $data = []
4956
) {
5057
$this->_yesNo = $yesNo;
5158
$this->_eavData = $eavData;
59+
$this->disableScopeChangeList = $disableScopeChangeList;
5260
parent::__construct($context, $registry, $formFactory, $data);
5361
}
5462

@@ -229,7 +237,7 @@ protected function _prepareForm()
229237
);
230238

231239
$this->_eventManager->dispatch('product_attribute_form_build', ['form' => $form]);
232-
if ($attributeObject->getId() && !$attributeObject->getIsUserDefined()) {
240+
if (in_array($attributeObject->getAttributeCode(), $this->disableScopeChangeList)) {
233241
$form->getElement('is_global')->setDisabled(1);
234242
}
235243
$this->setForm($form);

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Product attribute add/edit form options tab
99
*
1010
* @method \Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Options setReadOnly(bool $value)
11-
* @method null|bool getReadOnly
11+
* @method null|bool getReadOnly()
1212
*
1313
* @author Magento Core Team <core@magentocommerce.com>
1414
*/

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Options/Option.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,14 @@ public function getCustomOptionsUrl()
461461
{
462462
return $this->getUrl('catalog/*/customOptions');
463463
}
464+
465+
/**
466+
* Return current product id
467+
*
468+
* @return null|int
469+
*/
470+
public function getCurrentProductId()
471+
{
472+
return $this->getProduct()->getId();
473+
}
464474
}

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Options/Popup/Grid.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ public function _prepareMassaction()
6262
protected function _prepareCollection()
6363
{
6464
parent::_prepareCollection();
65-
$this->getCollection()->addFieldToFilter('has_options', 1);
65+
66+
if (null !== $this->getRequest()->getParam('current_product_id')) {
67+
$this->getCollection()->getSelect()->where(
68+
'e.entity_id != ?',
69+
$this->getRequest()->getParam('current_product_id')
70+
);
71+
}
72+
73+
$this->getCollection()->getSelect()->distinct()->join(
74+
['opt' => $this->getCollection()->getTable('catalog_product_option')],
75+
'opt.product_id = e.entity_id',
76+
null
77+
);
6678

6779
return $this;
6880
}

app/code/Magento/Catalog/Model/CategoryLinkManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ public function __construct(
3636
public function getAssignedProducts($categoryId)
3737
{
3838
$category = $this->categoryRepository->get($categoryId);
39-
$productsPosition = $category->getProductsPosition();
4039

41-
/** @var \Magento\Framework\Data\Collection\AbstractDb $products */
40+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $products */
4241
$products = $category->getProductCollection();
42+
$products->addFieldToSelect('position');
4343

4444
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */
4545
$links = [];
4646

4747
/** @var \Magento\Catalog\Model\Product $product */
48-
foreach ($products->getItems() as $productId => $product) {
48+
foreach ($products->getItems() as $product) {
4949
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface $link */
5050
$link = $this->productLinkFactory->create();
5151
$link->setSku($product->getSku())
52-
->setPosition($productsPosition[$productId])
52+
->setPosition($product->getData('cat_index_position'))
5353
->setCategoryId($category->getId());
5454
$links[] = $link;
5555
}

app/code/Magento/Catalog/Model/Config/Source/Product/Options/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function toOptionArray()
4343
$types[] = ['label' => __($type['label']), 'value' => $type['name']];
4444
}
4545
if (count($types)) {
46-
$groups[] = ['label' => __($option['label']), 'value' => $types];
46+
$groups[] = ['label' => __($option['label']), 'value' => $types, 'optgroup-name' => $option['label']];
4747
}
4848
}
4949

0 commit comments

Comments
 (0)