/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new DeliveryAddress();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['DeliveryAddress'])) {
         $model->attributes = $_POST['DeliveryAddress'];
         if ($model->save()) {
             $this->redirect(array('admin', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#2
0
 public function actionConfirm()
 {
     Yii::app()->user->setState('order_comment', @$_POST['Order']['Comment']);
     if (isset($_POST['accept_terms']) && $_POST['accept_terms'] == 1) {
         $order = new Order();
         $customer = Shop::getCustomer();
         $cart = Shop::getCartContent();
         $order->customer_id = $customer->customer_id;
         $address = new DeliveryAddress();
         if ($customer->deliveryAddress) {
             $address->attributes = $customer->deliveryAddress->attributes;
         } else {
             $address->attributes = $customer->address->attributes;
         }
         $address->save();
         $order->delivery_address_id = $address->id;
         $address = new BillingAddress();
         if ($customer->billingAddress) {
             $address->attributes = $customer->billingAddress->attributes;
         } else {
             $address->attributes = $customer->address->attributes;
         }
         $address->save();
         $order->billing_address_id = $address->id;
         $order->ordering_date = time();
         $order->payment_method = Yii::app()->user->getState('payment_method');
         $order->shipping_method = Yii::app()->user->getState('shipping_method');
         $order->comment = Yii::app()->user->getState('order_comment');
         $order->status = 'new';
         if ($order->save()) {
             foreach ($cart as $position => $product) {
                 $position = new OrderPosition();
                 $position->order_id = $order->order_id;
                 $position->product_id = $product['product_id'];
                 $position->amount = $product['amount'];
                 $position->specifications = json_encode($product['Variations']);
                 $position->save();
             }
             Shop::mailNotification($order);
             Shop::flushCart(true);
             if (Shop::module()->payPalMethod !== false && $order->payment_method == Shop::module()->payPalMethod) {
                 $this->redirect(array(Shop::module()->payPalUrl, 'order_id' => $order->order_id));
             } else {
                 $this->redirect(Shop::module()->successAction);
             }
         }
         $this->redirect(Shop::module()->failureAction);
     } else {
         Shop::setFlash(Shop::t('Please accept our Terms and Conditions to continue'));
         $this->redirect(array('//shop/order/create'));
     }
 }