Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
/**
 * Creates a blank order object, or upgrades a draft order
 * @param  APP_Draft_order $draft_order A draft order to be upgraded
 * @return APP_Order                    An order object representing the new order
 */
function appthemes_new_order($draft_order = null)
{
    if (!empty($draft_order)) {
        return APP_Draft_Order::upgrade($draft_order);
    } else {
        return APP_Order_Factory::create();
    }
}
Ejemplo n.º 3
0
 public function test_register()
 {
     $queue = new APP_Order_Processing();
     $queue->schedule_process();
     $this->assertNotEquals(0, wp_next_scheduled('app_order_processing'));
     $draft = new APP_Draft_Order();
     $draft->complete();
     $new_order = APP_Draft_Order::upgrade($draft);
     $child_order = APP_Order_Factory::duplicate($new_order);
     $child_order->set_gateway('mock-gateway');
     wp_update_post(array('ID' => $child_order->get_id(), 'post_status' => APPTHEMES_ORDER_COMPLETED, 'post_parent' => $new_order->get_id()));
     $child_order->schedule_payment(date('Y-m-d H:i:s', strtotime('-1 day')));
     $items_processed = $queue->process();
     $this->assertEquals(1, $items_processed);
     $order = appthemes_get_order($child_order->get_id(), true);
     $this->assertEquals(APPTHEMES_ORDER_ACTIVATED, $order->get_status());
 }
Ejemplo n.º 4
0
 public function test_upgrade_order()
 {
     $order = new APP_Draft_Order();
     $order->set_description('Draft');
     $order->set_gateway('paypal');
     $order->set_currency('EUR');
     // We need an existing order that can be connected to
     $real_order = APP_Order_Factory::create();
     $status = $order->add_item('test', 5, $real_order->get_id());
     $new_real_order = APP_Draft_Order::upgrade($order);
     $this->assertEquals('Draft', $new_real_order->get_description());
     $this->assertEquals('paypal', $new_real_order->get_gateway());
     $this->assertEquals('EUR', $new_real_order->get_currency());
     $this->assertCount(1, $new_real_order->get_items());
     $this->assertEquals(5, $new_real_order->get_total());
 }
Ejemplo n.º 5
0
 /**
  * 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());
 }