Skip to content

Conversation

@cammonro
Copy link
Contributor

PromInc and others added 6 commits September 28, 2025 14:13
Adding a product to the cart may trigger a PHP and Algolia error due to the discount amount being too large.

## PHP Error
```
main.CRITICAL: Unable to send add to cart event due to Algolia events model misconfiguration: Discount must be a valid decimal number and total length must be no longer than 16 characters [] []
```
@cammonro cammonro requested a review from damcou September 29, 2025 04:34
Copy link
Contributor

@damcou damcou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! All green ✅

I have a small comment on JIRA before merging though


protected function initDecimalPrecision(): void
{
$this->decimalPrecision = $this->localeFormat->getPriceFormat()['requiredPrecision']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that getPriceFormat can take $localeCode and $currencyCode as parameters (that we don't pass here), and I'm wondering how it would behave in case of a multicurrency store with different currencies and precisions (USD and KWD for example) ... But I guess this is an extremely unlikely scenario which wouldn't hurt that much at Insights level in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I looked at the implementation of \Magento\Framework\Locale\Format::getPriceFormat I noted that it fell back to resolvers on both values. I decided that rather try to get too fancy I would let Magento decide the locale and currency based on its own internals.

If that doesn't work for someone I did separate the initialization of the precision via protected method \Algolia\AlgoliaSearch\Service\Insights\EventProcessor::initDecimalPrecision. Worst case you could write a preference on that method and handle that method however you wish.

Also with the plugin available for \Algolia\AlgoliaSearch\Service\Insights\EventProcessor::applyPrecision I figured the implementation should be flexible enough for others. We shall see! 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ! No problem for me :)

Copy link
Contributor

@damcou damcou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All green 🚀

@cammonro cammonro merged commit c2c2172 into release/3.17.0-dev Sep 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants