frontend/controllers/OrderController.php
/**
     * Creates new order
     *
     * @param  integer $voucher voucher id
     * @return mixed
     */
Creates new order
@param  integer $voucher voucher id
@return mixed
Creates new order @param integer $voucher voucher id @return mixed
public function actionCreateForVoucher($id)
    {
        $user = Yii::$app->user->identity;
        $voucher = Voucher::find()
            ->where(['id' => $id])
            ->andWhere(['issuer_id' => $user->id])
            ->one();
        $fee = ResellerFee::findByUser($user);
        if ($voucher != null) {
            $order = new Order();
            $order->setScenario(Order::SCENARIO_CREATE);
            $order->user_id = $user->id;
            if ($fee != null) {
                $order->cost = $fee->applyDiscount($voucher->product->price);
            } else {
                $order->cost = $voucher->product->price;
            }
            $order->currency = $voucher->product->price_currency;
            $order->description = $voucher->product->description;
            $order->product_id = $voucher->product->id;
            $order->status = Order::STATUS_PENDING;
            $order->addOrderData('voucher', $voucher->id);
            if ($order->save()) {
                return $this->redirect(Url::to(['@order_checkout', 'id' => $order->id]));
            } else {
                return $this->redirect(Url::previous());
            }
        }
        throw new HttpException(500, 'Invalid voucher. Please try again later.');
    }
public function actionCreateForVoucher ( $ id ) { $ user = Yii :: $ app -> user -> identity ; $ voucher = Voucher :: find ( ) -> where ( [ 'id' => $ id ] ) -> andWhere ( [ 'issuer_id' => $ user -> id ] ) -> one ( ) ; $ fee = ResellerFee :: findByUser ( $ user ) ; if ( $ voucher != null ) { $ order = new Order ( ) ; $ order -> setScenario ( Order :: SCENARIO_CREATE ) ; $ order -> user_id = $ user -> id ; if ( $ fee != null ) { $ order -> cost = $ fee -> applyDiscount ( $ voucher -> product -> price ) ; } else { $ order -> cost = $ voucher -> product -> price ; } $ order -> currency = $ voucher -> product -> price_currency ; $ order -> description = $ voucher -> product -> description ; $ order -> product_id = $ voucher -> product -> id ; $ order -> status = Order :: STATUS_PENDING ; $ order -> addOrderData ( 'voucher' , $ voucher -> id ) ; if ( $ order -> save ( ) ) { return $ this -> redirect ( Url :: to ( [ '@order_checkout' , 'id' => $ order -> id ] ) ) ; } else { return $ this -> redirect ( Url :: previous ( ) ) ; } } throw new HttpException ( 500 , 'Invalid voucher. Please try again later.' ) ; }
Creates new order
 @param  integer $voucher voucher id
 @return mixed
Creates new order @param integer $voucher voucher id @return mixed