Skip to content

Commit a46576c

Browse files
committed
MAGETWO-83706: Scheduled Update to existing Group Price / Special Price removes the previously configured price, or results in changes not being saved
1 parent 9531261 commit a46576c

File tree

1 file changed

+76
-177
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend

1 file changed

+76
-177
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/TierpriceTest.php

Lines changed: 76 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -58,194 +58,93 @@ protected function setUp()
5858
);
5959
}
6060

61-
// public function testValidate()
62-
// {
63-
// $product = new \Magento\Framework\DataObject();
64-
// $product->setTierPrice(
65-
// [
66-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
67-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
68-
// ]
69-
// );
70-
// $this->assertTrue($this->_model->validate($product));
71-
// }
72-
//
73-
// /**
74-
// * @expectedException \Magento\Framework\Exception\LocalizedException
75-
// */
76-
// public function testValidateDuplicate()
77-
// {
78-
// $product = new \Magento\Framework\DataObject();
79-
// $product->setTierPrice(
80-
// [
81-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
82-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
83-
// ]
84-
// );
85-
//
86-
// $this->_model->validate($product);
87-
// }
88-
//
89-
// /**
90-
// * @expectedException \Magento\Framework\Exception\LocalizedException
91-
// */
92-
// public function testValidateDuplicateWebsite()
93-
// {
94-
// $product = new \Magento\Framework\DataObject();
95-
// $product->setTierPrice(
96-
// [
97-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
98-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
99-
// ['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
100-
// ]
101-
// );
102-
//
103-
// $this->_model->validate($product);
104-
// }
105-
//
106-
// /**
107-
// * @expectedException \Magento\Framework\Exception\LocalizedException
108-
// */
109-
// public function testValidatePercentage()
110-
// {
111-
// $product = new \Magento\Framework\DataObject();
112-
// $product->setTierPrice(
113-
// [
114-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'percentage_value' => 101],
115-
// ]
116-
// );
117-
//
118-
// $this->_model->validate($product);
119-
// }
120-
//
121-
// public function testPreparePriceData()
122-
// {
123-
// $data = [
124-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
125-
// ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
126-
// ['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
127-
// ];
128-
//
129-
// $newData = $this->_model->preparePriceData($data, \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, 1);
130-
// $this->assertEquals(2, count($newData));
131-
// $this->assertArrayHasKey('1-2', $newData);
132-
// $this->assertArrayHasKey('1-5', $newData);
133-
// }
134-
//
135-
// public function testAfterLoad()
136-
// {
137-
// /** @var $product \Magento\Catalog\Model\Product */
138-
// $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
139-
// \Magento\Catalog\Model\Product::class
140-
// );
141-
// $fixtureProduct = $this->productRepository->get('simple');
142-
// $product->setId($fixtureProduct->getId());
143-
// $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
144-
// $product->setData($linkField, $fixtureProduct->getData($linkField));
145-
// $this->_model->afterLoad($product);
146-
// $price = $product->getTierPrice();
147-
// $this->assertNotEmpty($price);
148-
// $this->assertEquals(4, count($price));
149-
// }
61+
public function testValidate()
62+
{
63+
$product = new \Magento\Framework\DataObject();
64+
$product->setTierPrice(
65+
[
66+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
67+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
68+
]
69+
);
70+
$this->assertTrue($this->_model->validate($product));
71+
}
15072

15173
/**
152-
* @magentoAppArea adminhtml
153-
* @param array $tierPricesData
154-
* @param bool $isChanged
155-
* @param int $tierPriceCtr
156-
* @dataProvider afterSaveDataProvider
74+
* @expectedException \Magento\Framework\Exception\LocalizedException
15775
*/
158-
public function testAfterSave(array $tierPricesData, $isChanged, $tierPriceCtr)
76+
public function testValidateDuplicate()
15977
{
160-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
161-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
162-
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
78+
$product = new \Magento\Framework\DataObject();
79+
$product->setTierPrice(
80+
[
81+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
82+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
83+
]
84+
);
16385

164-
/** @var $product \Magento\Catalog\Model\Product */
165-
$product = $productRepository->get('simple', true);
166-
$tierPrices = [];
167-
foreach ($tierPricesData as $tierPrice) {
168-
$tierPrices[] = $this->tierPriceFactory->create([
169-
'data' => $tierPrice
170-
]);
171-
}
86+
$this->_model->validate($product);
87+
}
17288

