Skip to content

Commit 8e09907

Browse files
committed
Merge branch 'ACP2E-4334' of https://github.com/adobe-commerce-tier-4/magento2ce into ACP2E-4334
# Conflicts: # app/code/Magento/Catalog/Model/Product/Price/Validation/TierPriceValidator.php # app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/TierPriceValidatorTest.php
2 parents fe2845a + 6ea1407 commit 8e09907

File tree

1 file changed

+94
-11
lines changed

1 file changed

+94
-11
lines changed

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

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
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;
1011
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;
1122
use Magento\TestFramework\TestCase\WebapiAbstract;
1223
use Magento\TestFramework\Fixture\DataFixture;
1324
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
@@ -27,16 +38,28 @@ class TierPriceStorageTest extends WebapiAbstract
2738
private const WRONG_CUSTOMER_GROUP_NAME ='general';
2839

2940
/**
30-
* @var \Magento\TestFramework\ObjectManager
41+
* @var ObjectManager
3142
*/
3243
private $objectManager;
3344

45+
/**
46+
* @var WebsiteRepositoryInterface
47+
*/
48+
private $websiteRepository;
49+
50+
/**
51+
* @var WebsiteResource
52+
*/
53+
private $websiteResource;
54+
3455
/**
3556
* Set up.
3657
*/
3758
protected function setUp(): void
3859
{
39-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
60+
$this->objectManager = Bootstrap::getObjectManager();
61+
$this->websiteRepository = $this->objectManager->create(WebsiteRepositoryInterface::class);
62+
$this->websiteResource = $this->objectManager->create(WebsiteResource::class);
4063
}
4164

4265
/**
@@ -59,7 +82,7 @@ public function testGet()
5982
],
6083
];
6184
$response = $this->_webApiCall($serviceInfo, ['skus' => [self::SIMPLE_PRODUCT_SKU]]);
62-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
85+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
6386
/** @var ProductInterface $product */
6487
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
6588
$this->assertNotEmpty($response);
@@ -77,7 +100,7 @@ public function testGet()
77100
*/
78101
public function testUpdate()
79102
{
80-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
103+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
81104
$prices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
82105
$tierPrice = array_shift($prices);
83106
$serviceInfo = [
@@ -108,7 +131,7 @@ public function testUpdate()
108131
'quantity' => $tierPrice->getQty()
109132
];
110133
$response = $this->_webApiCall($serviceInfo, ['prices' => [$updatedPrice, $newPrice]]);
111-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
134+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
112135
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
113136
$this->assertEmpty($response);
114137
$this->assertTrue($this->isPriceCorrect($newPrice, $tierPrices));
@@ -198,7 +221,7 @@ public function testReplaceWithoutErrorMessage()
198221
]
199222
];
200223
$response = $this->_webApiCall($serviceInfo, ['prices' => $newPrices]);
201-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
224+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
202225
/** @var ProductInterface $product */
203226
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
204227
$this->assertEmpty($response);
@@ -260,7 +283,7 @@ public function testReplaceWithErrorMessage()
260283
*/
261284
public function testDelete()
262285
{
263-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
286+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
264287
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
265288
$pricesToStore = array_pop($tierPrices);
266289
$pricesToDelete = [];
@@ -270,7 +293,7 @@ public function testDelete()
270293
$priceType = $tierPrice->getExtensionAttributes()->getPercentageValue()
271294
? TierPriceInterface::PRICE_TYPE_DISCOUNT
272295
: TierPriceInterface::PRICE_TYPE_FIXED;
273-
$customerGroup = $tierPrice->getCustomerGroupId() == \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID
296+
$customerGroup = $tierPrice->getCustomerGroupId() == Group::NOT_LOGGED_IN_ID
274297
? self::CUSTOMER_NOT_LOGGED_IN_GROUP_NAME
275298
: self::CUSTOMER_ALL_GROUPS_NAME;
276299
$pricesToDelete[] = [
@@ -295,7 +318,7 @@ public function testDelete()
295318
],
296319
];
297320
$response = $this->_webApiCall($serviceInfo, ['prices' => $pricesToDelete]);
298-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
321+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
299322
$tierPrices = $productRepository->get(self::SIMPLE_PRODUCT_SKU)->getTierPrices();
300323
$tierPrice = $tierPrices[0];
301324
$this->assertEmpty($response);
@@ -354,6 +377,66 @@ public function testCheckWebsite()
354377
}
355378
}
356379

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+
357440
/**
358441
* Test replace method.
359442
*

0 commit comments

Comments
 (0)