algoliasearch-magento-2
algoliasearch-magento-2 copied to clipboard
Algolia's usage of `queryId` on the add to cart before/after event observers is potentially problematic.
Empty Commit for purposes of PR, in order to report issue on GitHub, because they have Issues disabled on the repository
Summary
Explain the motivation for making this change. What existing problem does the pull request solve? Are there any linked issues?
- Explain the motivation for making this change:
- To report a problem
- What existing problem does the pull request solve?:
- None, pointing out a problem via PR because the repository has Issues
- Are there any linked issues?
- If you guys would re-enable issues on your repository, I would have reported this there instead.
Summary of Problem:
The Algolia\AlgoliaSearch\Model\Observer\Insights\CheckoutCartProductAddBefore and Algolia\AlgoliaSearch\Model\Observer\Insights\CheckoutCartProductAddAfter class relies on performing a $product->setData('queryId', $requestInfo['queryID']) and $product->getData('queryId') to pass data back and forth between each other.
This is potentially problematic because:
- it does not account for a scenario where a client or other third party module has actually added an EAV product attribute
queryIdand utilizes it for their own purposes. - In such an event, Algolia's
_beforeobserver would pollute the EAV attribute with bad data. - AlgoliaSearch, does not bother to register any EAV
queryIdcatalog_product attribute, but because it is treating it like it does have this attribute, this could make debugging the problematic scenario above somewhat difficult for developers who may encounter this situation.
Possible suggestions for a better approach would be to:
- Algolia creates a
Algolia\AlgoliaSearch\Model\Observer\Insights\QueryIdclass.
- This class has two methods:
setQueryId(?string $queryId = null): voidgetQueryId(): ?string
- This
QueryIdclass is then injected intoCheckoutCartProductAddBefore, and this class performs thesetQueryId()call to store the current value. - This
QueryIdclass is also injected intoCheckoutCartProductAddAfterand uses thegetQueryId()method to fetch the current value.
- Algolia revises the
CheckoutCartProductAddBeforeandCheckoutCartProductAddAfterclasses to utilize aSessionInterfaceobject to store & fetchqueryId.