53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\OrderDiscountBundle\Triggers;
|
|
|
|
use KupShop\KupShopBundle\Context\CountryContext;
|
|
use KupShop\KupShopBundle\Query\JsonOperator;
|
|
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
|
use Query\Operator;
|
|
|
|
class CountryTrigger extends AbstractTrigger
|
|
{
|
|
protected static $type = 'country';
|
|
protected static $position = 80;
|
|
protected $adminTemplate = 'triggers/country.tpl';
|
|
|
|
/** @var CountryContext */
|
|
private $countryContext;
|
|
|
|
/**
|
|
* @return $this
|
|
*
|
|
* @required
|
|
*/
|
|
public function setCountryContext(CountryContext $countryContext)
|
|
{
|
|
$this->countryContext = $countryContext;
|
|
|
|
return $this;
|
|
}
|
|
|
|
private function getCountryId()
|
|
{
|
|
return $this->countryContext->getActiveId();
|
|
}
|
|
|
|
public function getDiscountFilterSpec(PurchaseState $purchaseState)
|
|
{
|
|
return Operator::andX(
|
|
Operator::equals(['odt.type' => static::getType()]),
|
|
Operator::orX(
|
|
Operator::andX(
|
|
JsonOperator::contains('odt.data', 'country', $this->getCountryId()),
|
|
JsonOperator::contains('odt.data', 'country_invert', 'invert')
|
|
),
|
|
Operator::andX(
|
|
Operator::not(JsonOperator::contains('odt.data', 'country', $this->getCountryId())),
|
|
Operator::not(JsonOperator::contains('odt.data', 'country_invert', 'invert'))
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|