Skip to content

Commit e46aa79

Browse files
author
Mike Weis
committed
Merge branch 'FearlessKiwis-MAGETWO-28251-Catalog-Additional-Methods-2' into FearlessKiwis-MAGETWO-28251-Catalog-Additional-Methods
Conflicts: app/code/Magento/Catalog/Api/Data/ProductInterface.php app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php
2 parents c711bf5 + 9e632cf commit e46aa79

File tree

18 files changed

+1013
-67
lines changed

18 files changed

+1013
-67
lines changed

app/code/Magento/Bundle/Model/Product/Price.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
4747
* @param \Magento\Framework\Event\ManagerInterface $eventManager
4848
* @param PriceCurrencyInterface $priceCurrency
4949
* @param GroupManagementInterface $groupManagement
50+
* @param \Magento\Catalog\Api\Data\ProductGroupPriceInterfaceFactory $groupPriceFactory
51+
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory
52+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
5053
* @param \Magento\Catalog\Helper\Data $catalogData
54+
*
55+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5156
*/
5257
public function __construct(
5358
\Magento\CatalogRule\Model\Resource\RuleFactory $ruleFactory,
@@ -57,6 +62,9 @@ public function __construct(
5762
\Magento\Framework\Event\ManagerInterface $eventManager,
5863
PriceCurrencyInterface $priceCurrency,
5964
GroupManagementInterface $groupManagement,
65+
\Magento\Catalog\Api\Data\ProductGroupPriceInterfaceFactory $groupPriceFactory,
66+
\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory,
67+
\Magento\Framework\App\Config\ScopeConfigInterface $config,
6068
\Magento\Catalog\Helper\Data $catalogData
6169
) {
6270
$this->_catalogData = $catalogData;
@@ -67,7 +75,10 @@ public function __construct(
6775
$customerSession,
6876
$eventManager,
6977
$priceCurrency,
70-
$groupManagement
78+
$groupManagement,
79+
$groupPriceFactory,
80+
$tierPriceFactory,
81+
$config
7182
);
7283
}
7384

app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Bundle\Test\Unit\Model\Product;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
810
class PriceTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -75,16 +77,26 @@ protected function setUp()
7577
$this->priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')->getMock();
7678
$this->groupManagement = $this->getMockBuilder('Magento\Customer\Api\GroupManagementInterface')
7779
->getMockForAbstractClass();
78-
79-
$this->model = new \Magento\Bundle\Model\Product\Price(
80-
$this->ruleFactoryMock,
81-
$this->storeManagerMock,
82-
$this->localeDateMock,
83-
$this->customerSessionMock,
84-
$this->eventManagerMock,
85-
$this->priceCurrency,
86-
$this->groupManagement,
87-
$this->catalogHelperMock
80+
$gpFactory = $this->getMock('Magento\Catalog\Api\Data\ProductGroupPriceInterfaceFactory', [], [], '', false);
81+
$tpFactory = $this->getMock('Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory', [], [], '', false);
82+
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
83+
84+
$objectManagerHelper = new ObjectManagerHelper($this);
85+
$this->model = $objectManagerHelper->getObject(
86+
'Magento\Bundle\Model\Product\Price',
87+
[
88+
'ruleFactory' => $this->ruleFactoryMock,
89+
'storeManager' => $this->storeManagerMock,
90+
'localeDate' => $this->localeDateMock,
91+
'customerSession' => $this->customerSessionMock,
92+
'eventManager' => $this->eventManagerMock,
93+
'priceCurrency' => $this->priceCurrency,
94+
'groupManagement' => $this->groupManagement,
95+
'groupPriceFactory' => $gpFactory,
96+
'tierPriceFactory' => $tpFactory,
97+
'config' => $scopeConfig,
98+
'catalogData' => $this->catalogHelperMock
99+
]
88100
);
89101
}
90102

app/code/Magento/Catalog/Api/Data/ProductInterface.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,55 @@ public function setProductLinks(array $links = null);
253253
public function getOptions();
254254

255255
/**
256+
* Set list of product options
257+
*
256258
* @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface[] $options
257259
* @return $this
258260
*/
259261
public function setOptions(array $options = null);
260262

261263
/**
264+
* Get media gallery entries
265+
*
262266
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
263267
*/
264268
public function getMediaGalleryEntries();
265269

266270
/**
271+
* Set media gallery entries
272+
*
267273
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[] $mediaGalleryEntries
268274
* @return $this
269275
*/
270276
public function setMediaGalleryEntries(array $mediaGalleryEntries = null);
277+
278+
/**
279+
* Gets list of product group prices
280+
*
281+
* @return \Magento\Catalog\Api\Data\ProductGroupPriceInterface[]|null
282+
*/
283+
public function getGroupPrices();
284+
285+
/**
286+
* Sets list of product group prices
287+
*
288+
* @param \Magento\Catalog\Api\Data\ProductGroupPriceInterface[] $groupPrices
289+
* @return $this
290+
*/
291+
public function setGroupPrices(array $groupPrices = null);
292+
293+
/**
294+
* Gets list of product tier prices
295+
*
296+
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]|null
297+
*/
298+
public function getTierPrices();
299+
300+
/**
301+
* Sets list of product tier prices
302+
*
303+
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterface[] $tierPrices
304+
* @return $this
305+
*/
306+
public function setTierPrices(array $tierPrices = null);
271307
}

