Beispiel #1
0
 /**
  * Upgrrades a Draft Order to a Main Order
  * @param  APP_Draft_Order $draft_order The draft order to Upgrade
  * @return APP_Order              		An upgraded order
  */
 public static function upgrade($draft_order)
 {
     if (!$draft_order instanceof APP_Draft_Order) {
         trigger_error('Invalid draft order given. Must be instance of APP_Draft_Order');
     }
     $order = APP_Order_Factory::create();
     $order->set_description($draft_order->get_description());
     $order->set_gateway($draft_order->get_gateway());
     $order->set_currency($draft_order->get_currency());
     foreach ($draft_order->get_items() as $item) {
         $order->add_item($item['type'], $item['price'], $item['post_id']);
     }
     return $order;
 }
 /**
  * Test creating a draft order and upgrading it
  */
 public function test_draft_order_creation()
 {
     $order = appthemes_new_order();
     $this->assertNotEmpty($order);
     $draft_order = new APP_Draft_Order();
     $draft_order->set_description('Draft');
     $draft_order->set_gateway('paypal');
     $draft_order->set_currency('EUR');
     $draft_order->add_item('test', 5, $order->get_id());
     $this->assertEquals('Draft', $draft_order->get_description());
     $this->assertEquals('paypal', $draft_order->get_gateway());
     $this->assertEquals('EUR', $draft_order->get_currency());
     $this->assertEquals(5, $draft_order->get_total());
     $this->assertCount(1, $draft_order->get_items());
     $new_order = appthemes_new_order($draft_order);
     $this->assertEquals('Draft', $new_order->get_description());
     $this->assertEquals('paypal', $new_order->get_gateway());
     $this->assertEquals('EUR', $new_order->get_currency());
     $this->assertEquals(5, $new_order->get_total());
     $this->assertCount(1, $new_order->get_items());
 }
Beispiel #3
0
 /**
  * Checks that the total returns properly
  */
 function test_get_total_basic()
 {
     $order = new APP_Draft_Order();
     // By default, order's totals should be 0
     $this->assertEquals(0, $order->get_total());
     // Total should reflect added items prices
     $order->add_item('payment-test', 5, $order->get_id());
     $this->assertCount(1, $order->get_items());
     $this->assertEquals(5, $order->get_total());
     // Adding another item should increase the price
     $order->add_item('payment-test', 5, $order->get_id());
     $this->assertCount(2, $order->get_items());
     $this->assertEquals(10, $order->get_total());
     // Adding another item type should increase the price
     $order->add_item('payment-test1', 5, $order->get_id());
     $this->assertCount(3, $order->get_items());
     $this->assertEquals(15, $order->get_total());
     // Adding a float value as a price should correctly calculate the total with cents
     $order->add_item('payment-test1', 5.99, $order->get_id());
     $this->assertCount(4, $order->get_items());
     $this->assertEquals(20.99, $order->get_total());
 }