Skip to content

Commit bbb6f9a

Browse files
author
Alexander Akimov
authored
Merge pull request #2074 from magento-tsg/2.1-develop-pr45
[TSG] Backporting for 2.1 (pr45) (2.1.13)
2 parents c1b7710 + d90888d commit bbb6f9a

File tree

21 files changed

+822
-376
lines changed

21 files changed

+822
-376
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
401401
$linksToInitialize = [];
402402
foreach ($linksByType as $link) {
403403
$linkDataArray = $this->extensibleDataObjectConverter
404-
->toNestedArray($link, [], 'Magento\Catalog\Api\Data\ProductLinkInterface');
404+
->toNestedArray($link, [], \Magento\Catalog\Api\Data\ProductLinkInterface::class);
405405
$linkedSku = $link->getLinkedProductSku();
406406
if (!isset($linkedProductIds[$linkedSku])) {
407407
throw new NoSuchEntityException(
@@ -518,7 +518,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
518518
}
519519

520520
$productDataArray = $this->extensibleDataObjectConverter
521-
->toNestedArray($product, [], 'Magento\Catalog\Api\Data\ProductInterface');
521+
->toNestedArray($product, [], \Magento\Catalog\Api\Data\ProductInterface::class);
522522
$productDataArray = array_replace($productDataArray, $product->getData());
523523
$ignoreLinksFlag = $product->getData('ignore_links_flag');
524524
$productLinks = null;
@@ -631,6 +631,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
631631
$collection->setCurPage($searchCriteria->getCurrentPage());
632632
$collection->setPageSize($searchCriteria->getPageSize());
633633
$collection->load();
634+
$collection->addCategoryIds();
634635

635636
$searchResult = $this->searchResultsFactory->create();
636637
$searchResult->setSearchCriteria($searchCriteria);
@@ -717,7 +718,7 @@ private function getMediaGalleryProcessor()
717718
{
718719
if (null === $this->mediaGalleryProcessor) {
719720
$this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
720-
->get('Magento\Catalog\Model\Product\Gallery\Processor');
721+
->get(\Magento\Catalog\Model\Product\Gallery\Processor::class);
721722
}
722723
return $this->mediaGalleryProcessor;
723724
}

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 95 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
namespace Magento\Catalog\Test\Unit\Model;
1111

12+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
13+
use Magento\Catalog\Api\Data\ProductAttributeSearchResultsInterface;
14+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1215
use Magento\Framework\Api\Data\ImageContentInterface;
16+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1317
use Magento\Framework\Api\SortOrder;
1418
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1519

@@ -153,6 +157,11 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
153157
*/
154158
private $optionConverterMock;
155159

160+
/**
161+
* @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
162+
*/
163+
private $extensionAttributesJoinProcessor;
164+
156165
/**
157166
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
158167
*/
@@ -322,6 +331,9 @@ protected function setUp()
322331
$this->optionConverterMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Converter::class)
323332
->disableOriginalConstructor()
324333
->getMock();
334+
$this->extensionAttributesJoinProcessor = $this->getMockBuilder(JoinProcessorInterface::class)
335+
->disableOriginalConstructor()
336+
->getMock();
325337

326338
$this->model = $this->objectManager->getObject(
327339
\Magento\Catalog\Model\ProductRepository::class,
@@ -347,6 +359,7 @@ protected function setUp()
347359
'imageProcessor' => $this->imageProcessorMock,
348360
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
349361
'mediaGalleryProcessor' => $this->mediaGalleryProcessor,
362+
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessor,
350363
]
351364
);
352365
}
@@ -671,85 +684,95 @@ public function testDeleteById()
671684
*/
672685
public function testGetList($fieldName)
673686
{
674-
$searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteriaInterface::class, [], [], '', false);
675687
$attributeCode = 'attribute_code';
676-
$collectionMock = $this->getMock(
677-
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
678-
[],
679-
[],
680-
'',
681-
false
682-
);
683-
$extendedSearchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
684-
$productAttributeSearchResultsMock = $this->getMock(
685-
\Magento\Framework\Api\SearchResults::class,
686-
[],
687-
[],
688-
'',
689-
false
690-
);
691-
$productAttributeMock = $this->getMock(
692-
\Magento\Catalog\Api\Data\ProductAttributeInterface::class,
693-
[],
694-
[],
695-
'',
696-
false
697-
);
698-
$filterGroupMock = $this->getMock(\Magento\Framework\Api\Search\FilterGroup::class, [], [], '', false);
699-
$filterGroupFilterMock = $this->getMock(\Magento\Framework\Api\Filter::class, [], [], '', false);
700-
$sortOrderMock = $this->getMock(\Magento\Framework\Api\SortOrder::class, [], [], '', false);
701-
$itemsMock = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false);
702688

