Skip to content

Commit 46a6f4f

Browse files
author
Sergii Kovalenko
committed
Merge branch '2.2-develop' of https://github.com/magento/magento2ce into MAGETWO-71613
2 parents 71e7238 + 6d61ccd commit 46a6f4f

File tree

67 files changed

+5248
-851
lines changed

Some content is hidden

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

67 files changed

+5248
-851
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
687687
$options
688688
);
689689

690-
$optionsCollection->appendSelections($selections, false, $_appendAllSelections);
690+
$optionsCollection->appendSelections($selections, true, $_appendAllSelections);
691691

692692
$selections = $selections->getItems();
693693
} else {
@@ -704,7 +704,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
704704
->getOptionsIds($product);
705705
$selectionCollection = $product->getTypeInstance()
706706
->getSelectionsCollection($optionIds, $product);
707-
$options = $optionCollection->appendSelections($selectionCollection, false, $_appendAllSelections);
707+
$options = $optionCollection->appendSelections($selectionCollection, true, $_appendAllSelections);
708708

709709
$selections = $this->mergeSelectionsWithOptions($options, $selections);
710710
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public function testPrepareForCartAdvancedWithoutOptions()
249249
->willReturn($productType);
250250
$optionCollection->expects($this->any())
251251
->method('appendSelections')
252+
->with($selectionCollection, true, true)
252253
->willReturn([$option]);
253254
$productType->expects($this->once())
254255
->method('setStoreFilter');
@@ -433,7 +434,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
433434
->method('getItemById')
434435
->willReturn($option);
435436
$optionCollection->expects($this->once())
436-
->method('appendSelections');
437+
->method('appendSelections')
438+
->with($selectionCollection, true, true);
437439
$productType->expects($this->once())
438440
->method('setStoreFilter');
439441
$buyRequest->expects($this->once())
@@ -668,7 +670,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
668670
->method('getItemById')
669671
->willReturn($option);
670672
$optionCollection->expects($this->once())
671-
->method('appendSelections');
673+
->method('appendSelections')
674+
->with($selectionCollection, true, true);
672675
$productType->expects($this->once())
673676
->method('setStoreFilter');
674677
$buyRequest->expects($this->once())
@@ -891,7 +894,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
891894
->method('getItemById')
892895
->willReturn($option);
893896
$optionCollection->expects($this->once())
894-
->method('appendSelections');
897+
->method('appendSelections')
898+
->with($selectionCollection, true, true);
895899
$productType->expects($this->once())
896900
->method('setStoreFilter');
897901
$buyRequest->expects($this->once())
@@ -1169,7 +1173,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
11691173
}
11701174
);
11711175
$optionCollection->expects($this->once())
1172-
->method('appendSelections');
1176+
->method('appendSelections')
1177+
->with($selectionCollection, true, true);
11731178
$productType->expects($this->once())
11741179
->method('setStoreFilter');
11751180
$buyRequest->expects($this->once())

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace Magento\Catalog\Controller\Adminhtml\Product;
88

99
use Magento\Framework\Controller\ResultFactory;
10-
use Magento\Catalog\Controller\Adminhtml\Product\Builder;
1110
use Magento\Backend\App\Action\Context;
1211
use Magento\Ui\Component\MassAction\Filter;
1312
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use Magento\Catalog\Api\ProductRepositoryInterface;
1414