app/code/Magento/Catalog/Api/Data/ProductTierPriceInterface.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@
99

1010
use Magento\Framework\Api\ExtensibleDataInterface;
1111

12-
/**
13-
* @todo remove this interface if framework support return array
14-
*/
1512
interface ProductTierPriceInterface extends ExtensibleDataInterface
1613
{
1714
const QTY = 'qty';
1815

1916
const VALUE = 'value';
2017

18+
const CUSTOMER_GROUP_ID = 'customer_group_id';
19+
20+
/**
21+
* Retrieve customer group id
22+
*
23+
* @return int
24+
*/
25+
public function getCustomerGroupId();
26+
27+
/**
28+
* Set customer group id
29+
*
30+
* @param int $customerGroupId
31+
* @return $this
32+
*/
33+
public function setCustomerGroupId($customerGroupId);
34+
2135
/**
2236
* Retrieve tier qty
2337
*

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: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ public function getPriceInfo()
10011001
}
10021002

10031003
/**
1004-
* Get product group price
1004+
* Get product group price for the customer
10051005
*
10061006
* @return float
10071007
*/
@@ -1011,7 +1011,51 @@ public function getGroupPrice()
10111011
}
10121012

10131013
/**
1014-
* Get product tier price by qty
1014+
* Gets list of product group prices
1015+
*
1016+
* @return \Magento\Catalog\Api\Data\ProductGroupPriceInterface[]|null
1017+
*/
1018+
public function getGroupPrices()
1019+
{
1020+
return $this->getPriceModel()->getGroupPrices($this);
1021+
}
1022+
1023+
/**
1024+
* Sets list of product group prices
1025+
*
1026+
* @param \Magento\Catalog\Api\Data\ProductGroupPriceInterface[] $groupPrices
1027+
* @return $this
1028+
*/
1029+
public function setGroupPrices(array $groupPrices = null)
1030+
{
1031+
$this->getPriceModel()->setGroupPrices($this, $groupPrices);
1032+
return $this;
1033+
}
1034+
1035+
/**
1036+
* Gets list of product tier prices
1037+
*
1038+
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]|null
1039+
*/
1040+
public function getTierPrices()
1041+
{
1042+
return $this->getPriceModel()->getTierPrices($this);
1043+
}
1044+
1045+
/**
1046+
* Sets list of product tier prices
1047+
*
1048+
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterface[] $tierPrices
1049+
* @return $this
1050+
*/
1051+
public function setTierPrices(array $tierPrices = null)
1052+
{
1053+
$this->getPriceModel()->setTierPrices($this, $tierPrices);
1054+
return $this;
1055+
}
1056+
1057+
/**
1058+
* Get product tier price for the customer, based on qty of this product
10151059
*
10161060
* @param float $qty
10171061
* @return float|array

app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,7 @@ public function afterSave($object)
300300
$isGlobal = $this->getAttribute()->isScopeGlobal() || $websiteId == 0;
301301

302302
$priceRows = $object->getData($this->getAttribute()->getName());
303-
if (empty($priceRows)) {
304-
if ($isGlobal) {
305-
$this->_getResource()->deletePriceData($object->getId());
306-
} else {
307-
$this->_getResource()->deletePriceData($object->getId(), $websiteId);
308-
}
303+
if ($priceRows === null) {
309304
return $this;
310305
}
311306

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ public function setValue($value)
5555
return $this->setData(self::VALUE, $value);
5656
}
5757

58+
/**
59+
* Retrieve customer group id
60+
*
61+
* @return int
62+
*/
63+
public function getCustomerGroupId()
64+
{
65+
return $this->getData(self::CUSTOMER_GROUP_ID);
66+
}
67+
68+
/**
69+
* Set customer group id
70+
*
71+
* @param int $customerGroupId
72+
* @return $this
73+
*/
74+
public function setCustomerGroupId($customerGroupId)
75+
{
76+
return $this->setData(self::CUSTOMER_GROUP_ID, $customerGroupId);
77+
}
78+
5879
/**
5980
* {@inheritdoc}
6081
*

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ public function getList($sku, $customerGroupId)
170170
$priceKey = 'price';
171171
}
172172

173+
$cgi = ($customerGroupId === 'all'
174+
? $this->groupManagement->getAllCustomersGroup()->getId()
175+
: $customerGroupId);
176+
173177
$prices = [];
174178
foreach ($product->getData('tier_price') as $price) {
175179
if ((is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId))
@@ -178,7 +182,8 @@ public function getList($sku, $customerGroupId)
178182
/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
179183
$tierPrice = $this->priceFactory->create();
180184
$tierPrice->setValue($price[$priceKey])
181-
->setQty($price['price_qty']);
185+
->setQty($price['price_qty'])
186+
->setCustomerGroupId($cgi);
182187
$prices[] = $tierPrice;
183188
}
184189
}

0 commit comments

Comments
 (0)