Files
2025-08-02 16:30:27 +02:00

53 lines
1.5 KiB
PHP

<?php
namespace KupShop\OrderDiscountBundle\Triggers;
use KupShop\KupShopBundle\Context\CurrencyContext;
use KupShop\KupShopBundle\Query\JsonOperator;
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
use Query\Operator;
class CurrencyTrigger extends AbstractTrigger
{
protected static $type = 'currency';
protected static $position = 81;
protected $adminTemplate = 'triggers/currency.tpl';
/** @var CurrencyContext */
private $currencyContext;
/**
* @return $this
*
* @required
*/
public function setCurrencyContext(CurrencyContext $currencyContext)
{
$this->currencyContext = $currencyContext;
return $this;
}
private function getCurrencyId()
{
return $this->currencyContext->getActiveId();
}
public function getDiscountFilterSpec(PurchaseState $purchaseState)
{
return Operator::andX(
Operator::equals(['odt.type' => static::getType()]),
Operator::orX(
Operator::andX(
JsonOperator::contains('odt.data', 'currency', $this->getCurrencyId()),
JsonOperator::contains('odt.data', 'currency_invert', 'invert')
),
Operator::andX(
Operator::not(JsonOperator::contains('odt.data', 'currency', $this->getCurrencyId())),
Operator::not(JsonOperator::contains('odt.data', 'currency_invert', 'invert'))
)
)
);
}
}