Skip to content

Commit bd4fbd2

Browse files
Merge pull request #721 from magento-nord/SPRINT-26-NORD
Task: - MAGETWO-62850: API for price update: Special price
2 parents 2d6bb43 + a769614 commit bd4fbd2

34 files changed

+3283
-1165
lines changed

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,19 @@ private function removeFixedTierPrice(array $meta)
203203
$pricePath = $this->arrayManager->slicePath($pricePath, 0, -1) . '/value_type/arguments/data/options';
204204

205205
$price = $this->arrayManager->get($pricePath, $meta);
206-
$meta = $this->arrayManager->remove($pricePath, $meta);
207-
foreach ($price as $key => $item) {
208-
if ($item['value'] == ProductPriceOptionsInterface::VALUE_FIXED) {
209-
unset($price[$key]);
206+
if ($price) {
207+
$meta = $this->arrayManager->remove($pricePath, $meta);
208+
foreach ($price as $key => $item) {
209+
if ($item['value'] == ProductPriceOptionsInterface::VALUE_FIXED) {
210+
unset($price[$key]);
211+
}
210212
}
213+
$meta = $this->arrayManager->merge(
214+
$this->arrayManager->slicePath($pricePath, 0, -1),
215+
$meta,
216+
['options' => $price]
217+
);
211218
}
212-
$meta = $this->arrayManager->merge(
213-
$this->arrayManager->slicePath($pricePath, 0, -1),
214-
$meta,
215-
['options' => $price]
216-
);
217219

218220
return $meta;
219221
}

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,11 @@
130130
</argument>
131131
</arguments>
132132
</type>
133-
133+
<type name="Magento\Catalog\Model\Product\Price\SpecialPriceStorage">
134+
<arguments>
135+
<argument name="allowedProductTypes" xsi:type="array">
136+
<item name="2" xsi:type="string">bundle</item>
137+
</argument>
138+
</arguments>
139+
</type>
134140
</config>

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@
1313
interface BasePriceStorageInterface
1414
{
1515
/**
16-
* Return product prices.
16+
* Return product prices. In case of at least one of skus is not found exception will be thrown.
1717
*
1818
* @param string[] $skus
1919
* @return \Magento\Catalog\Api\Data\BasePriceInterface[]
20+
* @throws \Magento\Framework\Exception\NoSuchEntityException
2021
*/
2122
public function get(array $skus);
2223

2324
/**
2425
* Add or update product prices.
26+
* Input item should correspond \Magento\Catalog\Api\Data\CostInterface.
27+
* If any items will have invalid price, store id or sku, they will be marked as failed and excluded from
28+
* update list and \Magento\Catalog\Api\Data\PriceUpdateResultInterface[] with problem description will be returned.
29+
* If there were no failed items during update empty array will be returned.
30+
* If error occurred during the update exception will be thrown.
2531
*
2632
* @param \Magento\Catalog\Api\Data\BasePriceInterface[] $prices
27-
* @return bool Will returned True if updated.
33+
* @return \Magento\Catalog\Api\Data\PriceUpdateResultInterface[]
34+
* @throws \Magento\Framework\Exception\CouldNotSaveException
2835
*/
2936
public function update(array $prices);
3037
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,34 @@
1313
interface CostStorageInterface
1414
{
1515
/**
16-
* Return product prices.
16+
* Return product prices. In case of at least one of skus is not found exception will be thrown.
1717
*
1818
* @param string[] $skus
1919
* @return \Magento\Catalog\Api\Data\CostInterface[]
20+
* @throws \Magento\Framework\Exception\NoSuchEntityException
2021
*/
2122
public function get(array $skus);
2223

2324
/**
2425
* Add or update product cost.
26+
* Input item should correspond to \Magento\Catalog\Api\Data\CostInterface.
27+
* If any items will have invalid cost, store id or sku, they will be marked as failed and excluded from
28+
* update list and \Magento\Catalog\Api\Data\PriceUpdateResultInterface[] with problem description will be returned.
29+
* If there were no failed items during update empty array will be returned.
30+
* If error occurred during the update exception will be thrown.
2531
*
2632
* @param \Magento\Catalog\Api\Data\CostInterface[] $prices
27-
* @return bool Will returned True if updated.
33+
* @return \Magento\Catalog\Api\Data\PriceUpdateResultInterface[]
2834
*/
2935
public function update(array $prices);
3036

3137
/**
32-
* Delete product cost.
38+
* Delete product cost. In case of at least one of skus is not found exception will be thrown.
39+
* If error occurred during the delete exception will be thrown.
3340
*
3441
* @param string[] $skus
35-
* @return bool Will returned True if deleted.
42+
* @return bool Will return True if deleted.
43+
* @throws \Magento\Framework\Exception\NoSuchEntityException
3644
* @throws \Magento\Framework\Exception\CouldNotDeleteException
3745
*/
3846
public function delete(array $skus);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Api\Data;
8+
9+
/**
10+
* Interface returned in case of incorrect price passed to efficient price API.
11+
* @api
12+
*/
13+
interface PriceUpdateResultInterface extends \Magento\Framework\Api\ExtensibleDataInterface
14+
{
15+
/**#@+
16+
* Constants
17+
*/
18+
const MESSAGE = 'message';
19+
const PARAMETERS = 'parameters';
20+
/**#@-*/
21+
22+
/**
23+
* Get error message, that contains description of error occurred during price update.
24+
*
25+
* @return string
26+
*/
27+
public function getMessage();
28+
29+
/**
30+
* Set error message, that contains description of error occurred during price update.
31+
*
32+
* @param string $message
33+
* @return $this
34+
*/
35+
public function setMessage($message);
36+
37+
/**
38+
* Get parameters, that could be displayed in error message placeholders.
39+
*
40+
* @return string[]
41+
*/
42+
public function getParameters();
43+
44+
/**
45+
* Set parameters, that could be displayed in error message placeholders.
46+
*
47+
* @param string[] $parameters
48+
* @return $this
49+
*/
50+
public function setParameters(array $parameters);
51+
52+
/**
53+
* Retrieve existing extension attributes object.
54+
* If extension attributes do not exist return null.
55+
*
56+
* @return \Magento\Catalog\Api\Data\PriceUpdateResultExtensionInterface|null
57+
*/
58+
public function getExtensionAttributes();
59+
60+
/**
61+
* Set an extension attributes object.
62+
*
63+
* @param \Magento\Catalog\Api\Data\PriceUpdateResultExtensionInterface $extensionAttributes
64+
* @return $this
65+
*/
66+
public function setExtensionAttributes(
67+
\Magento\Catalog\Api\Data\PriceUpdateResultExtensionInterface $extensionAttributes
68+
);
69+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Api\Data;
8+
9+
/**
10+
* Product Special Price Interface is used to encapsulate data that can be processed by efficient price API.
11+
* @api
12+
*/
13+
interface SpecialPriceInterface extends \Magento\Framework\Api\ExtensibleDataInterface
14+
{
15+
/**#@+
16+
* Constants
17+
*/
18+
const PRICE = 'price';
19+
const STORE_ID = 'store_id';
20+
const SKU = 'sku';
21+
const PRICE_FROM = 'price_from';
22+
const PRICE_TO = 'price_to';
23+
/**#@-*/
24+
25+
/**
26+
* Set product special price value.
27+
*
28+
* @param float $price
29+
* @return $this
30+
*/
31+
public function setPrice($price);
32+
33+
/**
34+
* Get product special price value.
35+
*
36+
* @return float
37+
*/
38+
public function getPrice();
39+
40+
/**
41+
* Set ID of store, that contains special price value.
42+
*
43+
* @param int $storeId
44+
* @return $this
45+
*/
46+
public function setStoreId($storeId);
47+
48+
/**
49+
* Get ID of store, that contains special price value.
50+
*
51+
* @return int
52+
*/
53+
public function getStoreId();
54+
55+
/**
56+
* Set SKU of product, that contains special price value.
57+
*
58+
* @param string $sku
59+
* @return $this
60+
*/
61+
public function setSku($sku);
62+
63+
/**
64+
* Get SKU of product, that contains special price value.
65+
*
66+
* @return string
67+
*/
68+
public function getSku();
69+
70+
/**
71+
* Set start date for special price in Y-m-d H:i:s format.
72+
*
73+
* @param string $datetime
74+
* @return $this
75+
*/
76+
public function setPriceFrom($datetime);
77+
78+
/**
79+
* Get start date for special price in Y-m-d H:i:s format.
80+
*
81+
* @return string
82+
*/
83+
public function getPriceFrom();
84+
85+
/**
86+
* Set end date for special price in Y-m-d H:i:s format.
87+
*
88+
* @param string $datetime
89+
* @return $this
90+
*/
91+
public function setPriceTo($datetime);
92+
93+
/**
94+
* Get end date for special price in Y-m-d H:i:s format.
95+
*
96+
* @return string
97+
*/
98+
public function getPriceTo();
99+
100+
/**
101+
* Retrieve existing extension attributes object.
102+
* If extension attributes do not exist return null.
103+
*
104+
* @return \Magento\Catalog\Api\Data\SpecialPriceExtensionInterface|null
105+
*/
106+
public function getExtensionAttributes();
107+
108+
/**
109+
* Set an extension attributes object.
110+
*
111+
* @param \Magento\Catalog\Api\Data\SpecialPriceExtensionInterface $extensionAttributes
112+
* @return $this
113+
*/
114+
public function setExtensionAttributes(
115+
\Magento\Catalog\Api\Data\SpecialPriceExtensionInterface $extensionAttributes
116+
);
117+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Api;
8+
9+
/**
10+
* Special prices resource model.
11+
* @api
12+
*/
13+
interface SpecialPriceInterface
14+
{
15+
/**
16+
* Get product special prices by SKUs.
17+
*
18+
* @param string[] $skus Array containing SKUs
19+
* $skus = [
20+
* 'sku value 1',
21+
* 'sku value 2'
22+
* ];
23+
* @return [
24+
* 'entity_id' => (int) Entity identified or entity link field.
25+
* 'value' => (float) Special price value.
26+
* 'store_id' => (int) Store Id.
27+
* 'sku' => (string) Product SKU.
28+
* 'price_from' => (string) Special price from date value in UTC.
29+
* 'price_to' => (string) Special price to date value in UTC.
30+
* ]
31+
*/
32+
public function get(array $skus);
33+
34+
/**
35+
* Update product special prices.
36+
*
37+
* @param array $prices
38+
* $prices = [
39+
* 'entity_id' => (int) Entity identified or entity link field. Required.
40+
* 'attribute_id' => (int) Special price attribute Id. Required.
41+
* 'store_id' => (int) Store Id. Required.
42+
* 'value' => (float) Special price value. Required.
43+
* 'price_from' => (string) Special price from date value in Y-m-d H:i:s format in UTC. Optional.
44+
* 'price_to' => (string) Special price to date value in Y-m-d H:i:s format in UTC. Optional.
45+
* ];
46+
* @return bool
47+
* @throws \Magento\Framework\Exception\CouldNotSaveException Thrown if error occurred during price save.
48+
*/
49+
public function update(array $prices);
50+
51+
/**
52+
* Delete product special prices.
53+
*
54+
* @param array $prices
55+
* $prices = [
56+
* 'entity_id' => (int) Entity identified or entity link field. Required.
57+
* 'attribute_id' => (int) Special price attribute Id. Required.
58+
* 'store_id' => (int) Store Id. Required.
59+
* 'value' => (float) Special price value. Required.
60+
* 'price_from' => (string) Special price from date value in Y-m-d H:i:s format in UTC. Optional.
61+
* 'price_to' => (string) Special price to date value in Y-m-d H:i:s format in UTC. Optional.
62+
* ];
63+
* @return bool
64+
* @throws \Magento\Framework\Exception\CouldNotDeleteException Thrown if error occurred during price delete.
65+
*/
66+
public function delete(array $prices);
67+
}

0 commit comments

Comments
 (0)