Skip to content

Commit 8ce4144

Browse files
committed
AC-5979: Rest API products-render-info return wrong final price for logged in customer
1 parent edf6388 commit 8ce4144

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Api;
10+
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
13+
use Magento\Framework\Webapi\Rest\Request;
14+
use Magento\TestFramework\Fixture\DataFixture;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\TestCase\WebapiAbstract;
17+
use Magento\TestFramework\Fixture\DataFixtureStorage;
18+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
19+
use Magento\Integration\Api\CustomerTokenServiceInterface;
20+
21+
/**
22+
* Test tier pricing functionality in products-render-info API
23+
*/
24+
class ProductRenderListTierPricingTest extends WebapiAbstract
25+
{
26+
private const RESOURCE_PATH = '/V1/products-render-info';
27+
28+
/**
29+
* @var CustomerTokenServiceInterface
30+
*/
31+
private $customerTokenService;
32+
33+
/**
34+
* Set up test dependencies
35+
*/
36+
protected function setUp(): void
37+
{
38+
$this->_markTestAsRestOnly();
39+
parent::setUp();
40+
$objectManager = Bootstrap::getObjectManager();
41+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
42+
}
43+
44+
#[
45+
DataFixture(
46+
ProductFixture::class,
47+
[
48+
'sku' => 'simple',
49+
'website_id' => 0,
50+
'tier_prices' => [
51+
[
52+
'customer_group_id' => 2,
53+
'qty' => 1,
54+
'value' => 6
55+
]
56+
]
57+
]
58+
),
59+
DataFixture(CustomerFixture::class, ['group_id' => 1], as: 'customer_a'),
60+
DataFixture(CustomerFixture::class, ['group_id' => 2], as: 'customer_b')
61+
]
62+
public function testGuestUserGetsBasePriceNotTierPrice(): void
63+
{
64+
$searchCriteria = [
65+
'searchCriteria' => [
66+
'page_size' => 1,
67+
],
68+
'store_id' => 1,
69+
'currencyCode' => 'USD'
70+
];
71+
$customerEmail = DataFixtureStorageManager::getStorage()->get('customer_a')->getEmail();
72+
$customerPassword = "password";
73+
// Get customer token
74+
$token = $this->customerTokenService
75+
->createCustomerAccessToken($customerEmail, $customerPassword);
76+
$serviceInfo = [
77+
'rest' => [
78+
'resourcePath' => self::RESOURCE_PATH .
79+
'?' . http_build_query($searchCriteria) . '&storeId=1&currencyCode=USD',
80+
'httpMethod' => Request::HTTP_METHOD_GET,
81+
'token' => $token,
82+
],
83+
];
84+
$response = $this->_webApiCall($serviceInfo);
85+
$this->assertArrayHasKey('items', $response);
86+
$this->assertNotEmpty($response['items']);
87+
$product = reset($response['items']);
88+
$this->assertArrayHasKey('price_info', $product);
89+
// Guest should get regular price, not tier price
90+
$finalPrice = $product['price_info']['final_price'];
91+
$this->assertEquals(6, $finalPrice, 'customer_a should get tier price');
92+
93+
$customerEmail = DataFixtureStorageManager::getStorage()->get('customer_b')->getEmail();
94+
// Get customer token
95+
$token = $this->customerTokenService
96+
->createCustomerAccessToken($customerEmail, $customerPassword);
97+
$serviceInfo = [
98+
'rest' => [
99+
'resourcePath' => self::RESOURCE_PATH .
100+
'?' . http_build_query($searchCriteria) . '&storeId=1&currencyCode=USD',
101+
'httpMethod' => Request::HTTP_METHOD_GET,
102+
'token' => $token,
103+
],
104+
];
105+
106+
$response = $this->_webApiCall($serviceInfo);
107+
$product = reset($response['items']);
108+
$this->assertArrayHasKey('price_info', $product);
109+
// Guest should get regular price, not tier price
110+
$finalPrice = $product['price_info']['final_price'];
111+
$this->assertEquals(10, $finalPrice, 'customer_b should not get tier price');
112+
}
113+
}

0 commit comments

Comments
 (0)