Skip to content

Commit ffc1764

Browse files
author
Mike Weis
committed
MAGETWO-27267: Add getTierPrices() to the Product
-- updated per code review -- updated per demo review
1 parent 4dd930d commit ffc1764

File tree

4 files changed

+22
-36
lines changed

4 files changed

+22
-36
lines changed

app/code/Magento/Catalog/Api/ProductTierPriceManagementInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface ProductTierPriceManagementInterface
1212
* Create tier price for product
1313
*
1414
* @param string $sku
15-
* @param string $customerGroupId
15+
* @param string $customerGroupId 'all' can be used to specify 'ALL GROUPS'
1616
* @param float $price
1717
* @param float $qty
1818
* @return boolean
@@ -22,10 +22,10 @@ interface ProductTierPriceManagementInterface
2222
public function add($sku, $customerGroupId, $price, $qty);
2323

2424
/**
25-
* Remove tire price from product
25+
* Remove tier price from product
2626
*
2727
* @param string $sku
28-
* @param string $customerGroupId
28+
* @param string $customerGroupId 'all' can be used to specify 'ALL GROUPS'
2929
* @param float $qty
3030
* @return boolean
3131
* @throws \Magento\Framework\Exception\NoSuchEntityException
@@ -34,10 +34,10 @@ public function add($sku, $customerGroupId, $price, $qty);
3434
public function remove($sku, $customerGroupId, $qty);
3535

3636
/**
37-
* Get tire price of product
37+
* Get tier price of product
3838
*
3939
* @param string $sku
40-
* @param string $customerGroupId
40+
* @param string $customerGroupId 'all' can be used to specify 'ALL GROUPS'
4141
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
4242
* @throws \Magento\Framework\Exception\NoSuchEntityException
4343
*/

app/code/Magento/Catalog/Model/Product.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -962,15 +962,11 @@ public function getGroupPrice()
962962
/**
963963
* Gets list of product group prices
964964
*
965-
* @return \Magento\Catalog\Api\Data\ProductGroupPriceInterface[]|null
965+
* @return \Magento\Catalog\Api\Data\ProductGroupPriceInterface[]
966966
*/
967967
public function getGroupPrices()
968968
{
969-
$groupPrices = $this->getPriceModel()->getGroupPrices($this);
970-
if (empty($groupPrices)) {
971-
$groupPrices = null;
972-
}
973-
return $groupPrices;
969+
return $this->getPriceModel()->getGroupPrices($this);
974970
}
975971

976972
/**
@@ -988,15 +984,11 @@ public function setGroupPrices(array $groupPrices = null)
988984
/**
989985
* Gets list of product tier prices
990986
*
991-
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]|null
987+
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
992988
*/
993989
public function getTierPrices()
994990
{
995-
$tierPrices = $this->getPriceModel()->getTierPrices($this);
996-
if (empty($tierPrices)) {
997-
$tierPrices = null;
998-
}
999-
return $tierPrices;
991+
return $this->getPriceModel()->getTierPrices($this);
1000992
}
1001993

