Open TalkMarc opened 10 months ago
I will be working on these issues in the upcoming weeks. The first PR I did today where I dropped support for PHP 7.4 and PHP 8.0 to make it easier for me.
Thank you for the update. You can also check out my simple approach to fix this issue on my fork https://github.com/TalkMarc/SyliusGiftCardPlugin/commit/bfa384b303b48e117060828cec04e6e6f2dab038
Plugin version
0.12.0-alpha.5
Sylius version
1.12.10
What happened?
When a product is added to a cart via API (POST /api/v2/shop/orders/[TOKEN]/items) a new gift card with the value of that product is created, even if the product added is not a gift card.
This also creates follow up issues when an item already existing in a cart is added again. (A new entity was found through the relationship...)
Details
I see that the api platform data persister dispatches a message event with the Message of type
Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart
. This message then gets picked up by the pluginsAddItemToCartHandler
. This handler does not check if the item/product added is a gift card. It only checks if the passed message is of typeSetono\SyliusGiftCardPlugin\Api\Command\AddItemToCart
, which it always will be, since that is the "input" that is has to be changed in the Order api resource configuration during plugin installation.API resource config deviation
I find it important to add that, in the installation instructions for the API, the "shop_add_item" operation of the Order has the method "PATCH", while in the Sylius api bundle it's actually configured with method "POST".
Relevant log output