173-
// Added tier price
174-
$product->setTierPrices($tierPrices);
175-
$product->save();
89+
/**
90+
* @expectedException \Magento\Framework\Exception\LocalizedException
91+
*/
92+
public function testValidateDuplicateWebsite()
93+
{
94+
$product = new \Magento\Framework\DataObject();
95+
$product->setTierPrice(
96+
[
97+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
98+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
99+
['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
100+
]
101+
);
176102

177-
$this->assertEquals($isChanged, $product->getData('tier_price_changed'));
103+
$this->_model->validate($product);
104+
}
178105

179-
/** @var $product \Magento\Catalog\Model\Product */
180-
$product = $productRepository->get('simple', true, null, true);
181-
$this->assertEquals($tierPriceCtr, count($product->getTierPrice()));
182-
$this->assertEquals(0, $product->getData('tier_price_changed'));
106+
/**
107+
* @expectedException \Magento\Framework\Exception\LocalizedException
108+
*/
109+
public function testValidatePercentage()
110+
{
111+
$product = new \Magento\Framework\DataObject();
112+
$product->setTierPrice(
113+
[
114+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'percentage_value' => 101],
115+
]
116+
);
117+
118+
$this->_model->validate($product);
183119
}
184120

185-
public function afterSaveDataProvider()
121+
public function testPreparePriceData()
186122
{
187-
return [
188-
'same' => [
189-
[
190-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 2, 'value' => 8],
191-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 5, 'value' => 5],
192-
['website_id' => 0, 'customer_group_id' => 0, 'qty' => 3, 'value' => 5],
193-
[
194-
'website_id' => 0,
195-
'customer_group_id' => 0,
196-
'qty' => 10,
197-
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
198-
],
199-
],
200-
0,
201-
4,
202-
],
203-
'update one' => [
204-
[
205-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 2, 'value' => 8],
206-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 5, 'value' => 5],
207-
['website_id' => 0, 'customer_group_id' => 0, 'qty' => 3, 'value' => 5],
208-
[
209-
'website_id' => 0,
210-
'customer_group_id' => 0,
211-
'qty' => 10,
212-
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 10])
213-
],
214-
],
215-
1,
216-
4,
217-
],
218-
'delete one' => [
219-
[
220-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 5, 'value' => 5],
221-
['website_id' => 0, 'customer_group_id' => 0, 'qty' => 3, 'value' => 5],
222-
[
223-
'website_id' => 0,
224-
'customer_group_id' => 0,
225-
'qty' => 10,
226-
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
227-
],
228-
],
229-
1,
230-
3,
231-
],
232-
'add one' => [
233-
[
234-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 2, 'value' => 8],
235-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 5, 'value' => 5],
236-
['website_id' => 0, 'customer_group_id' => 32000, 'qty' => 20, 'percentage_value' => 90],
237-
['website_id' => 0, 'customer_group_id' => 0, 'qty' => 3, 'value' => 5],
238-
[
239-
'website_id' => 0,
240-
'customer_group_id' => 0,
241-
'qty' => 10,
242-
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
243-
],
244-
],
245-
1,
246-
5,
247-
],
248-
'delete all' => [[], 1, 0,],
123+
$data = [
124+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
125+
['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
126+
['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
249127
];
128+
129+
$newData = $this->_model->preparePriceData($data, \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, 1);
130+
$this->assertEquals(2, count($newData));
131+
$this->assertArrayHasKey('1-2', $newData);
132+
$this->assertArrayHasKey('1-5', $newData);
133+
}
134+
135+
public function testAfterLoad()
136+
{
137+
/** @var $product \Magento\Catalog\Model\Product */
138+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
139+
\Magento\Catalog\Model\Product::class
140+
);
141+
$fixtureProduct = $this->productRepository->get('simple');
142+
$product->setId($fixtureProduct->getId());
143+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
144+
$product->setData($linkField, $fixtureProduct->getData($linkField));
145+
$this->_model->afterLoad($product);
146+
$price = $product->getTierPrice();
147+
$this->assertNotEmpty($price);
148+
$this->assertEquals(4, count($price));
250149
}
251150
}

0 commit comments

Comments
 (0)