Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a giftcard is bought with a coupon code it affects its value #116

Open
lamasfoker opened this issue Dec 10, 2020 · 6 comments
Open

If a giftcard is bought with a coupon code it affects its value #116

lamasfoker opened this issue Dec 10, 2020 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@lamasfoker
Copy link

Step to reproduce

  1. Add to cart a giftcard with the value of 500€;
  2. Use a coupon code with 50% discount;
  3. Complete the order.

Expected result

In admin I have to se a new giftcard with the amount of 500€

Actual result

In admin I see a new giftcard with the amount of 250€

@lamasfoker lamasfoker changed the title If a gift card is buyed with a coupon code it affects its value If a giftcard is buyed with a coupon code it affects its value Dec 10, 2020
@igormukhingmailcom igormukhingmailcom added the bug Something isn't working label Dec 10, 2020
@igormukhingmailcom
Copy link
Member

Thanks, @lamasfoker

@tuxes3
Copy link

tuxes3 commented May 25, 2021

Solution

Use unit_percentage_discount instead of order_percentage_discount and unit_fixed_discount instead of order_fixed_discount. Leave the Filter Options empty.

Then create a Decorator for the sylius.promotion_filter.product like that:

App\Promotion\Filter\ProductFilterDecorator:
    decorates: sylius.promotion_filter.product

The Decorator looks like that:

namespace App\Promotion\Filter;

use App\Entity\Order\OrderItem;
use Sylius\Component\Core\Promotion\Filter\FilterInterface;
use Sylius\Component\Core\Promotion\Filter\ProductFilter;

class ProductFilterDecorator implements FilterInterface
{

    protected ProductFilter $original;

    public function __construct(ProductFilter $original)
    {
        $this->original = $original;
    }

    public function filter(array $items, array $configuration): array
    {
        $filtered = $this->original->filter($items, $configuration);
        return array_filter($filtered, static fn (OrderItem $orderItem) => !$orderItem->getProduct()->isGiftCard());
    }

}

This filters all Gift Cards from getting promotions.

@loevgaard
Copy link
Member

loevgaard commented Dec 17, 2021

Thanks for your solution here, @tuxes3. I really like it and I think we should implement this decorator in the plugin and add a few lines to the readme explaining this.

However, what do you think about also adding an 'out of box' solution like so:

  1. Decorate the \Sylius\Component\Promotion\Processor\PromotionProcessor and do not process the order if there is a gift card on the order.
  2. Create a twig block to the cart that will show if the order is eligible for any promotions which will say something like: Your order is eligible for one or more promotions, however, you have a gift card in your cart and promotions are therefore disabled. Instead create two orders, one with your gift card and one with your other products to obtain your discounts.

This would be kind of a 'seat belt' solution. What do you think? cc @igormukhingmailcom @Roshyo

@loevgaard loevgaard added this to the v1.0 milestone Dec 17, 2021
@loevgaard
Copy link
Member

Btw. we also have the rule \Setono\SyliusGiftCardPlugin\Promotion\Checker\Rule\HasNoGiftCardRuleChecker which more or less does the same as my idea, but you still have to actively do something

@Roshyo
Copy link
Contributor

Roshyo commented Dec 20, 2021

I would rather go for something to allow buying a discounted GiftCard. I mean, I can easily imagine scenario where we want to sell 5% discounted GC (buy a 100€ GC for 95€) and this has to be handled correctly.

@tuxes3
Copy link

tuxes3 commented Dec 21, 2021

@loevgaard not bad of an idea, but be sure to only not process the promotions which cannot be filtered. So only show the error on the promotion order_percentage_discount and promotion order_fixed_discount, probably check all existing standard promotions too.

@Roshyo I'm not sure about that, this is not possible in the moment as the gift card amount is set of the order item unit total, which subtracts all adjustments made. Furthermore I'm not sure if that would work legally for taxation.

@loevgaard loevgaard changed the title If a giftcard is buyed with a coupon code it affects its value If a giftcard is bought with a coupon code it affects its value Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants