public function actionCreate()
 {
     if ($model = Shop::getCustomer()) {
         $address = $model->address;
     } else {
         $model = new Customer();
     }
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         if (isset($_POST['Address'])) {
             $address = new Address();
             $address->attributes = $_POST['Address'];
             if ($address->save()) {
                 $model->address_id = $address->id;
             }
         }
         if (!Yii::app()->user->isGuest) {
             $model->user_id = Yii::app()->user->id;
         }
         if ($model->save()) {
             Yii::app()->user->setState('customer_id', $model->customer_id);
             $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id));
         }
     }
     $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address()));
 }
 public function actionCreate()
 {
     // if some data has been entered before or the user is already logged in,
     // take the already existing data and prefill the input form
     if ($model = Shop::getCustomer()) {
         $address = $model->address;
     } else {
         $model = new Customer();
     }
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         if (isset($_POST['Address'])) {
             $address = new Address();
             $address->attributes = $_POST['Address'];
             if ($address->save()) {
                 $model->address_id = $address->id;
             }
         }
         if (!Yii::app()->user->isGuest) {
             $model->user_id = Yii::app()->user->id;
         }
         $model->validate();
         if (Shop::module()->useWithYum && isset($_POST['register']) && ($_POST['register'] = true)) {
             if (isset($_POST['Customer']['password']) && isset($_POST['Customer']['passwordRepeat'])) {
                 if ($_POST['Customer']['password'] != $_POST['Customer']['passwordRepeat']) {
                     $model->addError('password', Shop::t('Passwords do not match'));
                 } else {
                     if ($_POST['Customer']['password'] == '') {
                         $model->addError('password', Shop::t('Password is empty'));
                     } else {
                         $user = new YumUser();
                         $profile = new YumProfile();
                         $profile->attributes = $_POST['Customer'];
                         $profile->attributes = $_POST['Address'];
                         if ($user->register(strtr($model->email, array('@' => '_', '.' => '_')), $_POST['Customer']['password'], $profile)) {
                             $user->status = YumUser::STATUS_ACTIVE;
                             $user->save(false, array('status'));
                             $model->user_id = $user->id;
                             Shop::setFlash(Shop::t('Successfully registered user'));
                         } else {
                             $model->addErrors($user->getErrors());
                             $model->addErrors($profile->getErrors());
                             Shop::setFlash(Shop::t('Error while registering user'));
                         }
                     }
                 }
             }
         }
         if (!$model->hasErrors()) {
             if ($model->save()) {
                 Yii::app()->user->setState('customer_id', $model->customer_id);
                 $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id));
             }
         }
     }
     $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address()));
 }
 public function actionChoose()
 {
     $this->render('choose', array('customer' => Shop::getCustomer()));
 }
Example #4
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'));
     }
 }
Example #5
0
$this->renderPartial('/order/waypoint', array('point' => 4));
$this->breadcrumbs = array(Shop::t('Order') => array('index'), Shop::t('New Order'));
?>

<?php 
Shop::renderFlash();
echo CHtml::beginForm(array('//shop/order/confirm'));
echo '<h2>' . Shop::t('Confirmation') . '</h2>';
if (Shop::getCartContent() == array()) {
    return false;
}
// If the customer is not passed over to the view, we assume the user is
// logged in and we fetch the customer data from the customer table
if (!isset($customer)) {
    $customer = Shop::getCustomer();
}
$this->renderPartial('application.modules.shop.views.customer.view', array('model' => $customer, 'hideAddress' => true, 'hideEmail' => true));
echo '<br />';
echo '<hr />';
echo '<p>';
$shipping = ShippingMethod::model()->find('id = :id', array(':id' => Yii::app()->user->getState('shipping_method')));
echo '<strong>' . Shop::t('Shipping Method') . ': </strong>' . ' ' . $shipping->title . ' (' . $shipping->description . ')';
echo '<br />';
echo CHtml::link(Shop::t('Edit shipping method'), array('//shop/shippingMethod/choose', 'order' => true));
echo '</p>';
echo '<p>';
$payment = PaymentMethod::model()->findByPk(Yii::app()->user->getState('payment_method'));
echo '<strong>' . Shop::t('Payment method') . ': </strong>' . ' ' . $payment->title . ' (' . $payment->description . ')';
echo '<br />';
echo CHtml::link(Shop::t('Edit payment method'), array('//shop/paymentMethod/choose', 'order' => true));