1002994
/**

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,10 @@ protected function invokeGetGroupOrTierPrices($originalPrices, $getter)
738738
]
739739
);
740740

741-
$expectedResultIsNull = (empty($originalPrices) ? true : false);
741+
$expectedResultIsEmpty = (empty($originalPrices) ? true : false);
742742
$groupPrices = $productModel->$getter();
743-
$actualResultIsNull = (empty($groupPrices) ? true : false);
744-
$this->assertEquals($expectedResultIsNull,$actualResultIsNull );
743+
$actualResultIsEmpty = (empty($groupPrices) ? true : false);
744+
$this->assertEquals($expectedResultIsEmpty, $actualResultIsEmpty);
745745
}
746746

747747
/**

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ public function testGroupPrices()
358358
'value' => 2.10,
359359
];
360360
$response[self::KEY_GROUP_PRICES] = $groupPrices;
361-
$this->updateProduct($response);
361+
$response = $this->updateProduct($response);
362362

363-
$response = $this->getProduct($productData[ProductInterface::SKU]);
364363
$this->assertArrayHasKey(self::KEY_GROUP_PRICES, $response);
365364
$groupPrices = $response[self::KEY_GROUP_PRICES];
366365
$this->assertNotNull($groupPrices, "UPDATE 1: expected to have group prices");
@@ -373,9 +372,8 @@ public function testGroupPrices()
373372
// update the product without any mention of group prices; no change expected for group pricing
374373
$response = $this->getProduct($productData[ProductInterface::SKU]);
375374
unset($response[self::KEY_GROUP_PRICES]);
376-
$this->updateProduct($response);
375+
$response = $this->updateProduct($response);
377376

378-
$response = $this->getProduct($productData[ProductInterface::SKU]);
379377
$this->assertArrayHasKey(self::KEY_GROUP_PRICES, $response);
380378
$groupPrices = $response[self::KEY_GROUP_PRICES];
381379
$this->assertNotNull($groupPrices, "UPDATE 2: expected to have group prices");
@@ -388,10 +386,9 @@ public function testGroupPrices()
388386
// update the product with empty group prices; expect to have the existing group prices removed
389387
$response = $this->getProduct($productData[ProductInterface::SKU]);
390388
$response[self::KEY_GROUP_PRICES] = [];
391-
$this->updateProduct($response);
392-
393-
$response = $this->getProduct($productData[ProductInterface::SKU]);
394-
$this->assertArrayNotHasKey(self::KEY_GROUP_PRICES, $response, "expected to not have any 'group_prices' data");
389+
$response = $this->updateProduct($response);
390+
$this->assertArrayHasKey(self::KEY_GROUP_PRICES, $response, "expected to have the 'group_prices' key");
391+
$this->assertEmpty($response[self::KEY_GROUP_PRICES], "expected to have an empty array of 'group_prices'");
395392

396393
// delete the product with group prices; expect that all goes well
397394
$response = $this->deleteProduct($productData[ProductInterface::SKU]);
@@ -440,9 +437,8 @@ public function testTierPrices()
440437
'qty' => 12,
441438
];
442439
$response[self::KEY_TIER_PRICES] = $tierPrices;
443-
$this->updateProduct($response);
440+
$response = $this->updateProduct($response);
444441

445-
$response = $this->getProduct($productData[ProductInterface::SKU]);
446442
$this->assertArrayHasKey(self::KEY_TIER_PRICES, $response);
447443
$tierPrices = $response[self::KEY_TIER_PRICES];
448444
$this->assertNotNull($tierPrices, "UPDATE 1: expected to have tier prices");
@@ -457,9 +453,8 @@ public function testTierPrices()
457453
// update the product without any mention of tier prices; no change expected for tier pricing
458454
$response = $this->getProduct($productData[ProductInterface::SKU]);
459455
unset($response[self::KEY_TIER_PRICES]);
460-
$this->updateProduct($response);
456+
$response = $this->updateProduct($response);
461457

462-
$response = $this->getProduct($productData[ProductInterface::SKU]);
463458
$this->assertArrayHasKey(self::KEY_TIER_PRICES, $response);
464459
$tierPrices = $response[self::KEY_TIER_PRICES];
465460
$this->assertNotNull($tierPrices, "UPDATE 2: expected to have tier prices");
@@ -474,10 +469,9 @@ public function testTierPrices()
474469
// update the product with empty tier prices; expect to have the existing tier prices removed
475470
$response = $this->getProduct($productData[ProductInterface::SKU]);
476471
$response[self::KEY_TIER_PRICES] = [];
477-
$this->updateProduct($response);
478-
479-
$response = $this->getProduct($productData[ProductInterface::SKU]);
480-
$this->assertArrayNotHasKey(self::KEY_TIER_PRICES, $response, "expected to not have any 'tier_prices' data");
472+
$response = $this->updateProduct($response);
473+
$this->assertArrayHasKey(self::KEY_TIER_PRICES, $response, "expected to have the 'tier_prices' key");
474+
$this->assertEmpty($response[self::KEY_TIER_PRICES], "expected to have an empty array of 'tier_prices'");
481475

482476
// delete the product with tier prices; expect that all goes well
483477
$response = $this->deleteProduct($productData[ProductInterface::SKU]);

0 commit comments

Comments
 (0)