Skip to content

Commit 5923c2b

Browse files
Slabko,Michael(mslabko)Slabko,Michael(mslabko)
authored andcommitted
Merge pull request #184 from magento-goinc/MAGETWO-45453
[GoInc] BugsFixing
2 parents c044a2d + 1553d12 commit 5923c2b

File tree

14 files changed

+35
-172
lines changed

14 files changed

+35
-172
lines changed

app/code/Magento/Catalog/Api/Data/ProductInterface.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ interface ProductInterface extends \Magento\Framework\Api\CustomAttributesDataIn
3535

3636
const UPDATED_AT = 'updated_at';
3737

38-
const STORE_ID = 'store_id';
3938
/**#@-*/
4039

4140
/**
@@ -83,21 +82,6 @@ public function getName();
8382
*/
8483
public function setName($name);
8584

86-
/**
87-
* Product store id
88-
*
89-
* @return int|null
90-
*/
91-
public function getStoreId();
92-
93-
/**
94-
* Set product store id
95-
*
96-
* @param int $storeId
97-
* @return $this
98-
*/
99-
public function setStoreId($storeId);
100-
10185
/**
10286
* Product attribute set id
10387
*

app/code/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,28 @@ interface ProductAttributeMediaGalleryManagementInterface
1919
*
2020
* @param string $sku
2121
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry
22-
* @param int $storeId
2322
* @return int gallery entry ID
2423
* @throws \Magento\Framework\Exception\InputException
2524
* @throws \Magento\Framework\Exception\NoSuchEntityException
2625
* @throws \Magento\Framework\Exception\StateException
2726
*/
2827
public function create(
2928
$sku,
30-
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry,
31-
$storeId = 0
29+
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry
3230
);
3331

3432
/**
3533
* Update gallery entry
3634
*
3735
* @param string $sku
3836
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry
39-
* @param int $storeId
4037
* @return bool
4138
* @throws \Magento\Framework\Exception\NoSuchEntityException
4239
* @throws \Magento\Framework\Exception\StateException
4340
*/
4441
public function update(
4542
$sku,
46-
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry,
47-
$storeId = 0
43+
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry
4844
);
4945

5046
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
5959
*/
6060
const CACHE_PRODUCT_CATEGORY_TAG = 'catalog_category_product';
6161

62+
/**
63+
* Product Store Id
64+
*/
65+
const STORE_ID = 'store_id';
66+
6267
/**
6368
* @var string
6469
*/
@@ -316,7 +321,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
316321
ProductInterface::TYPE_ID,
317322
ProductInterface::CREATED_AT,
318323
ProductInterface::UPDATED_AT,
319-
ProductInterface::STORE_ID,
320324
'media_gallery',
321325
'tier_price',
322326
];

