Skip to content

Commit 5da4d35

Browse files
committed
MC-20682: Storefront: Add/remove product from other storeviews and websites
1 parent 8e417d7 commit 5da4d35

File tree

3 files changed

+11
-39
lines changed

3 files changed

+11
-39
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class ViewTest extends TestCase
6767
protected function setUp()
6868
{
6969
$this->objectManager = Bootstrap::getObjectManager();
70-
$this->block = $this->objectManager->create(View::class);
7170
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
7271
$this->layout = $this->objectManager->get(LayoutInterface::class);
72+
$this->block = $this->layout->createBlock(View::class);
7373
$this->registry = $this->objectManager->get(Registry::class);
7474
$this->json = $this->objectManager->get(Json::class);
7575
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);

dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/ViewTest.php

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
use Magento\Catalog\Api\ProductRepositoryInterface;
1313
use Magento\Catalog\Model\Product;
1414
use Magento\Catalog\Model\Product\Visibility;
15-
use Magento\Eav\Model\AttributeSetSearchResults;
16-
use Magento\Eav\Model\Entity\Attribute\Set;
1715
use Magento\Eav\Model\Entity\Type;
1816
use Magento\Framework\Api\SearchCriteriaBuilder;
1917
use Magento\Framework\Api\SortOrderBuilder;
2018
use Magento\Framework\App\Http;
21-
use Magento\Framework\Data\Collection;
2219
use Magento\Framework\Registry;
23-
use Magento\Store\Api\WebsiteRepositoryInterface;
2420
use Magento\Store\Model\StoreManagerInterface;
21+
use Magento\TestFramework\Eav\Model\GetAttributeSetByName;
2522
use Magento\TestFramework\Request;
2623
use PHPUnit\Framework\MockObject\MockObject;
2724
use Psr\Log\LoggerInterface;
@@ -66,15 +63,15 @@ class ViewTest extends AbstractController
6663
/** @var StoreManagerInterface */
6764
private $storeManager;
6865

69-
/** @var WebsiteRepositoryInterface */
70-
private $websiteRepository;
71-
7266
/** @var SortOrderBuilder */
7367
private $sortOrderBuilder;
7468

7569
/** @var SearchCriteriaBuilder */
7670
private $searchCriteriaBuilder;
7771

72+
/** @var GetAttributeSetByName */
73+
private $getAttributeSetByName;
74+
7875
/**
7976
* @inheritdoc
8077
*/
@@ -89,9 +86,9 @@ protected function setUp()
8986
->loadByCode(Product::ENTITY);
9087
$this->registry = $this->_objectManager->get(Registry::class);
9188
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
92-
$this->websiteRepository = $this->_objectManager->get(WebsiteRepositoryInterface::class);
9389
$this->sortOrderBuilder = $this->_objectManager->create(SortOrderBuilder::class);
9490
$this->searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
91+
$this->getAttributeSetByName = $this->_objectManager->get(GetAttributeSetByName::class);
9592
}
9693

9794
/**
@@ -128,7 +125,7 @@ public function testViewActionCustomAttributeSetWithoutCountryOfManufacture(): v
128125
/** @var MockObject|LoggerInterface $logger */
129126
$logger = $this->setupLoggerMock();
130127
$product = $this->productRepository->get('simple_with_com');
131-
$attributeSetCustom = $this->getProductAttributeSetByName('custom_attribute_set_wout_com');
128+
$attributeSetCustom = $this->getAttributeSetByName->execute('custom_attribute_set_wout_com');
132129
$product->setAttributeSetId($attributeSetCustom->getAttributeSetId());
133130
$this->productRepository->save($product);
134131

@@ -226,7 +223,7 @@ public function testProductVisibleOnTwoWebsites(): void
226223
*/
227224
public function testRemoveProductFromOneWebsiteVisibility(): void
228225
{
229-
$websiteId = $this->websiteRepository->get('test')->getId();
226+
$websiteId = $this->storeManager->getWebsite('test')->getId();
230227
$currentStore = $this->storeManager->getStore();
231228
$secondStoreId = $this->storeManager->getStore('fixture_second_store')->getId();
232229
$product = $this->updateProduct('simple-on-two-websites', ['website_ids' => [$websiteId]]);
@@ -355,31 +352,6 @@ private function setupLoggerMock(): MockObject
355352
return $logger;
356353
}
357354

358-
/**
359-
* Get product attribute set by name.
360-
*
361-
* @param string $attributeSetName
362-
* @return Set|null
363-
*/
364-
private function getProductAttributeSetByName(string $attributeSetName): ?Set
365-
{
366-
$this->searchCriteriaBuilder->addFilter('attribute_set_name', $attributeSetName);
367-
$this->searchCriteriaBuilder->addFilter('entity_type_id', $this->productEntityType->getId());
368-
$attributeSetIdSortOrder = $this->sortOrderBuilder
369-
->setField('attribute_set_id')
370-
->setDirection(Collection::SORT_ORDER_DESC)
371-
->create();
372-
$this->searchCriteriaBuilder->addSortOrder($attributeSetIdSortOrder);
373-
$this->searchCriteriaBuilder->setPageSize(1);
374-
$this->searchCriteriaBuilder->setCurrentPage(1);
375-
/** @var AttributeSetSearchResults $searchResult */
376-
$searchResult = $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
377-
$items = $searchResult->getItems();
378-
$result = count($items) > 0 ? reset($items) : null;
379-
380-
return $result;
381-
}
382-
383355
/**
384356
* Update product visibility
385357
*

dev/tests/integration/testsuite/Magento/Catalog/_files/product_multistore_different_short_description.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$productFactory = $objectManager->get(ProductFactory::class);
2222

2323
$currentStoreId = $storeManager->getStore()->getId();
24-
$storeId = $storeManager->getStore('fixturestore')->getId();
24+
$secondStoreId = $storeManager->getStore('fixturestore')->getId();
2525

2626
$product = $productFactory->create();
2727
$product->setTypeId(Type::TYPE_SIMPLE)
@@ -38,8 +38,8 @@
3838
$productRepository->save($product);
3939

4040
try {
41-
$storeManager->setCurrentStore($store->getId());
42-
$product = $productRepository->get('simple-different-short-description', false, $storeId);
41+
$storeManager->setCurrentStore($secondStoreId);
42+
$product = $productRepository->get('simple-different-short-description', false, $secondStoreId);
4343
$product->setShortDescription('Second store view short description');
4444
$productRepository->save($product);
4545
} finally {

0 commit comments

Comments
 (0)