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