From 3701659856dfd325e6ca7a0be10bea72e946bbc0 Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Fri, 13 Nov 2015 18:38:50 +0200 Subject: [PATCH 1/4] MAGETWO-45453: Product API does not work properly for non-default store code --- .../Catalog/Api/Data/ProductInterface.php | 16 ----- ...tributeMediaGalleryManagementInterface.php | 8 +-- app/code/Magento/Catalog/Model/Product.php | 6 +- .../Product/Gallery/GalleryManagement.php | 23 +------ .../Catalog/Model/ProductRepository.php | 6 +- .../Product/Gallery/GalleryManagementTest.php | 61 ++---------------- .../AroundProductRepositorySaveTest.php | 2 +- .../Observer/AfterImportDataObserver.php | 2 +- .../AroundProductRepositorySaveTest.php | 2 +- ...uteMediaGalleryManagementInterfaceTest.php | 64 ++----------------- .../Api/ConfigurableProductManagementTest.php | 1 - .../Catalog/Model/AbstractModel/Stub.php | 4 +- 12 files changed, 26 insertions(+), 169 deletions(-) diff --git a/app/code/Magento/Catalog/Api/Data/ProductInterface.php b/app/code/Magento/Catalog/Api/Data/ProductInterface.php index cdf7f2f208734..b0102639b5cd6 100644 --- a/app/code/Magento/Catalog/Api/Data/ProductInterface.php +++ b/app/code/Magento/Catalog/Api/Data/ProductInterface.php @@ -35,7 +35,6 @@ interface ProductInterface extends \Magento\Framework\Api\CustomAttributesDataIn const UPDATED_AT = 'updated_at'; - const STORE_ID = 'store_id'; /**#@-*/ /** @@ -83,21 +82,6 @@ public function getName(); */ public function setName($name); - /** - * Product store id - * - * @return int|null - */ - public function getStoreId(); - - /** - * Set product store id - * - * @param int $storeId - * @return $this - */ - public function setStoreId($storeId); - /** * Product attribute set id * diff --git a/app/code/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php b/app/code/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php index 5dd3602624138..1f6f62bada0f9 100644 --- a/app/code/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php +++ b/app/code/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php @@ -19,7 +19,6 @@ interface ProductAttributeMediaGalleryManagementInterface * * @param string $sku * @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry - * @param int $storeId * @return int gallery entry ID * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\NoSuchEntityException @@ -27,8 +26,7 @@ interface ProductAttributeMediaGalleryManagementInterface */ public function create( $sku, - \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry, - $storeId = 0 + \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry ); /** @@ -36,15 +34,13 @@ public function create( * * @param string $sku * @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry - * @param int $storeId * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException */ public function update( $sku, - \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry, - $storeId = 0 + \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry ); /** diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index b7277d9834a9a..82547d5c9e028 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -59,6 +59,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements */ const CACHE_PRODUCT_CATEGORY_TAG = 'catalog_category_product'; + /** + * Product Store Id + */ + const STORE_ID = 'store_id'; + /** * @var string */ @@ -316,7 +321,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements ProductInterface::TYPE_ID, ProductInterface::CREATED_AT, ProductInterface::UPDATED_AT, - ProductInterface::STORE_ID, 'media_gallery', 'tier_price', ]; diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php index 1d3b5fb26b1ff..7c2a1575b3872 100644 --- a/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php +++ b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php @@ -18,11 +18,6 @@ */ class GalleryManagement implements \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface { - /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - protected $storeManager; - /** * @var \Magento\Catalog\Api\ProductRepositoryInterface */ @@ -34,19 +29,16 @@ class GalleryManagement implements \Magento\Catalog\Api\ProductAttributeMediaGal protected $contentValidator; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository * @param ImageContentValidatorInterface $contentValidator * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, ImageContentValidatorInterface $contentValidator ) { $this->productRepository = $productRepository; - $this->storeManager = $storeManager; $this->contentValidator = $contentValidator; } @@ -69,13 +61,8 @@ protected function getGalleryAttributeBackend(Product $product) /** * {@inheritdoc} */ - public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry, $storeId = 0) + public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry) { - try { - $this->storeManager->getStore($storeId); - } catch (\Exception $exception) { - throw new NoSuchEntityException(__('There is no store with provided ID.')); - } /** @var $entry ProductAttributeMediaGalleryEntryInterface */ $entryContent = $entry->getContent(); @@ -114,13 +101,8 @@ public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry, /** * {@inheritdoc} */ - public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry, $storeId = 0) + public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry) { - try { - $this->storeManager->getStore($storeId); - } catch (\Exception $exception) { - throw new NoSuchEntityException(__('There is no store with provided ID.')); - } $product = $this->productRepository->get($sku); $existingMediaGalleryEntries = $product->getMediaGalleryEntries(); if ($existingMediaGalleryEntries == null) { @@ -138,7 +120,6 @@ public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry, throw new NoSuchEntityException(__('There is no image with provided ID.')); } $product->setMediaGalleryEntries($existingMediaGalleryEntries); - $product->setStoreId($storeId); try { $this->productRepository->save($product); diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index a1842dcf216f6..2016123483bd9 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -287,11 +287,6 @@ protected function initializeProductData(array $productData, $createNew) $product = $this->productFactory->create(); if ($this->storeManager->hasSingleStore()) { $product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]); - } elseif (isset($productData['store_id']) - && !empty($productData['store_id']) - && $this->storeManager->getStore($productData['store_id']) - ) { - $product->setWebsiteIds([$this->storeManager->getStore($productData['store_id'])->getWebsiteId()]); } } else { unset($this->instances[$productData['sku']]); @@ -582,6 +577,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO $productLinks = $product->getProductLinks(); } + $productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId(); $product = $this->initializeProductData($productDataArray, empty($productId)); if (isset($productDataArray['options'])) { diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php index af4af37aa5a4d..d5189204eac98 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php @@ -16,11 +16,6 @@ class GalleryManagementTest extends \PHPUnit_Framework_TestCase */ protected $model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $storeManagerMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -48,7 +43,6 @@ class GalleryManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface'); $this->productRepositoryMock = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface'); $this->contentValidatorMock = $this->getMock('\Magento\Framework\Api\ImageContentValidatorInterface'); $this->productMock = $this->getMock( @@ -69,7 +63,6 @@ protected function setUp() $this->mediaGalleryEntryMock = $this->getMock('Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); $this->model = new \Magento\Catalog\Model\Product\Gallery\GalleryManagement( - $this->storeManagerMock, $this->productRepositoryMock, $this->contentValidatorMock ); @@ -78,17 +71,6 @@ protected function setUp() ->getMock(); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage There is no store with provided ID. - */ - public function testCreateWithNoStoreException() - { - $this->storeManagerMock->expects($this->once())->method('getStore') - ->willThrowException(new \Exception()); - $this->model->create('sku', $this->mediaGalleryEntryMock); - } - /** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage The image content is not valid. @@ -100,13 +82,10 @@ public function testCreateWithInvalidImageException() ->getMock(); $this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock); - $storeId = 0; - - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock) ->willReturn(false); - $this->model->create("sku", $this->mediaGalleryEntryMock, $storeId); + $this->model->create("sku", $this->mediaGalleryEntryMock); } /** @@ -120,20 +99,17 @@ public function testCreateWithCannotSaveException() ->disableOriginalConstructor() ->getMock();; $this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock); - - $storeId = 0; $this->productRepositoryMock->expects($this->once()) ->method('get') ->with($productSku) ->willReturn($this->productMock); - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock) ->willReturn(true); $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock) ->willThrowException(new \Exception()); - $this->model->create($productSku, $this->mediaGalleryEntryMock, $storeId); + $this->model->create($productSku, $this->mediaGalleryEntryMock); } public function testCreate() @@ -144,8 +120,6 @@ public function testCreate() ); $this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock); - $storeId = 0; - $this->productRepositoryMock->expects($this->once()) ->method('get') ->with($productSku) @@ -155,7 +129,6 @@ public function testCreate() ->with($this->productMock) ->willReturn($this->productMock); - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->contentValidatorMock->expects($this->once())->method('isValid')->with($entryContentMock) ->willReturn(true); @@ -166,21 +139,7 @@ public function testCreate() $this->productMock->expects($this->once())->method('setMediaGalleryEntries') ->with([$this->mediaGalleryEntryMock]); - $this->assertEquals(42, $this->model->create($productSku, $this->mediaGalleryEntryMock, $storeId)); - } - - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage There is no store with provided ID. - */ - public function testUpdateWithNonExistingStore() - { - $productSku = 'testProduct'; - $entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); - $storeId = 0; - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId) - ->willThrowException(new \Exception()); - $this->model->update($productSku, $entryMock, $storeId); + $this->assertEquals(42, $this->model->create($productSku, $this->mediaGalleryEntryMock)); } /** @@ -191,9 +150,7 @@ public function testUpdateWithNonExistingImage() { $productSku = 'testProduct'; $entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); - $storeId = 0; $entryId = 42; - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku) ->willReturn($this->productMock); $existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); @@ -201,7 +158,7 @@ public function testUpdateWithNonExistingImage() $this->productMock->expects($this->once())->method('getMediaGalleryEntries') ->willReturn([$existingEntryMock]); $entryMock->expects($this->once())->method('getId')->willReturn($entryId); - $this->model->update($productSku, $entryMock, $storeId); + $this->model->update($productSku, $entryMock); } /** @@ -212,9 +169,7 @@ public function testUpdateWithCannotSaveException() { $productSku = 'testProduct'; $entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); - $storeId = 0; $entryId = 42; - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku) ->willReturn($this->productMock); $existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); @@ -222,19 +177,16 @@ public function testUpdateWithCannotSaveException() $this->productMock->expects($this->once())->method('getMediaGalleryEntries') ->willReturn([$existingEntryMock]); $entryMock->expects($this->once())->method('getId')->willReturn($entryId); - $this->productMock->expects($this->once())->method('setStoreId')->with($storeId); $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock) ->willThrowException(new \Exception()); - $this->model->update($productSku, $entryMock, $storeId); + $this->model->update($productSku, $entryMock); } public function testUpdate() { $productSku = 'testProduct'; $entryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); - $storeId = 0; $entryId = 42; - $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId); $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku) ->willReturn($this->productMock); $existingEntryMock = $this->getMock('\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface'); @@ -245,9 +197,8 @@ public function testUpdate() $this->productMock->expects($this->once())->method('setMediaGalleryEntries') ->willReturn([$entryMock]); - $this->productMock->expects($this->once())->method('setStoreId')->with($storeId); $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock); - $this->assertTrue($this->model->update($productSku, $entryMock, $storeId)); + $this->assertTrue($this->model->update($productSku, $entryMock)); } /** diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php index 95560e7ce7be3..820748696b402 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php @@ -71,7 +71,7 @@ public function setUp() ->getMock(); $this->productRepositoryMock = $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface'); $this->productMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface'); - $this->savedProductMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface'); + $this->savedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->closureMock = function () { return $this->savedProductMock; }; diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php index 855d800fcfdcb..c27de6088f416 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php @@ -220,7 +220,7 @@ protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, ar && ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE])) ) { $product->setStoreId($storeId); - } elseif (!$product->hasData(\Magento\Catalog\Api\Data\ProductInterface::STORE_ID)) { + } elseif (!$product->hasData(\Magento\Catalog\Model\Product::STORE_ID)) { $product->setStoreId(Store::DEFAULT_STORE_ID); } } diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php index e33241defa659..2c3e02c827c44 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php @@ -64,7 +64,7 @@ protected function setUp() $this->linkRepositoryMock = $this->getMock('Magento\Downloadable\Api\LinkRepositoryInterface'); $this->sampleRepositoryMock = $this->getMock('Magento\Downloadable\Api\SampleRepositoryInterface'); $this->productMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface'); - $this->savedProductMock = $this->getMock('\Magento\Catalog\Api\Data\ProductInterface'); + $this->savedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->closureMock = function () { return $this->savedProductMock; }; diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index fcd48029ba062..a9521ee0f48a3 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -194,13 +194,12 @@ public function testUpdate() 'disabled' => true, 'media_type' => 'image', ], - // Store ID is not provided so the default one must be used ]; $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath'] . '/' . $this->getTargetGalleryEntryId(); - $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData)); + $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all')); $targetProduct = $this->getTargetSimpleProduct(); $this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail')); @@ -232,14 +231,13 @@ public function testUpdateWithNotDefaultStoreId() 'types' => ['thumbnail'], 'disabled' => true, 'media_type' => 'image', - ], - 'store_id' => 1, + ] ]; $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath'] . '/' . $this->getTargetGalleryEntryId(); - $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData)); + $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData, null, 'default')); $targetProduct = $this->getTargetSimpleProduct(); $this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail')); @@ -277,30 +275,6 @@ public function testDelete() $this->assertCount(0, $mediaGallery['images']); } - /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php - * @expectedException \Exception - * @expectedExceptionMessage There is no store with provided ID. - */ - public function testCreateThrowsExceptionIfThereIsNoStoreWithProvidedStoreId() - { - $requestData = [ - 'id' => null, - 'media_type' => 'image', - 'label' => 'Image Text', - 'position' => 1, - 'types' => ['image'], - 'disabled' => false, - 'content' => [ - 'base64_encoded_data' => base64_encode(file_get_contents($this->testImagePath)), - 'type' => 'image/jpeg', - 'name' => 'test_image.jpg', - ] - ]; - - $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData, 'storeId' => 99999]); - } - /** * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @expectedException \Exception @@ -425,32 +399,6 @@ public function testCreateThrowsExceptionIfProvidedImageNameContainsForbiddenCha $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]); } - /** - * @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php - * @expectedException \Exception - * @expectedExceptionMessage There is no store with provided ID. - */ - public function testUpdateIfThereIsNoStoreWithProvidedStoreId() - { - $requestData = [ - 'sku' => 'simple', - 'entry' => [ - 'id' => $this->getTargetGalleryEntryId(), - 'media_type' => 'image', - 'label' => 'Updated Image Text', - 'position' => 10, - 'types' => ['thumbnail'], - 'disabled' => true, - ], - 'store_id' => 9999, // target store view does not exist - ]; - - $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath'] - . '/' . $this->getTargetGalleryEntryId(); - - $this->_webApiCall($this->updateServiceInfo, $requestData); - } - /** * @expectedException \Exception * @expectedExceptionMessage Requested product doesn't exist @@ -469,10 +417,9 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() 'types' => ['thumbnail'], 'disabled' => true, ], - 'store_id' => 0, ]; - $this->_webApiCall($this->updateServiceInfo, $requestData); + $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'); } /** @@ -492,13 +439,12 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() 'types' => ['thumbnail'], 'disabled' => true, ], - 'store_id' => 0, ]; $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath'] . '/' . $this->getTargetGalleryEntryId(); - $this->_webApiCall($this->updateServiceInfo, $requestData); + $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php index 37b5113ea7540..519099ff05014 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php @@ -60,7 +60,6 @@ public function testGetVariation() 'sku' => 'test-', 'price' => 10.0, 'name' => '-', - 'store_id' => 1, 'status' => 1, 'visibility' => \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE, 'options' => [], diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/AbstractModel/Stub.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/AbstractModel/Stub.php index ced9dd4c1ea77..351fdeb6e1270 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/AbstractModel/Stub.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/AbstractModel/Stub.php @@ -14,7 +14,7 @@ abstract class Stub extends \Magento\Catalog\Model\AbstractModel implements \Mag */ public function getStoreId() { - return $this->getData(self::STORE_ID); + return $this->getData(\Magento\Catalog\Model\Product::STORE_ID); } /** @@ -25,6 +25,6 @@ public function getStoreId() */ public function setStoreId($storeId) { - return $this->setData(self::STORE_ID, $storeId); + return $this->setData(\Magento\Catalog\Model\Product::STORE_ID, $storeId); } } From 55063d7e865adb18f9ff3f8f72eaffdb5c4e33fa Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Fri, 13 Nov 2015 19:55:20 +0200 Subject: [PATCH 2/4] MAGETWO-44927: Two products are added to shopping cart when MAP is enabled + Production mode --- app/code/Magento/Webapi/Controller/PathProcessor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Webapi/Controller/PathProcessor.php b/app/code/Magento/Webapi/Controller/PathProcessor.php index 78eaec1b71066..e696f87a9f413 100644 --- a/app/code/Magento/Webapi/Controller/PathProcessor.php +++ b/app/code/Magento/Webapi/Controller/PathProcessor.php @@ -53,7 +53,8 @@ public function process($pathInfo) if (isset($stores[$storeCode])) { $this->storeManager->setCurrentStore($storeCode); $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); - } else if ($storeCode === self::ALL_STORE_CODE) { + } else if ($storeCode === self::ALL_STORE_CODE || $storeCode === \Magento\Store\Model\Store::ADMIN_CODE) { + //TODO: eliminate "admin" check after MAGETWO-45544 $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE); $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); } else { From c64f6d365341c83edc192689d6e690c367f1bef7 Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Fri, 13 Nov 2015 20:18:32 +0200 Subject: [PATCH 3/4] MAGETWO-45453: Product API does not work properly for non-default store code - fix SOAP issue with "all" store code --- app/code/Magento/Webapi/Controller/PathProcessor.php | 3 +-- app/code/Magento/Webapi/Model/Soap/Server.php | 5 ++++- .../Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Webapi/Controller/PathProcessor.php b/app/code/Magento/Webapi/Controller/PathProcessor.php index e696f87a9f413..78eaec1b71066 100644 --- a/app/code/Magento/Webapi/Controller/PathProcessor.php +++ b/app/code/Magento/Webapi/Controller/PathProcessor.php @@ -53,8 +53,7 @@ public function process($pathInfo) if (isset($stores[$storeCode])) { $this->storeManager->setCurrentStore($storeCode); $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); - } else if ($storeCode === self::ALL_STORE_CODE || $storeCode === \Magento\Store\Model\Store::ADMIN_CODE) { - //TODO: eliminate "admin" check after MAGETWO-45544 + } else if ($storeCode === self::ALL_STORE_CODE) { $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE); $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); } else { diff --git a/app/code/Magento/Webapi/Model/Soap/Server.php b/app/code/Magento/Webapi/Model/Soap/Server.php index 3d4ee5b7e344d..bd9e749994bce 100644 --- a/app/code/Magento/Webapi/Model/Soap/Server.php +++ b/app/code/Magento/Webapi/Model/Soap/Server.php @@ -148,9 +148,12 @@ public function generateUri($isWsdl = false) */ public function getEndpointUri() { + $storeCode = $this->_storeManager->getStore()->getCode() === \Magento\Store\Model\Store::ADMIN_CODE + ? \Magento\Webapi\Controller\PathProcessor::ALL_STORE_CODE + : $this->_storeManager->getStore()->getCode(); return $this->_storeManager->getStore()->getBaseUrl() . $this->_areaList->getFrontName($this->_configScope->getCurrentScope()) - . '/' . $this->_storeManager->getStore()->getCode(); + . '/' . $storeCode; } /** diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php index 80e9cebd7c585..ba10bcded181d 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php @@ -127,8 +127,6 @@ public function generateWsdlUrl($services, $storeCode = null) ->get('Magento\Store\Model\StoreManagerInterface') ->getStore() ->getCode(); - } elseif ($storeCode === \Magento\Webapi\Controller\PathProcessor::ALL_STORE_CODE) { - $storeCode = \Magento\Store\Model\Store::ADMIN_CODE; } /** TESTS_BASE_URL is initialized in PHPUnit configuration */ From 1553d125829e82e7ff4ec474cc3a0355e140fdf1 Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Fri, 13 Nov 2015 23:26:09 +0200 Subject: [PATCH 4/4] MAGETWO-45453: Product API does not work properly for non-default store code - fix static --- app/code/Magento/Webapi/Model/Soap/Server.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Webapi/Model/Soap/Server.php b/app/code/Magento/Webapi/Model/Soap/Server.php index bd9e749994bce..19ea6711dc167 100644 --- a/app/code/Magento/Webapi/Model/Soap/Server.php +++ b/app/code/Magento/Webapi/Model/Soap/Server.php @@ -9,6 +9,11 @@ use Magento\Framework\Webapi\Request; +/** + * SOAP Server + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Server { const SOAP_DEFAULT_ENCODING = 'UTF-8';