Skip to content

Commit 6b92366

Browse files
committed
Merge branch '2.1-develop' of https://github.com/magento/magento2ce into MAGETWO-80502-2
2 parents d1a13bf + bbb6f9a commit 6b92366

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
@@ -408,7 +408,7 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
408408
$linksToInitialize = [];
409409
foreach ($linksByType as $link) {
410410
$linkDataArray = $this->extensibleDataObjectConverter
411-
->toNestedArray($link, [], 'Magento\Catalog\Api\Data\ProductLinkInterface');
411+
->toNestedArray($link, [], \Magento\Catalog\Api\Data\ProductLinkInterface::class);
412412
$linkedSku = $link->getLinkedProductSku();
413413
if (!isset($linkedProductIds[$linkedSku])) {
414414
throw new NoSuchEntityException(
@@ -525,7 +525,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
525525
}
526526

527527
$productDataArray = $this->extensibleDataObjectConverter
528-
->toNestedArray($product, [], 'Magento\Catalog\Api\Data\ProductInterface');
528+
->toNestedArray($product, [], \Magento\Catalog\Api\Data\ProductInterface::class);
529529
$productDataArray = array_replace($productDataArray, $product->getData());
530530
$ignoreLinksFlag = $product->getData('ignore_links_flag');
531531
$productLinks = null;
@@ -638,6 +638,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
638638
$collection->setCurPage($searchCriteria->getCurrentPage());
639639
$collection->setPageSize($searchCriteria->getPageSize());
640640
$collection->load();
641+
$collection->addCategoryIds();
641642

642643
$searchResult = $this->searchResultsFactory->create();
643644
$searchResult->setSearchCriteria($searchCriteria);
@@ -724,7 +725,7 @@ private function getMediaGalleryProcessor()
724725
{
725726
if (null === $this->mediaGalleryProcessor) {
726727
$this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
727-
->get('Magento\Catalog\Model\Product\Gallery\Processor');
728+
->get(\Magento\Catalog\Model\Product\Gallery\Processor::class);
728729
}
729730
return $this->mediaGalleryProcessor;
730731
}

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
use Magento\Store\Api\Data\StoreInterface;
@@ -154,6 +158,11 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
154158
*/
155159
private $optionConverterMock;
156160

161+
/**
162+
* @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
163+
*/
164+
private $extensionAttributesJoinProcessor;
165+
157166
/**
158167
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
159168
*/
@@ -323,6 +332,9 @@ protected function setUp()
323332
$this->optionConverterMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Converter::class)
324333
->disableOriginalConstructor()
325334
->getMock();
335+
$this->extensionAttributesJoinProcessor = $this->getMockBuilder(JoinProcessorInterface::class)
336+
->disableOriginalConstructor()
337+
->getMock();
326338

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

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

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

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)