703-
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
704-
$this->searchCriteriaBuilderMock
705-
->expects($this->once())
706-
->method('create')
707-
->willReturn($extendedSearchCriteriaMock);
708-
$this->metadataServiceMock
709-
->expects($this->once())
710-
->method('getList')
711-
->with($extendedSearchCriteriaMock)
712-
->willReturn($productAttributeSearchResultsMock);
713-
$productAttributeSearchResultsMock->expects($this->once())
714-
->method('getItems')
715-
->willReturn([$productAttributeMock]);
716-
$productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
717-
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with($attributeCode);
718-
$collectionMock->expects($this->exactly(2))
719-
->method('joinAttribute')
689+
$filterGroupFilterMock = $this->getMockBuilder(\Magento\Framework\Api\Filter::class)
690+
->disableOriginalConstructor()
691+
->getMock();
692+
$filterGroupFilterMock->expects(self::exactly(2))->method('getConditionType')->willReturn('eq');
693+
$filterGroupFilterMock->expects(self::atLeastOnce())->method('getField')->willReturn($fieldName);
694+
$filterGroupFilterMock->expects(self::once())->method('getValue')->willReturn('value');
695+
696+
$filterGroupMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class)
697+
->disableOriginalConstructor()
698+
->getMock();
699+
$filterGroupMock->expects(self::once())->method('getFilters')->willReturn([$filterGroupFilterMock]);
700+
701+
$sortOrderMock = $this->getMockBuilder(\Magento\Framework\Api\SortOrder::class)
702+
->disableOriginalConstructor()
703+
->getMock();
704+
$sortOrderMock->expects(self::atLeastOnce())->method('getField')->willReturn($fieldName);
705+
$sortOrderMock->expects(self::once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);
706+
707+
/** @var \Magento\Framework\Api\SearchCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
708+
$searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class)
709+
->disableOriginalConstructor()
710+
->getMock();
711+
$searchCriteriaMock->expects(self::once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
712+
$searchCriteriaMock->expects(self::once())->method('getCurrentPage')->willReturn(4);
713+
$searchCriteriaMock->expects(self::once())->method('getPageSize')->willReturn(42);
714+
$searchCriteriaMock->expects(self::once())->method('getSortOrders')->willReturn([$sortOrderMock]);
715+
716+
$itemsMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
717+
->disableOriginalConstructor()
718+
->getMock();
719+
720+
$collectionMock = $this->getMockBuilder(Collection::class)
721+
->disableOriginalConstructor()
722+
->getMock();
723+
$collectionMock->expects(self::once())->method('addAttributeToSelect')->with($attributeCode);
724+
$collectionMock->expects(self::once())->method('setPageSize')->with(42);
725+
$collectionMock->expects(self::once())->method('load');
726+
$collectionMock->expects(self::once())->method('addCategoryIds');
727+
$collectionMock->expects(self::once())->method('getItems')->willReturn([$itemsMock]);
728+
$collectionMock->expects(self::once())->method('getSize')->willReturn(128);
729+
$collectionMock->expects(self::once())->method('addOrder')->with($fieldName, 'ASC');
730+
$collectionMock->expects(self::once())->method('setCurPage')->with(4);
731+
$collectionMock->expects(self::exactly(2))->method('joinAttribute')
720732
->withConsecutive(
721733
['status', 'catalog_product/status', 'entity_id', null, 'inner'],
722734
['visibility', 'catalog_product/visibility', 'entity_id', null, 'inner']
723-
);
724-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
725-
$filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterGroupFilterMock]);
726-
$filterGroupFilterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('eq');
727-
$filterGroupFilterMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
728-
$filterGroupFilterMock->expects($this->once())->method('getValue')->willReturn('value');
735+
);
736+
737+
$productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
738+
->disableOriginalConstructor()
739+
->getMock();
740+
$productAttributeMock->expects(self::once())->method('getAttributeCode')->willReturn($attributeCode);
741+
742+
$extendedSearchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class)
743+
->disableOriginalConstructor()
744+
->getMock();
745+
746+
$productAttributeSearchResultsMock = $this->getMockBuilder(ProductAttributeSearchResultsInterface::class)
747+
->disableOriginalConstructor()
748+
->setMethods(['getItems'])
749+
->getMockForAbstractClass();
750+
$productAttributeSearchResultsMock->expects(self::once())->method('getItems')
751+
->willReturn([$productAttributeMock]);
752+
753+
$this->collectionFactoryMock->expects(self::once())
754+
->method('create')
755+
->willReturn($collectionMock);
756+
757+
$this->extensionAttributesJoinProcessor->expects(self::once())
758+
->method('process')
759+
->with($collectionMock);
760+
761+
$this->metadataServiceMock->expects(self::once())->method('getList')->with($extendedSearchCriteriaMock)
762+
->willReturn($productAttributeSearchResultsMock);
763+
764+
$this->searchCriteriaBuilderMock->expects(self::once())->method('create')
765+
->willReturn($extendedSearchCriteriaMock);
766+
729767
$this->expectAddToFilter($fieldName, $collectionMock);
730-
$searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]);
731-
$sortOrderMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
732-
$sortOrderMock->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);
733-
$collectionMock->expects($this->once())->method('addOrder')->with($fieldName, 'ASC');
734-
$searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4);
735-
$collectionMock->expects($this->once())->method('setCurPage')->with(4);
736-
$searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn(42);
737-
$collectionMock->expects($this->once())->method('setPageSize')->with(42);
738-
$collectionMock->expects($this->once())->method('load');
739-
$collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]);
740-
$collectionMock->expects($this->once())->method('getSize')->willReturn(128);
741-
$searchResultsMock = $this->getMock(
742-
\Magento\Catalog\Api\Data\ProductSearchResultsInterface::class,
743-
[],
744-
[],
745-
'',
746-
false
747-
);
748-
$searchResultsMock->expects($this->once())->method('setSearchCriteria')->with($searchCriteriaMock);
749-
$searchResultsMock->expects($this->once())->method('setItems')->with([$itemsMock]);
750-
$searchResultsMock->expects($this->once())->method('setTotalCount')->with(128);
751-
$this->searchResultsFactoryMock->expects($this->once())->method('create')->willReturn($searchResultsMock);
752768

769+
$searchResultsMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductSearchResultsInterface::class)
770+
->disableOriginalConstructor()
771+
->getMock();
772+
$searchResultsMock->expects(self::once())->method('setSearchCriteria')->with($searchCriteriaMock);
773+
$searchResultsMock->expects(self::once())->method('setItems')->with([$itemsMock]);
774+
775+
$this->searchResultsFactoryMock->expects($this->once())->method('create')->willReturn($searchResultsMock);
753776
$this->assertEquals($searchResultsMock, $this->model->getList($searchCriteriaMock));
754777
}
755778

app/code/Magento/Catalog/view/adminhtml/web/catalog/product.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,27 @@ require([
2222
}
2323

2424
function disableFieldEditMode(fieldId) {
25-
byId(fieldId).prop('disabled', true);
25+
var field = byId(fieldId);
26+
27+
field.prop('disabled', true);
28+
29+
if (field.next().hasClass('addafter')) {
30+
field.parent().addClass('_update-attributes-disabled');
31+
}
2632

2733
if (byId(fieldId + '_hidden').length) {
2834
byId(fieldId + '_hidden').prop('disabled', true);
2935
}
3036
}
3137

3238
function enableFieldEditMode(fieldId) {
33-
byId(fieldId).prop('disabled', false);
39+
var field = byId(fieldId);
40+
41+
field.prop('disabled', false);
42+
43+
if (field.parent().hasClass('_update-attributes-disabled')) {
44+
field.parent().removeClass('_update-attributes-disabled');
45+
}
3446

3547
if (byId(fieldId + '_hidden').length) {
3648
byId(fieldId + '_hidden').prop('disabled', false);

app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,32 @@ class Save extends \Magento\Backend\App\Action
3535
*/
3636
private $pageFactory;
3737