1515
class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product
1616
{
@@ -26,20 +26,29 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product
2626
*/
2727
protected $collectionFactory;
2828

29+
/**
30+
* @var ProductRepositoryInterface
31+
*/
32+
private $productRepository;
33+
2934
/**
3035
* @param Context $context
3136
* @param Builder $productBuilder
3237
* @param Filter $filter
3338
* @param CollectionFactory $collectionFactory
39+
* @param ProductRepositoryInterface $productRepository
3440
*/
3541
public function __construct(
3642
Context $context,
3743
Builder $productBuilder,
3844
Filter $filter,
39-
CollectionFactory $collectionFactory
45+
CollectionFactory $collectionFactory,
46+
ProductRepositoryInterface $productRepository = null
4047
) {
4148
$this->filter = $filter;
4249
$this->collectionFactory = $collectionFactory;
50+
$this->productRepository = $productRepository
51+
?: \Magento\Framework\App\ObjectManager::getInstance()->create(ProductRepositoryInterface::class);
4352
parent::__construct($context, $productBuilder);
4453
}
4554

@@ -50,8 +59,9 @@ public function execute()
5059
{
5160
$collection = $this->filter->getCollection($this->collectionFactory->create());
5261
$productDeleted = 0;
62+
/** @var \Magento\Catalog\Model\Product $product */
5363
foreach ($collection->getItems() as $product) {
54-
$product->delete();
64+
$this->productRepository->delete($product);
5565
$productDeleted++;
5666
}
5767
$this->messageManager->addSuccess(
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Indexer\Product;
8+
9+
use Magento\Framework\Indexer\ActionInterface;
10+
use Magento\Framework\Indexer\IndexerRegistry;
11+
12+
/**
13+
* Reindex all relevant product indexers
14+
*/
15+
class Full implements ActionInterface
16+
{
17+
/**
18+
* @var IndexerRegistry
19+
*/
20+
private $indexerRegistry;
21+
22+
/**
23+
* @var string[]
24+
*/
25+
private $indexerList;
26+
27+
/**
28+
* Initialize dependencies
29+
*
30+
* @param IndexerRegistry $indexerRegistry
31+
* @param string[] $indexerList
32+
*/
33+
public function __construct(
34+
IndexerRegistry $indexerRegistry,
35+
array $indexerList
36+
) {
37+
$this->indexerRegistry = $indexerRegistry;
38+
$this->indexerList = $indexerList;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function executeFull()
45+
{
46+
foreach ($this->indexerList as $indexerName) {
47+
$indexer = $this->indexerRegistry->get($indexerName);
48+
if (!$indexer->isScheduled()) {
49+
$indexer->reindexAll();
50+
}
51+
}
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function executeList(array $ids)
58+
{
59+
if (!empty($ids)) {
60+
foreach ($this->indexerList as $indexerName) {
61+
$indexer = $this->indexerRegistry->get($indexerName);
62+
if (!$indexer->isScheduled()) {
63+
$indexer->reindexList($ids);
64+
}
65+
}
66+
}
67+
}
68+
69+
/**
70+
* {@inheritDoc}
71+
*/
72+
public function executeRow($id)
73+
{
74+
if (!empty($id)) {
75+
foreach ($this->indexerList as $indexerName) {
76+
$indexer = $this->indexerRegistry->get($indexerName);
77+
if (!$indexer->isScheduled()) {
78+
$indexer->reindexRow($id);
79+
}
80+
}
81+
}
82+
}
83+
}

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Pricing\Price\AbstractPrice;
1717
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
1818
use Magento\Framework\Pricing\PriceInfoInterface;
19+
use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface;
1920

2021
/**
2122
* @api
@@ -30,6 +31,7 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
3031

3132
/**
3233
* @var Session
34+
* @deprecated
3335
*/
3436
protected $customerSession;
3537

@@ -57,30 +59,39 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
5759
*/
5860
protected $groupManagement;
5961

62+
/**
63+
* @var CustomerGroupRetrieverInterface
64+
*/
65+
private $customerGroupRetriever;
66+
6067
/**
6168
* @param Product $saleableItem
6269
* @param float $quantity
6370
* @param CalculatorInterface $calculator
6471
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
6572
* @param Session $customerSession
6673
* @param GroupManagementInterface $groupManagement
74+
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
6775
*/
6876
public function __construct(
6977
Product $saleableItem,
7078
$quantity,
7179
CalculatorInterface $calculator,
7280
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
7381
Session $customerSession,
74-
GroupManagementInterface $groupManagement
82+
GroupManagementInterface $groupManagement,
83+
CustomerGroupRetrieverInterface $customerGroupRetriever = null
7584
) {
7685
$quantity = $quantity ?: 1;
7786
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
7887
$this->customerSession = $customerSession;
7988
$this->groupManagement = $groupManagement;
89+
$this->customerGroupRetriever = $customerGroupRetriever
90+
?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomerGroupRetrieverInterface::class);
8091
if ($saleableItem->hasCustomerGroupId()) {
8192
$this->customerGroup = (int) $saleableItem->getCustomerGroupId();
8293
} else {
83-
$this->customerGroup = (int) $this->customerSession->getCustomerGroupId();
94+
$this->customerGroup = (int) $this->customerGroupRetriever->getCustomerGroupId();
8495
}
8596
}
8697

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product;
8+
9+
use Magento\Catalog\Model\Indexer\Product\Full;
10+
use Magento\Framework\Indexer\IndexerInterface;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Framework\Indexer\IndexerRegistry;
13+
14+
class FullTest extends TestCase
15+
{
16+
/**
17+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
18+
*/
19+
private $objectManager;
20+
21+
/**
22+
* @var IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $indexerRegistryMock;
25+
26+
/**
27+
* @var Full
28+
*/
29+
private $full;
30+
31+
public function setUp()
32+
{
33+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34+
$this->indexerRegistryMock = $this->createMock(IndexerRegistry::class);
35+
36+
$this->full = $this->objectManager->getObject(
37+
Full::class,
38+
[
39+
'indexerRegistry' => $this->indexerRegistryMock,
40+
'indexerList' => ['catalog_indexer', 'product_indexer', 'stock_indexer', 'search_indexer']
41+
]
42+
);
43+
}
44+
45+
public function testExecuteFull()
46+
{
47+
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false);
48+
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false);
49+
$indexerMock->expects($this->exactly(4))->method('reindexAll');
50+
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock);
51+
52+
$this->full->executeFull();
53+
}
54+
55+
public function testExecuteList()
56+
{
57+
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false);
58+
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false);
59+
$indexerMock->expects($this->exactly(4))->method('reindexList')->with([1, 2]);
60+
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock);
61+
62+
$this->full->executeList([1, 2]);
63+
}
64+
65+
public function testExecuteRow()
66+
{
67+
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false);
68+
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false);
69+
$indexerMock->expects($this->exactly(4))->method('reindexRow')->with(1);
70+
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock);
71+
72+
$this->full->executeRow(1);
73+
}
74+
}

0 commit comments

Comments
 (0)