View source
<?php
namespace Drupal\Tests\commerce_promotion\Kernel\Plugin\Commerce\PromotionOffer;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_price\Calculator;
use Drupal\commerce_price\Price;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_product\Entity\ProductType;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class BuyXGetYTest extends OrderKernelTestBase {
protected $order;
protected $promotion;
protected $variations = [];
public static $modules = [
'commerce_promotion',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_promotion');
$this
->installConfig([
'commerce_promotion',
]);
$this
->installSchema('commerce_promotion', [
'commerce_promotion_usage',
]);
$product_type = ProductType::create([
'id' => 'test',
'label' => 'Test',
'variationType' => 'default',
]);
$product_type
->save();
for ($i = 0; $i < 4; $i++) {
$this->variations[$i] = ProductVariation::create([
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => Calculator::multiply('10', $i + 1),
'currency_code' => 'USD',
],
]);
$this->variations[$i]
->save();
}
$first_product = Product::create([
'type' => 'test',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$this->variations[0],
],
]);
$first_product
->save();
$second_product = Product::create([
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$this->variations[1],
],
]);
$second_product
->save();
$third_product = Product::create([
'type' => 'default',
'title' => 'Hat 1',
'stores' => [
$this->store,
],
'variations' => [
$this->variations[2],
],
]);
$third_product
->save();
$fourth_product = Product::create([
'type' => 'default',
'title' => 'Hat 2',
'stores' => [
$this->store,
],
'variations' => [
$this->variations[3],
],
]);
$fourth_product
->save();
$this->order = Order::create([
'type' => 'default',
'state' => 'completed',
'mail' => 'test@example.com',
'ip_address' => '127.0.0.1',
'order_number' => '6',
'uid' => $this
->createUser(),
'store_id' => $this->store,
'order_items' => [],
]);
$promotion = Promotion::create([
'name' => 'Promotion 1',
'order_types' => [
$this->order
->bundle(),
],
'stores' => [
$this->store
->id(),
],
'offer' => [
'target_plugin_id' => 'order_buy_x_get_y',
'target_plugin_configuration' => [
'buy_quantity' => 6,
'buy_conditions' => [
[
'plugin' => 'order_item_product_type',
'configuration' => [
'product_types' => [
'test',
],
],
],
],
'get_quantity' => 4,
'get_conditions' => [
[
'plugin' => 'order_item_product',
'configuration' => [
'products' => [
[
'product' => $third_product
->uuid(),
],
[
'product' => $fourth_product
->uuid(),
],
],
],
],
],
'offer_type' => 'fixed_amount',
'offer_amount' => [
'number' => '1.00',
'currency_code' => 'USD',
],
],
],
'status' => TRUE,
]);
$promotion
->save();
$this->promotion = $this
->reloadEntity($promotion);
}
public function testNotApplicable() {
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '2',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[1], [
'quantity' => '4',
]);
$second_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEmpty($this->order
->collectAdjustments());
$first_order_item
->setQuantity(6);
$first_order_item
->save();
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEmpty($this->order
->collectAdjustments());
}
public function testFixedAmountOff() {
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '7',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[1], [
'quantity' => '2',
]);
$third_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '3',
]);
$second_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
$third_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Discount', $adjustment
->getLabel());
$this
->assertEquals(new Price('-3', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
$fourth_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '2',
]);
$this->order
->addItem($fourth_order_item);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item, $fourth_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$this
->assertCount(1, $fourth_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Discount', $adjustment
->getLabel());
$this
->assertEquals(new Price('-3', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
$adjustments = $fourth_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Discount', $adjustment
->getLabel());
$this
->assertEquals(new Price('-1', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
public function testPercentageOff() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['offer_type'] = 'percentage';
$offer_configuration['offer_percentage'] = '0.1';
$offer_configuration['offer_amount'] = NULL;
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$this->promotion
->setDisplayName('Buy X Get Y!');
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '13',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[1], [
'quantity' => '2',
]);
$third_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '6',
]);
$second_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
$third_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Buy X Get Y!', $adjustment
->getLabel());
$this
->assertEquals(new Price('-18', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
$fourth_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '3',
]);
$this->order
->addItem($fourth_order_item);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item, $fourth_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$this
->assertCount(1, $fourth_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Buy X Get Y!', $adjustment
->getLabel());
$this
->assertEquals(new Price('-18', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
$adjustments = $fourth_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals('Buy X Get Y!', $adjustment
->getLabel());
$this
->assertEquals(new Price('-6', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
public function testSameOrderItem() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['buy_quantity'] = '1';
$offer_configuration['buy_conditions'] = [];
$offer_configuration['get_quantity'] = '1';
$offer_configuration['get_conditions'] = [];
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '5',
]);
$order_item
->save();
$this->order
->addItem($order_item);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($order_item) = $this->order
->getItems();
$this
->assertCount(1, $order_item
->getAdjustments());
$adjustments = $order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals(new Price('-2', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
public function testOrderItemSorting() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['get_quantity'] = '1';
$offer_configuration['offer_type'] = 'percentage';
$offer_configuration['offer_percentage'] = '0.5';
$offer_configuration['offer_amount'] = NULL;
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '6',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[3], [
'quantity' => '1',
]);
$second_order_item
->save();
$third_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '1',
]);
$third_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
$third_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
}
public function testOrderItemSortingWithHigherValueGetCondition() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['buy_quantity'] = '2';
$offer_configuration['buy_conditions'] = [];
$offer_configuration['get_quantity'] = '1';
$offer_configuration['get_conditions'] = [
[
'plugin' => 'order_item_purchased_entity:commerce_product_variation',
'configuration' => [
'entities' => [
$this->variations[2]
->uuid(),
],
],
],
];
$offer_configuration['offer_type'] = 'percentage';
$offer_configuration['offer_percentage'] = '1';
$offer_configuration['offer_amount'] = NULL;
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '1',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[1], [
'quantity' => '1',
]);
$second_order_item
->save();
$third_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '1',
]);
$third_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
$third_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals(new Price('-30', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
public function testDecimalQuantities() {
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '2.5',
]);
$first_order_item
->save();
$second_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '3.5',
]);
$second_order_item
->save();
$third_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '1.5',
]);
$third_order_item
->save();
$fourth_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[2], [
'quantity' => '5.5',
]);
$fourth_order_item
->save();
$this->order
->setItems([
$first_order_item,
$second_order_item,
$third_order_item,
$fourth_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item, $third_order_item, $fourth_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(0, $second_order_item
->getAdjustments());
$this
->assertCount(1, $third_order_item
->getAdjustments());
$this
->assertCount(1, $fourth_order_item
->getAdjustments());
$adjustments = $third_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals(new Price('-1.5', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
$adjustments = $fourth_order_item
->getAdjustments();
$adjustment = reset($adjustments);
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals(new Price('-2.5', 'USD'), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
public function testAutoAddOrderItem() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['buy_quantity'] = '3';
$offer_configuration['buy_conditions'] = [];
$offer_configuration['get_quantity'] = '1';
$offer_configuration['get_conditions'] = [
[
'plugin' => 'order_item_purchased_entity:commerce_product_variation',
'configuration' => [
'entities' => [
$this->variations[2]
->uuid(),
],
],
],
];
$offer_configuration['get_auto_add'] = TRUE;
$offer_configuration['offer_type'] = 'percentage';
$offer_configuration['offer_percentage'] = '1';
$offer_configuration['offer_amount'] = NULL;
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '3',
]);
$this->order
->setItems([
$first_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertEquals(1, $second_order_item
->getQuantity());
$this
->assertEquals($this->variations[2]
->id(), $second_order_item
->getPurchasedEntityId());
$this
->assertAdjustmentPrice($second_order_item
->getAdjustments()[0], '-30');
$first_order_item
->setQuantity(4);
$this->order
->setItems([
$first_order_item,
$second_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertEquals(4, $first_order_item
->getQuantity());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertEquals(1, $second_order_item
->getQuantity());
$first_order_item
->setQuantity(6);
$this->order
->setItems([
$first_order_item,
$second_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertEquals(6, $first_order_item
->getQuantity());
$this
->assertCount(0, $first_order_item
->getAdjustments());
$this
->assertEquals(2, $second_order_item
->getQuantity());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertAdjustmentPrice($second_order_item
->getAdjustments()[0], '-60');
$this->order
->removeItem($second_order_item);
$this
->assertCount(1, $this->order
->getItems());
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertEquals(6, $first_order_item
->getQuantity());
$this
->assertEquals(2, $second_order_item
->getQuantity());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertAdjustmentPrice($second_order_item
->getAdjustments()[0], '-60');
$first_order_item
->setQuantity(5);
$this->order
->setItems([
$first_order_item,
$second_order_item,
]);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertEquals(5, $first_order_item
->getQuantity());
$this
->assertEquals(1, $second_order_item
->getQuantity());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertAdjustmentPrice($second_order_item
->getAdjustments()[0], '-30');
$this
->assertNotNull($second_order_item
->getData('promotion:1:auto_add_quantity'));
$second_order_item
->setQuantity('2');
$first_order_item
->setQuantity('1');
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list(, $second_order_item) = $this->order
->getItems();
$this
->assertNull($second_order_item
->getData('promotion:1:auto_add_quantity'));
$this
->assertEquals(1, $second_order_item
->getQuantity());
}
public function testAutoRemoveOrderItem() {
$offer = $this->promotion
->getOffer();
$offer_configuration = $offer
->getConfiguration();
$offer_configuration['buy_quantity'] = '1';
$offer_configuration['buy_conditions'] = [
[
'plugin' => 'order_item_purchased_entity:commerce_product_variation',
'configuration' => [
'entities' => [
$this->variations[0]
->uuid(),
],
],
],
];
$offer_configuration['get_quantity'] = '1';
$offer_configuration['get_conditions'] = [
[
'plugin' => 'order_item_purchased_entity:commerce_product_variation',
'configuration' => [
'entities' => [
$this->variations[1]
->uuid(),
],
],
],
];
$offer_configuration['get_auto_add'] = TRUE;
$offer_configuration['offer_type'] = 'percentage';
$offer_configuration['offer_percentage'] = '1';
$offer_configuration['offer_amount'] = NULL;
$offer
->setConfiguration($offer_configuration);
$this->promotion
->setOffer($offer);
$this->promotion
->set('conditions', [
[
'target_plugin_id' => 'order_total_price',
'target_plugin_configuration' => [
'operator' => '>=',
'amount' => [
'number' => '15.00',
'currency_code' => 'USD',
],
],
],
]);
$this->promotion
->save();
$this->variations[1]
->setPrice(new Price('15', 'USD'))
->save();
$order_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_order_item');
$first_order_item = $order_item_storage
->createFromPurchasableEntity($this->variations[0], [
'quantity' => '2',
]);
$first_order_item
->save();
$this->order
->setItems([
$first_order_item,
]);
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
list($first_order_item, $second_order_item) = $this->order
->getItems();
$this
->assertEquals(2, $first_order_item
->getQuantity());
$this
->assertEquals(2, $second_order_item
->getQuantity());
$this
->assertCount(1, $second_order_item
->getAdjustments());
$this
->assertAdjustmentPrice($second_order_item
->getAdjustments()[0], '-30');
$first_order_item
->setQuantity('1');
$first_order_item
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertCount(1, $this->order
->getItems());
$this
->assertEquals(new Price('10', 'USD'), $this->order
->getTotalPrice());
$first_order_item
->setQuantity('2');
$first_order_item
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertCount(2, $this->order
->getItems());
$this->promotion
->setEnabled(FALSE);
$this->promotion
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertCount(1, $this->order
->getItems());
$this->promotion
->setEnabled(TRUE);
$this->promotion
->save();
$this->variations[1]
->setPrice(new Price('0', 'USD'));
$this->variations[1]
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$order_items = $this->order
->getItems();
$this
->assertCount(2, $order_items);
$this
->assertEquals(new Price('0', 'USD'), $order_items[1]
->getUnitPrice());
$this->promotion
->setEnabled(FALSE);
$this->promotion
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$order_items = $this->order
->getItems();
$this
->assertCount(1, $order_items);
$this
->assertEquals(new Price('20', 'USD'), $order_items[0]
->getTotalPrice());
}
protected function assertAdjustmentPrice(Adjustment $adjustment, $price, $currency_code = 'USD') {
$this
->assertEquals('promotion', $adjustment
->getType());
$this
->assertEquals(new Price($price, $currency_code), $adjustment
->getAmount());
$this
->assertEquals($this->promotion
->id(), $adjustment
->getSourceId());
}
}