Setono/SyliusGiftCardPlugin

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

lamasfoker opened this issue · 6 comments

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€

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.

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

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

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.

@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.