1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
measureratio.php
См. документацию.
1
<?php
2
namespace
Bitrix\Catalog;
3
4
use Bitrix\Main,
5
Bitrix\Main\Localization\Loc;
6
7
Loc::loadMessages(__FILE__);
8
34
35
class
MeasureRatioTable
extends
Main\Entity\DataManager
36
{
42
public
static
function
getTableName
()
43
{
44
return
'b_catalog_measure_ratio'
;
45
}
46
52
public
static
function
getMap
()
53
{
54
return
array
(
55
'ID'
=>
new
Main
\
Entity
\
IntegerField
(
'ID'
,
array
(
56
'primary'
=>
true
,
57
'autocomplete'
=>
true
,
58
'title'
=> Loc::getMessage(
'MEASURE_RATIO_ENTITY_ID_FIELD'
)
59
)),
60
'PRODUCT_ID'
=>
new
Main
\
Entity
\
IntegerField
(
'PRODUCT_ID'
,
array
(
61
'required'
=>
true
,
62
'title'
=> Loc::getMessage(
'MEASURE_RATIO_ENTITY_PRODUCT_ID_FIELD'
)
63
)),
64
'RATIO'
=>
new
Main
\
Entity
\
FloatField
(
'RATIO'
,
array
(
65
'required'
=>
true
,
66
'title'
=> Loc::getMessage(
'MEASURE_RATIO_ENTITY_RATIO_FIELD'
)
67
)),
68
'IS_DEFAULT'
=>
new
Main
\
Entity
\
BooleanField
(
'IS_DEFAULT'
,
array
(
69
'values'
=>
array
(
'N'
,
'Y'
),
70
'default_value'
=>
'N'
,
71
'title'
=> Loc::getMessage(
'MEASURE_RATIO_ENTITY_IS_DEFAULT_FIELD'
)
72
)),
73
'PRODUCT'
=>
new
Main
\
Entity
\ReferenceField(
74
'PRODUCT'
,
75
'\Bitrix\Catalog\Product'
,
76
array
(
'=this.PRODUCT_ID'
=>
'ref.ID'
),
77
array
(
'join_type'
=>
'LEFT'
)
78
),
79
);
80
}
81
89
public
static
function
getCurrentRatio
($product)
90
{
91
if
(!is_array($product))
92
$product =
array
($product);
93
Main\Type\Collection::normalizeArrayValuesByInt
($product,
true
);
94
if
(empty($product))
95
return
false
;
96
97
$result
= array_fill_keys($product, 1);
98
$ratioRows = array_chunk($product, 500);
99
foreach
($ratioRows as $row)
100
{
101
$ratioIterator = self::getList(
array
(
102
'select'
=>
array
(
'PRODUCT_ID'
,
'RATIO'
),
103
'filter'
=>
array
(
'@PRODUCT_ID'
=> $row,
'=IS_DEFAULT'
=>
'Y'
)
104
));
105
while
($ratio = $ratioIterator->fetch())
106
{
107
$ratio[
'PRODUCT_ID'
] = (int)$ratio[
'PRODUCT_ID'
];
108
$ratioInt = (int)$ratio[
'RATIO'
];
109
$ratioFloat = (float)$ratio[
'RATIO'
];
110
$ratioResult = ($ratioFloat > $ratioInt ? $ratioFloat : $ratioInt);
111
if
($ratioResult <
CATALOG_VALUE_EPSILON
)
112
continue
;
113
$result
[$ratio[
'PRODUCT_ID'
]] = $ratioResult;
114
}
115
unset($module, $moduleIterator);
116
}
117
unset($row, $ratioRows);
118
return
$result
;
119
}
120
128
public
static
function
deleteByProduct
($id)
129
{
130
$id = (int)$id;
131
if
($id <= 0)
132
return
;
133
134
$conn =
Main\Application::getConnection
();
135
$helper = $conn->getSqlHelper();
136
$conn->queryExecute(
137
'delete from '
.$helper->quote(self::getTableName()).
' where '
.$helper->quote(
'PRODUCT_ID'
).
' = '
.$id
138
);
139
unset($helper, $conn);
140
}
141
}
CATALOG_VALUE_EPSILON
const CATALOG_VALUE_EPSILON
Определения
include.php:108
Bitrix\Catalog\MeasureRatioTable
Определения
measureratio.php:36
Bitrix\Catalog\MeasureRatioTable\getMap
static getMap()
Определения
measureratio.php:52
Bitrix\Catalog\MeasureRatioTable\deleteByProduct
static deleteByProduct($id)
Определения
measureratio.php:128
Bitrix\Catalog\MeasureRatioTable\getCurrentRatio
static getCurrentRatio($product)
Определения
measureratio.php:89
Bitrix\Catalog\MeasureRatioTable\getTableName
static getTableName()
Определения
measureratio.php:42
Bitrix\Main\Application\getConnection
static getConnection($name="")
Определения
application.php:638
Bitrix\Main\ORM\Fields\BooleanField
Определения
booleanfield.php:20
Bitrix\Main\ORM\Fields\FloatField
Определения
floatfield.php:20
Bitrix\Main\ORM\Fields\IntegerField
Определения
integerfield.php:20
Bitrix\Main\Type\Collection\normalizeArrayValuesByInt
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения
collection.php:150
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Main\Entity
Определения
ufield.php:9
Bitrix\Main
bitrix
modules
catalog
lib
measureratio.php
Создано системой
1.14.0