OrderConditionBase.php in Ubercart 8.4
File
uc_order/src/Plugin/Condition/OrderConditionBase.php
View source
<?php
namespace Drupal\uc_order\Plugin\Condition;
use Drupal\Core\Database\Connection;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\rules\Core\RulesConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class OrderConditionBase extends RulesConditionBase implements ContainerFactoryPluginInterface {
protected $database;
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->database = $database;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('database'));
}
public function comparisonOptions() {
return [
'less' => $this
->t('Total is less than specified value.'),
'less_equal' => $this
->t('Total is less than or equal to specified value.'),
'equal' => $this
->t('Total is equal to specified value.'),
'greater_equal' => $this
->t('Total is greater than or equal to specified value.'),
'greater' => $this
->t('Total is greater than specified value.'),
];
}
public function compareComparisonOptions($source, $operator, $target) {
switch ($operator) {
case 'less':
return $source < $target;
case 'less_equal':
return $source <= $target;
case 'equal':
return $source == $target;
case 'greater_equal':
return $source >= $target;
case 'greater':
return $source > $target;
}
}
}