Skip to content

Commit

Permalink
Remove 'spend_points' from session after order placement
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaahed committed Dec 22, 2023
1 parent 78afa03 commit f43b3a2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Plugin/RemoveSpendPointsFromSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);
/**
* @copyright Copyright (c) Vendic B.V https://vendic.nl/
*/

namespace Vendic\HyvaCheckoutMirasvitRewards\Plugin;

use Magento\Checkout\Model\Session;
use Magento\Quote\Api\CartManagementInterface;

class RemoveSpendPointsFromSession
{

private const SPEND_POINTS = 'spend_points';

public function __construct(private Session $checkoutSession)
{
}

/**
* After an order is placed, the spent points should be
* reset to zero on the session so that the old spent points won't
* be displayed again on the checkout page.
*
* @param CartManagementInterface $subject
* @param int $result
* @return int
*/
public function afterPlaceOrder(
CartManagementInterface $subject,
$result,
) {
$this->checkoutSession->setData(self::SPEND_POINTS, 0);
return $result;
}
}
13 changes: 13 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* @copyright Copyright (c) Vendic B.V https://vendic.nl/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Api\CartManagementInterface">
<plugin name="vendic_remove_spend_points_from_checkout_session"
type="Vendic\HyvaCheckoutMirasvitRewards\Plugin\RemoveSpendPointsFromSession"/>
</type>
</config>

0 comments on commit f43b3a2

Please sign in to comment.