Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
inventory.php
1
<?php
2
3
namespace
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters
;
4
5
use
Bitrix\Main\ArgumentNullException
;
6
use \Bitrix\Main\SystemException;
7
8
class
Inventory
extends
DataConverter
9
{
10
protected
$maxProductQuantity
=
null
;
11
12
public
function
__construct
($params)
13
{
14
if
(!isset($params[
"SITE_ID"
]) || $params[
"SITE_ID"
] ==
''
)
15
throw
new
ArgumentNullException
(
"SITE_ID"
);
16
17
$ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
18
$settings = $ebay->getSettings();
19
20
if
(!empty($settings[$params[
"SITE_ID"
]][
'MAX_PRODUCT_QUANTITY'
]))
21
$this->maxProductQuantity = (float)$settings[$params[
"SITE_ID"
]][
'MAX_PRODUCT_QUANTITY'
];
22
}
23
24
public
function
convert
($data)
25
{
26
$result =
""
;
27
28
if
(isset($data[
"OFFERS"
]) && is_array($data[
"OFFERS"
]) && !empty($data[
"OFFERS"
]))
29
{
30
foreach
($data[
"OFFERS"
] as $offer)
31
$result .= $this->
getItemData
($offer, $data[
"IBLOCK_ID"
].
"_"
.$data[
"ID"
].
"_"
);
32
}
33
else
34
{
35
$result .= $this->
getItemData
($data, $data[
"IBLOCK_ID"
].
"_"
);
36
}
37
38
return
$result;
39
}
40
41
protected
function
getItemData
($data, $skuPrefix =
""
)
42
{
43
if
(!isset($data[
"PRICES"
][
"MIN"
]) || $data[
"PRICES"
][
"MIN"
] <= 0)
44
throw
new
SystemException
(
"Can't find the price for product id: "
.$data[
"ID"
].
" ! "
.__METHOD__);
45
46
if
((
float
)$data[
"QUANTITY"
] <= 0)
47
return
''
;
48
49
$quantity = (float)$data[
"QUANTITY"
];
50
51
if
($this->maxProductQuantity !==
null
&& $quantity > $this->maxProductQuantity)
52
$quantity =
$this->maxProductQuantity
;
53
54
$result =
"\t<Inventory>\n"
;
55
$result .=
"\t\t<SKU>"
.$skuPrefix.$data[
"ID"
].
"</SKU>\n"
;
56
$result .=
"\t\t<Price>"
.$data[
"PRICES"
][
"MIN"
].
"</Price>\n"
;
57
$result .=
"\t\t<Quantity>"
.$quantity.
"</Quantity>\n"
;
58
$result .=
"\t</Inventory>\n"
;
59
60
return
$result;
61
}
62
}
Bitrix\Main\ArgumentNullException
Definition
exception.php:54
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\DataConverter
Definition
dataconverter.php:6
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\Inventory
Definition
inventory.php:9
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\Inventory\getItemData
getItemData($data, $skuPrefix="")
Definition
inventory.php:41
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\Inventory\convert
convert($data)
Definition
inventory.php:24
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\Inventory\__construct
__construct($params)
Definition
inventory.php:12
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters\Inventory\$maxProductQuantity
$maxProductQuantity
Definition
inventory.php:10
Bitrix\Sale\TradingPlatform\Ebay\Feed\Data\Converters
Definition
dataconverter.php:3
modules
sale
lib
tradingplatform
ebay
feed
data
converters
inventory.php
Создано системой
1.10.0