38+
/**
39+
* @var \Magento\Cms\Api\PageRepositoryInterface
40+
*/
41+
private $pageRepository;
42+
3843
/**
3944
* @param Action\Context $context
4045
* @param PostDataProcessor $dataProcessor
4146
* @param DataPersistorInterface $dataPersistor
4247
* @param \Magento\Cms\Model\PageFactory $pageFactory
48+
* @param \Magento\Cms\Api\PageRepositoryInterface $pageRepository
4349
*/
4450
public function __construct(
4551
Action\Context $context,
4652
PostDataProcessor $dataProcessor,
4753
DataPersistorInterface $dataPersistor,
48-
\Magento\Cms\Model\PageFactory $pageFactory = null
54+
\Magento\Cms\Model\PageFactory $pageFactory = null,
55+
\Magento\Cms\Api\PageRepositoryInterface $pageRepository = null
4956
) {
5057
$this->dataProcessor = $dataProcessor;
5158
$this->dataPersistor = $dataPersistor;
5259
$this->pageFactory = $pageFactory
5360
?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Cms\Model\PageFactory::class);
61+
$this->pageRepository = $pageRepository
62+
?: \Magento\Framework\App\ObjectManager::getInstance()
63+
->get(\Magento\Cms\Api\PageRepositoryInterface::class);
5464

5565
parent::__construct($context);
5666
}
@@ -102,7 +112,7 @@ public function execute()
102112
}
103113

104114
try {
105-
$model->save();
115+
$this->pageRepository->save($model);
106116
$this->messageManager->addSuccess(__('You saved the page.'));
107117
$this->dataPersistor->clear('cms_page');
108118
if ($this->getRequest()->getParam('back')) {

0 commit comments

Comments
 (0)