Skip to content

Commit

Permalink
Merge pull request #3274 from vahonc/3256-allow-date-attributes-in-ru…
Browse files Browse the repository at this point in the history
…le-engine

Feature #3256, allow date attributes in the rule engine
romainruaud authored Jun 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 9417677 + 2e8edf2 commit c4ef36d
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -293,6 +293,18 @@ public function getValue()
);
}

if ($this->getInputType() == 'date' && !$this->getIsValueParsed()) {
// Date format intentionally hard-coded.
$date = $this->getData('value');
$date = (\is_numeric($date) ? '@' : '') . $date;
$this->setData(
'value',
(new \DateTime($date, new \DateTimeZone((string) $this->_localeDate->getConfigTimezone())))
->format('Y-m-d')
);
$this->setIsValueParsed(true);
}

return $this->getData('value');
}

Original file line number Diff line number Diff line change
@@ -189,8 +189,9 @@ private function getMatchQueryParams(ProductCondition $productCondition)
private function getRangeQueryParams(ProductCondition $productCondition)
{
$fieldName = $this->getSearchFieldName($productCondition);
$inputType = $productCondition->getInputType();
$operator = $productCondition->getOperator();
$value = $productCondition->getValue();
$value = ($inputType == 'date') ? $productCondition->getValue() : (float) $productCondition->getValue();

switch ($operator) {
case '>':
@@ -207,7 +208,7 @@ private function getRangeQueryParams(ProductCondition $productCondition)
break;
}

return ['bounds' => [$operator => (float) $value], 'field' => $fieldName];
return ['bounds' => [$operator => $value], 'field' => $fieldName];
}

/**

0 comments on commit c4ef36d

Please sign in to comment.