Skip to content

Commit

Permalink
Showing 2 changed files with 70 additions and 24 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
use Magento\Framework\Api\ImageProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
@@ -219,6 +218,9 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal
if ($editMode) {
$product->setData('_edit_mode', true);
}
if ($storeId !== null) {
$product->setData('store_id', $storeId);
}
$product->load($productId);
$this->instances[$sku][$cacheKey] = $product;
$this->instancesById[$product->getId()][$cacheKey] = $product;
@@ -234,7 +236,6 @@ public function getById($productId, $editMode = false, $storeId = null, $forceRe
$cacheKey = $this->getCacheKey(func_get_args());
if (!isset($this->instancesById[$productId][$cacheKey]) || $forceReload) {
$product = $this->productFactory->create();

if ($editMode) {
$product->setData('_edit_mode', true);
}
89 changes: 67 additions & 22 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ protected function setUp()
'contentFactory' => $this->contentFactoryMock,
'mimeTypeExtensionMap' => $this->mimeTypeExtensionMapMock,
'linkTypeProvider' => $this->linkTypeProviderMock,
'imageProcessor' => $this->imageProcessorMock
'imageProcessor' => $this->imageProcessorMock,
]
);
}
@@ -271,6 +271,19 @@ public function testGetProductInEditMode()
$this->assertEquals($this->productMock, $this->model->get('test_sku', true));
}

public function testGetWithSetStoreId()
{
$productId = 123;
$sku = 'test-sku';
$storeId = 7;
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock);
$this->resourceModelMock->expects($this->once())->method('getIdBySku')->with($sku)->willReturn($productId);
$this->productMock->expects($this->once())->method('setData')->with('store_id', $storeId);
$this->productMock->expects($this->once())->method('load')->with($productId);
$this->productMock->expects($this->once())->method('getId')->willReturn($productId);
$this->assertSame($this->productMock, $this->model->get($sku, false, $storeId));
}

/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedExceptionMessage Requested product doesn't exist
@@ -729,8 +742,8 @@ public function saveExistingWithOptionsDataProvider()
[ //new option value
"title" => "DropdownOptions_3",
"price" => 4,
]
]
],
],
],
[//new option
"type" => "checkbox",
@@ -739,7 +752,7 @@ public function saveExistingWithOptionsDataProvider()
"title" => "CheckBoxValue2",
"price" => 5,
],
]
],
],
];

@@ -819,16 +832,16 @@ public function saveExistingWithOptionsDataProvider()
"price" => 6,
"is_delete" => 1,
],
]
],
],
[
"type" => "checkbox",
"values" => [
[
"title" => "CheckBoxValue2",
"price" => 5,
]
]
],
],
],
[
"option_id" => 11,
@@ -945,32 +958,65 @@ public function saveWithLinksDataProvider()
// Scenario 1
// No existing, new links
$data['scenario_1'] = [
'newLinks' => ["product_sku" => "Simple Product 1", "link_type" => "associated", "linked_product_sku" =>
"Simple Product 2", "linked_product_type" => "simple", "position" => 0, "qty" => 1],
'newLinks' => [
"product_sku" => "Simple Product 1",
"link_type" => "associated",
"linked_product_sku" => "Simple Product 2",
"linked_product_type" => "simple",
"position" => 0,
"qty" => 1,
],
'existingLinks' => [],
'expectedData' => [["product_sku" => "Simple Product 1", "link_type" => "associated", "linked_product_sku" =>
"Simple Product 2", "linked_product_type" => "simple", "position" => 0, "qty" => 1]]
];
'expectedData' => [[
"product_sku" => "Simple Product 1",
"link_type" => "associated",
"linked_product_sku" => "Simple Product 2",
"linked_product_type" => "simple",
"position" => 0,
"qty" => 1,
]],
];

// Scenario 2
// Existing, no new links
$data['scenario_2'] = [
'newLinks' => [],
'existingLinks' => ["product_sku" => "Simple Product 1", "link_type" => "related", "linked_product_sku" =>
"Simple Product 2", "linked_product_type" => "simple", "position" => 0],
'expectedData' => []
'existingLinks' => [
"product_sku" => "Simple Product 1",
"link_type" => "related",
"linked_product_sku" => "Simple Product 2",
"linked_product_type" => "simple",
"position" => 0,
],
'expectedData' => [],
];

// Scenario 3
// Existing and new links
$data['scenario_3'] = [
'newLinks' => ["product_sku" => "Simple Product 1", "link_type" => "related", "linked_product_sku" =>
"Simple Product 2", "linked_product_type" => "simple", "position" => 0],
'existingLinks' => ["product_sku" => "Simple Product 1", "link_type" => "related", "linked_product_sku" =>
"Simple Product 3", "linked_product_type" => "simple", "position" => 0],
'newLinks' => [
"product_sku" => "Simple Product 1",
"link_type" => "related",
"linked_product_sku" => "Simple Product 2",
"linked_product_type" => "simple",
"position" => 0,
],
'existingLinks' => [
"product_sku" => "Simple Product 1",
"link_type" => "related",
"linked_product_sku" => "Simple Product 3",
"linked_product_type" => "simple",
"position" => 0,
],
'expectedData' => [
["product_sku" => "Simple Product 1", "link_type" => "related", "linked_product_sku" =>
"Simple Product 2", "linked_product_type" => "simple", "position" => 0]]
[
"product_sku" => "Simple Product 1",
"link_type" => "related",
"linked_product_sku" => "Simple Product 2",
"linked_product_type" => "simple",
"position" => 0,
],
],
];

return $data;
@@ -1143,7 +1189,6 @@ public function testSaveExistingWithMediaGalleryEntries()
->method('setMediaAttribute')
->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');


$this->model->save($this->productMock);
$this->assertEquals($expectedResult, $this->initializedProductMock->getMediaGallery('images'));
}

0 comments on commit ec3964c

Please sign in to comment.