Commit 4108a137 authored by bojanz's avatar bojanz

Issue #2833000 by skyredwang, bojanz: Price::greaterThan() must be an instance...

Issue #2833000 by skyredwang, bojanz: Price::greaterThan() must be an instance of Drupal\commerce_price\Price
parent eaa3be0e
......@@ -3,6 +3,7 @@
namespace Drupal\commerce_promotion\Plugin\Commerce\PromotionCondition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_price\Price;
/**
* Provides an 'Order: Total amount comparison' condition.
......@@ -52,12 +53,16 @@ class OrderTotalPrice extends PromotionConditionBase {
* {@inheritdoc}
*/
public function evaluate() {
$amount = $this->configuration['amount'];
if (empty($amount)) {
return FALSE;
}
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $this->getTargetEntity();
/** @var \Drupal\commerce_price\Price $total_price */
$total_price = $order->getTotalPrice();
/** @var \Drupal\commerce_price\Price $comparison_price */
$comparison_price = $this->configuration['amount'];
$comparison_price = new Price($amount['number'], $amount['currency_code']);
switch ($this->configuration['operator']) {
case '==':
......
......@@ -5,7 +5,6 @@ namespace Drupal\Tests\commerce_promotion\Kernel;
use Drupal\commerce_order\Entity\OrderItem;
use Drupal\commerce_order\Entity\OrderItemType;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_price\Price;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase;
......@@ -80,7 +79,7 @@ class PromotionConditionTest extends CommerceKernelTestBase {
}
/**
* Tests the order amount condition.
* Tests the order total condition.
*/
public function testOrderTotal() {
// Use addOrderItem so the total is calculated.
......@@ -111,7 +110,10 @@ class PromotionConditionTest extends CommerceKernelTestBase {
[
'target_plugin_id' => 'commerce_promotion_order_total_price',
'target_plugin_configuration' => [
'amount' => new Price('20.00', 'USD'),
'amount' => [
'number' => '20.00',
'currency_code' => 'USD',
],
],
],
],
......@@ -119,7 +121,6 @@ class PromotionConditionTest extends CommerceKernelTestBase {
$promotion->save();
$result = $promotion->applies($this->order);
$this->assertTrue($result);
$promotion = Promotion::create([
......@@ -137,7 +138,10 @@ class PromotionConditionTest extends CommerceKernelTestBase {
[
'target_plugin_id' => 'commerce_promotion_order_total_price',
'target_plugin_configuration' => [
'amount' => new Price('50.00', 'USD'),
'amount' => [
'number' => '50.00',
'currency_code' => 'USD',
],
],
],
],
......
......@@ -107,7 +107,10 @@ class PromotionOrderProcessorTest extends CommerceKernelTestBase {
[
'target_plugin_id' => 'commerce_promotion_order_total_price',
'target_plugin_configuration' => [
'amount' => new Price('20.00', 'USD'),
'amount' => [
'number' => '20.00',
'currency_code' => 'USD',
],
],
],
],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment