Skip to content

Commit 64eb4d6

Browse files
committed
ACP2E-4334: Delete default website/store breaks tier prices API endpoint
1 parent 8e09907 commit 64eb4d6

File tree

1 file changed

+11
-94
lines changed

1 file changed

+11
-94
lines changed

dev/tests/api-functional/testsuite/Magento/Catalog/Api/TierPriceStorageTest.php

Lines changed: 11 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2016 Adobe
4-
* All Rights Reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Catalog\Api;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Api\Data\TierPriceInterface;
10-
use Magento\Catalog\Helper\Data;
1110
use Magento\Framework\Webapi\Rest\Request;
12-
use Magento\Store\Api\WebsiteRepositoryInterface;
13-
use Magento\Store\Model\ResourceModel\Website as WebsiteResource;
14-
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
15-
use Magento\Store\Test\Fixture\Store as StoreFixture;
16-
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
17-
use Magento\TestFramework\Fixture\Config;
18-
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
19-
use Magento\TestFramework\Fixture\DbIsolation;
20-
use Magento\TestFramework\Helper\Bootstrap;
21-
use Magento\TestFramework\ObjectManager;
2211
use Magento\TestFramework\TestCase\WebapiAbstract;
2312
use Magento\TestFramework\Fixture\DataFixture;
2413
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
@@ -38,28 +27,16 @@ class TierPriceStorageTest extends WebapiAbstract
3827
private const WRONG_CUSTOMER_GROUP_NAME ='general';
3928

4029
/**
41-
* @var ObjectManager
30+
* @var \Magento\TestFramework\ObjectManager
4231
*/
4332
private $objectManager;
4433

45-
/**
46-
* @var WebsiteRepositoryInterface
47-
*/
48-
private $websiteRepository;
49-
50-
/**
51-
* @var WebsiteResource
52-
*/
53-
private $websiteResource;
54-
5534
/**
5635
* Set up.
5736
*/
5837
protected function setUp(): void
5938
{
60-
$this->objectManager = Bootstrap::getObjectManager();
61-
$this->websiteRepository = $this->objectManager->create(WebsiteRepositoryInterface::class);
62-
$this->websiteResource = $this->objectManager->create(WebsiteResource::class);
39+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
6340
}
6441

6542
/**
@@ -82,7 +59,7 @@ public function testGet()
8259
],
8360
];
8461
$response = $this->_webApiCall($serviceInfo, ['skus' => [self::SIMPLE_PRODUCT_SKU]]);
85-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
62+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
8663
/** @var ProductInterface $product */
8764
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
8865
$this->assertNotEmpty($response);
@@ -100,7 +77,7 @@ public function testGet()
10077
*/
10178
public function testUpdate()
10279
{
103-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
80+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
10481
$prices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
10582
$tierPrice = array_shift($prices);
10683
$serviceInfo = [
@@ -131,7 +108,7 @@ public function testUpdate()
131108
'quantity' => $tierPrice->getQty()
132109
];
133110
$response = $this->_webApiCall($serviceInfo, ['prices' => [$updatedPrice, $newPrice]]);
134-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
111+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
135112
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
136113
$this->assertEmpty($response);
137114
$this->assertTrue($this->isPriceCorrect($newPrice, $tierPrices));
@@ -221,7 +198,7 @@ public function testReplaceWithoutErrorMessage()
221198
]
222199
];
223200
$response = $this->_webApiCall($serviceInfo, ['prices' => $newPrices]);
224-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
201+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
225202
/** @var ProductInterface $product */
226203
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
227204
$this->assertEmpty($response);
@@ -283,7 +260,7 @@ public function testReplaceWithErrorMessage()
283260
*/
284261
public function testDelete()
285262
{
286-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
263+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
287264
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
288265
$pricesToStore = array_pop($tierPrices);
289266
$pricesToDelete = [];
@@ -293,7 +270,7 @@ public function testDelete()
293270
$priceType = $tierPrice->getExtensionAttributes()->getPercentageValue()
294271
? TierPriceInterface::PRICE_TYPE_DISCOUNT
295272
: TierPriceInterface::PRICE_TYPE_FIXED;
296-
$customerGroup = $tierPrice->getCustomerGroupId() == Group::NOT_LOGGED_IN_ID
273+
$customerGroup = $tierPrice->getCustomerGroupId() == \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID
297274
? self::CUSTOMER_NOT_LOGGED_IN_GROUP_NAME
298275
: self::CUSTOMER_ALL_GROUPS_NAME;
299276
$pricesToDelete[] = [
@@ -318,7 +295,7 @@ public function testDelete()
318295
],
319296
];
320297
$response = $this->_webApiCall($serviceInfo, ['prices' => $pricesToDelete]);
321-
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
298+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
322299
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
323300
$tierPrice = $tierPrices[0];
324301
$this->assertEmpty($response);
@@ -377,66 +354,6 @@ public function testCheckWebsite()
377354
}
378355
}
379356

380-
/**
381-
* Test to validate the incorrect website id for multi website setup.
382-
*/
383-
#[
384-
Config(Data::XML_PATH_PRICE_SCOPE, Data::PRICE_SCOPE_WEBSITE),
385-
DataFixture(WebsiteFixture::class, ['code' => 'second'], 'second_website'),
386-
DataFixture(StoreGroupFixture::class, ['website_id' => '$second_website.id$'], 'second_store_group'),
387-
DataFixture(StoreFixture::class, ['store_group_id' => '$second_store_group.id$'], 'second_store'),
388-
DataFixture(
389-
ProductFixture::class,
390-
[
391-
'sku' => 'simple',
392-
'website_id' => '$second_website.id$',
393-
'tier_prices' => [
394-
[
395-
'customer_group_id' => Group::NOT_LOGGED_IN_ID,
396-
'qty' => 100,
397-
'value' => 100
398-
]
399-
]
400-
]
401-
)
402-
]
403-
public function testCheckWebsiteWithMultiWebsite()
404-
{
405-
$fixture = DataFixtureStorageManager::getStorage();
406-
$serviceInfo = [
407-
'rest' => [
408-
'resourcePath' => '/V1/products/tier-prices',
409-
'httpMethod' => Request::HTTP_METHOD_POST
410-
],
411-
'soap' => [
412-
'service' => self::SERVICE_NAME,
413-
'serviceVersion' => self::SERVICE_VERSION,
414-
'operation' => self::SERVICE_NAME . 'Update',
415-
],
416-
];
417-
418-
$secondWebsite = $fixture->get('second_website');
419-
$secondWebsiteCode = $secondWebsite->getCode();
420-
$secondWebsiteDetails = $this->websiteRepository->get($secondWebsiteCode);
421-
$secondWebsiteDetails->setIsDefault(true);
422-
$this->websiteResource->save($secondWebsiteDetails);
423-
$tierPriceWithInvalidWebsiteId = [
424-
'price' => 28,
425-
'price_type' => TierPriceInterface::PRICE_TYPE_DISCOUNT,
426-
'website_id' => 1,
427-
'sku' => self::SIMPLE_PRODUCT_SKU,
428-
'customer_group' => 'ALL GROUPS',
429-
'quantity' => 3,
430-
'extension_attributes' => []
431-
];
432-
$response = $this->_webApiCall($serviceInfo, ['prices' => [$tierPriceWithInvalidWebsiteId]]);
433-
$this->assertEmpty($response);
434-
435-
$mainWebsite = $this->websiteRepository->get('base');
436-
$mainWebsite->setIsDefault(true);
437-
$this->websiteResource->save($mainWebsite);
438-
}
439-
440357
/**
441358
* Test replace method.
442359
*

0 commit comments

Comments
 (0)