fix(web-api): normalize options JSON string in cart/change-option - #638
Open
Ibochkarev wants to merge 1 commit into
Open
fix(web-api): normalize options JSON string in cart/change-option#638Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Описание
POST /api/v1/cart/change-optionпринимаетoptionsкак JSON-строку (например"{\"size\":\"L\"}"), а не только как объект. Нормализация черезCartItemManager::normalizeOptions()на HTTP-границе, по тому же принципу, что иcart/addв #632/#633.Невалидный PHP-тип (
42,true) → 400 сms3_err_cart_options. Пустая карта после decode → 400 сms3_cart_change_options_error(как раньше).Тип изменений
Связанные Issues
Closes #635
Связано: #632, #633 (симметрия
cart/add).Как это было протестировано?
Новые тесты в
HeadlessStorefrontErrorsTest:testChangeOptionJsonStringOptionsReturns200testChangeOptionInvalidOptionsTypeReturns400Ручное тестирование
Автоматические тесты (
composer ci:php/composer test,npm run lint:ci,composer stan/ GitHub Actions CI)Тестирование на разных версиях PHP/MODX
Конфигурация тестирования:
fix/issue-635-cart-change-option-options-stringСкриншоты (если применимо)
Не применимо (API).
Чеклист
composer stan/ CI jobPHPStan)npm run lint:ciдля Vue)Дополнительные заметки
CartItemManager::normalizeOptions()сделанstatic, чтобы контроллер мог вызывать его без инстансаMiniShop3(в journey-тестахJourneyMs3не наследуетMiniShop3).CartMutationHandler::addпо-прежнему вызывает$this->itemManager->normalizeOptions()— DI-подменаms3_cart_item_managerсохраняется.Невалидная JSON-строка (
"{bad") по-прежнему даёт пустой map иms3_cart_change_options_error— поведение как у пустого[], в scope issue не менялось.