45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace KupShop\OrderDiscountBundle\Actions;
|
|
|
|
use KupShop\KupShopBundle\Context\CurrencyContext;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use KupShop\KupShopBundle\Util\Price\Price;
|
|
use KupShop\OrderDiscountBundle\Entity\OrderDiscount;
|
|
use KupShop\OrderDiscountBundle\Util\DiscountUtil;
|
|
use KupShop\OrderingBundle\Entity\Purchase\DiscountPurchaseItem;
|
|
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
|
|
|
class FreeDeliveryAction extends AbstractAction
|
|
{
|
|
protected static $type = 'free_delivery';
|
|
protected static $position = 20;
|
|
protected $adminTemplate = 'actions/free_delivery.tpl';
|
|
|
|
/**
|
|
* @var DiscountUtil
|
|
*/
|
|
private $discountUtil;
|
|
|
|
public function applyResult(PurchaseState &$purchaseState, OrderDiscount $orderDiscount, array $data)
|
|
{
|
|
$this->messages = [];
|
|
$purchaseState->setFreeDelivery(true);
|
|
$purchaseState->setDeliveryPrice(new Price(toDecimal(0), Contexts::get(CurrencyContext::class)->getActive(), 0));
|
|
$name = $orderDiscount->getDisplayName();
|
|
$purchaseState->addDiscount(new DiscountPurchaseItem($name, $this->discountUtil->createDiscountPrice(toDecimal(0)), $orderDiscount->getId()));
|
|
|
|
if ($message = $data['messages']['success'] ?? '') {
|
|
$this->messages['success'] = $message;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @required
|
|
*/
|
|
public function setDiscountUtil(DiscountUtil $discountUtil)
|
|
{
|
|
$this->discountUtil = $discountUtil;
|
|
}
|
|
}
|