Skip to content
Snippets Groups Projects
Commit c20317fe authored by Roman Khimin's avatar Roman Khimin Committed by Jonathan Sacksick
Browse files

Issue #3407043 by khiminrm, rszrama: Add a negate option to the customer...

Issue #3407043 by khiminrm, rszrama: Add a negate option to the customer shipping/billing address condition.
parent e94b9789
No related branches found
No related tags found
7 merge requests!418Issue #3511232 by ccjjmartin: Fix add to cart dropdown when only one non-default variation type is provided,!379Issue #3491248 Validation is breaking the amount number format decimal point,!375Issue #3413020 by czigor: Using a translatable string as a category for field...,!357Issue #2914933: Add service tags to order-related interfaces,!344Resolve #3107602 "Product attributes do not update visually when switching variations",!343Resolve #3107602 "Product attributes do not update visually when switching variations",!342Issue #3476581 by josephr5000: add OrderItemLabelEvent
Pipeline #70477 passed with warnings
......@@ -18,6 +18,7 @@ abstract class CustomerAddressBase extends ConditionBase {
public function defaultConfiguration() {
return [
'zone' => NULL,
'operator' => 'in',
] + parent::defaultConfiguration();
}
......@@ -27,6 +28,17 @@ abstract class CustomerAddressBase extends ConditionBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['operator'] = [
'#type' => 'select',
'#field_prefix' => $this->t('Address '),
'#field_suffix' => $this->t(' in one of the following territories:'),
'#options' => [
'in' => $this->t('must be'),
'not in' => $this->t('must NOT be'),
],
'#default_value' => $this->configuration['operator'],
];
$form['zone'] = [
'#type' => 'address_zone',
'#default_value' => $this->configuration['zone'],
......@@ -51,6 +63,7 @@ abstract class CustomerAddressBase extends ConditionBase {
unset($values['zone']['label']);
$this->configuration['zone'] = $values['zone'];
$this->configuration['operator'] = $values['operator'];
}
/**
......@@ -78,6 +91,10 @@ abstract class CustomerAddressBase extends ConditionBase {
return FALSE;
}
if (!empty($this->configuration['operator']) && $this->configuration['operator'] == 'not in') {
return !$zone->match($address);
}
return $zone->match($address);
}
......
......@@ -59,6 +59,16 @@ class OrderBillingAddressTest extends UnitTestCase {
], 'order_billing_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'billing']);
$this->assertFalse($condition->evaluate($order));
$condition = new OrderBillingAddress([
'zone' => [
'territories' => [
['country_code' => 'US', 'administrative_area' => 'CA'],
],
],
'operator' => 'not in',
], 'order_billing_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'billing']);
$this->assertTrue($condition->evaluate($order));
$condition = new OrderBillingAddress([
'zone' => [
'territories' => [
......@@ -67,6 +77,16 @@ class OrderBillingAddressTest extends UnitTestCase {
],
], 'order_billing_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'billing']);
$this->assertTrue($condition->evaluate($order));
$condition = new OrderBillingAddress([
'zone' => [
'territories' => [
['country_code' => 'US', 'administrative_area' => 'SC'],
],
],
'operator' => 'not in',
], 'order_billing_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'billing']);
$this->assertFalse($condition->evaluate($order));
}
}
......@@ -58,6 +58,16 @@ class OrderShippingAddressTest extends UnitTestCase {
], 'order_shipping_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'shipping']);
$this->assertFalse($condition->evaluate($order));
$condition = new OrderShippingAddress([
'zone' => [
'territories' => [
['country_code' => 'US', 'administrative_area' => 'CA'],
],
],
'operator' => 'not in',
], 'order_shipping_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'shipping']);
$this->assertTrue($condition->evaluate($order));
$condition = new OrderShippingAddress([
'zone' => [
'territories' => [
......@@ -66,6 +76,16 @@ class OrderShippingAddressTest extends UnitTestCase {
],
], 'order_shipping_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'shipping']);
$this->assertTrue($condition->evaluate($order));
$condition = new OrderShippingAddress([
'zone' => [
'territories' => [
['country_code' => 'US', 'administrative_area' => 'SC'],
],
],
'operator' => 'not in',
], 'order_shipping_address', ['entity_type' => 'commerce_order', 'profile_scope' => 'shipping']);
$this->assertFalse($condition->evaluate($order));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment