25 use CurrencyListItems;
26 use PrefixableDataProviderTrait;
28 private const VARIATION_PREFIX =
'VARIATION_';
34 parent::__construct($settings);
37 if ($variationIblockId > 0)
43 private function isWithVariations(): bool
45 return isset($this->variationFields);
50 $result = parent::prepareFields();
57 $result[
'AVAILABLE'] = $this->
createField(
'AVAILABLE', [
61 $result[
'QUANTITY'] = $this->
createField(
'QUANTITY', [
65 $result[
'QUANTITY_RESERVED'] = $this->
createField(
'QUANTITY_RESERVED', [
69 $result[
'PURCHASING_PRICE'] = $this->
createField(
'PURCHASING_PRICE', [
73 $result[
'PURCHASING_CURRENCY'] = $this->
createField(
'PURCHASING_CURRENCY', [
94 $result[
'MEASURE'] = $this->
createField(
'MEASURE', [
100 if ($this->isWithVariations())
102 $result += $this->prepareVariationElementFields();
113 private function prepareVariationElementFields(): array
125 $properties = $this->variationFields->getElementPropertiesParams();
126 foreach ($properties as $id => $params)
131 $nameWithPrefixTemplate =
Loc::getMessage(
'CATALOG_FILTER_PRODUCT_DATAPROVIDER_NAME_WITH_PREFIX');
133 return $this->prepareFieldsByPrefix(self::VARIATION_PREFIX, $result, $nameWithPrefixTemplate);
141 if ($fieldID ===
'PURCHASING_CURRENCY')
144 'items' => $this->getCurrencyListItems(),
147 elseif ($fieldID ===
'MEASURE')
150 'items' => $this->getMeasureListItems(),
153 elseif ($fieldID ===
'TYPE')
160 $result = parent::prepareFieldData($fieldID);
166 if ($this->isWithVariations())
168 return $this->prepareVariationFieldData($fieldID);
174 private function prepareVariationFieldData(
string $fieldIdWithPrefix): ?array
176 $fieldID = $this->removePrefix(self::VARIATION_PREFIX, $fieldIdWithPrefix);
178 return $this->variationFields->getPropertyDescription($fieldID);
186 return Loc::getMessage(
'CATALOG_FILTER_PRODUCT_DATAPROVIDER_FIELD_' . $fieldID) ?? parent::getFieldName($fieldID);
194 $rawFilterValue = parent::prepareFilterValue($rawFilterValue);
196 if (!$this->isWithVariations() || empty($rawFilterValue))
198 return $rawFilterValue;
201 [$variationFilterValue, $rawFilterValue] = $this->splitPrefixFilterValues(self::VARIATION_PREFIX, $rawFilterValue);
203 if (!empty($variationFilterValue))
205 $variationFilterValue = $this->variationFields->prepareFilterValue($variationFilterValue);
208 $variationFilterValue[
'IBLOCK_ID'] = $settings->getVariationIblockId();
209 $rawFilterValue[
'SUBQUERY'] = [
210 'FIELD' =>
'PROPERTY_' . $settings->getLinkPropertyId(),
211 'FILTER' => $variationFilterValue,
216 return $rawFilterValue;
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)