b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / MageWorx / GiftCards / Model / Total / Creditmemo /
Filename/home/dev2.destoffenstraat.com/app/code/MageWorx/GiftCards/Model/Total/Creditmemo/GiftCards.php
Size2.61 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified13-May-2022 10:39
Last accessed22-Aug-2025 14:45
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © MageWorx. All rights reserved.
* See LICENSE.txt for license details.
*/

namespace MageWorx\GiftCards\Model\Total\Creditmemo;

use Magento\Sales\Model\Order\Creditmemo\Total\AbstractTotal;

class GiftCards extends AbstractTotal
{
/**
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this|AbstractTotal
*/
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$order = $creditmemo->getOrder();
if ($order->getMageworxGiftcardsAmount() < 0) {
$orderMageworxGiftcardsAmountRefunded = 0;
$orderBaseMageworxGiftcardsAmountRefunded = 0;
foreach ($order->getCreditmemosCollection() as $oldCreditmemo) {
$orderMageworxGiftcardsAmountRefunded += $oldCreditmemo->getMageworxGiftcardsAmount();
$orderBaseMageworxGiftcardsAmountRefunded += $oldCreditmemo->getBaseMageworxGiftcardsAmount();
}
if (($creditmemo->getGrandTotal() + $order->getMageworxGiftcardsAmount()
- $orderMageworxGiftcardsAmountRefunded) > 0) {
$creditmemo->setMageworxGiftcardsAmount(
$order->getMageworxGiftcardsAmount() - $orderMageworxGiftcardsAmountRefunded
);
$creditmemo->setBaseMageworxGiftcardsAmount(
$order->getBaseMageworxGiftcardsAmount() - $orderBaseMageworxGiftcardsAmountRefunded
);
$creditmemo->setMageworxGiftcardsDescription($order->getMageworxGiftcardsDescription());
} else {
//for case when gift card amount more then creditmemo amount
$creditmemo->setMageworxGiftcardsAmount(
$order->getMageworxGiftcardsAmountRefunded() - $creditmemo->getGrandTotal()
);
$creditmemo->setBaseMageworxGiftcardsAmount(
$order->getBaseMageworxGiftcardsAmountRefunded() - $creditmemo->getBaseGrandTotal()
);
$creditmemo->setMageworxGiftcardsDescription($order->getMageworxGiftcardsDescription());
}
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $creditmemo->getMageworxGiftcardsAmount());
$creditmemo->setBaseGrandTotal(
$creditmemo->getBaseGrandTotal() + $creditmemo->getBaseMageworxGiftcardsAmount()
);
} else {
$creditmemo->setMageworxGiftcardsAmount(0);
$creditmemo->setBaseMageworxGiftcardsAmount(0);
$creditmemo->setMageworxGiftcardsDetails('');
}

return $this;
}
}