app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
*/
1919
class GalleryManagement implements \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface
2020
{
21-
/**
22-
* @var \Magento\Store\Model\StoreManagerInterface
23-
*/
24-
protected $storeManager;
25-
2621
/**
2722
* @var \Magento\Catalog\Api\ProductRepositoryInterface
2823
*/
@@ -34,19 +29,16 @@ class GalleryManagement implements \Magento\Catalog\Api\ProductAttributeMediaGal
3429
protected $contentValidator;
3530

3631
/**
37-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3832
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3933
* @param ImageContentValidatorInterface $contentValidator
4034
*
4135
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4236
*/
4337
public function __construct(
44-
\Magento\Store\Model\StoreManagerInterface $storeManager,
4538
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
4639
ImageContentValidatorInterface $contentValidator
4740
) {
4841
$this->productRepository = $productRepository;
49-
$this->storeManager = $storeManager;
5042
$this->contentValidator = $contentValidator;
5143
}
5244

@@ -69,13 +61,8 @@ protected function getGalleryAttributeBackend(Product $product)
6961
/**
7062
* {@inheritdoc}
7163
*/
72-
public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry, $storeId = 0)
64+
public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry)
7365
{
74-
try {
75-
$this->storeManager->getStore($storeId);
76-
} catch (\Exception $exception) {
77-
throw new NoSuchEntityException(__('There is no store with provided ID.'));
78-
}
7966
/** @var $entry ProductAttributeMediaGalleryEntryInterface */
8067
$entryContent = $entry->getContent();
8168

@@ -114,13 +101,8 @@ public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry,
114101
/**
115102
* {@inheritdoc}
116103
*/
117-
public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry, $storeId = 0)
104+
public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry)
118105
{
119-
try {
120-
$this->storeManager->getStore($storeId);
121-
} catch (\Exception $exception) {
122-
throw new NoSuchEntityException(__('There is no store with provided ID.'));
123-
}
124106
$product = $this->productRepository->get($sku);
125107
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
126108
if ($existingMediaGalleryEntries == null) {
@@ -138,7 +120,6 @@ public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry,
138120
throw new NoSuchEntityException(__('There is no image with provided ID.'));
139121
}
140122
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
141-
$product->setStoreId($storeId);
142123

143124
try {
144125
$this->productRepository->save($product);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ protected function initializeProductData(array $productData, $createNew)
287287
$product = $this->productFactory->create();
288288
if ($this->storeManager->hasSingleStore()) {
289289
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
290-
} elseif (isset($productData['store_id'])
291-
&& !empty($productData['store_id'])
292-
&& $this->storeManager->getStore($productData['store_id'])
293-
) {
294-
$product->setWebsiteIds([$this->storeManager->getStore($productData['store_id'])->getWebsiteId()]);
295290
}
296291
} else {
297292
unset($this->instances[$productData['sku']]);
@@ -582,6 +577,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
582577
$productLinks = $product->getProductLinks();
583578
}
584579

580+
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
585581
$product = $this->initializeProductData($productDataArray, empty($productId));
586582

587583
if (isset($productDataArray['options'])) {

app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ class GalleryManagementTest extends \PHPUnit_Framework_TestCase
1616
*/
1717
protected $model;
1818

19-
/**
20-
* @var \PHPUnit_Framework_MockObject_MockObject
21-
*/
22-
protected $storeManagerMock;
23-
2419
/**
2520
* @var \PHPUnit_Framework_MockObject_MockObject
2621
*/
@@ -48,7 +43,6 @@ class GalleryManagementTest extends \PHPUnit_Framework_TestCase
4843

4944
protected function setUp()
5045
{
51-
$this->storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface');
5246
$this->productRepositoryMock = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface');
5347
$this->contentValidatorMock = $this->getMock('\Magento\Framework\Api\ImageContentValidatorInterface');
5448
$this->productMock = $this->getMock(
@@ -69,7 +63,6 @@ protected function setUp()
6963
$this->mediaGalleryEntryMock =
7064
$this->getMock('Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
7165
$this->model = new \Magento\Catalog\Model\Product\Gallery\GalleryManagement(
72-
$this->storeManagerMock,
7366
$this->productRepositoryMock,
7467
$this->contentValidatorMock
7568
);
@@ -78,17 +71,6 @@ protected function setUp()
7871
->getMock();
7972
}
8073

81-
/**
82-
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
83-
* @expectedExceptionMessage There is no store with provided ID.
84-
*/
85-
public function testCreateWithNoStoreException()
86-
{
87-
$this->storeManagerMock->expects($this->once())->method('getStore')
88-
->willThrowException(new \Exception());
89-
$this->model->create('sku', $this->mediaGalleryEntryMock);
90-
}
91-
9274
/**
9375
* @expectedException \Magento\Framework\Exception\InputException
9476
* @expectedExceptionMessage The image content is not valid.
@@ -100,13 +82,10 @@ public function testCreateWithInvalidImageException()
10082
->getMock();
10183
$this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock);
10284

103-
$storeId = 0;
104-
105-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
10685
$this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock)
10786
->willReturn(false);
10887

109-
$this->model->create("sku", $this->mediaGalleryEntryMock, $storeId);
88+
$this->model->create("sku", $this->mediaGalleryEntryMock);
11089
}
11190

11291
/**
@@ -120,20 +99,17 @@ public function testCreateWithCannotSaveException()
12099
->disableOriginalConstructor()
121100
->getMock();;
122101
$this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock);
123-
124-
$storeId = 0;
125102
$this->productRepositoryMock->expects($this->once())
126103
->method('get')
127104
->with($productSku)
128105
->willReturn($this->productMock);
129106

130-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
131107
$this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock)
132108
->willReturn(true);
133109

134110
$this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock)
135111
->willThrowException(new \Exception());
136-
$this->model->create($productSku, $this->mediaGalleryEntryMock, $storeId);
112+
$this->model->create($productSku, $this->mediaGalleryEntryMock);
137113
}
138114

139115
public function testCreate()
@@ -144,8 +120,6 @@ public function testCreate()
144120
);
145121
$this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock);
146122

147-
$storeId = 0;
148-
149123
$this->productRepositoryMock->expects($this->once())
150124
->method('get')
151125
->with($productSku)
@@ -155,7 +129,6 @@ public function testCreate()
155129
->with($this->productMock)
156130
->willReturn($this->productMock);
157131

158-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
159132
$this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock)
160133
->willReturn(true);
161134

@@ -166,21 +139,7 @@ public function testCreate()
166139
$this->productMock->expects($this->once())->method('setMediaGalleryEntries')
167140
->with([$this->mediaGalleryEntryMock]);
168141

169-
$this->assertEquals(42, $this->model->create($productSku, $this->mediaGalleryEntryMock, $storeId));
170-
}
171-
172-
/**
173-
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
174-
* @expectedExceptionMessage There is no store with provided ID.
175-
*/
176-
public function testUpdateWithNonExistingStore()
177-
{
178-
$productSku = 'testProduct';
179-
$entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
180-
$storeId = 0;
181-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)
182-
->willThrowException(new \Exception());
183-
$this->model->update($productSku, $entryMock, $storeId);
142+
$this->assertEquals(42, $this->model->create($productSku, $this->mediaGalleryEntryMock));
184143
}
185144

186145
/**
@@ -191,17 +150,15 @@ public function testUpdateWithNonExistingImage()
191150
{
192151
$productSku = 'testProduct';
193152
$entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
194-
$storeId = 0;
195153
$entryId = 42;
196-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
197154
$this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)
198155
->willReturn($this->productMock);
199156
$existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
200157
$existingEntryMock->expects($this->once())->method('getId')->willReturn(43);
201158
$this->productMock->expects($this->once())->method('getMediaGalleryEntries')
202159
->willReturn([$existingEntryMock]);
203160
$entryMock->expects($this->once())->method('getId')->willReturn($entryId);
204-
$this->model->update($productSku, $entryMock, $storeId);
161+
$this->model->update($productSku, $entryMock);
205162
}
206163

207164
/**
@@ -212,29 +169,24 @@ public function testUpdateWithCannotSaveException()
212169
{
213170
$productSku = 'testProduct';
214171
$entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
215-
$storeId = 0;
216172
$entryId = 42;
217-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
218173
$this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)
219174
->willReturn($this->productMock);
220175
$existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
221176
$existingEntryMock->expects($this->once())->method('getId')->willReturn($entryId);
222177
$this->productMock->expects($this->once())->method('getMediaGalleryEntries')
223178
->willReturn([$existingEntryMock]);
224179
$entryMock->expects($this->once())->method('getId')->willReturn($entryId);
225-
$this->productMock->expects($this->once())->method('setStoreId')->with($storeId);
226180
$this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock)
227181
->willThrowException(new \Exception());
228-
$this->model->update($productSku, $entryMock, $storeId);
182+
$this->model->update($productSku, $entryMock);
229183
}
230184

231185
public function testUpdate()
232186
{
233187
$productSku = 'testProduct';
234188
$entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
235-
$storeId = 0;
236189
$entryId = 42;
237-
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
238190
$this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)
239191
->willReturn($this->productMock);
240192
$existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface');
@@ -245,9 +197,8 @@ public function testUpdate()
245197

246198
$this->productMock->expects($this->once())->method('setMediaGalleryEntries')
247199
->willReturn([$entryMock]);
248-
$this->productMock->expects($this->once())->method('setStoreId')->with($storeId);
249200
$this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock);
250-
$this->assertTrue($this->model->update($productSku, $entryMock, $storeId));
201+
$this->assertTrue($this->model->update($productSku, $entryMock));
251202
}
252203

253204
/**

app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setUp()
7171
->getMock();
7272
$this->productRepositoryMock = $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface');
7373
$this->productMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface');
74-
$this->savedProductMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface');
74+
$this->savedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
7575
$this->closureMock = function () {
7676
return $this->savedProductMock;
7777
};

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, ar
220220
&& ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))
221221
) {
222222
$product->setStoreId($storeId);
223-
} elseif (!$product->hasData(\Magento\Catalog\Api\Data\ProductInterface::STORE_ID)) {
223+
} elseif (!$product->hasData(\Magento\Catalog\Model\Product::STORE_ID)) {
224224
$product->setStoreId(Store::DEFAULT_STORE_ID);
225225
}
226226
}

app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function setUp()
6464
$this->linkRepositoryMock = $this->getMock('Magento\Downloadable\Api\LinkRepositoryInterface');
6565
$this->sampleRepositoryMock = $this->getMock('Magento\Downloadable\Api\SampleRepositoryInterface');
6666
$this->productMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface');
67-
$this->savedProductMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface');
67+
$this->savedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
6868
$this->closureMock = function () {
6969
return $this->savedProductMock;
7070
};

0 commit comments

Comments
 (0)