55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace KupShop\OrderDiscountBundle\Triggers;
|
|
|
|
use KupShop\KupShopBundle\Context\UserContext;
|
|
use KupShop\KupShopBundle\Query\JsonOperator;
|
|
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
|
use Query\Operator;
|
|
|
|
class UserNewsletterTrigger extends AbstractTrigger
|
|
{
|
|
protected static $type = 'user_newsletter';
|
|
protected static $position = 65;
|
|
protected $adminTemplate = 'triggers/user_newsletter.tpl';
|
|
|
|
/** @var UserContext */
|
|
private $userContext;
|
|
|
|
/**
|
|
* @return $this
|
|
*
|
|
* @required
|
|
*/
|
|
public function setUserContext(UserContext $userContext)
|
|
{
|
|
$this->userContext = $userContext;
|
|
|
|
return $this;
|
|
}
|
|
|
|
private function getUserNews()
|
|
{
|
|
if ($user = $this->userContext->getActive()) {
|
|
return $user->get_news ?? 'N';
|
|
}
|
|
|
|
return 'N';
|
|
}
|
|
|
|
public function getDiscountFilterSpec(PurchaseState $purchaseState)
|
|
{
|
|
return Operator::andX(
|
|
Operator::equals(['odt.type' => static::getType()]),
|
|
Operator::not(JsonOperator::contains('odt.data', 'user_newsletter', $this->getUserNews()))
|
|
);
|
|
}
|
|
|
|
public function handleData($data)
|
|
{
|
|
$data['user_newsletter'] = strval($data['user_newsletter']);
|
|
|
|
return $data;
|
|
}
|
|
}
|