Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
measureratio.php
1<?php
2namespace Bitrix\Catalog;
3
6
7Loc::loadMessages(__FILE__);
8
35class 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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29