code4business / freeproduct2

Magento2 extension that allows creating sales rules that add gift products.
64 stars 28 forks source link

Orders created via admin has multiple duplicate gift products #19

Closed rmjohn closed 2 years ago

rmjohn commented 5 years ago

Preconditions

Settings / Sale Rules

  1. Apply : Add A Gift
  2. Gift Sku : Post Card(Virtual)
  3. Discount Amount : 1
  4. No other conditions or actions

Steps to reproduce

  1. Configure Sales rules as above
  2. Create an order from admin panel
  3. For each item added , a gift also get added
  4. Remove extra gift created. Does not get removed
  5. This issue is only for orders created via admin panel

Expected result

  1. Only one gift per order of gift card .

Actual result

  1. Multiple gifts per order image
domeglic commented 5 years ago

You wrote version 1.0.0, can you please try with the latest version 1.2.6

rmjohn commented 5 years ago

Hi I put the latest version , but I am getting an error when trying to add a product to order via magento admin: Fatal error: Uncaught TypeError: Return value of C4B\FreeProduct\Observer\ResetGiftItems::removeDeletedItemsFromQuoteItems() must be an instance of C4B\FreeProduct\Observer\void, none returned in /var/www/magento2/app/code/C4B/FreeProduct/Observer/ResetGiftItems.php on line 174

domeglic commented 5 years ago

Hello, is your php version above 7.1?

rmjohn commented 5 years ago

Hi , my local version I'm testing on is php version 7.0.16 . Php version on server is 7.1.32. Before i deploy to server , is there any way to test this on 7.0?

domeglic commented 5 years ago

Php versions below 7.1 are not supported unfortunately. But if you are only testing if the module works, then removing the : void from any methods should work.

rmjohn commented 5 years ago

image Hello, I tested the new version and the same issue is there while creating orders via admin panel.(see atached image) Do you know how this can be fixed?

rmjohn commented 5 years ago

Adding products through storefront works well , it is only for orders created via admin.

domeglic commented 5 years ago

Ok, I will have a look into it. Currently I don't have any solution

rmjohn commented 5 years ago

Thank you @domeglic . Please do update if you find something. Thanks

rmjohn commented 5 years ago

Hi @domeglic , were you able to replicate this issue?

mokadev commented 4 years ago

Hi @domeglic

Same problem here. It seems that $quote->getItems() is always null for admin quotes so the ResetGiftItems observer never remove the gift items.

$quote->getItemsCollection() contains the items but when i use it instead of getItems() the frontend quotes start to be weird (duplicate quantity for non free items)

If you have any idea...

domeglic commented 4 years ago

Magento has weird behavior with getItems and getItemsCollection, one would assume they are the same but are actually not. Especially when adding to cart.

I haven't had the chance to look into it yet.

gihovani commented 4 years ago

You need change $quote->getItems() to $quote->getItemsCollection()->getItems(). i create a pr to resolve this bug #23 .