Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductTierPriceManagementTest.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Catalog\Api;
9 
11 
13 {
14  const SERVICE_NAME = 'catalogProductTierPriceManagementV1';
15  const SERVICE_VERSION = 'V1';
16  const RESOURCE_PATH = '/V1/products/';
17 
22  public function testGetList($customerGroupId, $count, $value, $qty)
23  {
24  $productSku = 'simple';
25  $serviceInfo = [
26  'rest' => [
27  'resourcePath' => self::RESOURCE_PATH . $productSku . '/group-prices/' . $customerGroupId . '/tiers',
29  ],
30  'soap' => [
31  'service' => self::SERVICE_NAME,
32  'serviceVersion' => self::SERVICE_VERSION,
33  'operation' => self::SERVICE_NAME . 'GetList',
34  ],
35  ];
36 
37  $tearPriceList = $this->_webApiCall(
38  $serviceInfo,
39  ['sku' => $productSku, 'customerGroupId' => $customerGroupId]
40  );
41 
42  $this->assertCount($count, $tearPriceList);
43  if ($count) {
44  $this->assertEquals($value, $tearPriceList[0]['value']);
45  $this->assertEquals($qty, $tearPriceList[0]['qty']);
46  }
47  }
48 
49  public function getListDataProvider()
50  {
51  return [
52  [0, 2, 5, 3],
53  [1, 0, null, null],
54  ['all', 2, 8, 2],
55  ];
56  }
57 
64  public function testDelete($customerGroupId, $qty)
65  {
66  $productSku = 'simple';
67  $serviceInfo = [
68  'rest' => [
69  'resourcePath' => self::RESOURCE_PATH
70  . $productSku . "/group-prices/" . $customerGroupId . "/tiers/" . $qty,
72  ],
73  'soap' => [
74  'service' => self::SERVICE_NAME,
75  'serviceVersion' => self::SERVICE_VERSION,
76  'operation' => self::SERVICE_NAME . 'Remove',
77  ],
78  ];
79  $requestData = ['sku' => $productSku, 'customerGroupId' => $customerGroupId, 'qty' => $qty];
80  $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
81  }
82 
83  public function deleteDataProvider()
84  {
85  return [
86  'delete_tier_price_for_specific_customer_group' => [0, 3],
87  'delete_tier_price_for_all_customer_group' => ['all', 5]
88  ];
89  }
90 
95  public function testAdd()
96  {
97  $productSku = 'simple';
98  $customerGroupId = 1;
99  $qty = 50;
100  $price = 10;
101  $serviceInfo = [
102  'rest' => [
103  'resourcePath' => '/V1/products/' . $productSku
104  . '/group-prices/' . $customerGroupId . '/tiers/' . $qty . '/price/' . $price,
106  ],
107  'soap' => [
108  'service' => self::SERVICE_NAME,
109  'serviceVersion' => self::SERVICE_VERSION,
110  'operation' => self::SERVICE_NAME . 'Add',
111  ],
112  ];
113 
114  $requestData = [
115  'sku' => $productSku,
116  'customerGroupId' => $customerGroupId,
117  'qty' => $qty,
118  'price' => $price,
119  ];
120  $this->_webApiCall($serviceInfo, $requestData);
123  $service = $objectManager->get(\Magento\Catalog\Api\ProductTierPriceManagementInterface::class);
124  $prices = $service->getList($productSku, 1);
125  $this->assertCount(1, $prices);
126  $this->assertEquals(10, $prices[0]->getValue());
127  $this->assertEquals(50, $prices[0]->getQty());
128  }
129 
134  public function testAddWithAllCustomerGrouped()
135  {
136  $productSku = 'simple';
137  $customerGroupId = 'all';
138  $qty = 50;
139  $price = 20;
140  $serviceInfo = [
141  'rest' => [
142  'resourcePath' => '/V1/products/' . $productSku
143  . '/group-prices/' . $customerGroupId . '/tiers/' . $qty . '/price/' . $price,
145  ],
146  'soap' => [
147  'service' => self::SERVICE_NAME,
148  'serviceVersion' => self::SERVICE_VERSION,
149  'operation' => self::SERVICE_NAME . 'Add',
150  ],
151  ];
152  $requestData = [
153  'sku' => $productSku,
154  'customerGroupId' => $customerGroupId,
155  'qty' => $qty,
156  'price' => $price,
157  ];
158  $this->_webApiCall($serviceInfo, $requestData);
161  $service = $objectManager->get(\Magento\Catalog\Api\ProductTierPriceManagementInterface::class);
162  $prices = $service->getList($productSku, 'all');
163  $this->assertCount(3, $prices);
164  $this->assertEquals(20, (int)$prices[2]->getValue());
165  $this->assertEquals(50, (int)$prices[2]->getQty());
166  }
167 
172  public function testUpdateWithAllGroups()
173  {
174  $productSku = 'simple';
175  $customerGroupId = 'all';
176  $qty = 2;
177  $price = 20;
178  $serviceInfo = [
179  'rest' => [
180  'resourcePath' => '/V1/products/' . $productSku
181  . '/group-prices/' . $customerGroupId . '/tiers/' . $qty . '/price/' . $price,
183  ],
184  'soap' => [
185  'service' => self::SERVICE_NAME,
186  'serviceVersion' => self::SERVICE_VERSION,
187  'operation' => self::SERVICE_NAME . 'Add',
188  ],
189  ];
190  $requestData = [
191  'sku' => $productSku,
192  'customerGroupId' => $customerGroupId,
193  'qty' => $qty,
194  'price' => $price,
195  ];
196  $this->_webApiCall($serviceInfo, $requestData);
199  $service = $objectManager->get(\Magento\Catalog\Api\ProductTierPriceManagementInterface::class);
200  $prices = $service->getList($productSku, 'all');
201  $this->assertCount(2, $prices);
202  $this->assertEquals(20, (int)$prices[0]->getValue());
203  $this->assertEquals(2, (int)$prices[0]->getQty());
204  }
205 }
$objectManager
Definition: bootstrap.php:17
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$count
Definition: recent.phtml:13
$price
$value
Definition: gender.phtml:16