示例#1
0
 /**
  * Manages all models.
  */
 public function actionIndex($cat = null)
 {
     if (!$cat) {
         $cat = SnapUtil::config('boxomatic/supplier_product_feature_category');
     }
     $BoxoCart = new BoxoCart();
     if (isset($_GET['set-date'])) {
         $BoxoCart->setDelivery_date_id($_GET['set-date']);
     }
     if (isset($_POST['BoxoCart']['location_id'])) {
         $BoxoCart->location_id = $_POST['BoxoCart']['location_id'];
         $this->refresh();
     }
     if (isset($_POST['Order']) && isset($_POST['add_to_cart'])) {
         if ($BoxoCart->addItems($_POST['Order'])) {
             Yii::app()->user->setFlash('success', 'Item added to cart.');
             #redirect to category
             if ($cat == 'box') {
                 $this->redirect(array('shop/index', 'date' => Yii::app()->request->getParam('date'), 'cat' => SnapUtil::config('boxomatic/redirectBoxCategory')));
             }
         }
         $this->refresh();
     }
     if (isset($_POST['Order']) && (isset($_POST['update_cart']) || isset($_POST['checkout']))) {
         if ($BoxoCart->updateItems($_POST['Order'])) {
             Yii::app()->user->setFlash('success', 'Cart updated.');
         }
         if (isset($_POST['checkout'])) {
             $this->redirect(array('shop/checkout'));
         }
         $this->refresh();
     }
     $userId = Yii::app()->user->id;
     $User = BoxomaticUser::model()->findByPk($userId);
     $Category = Category::model()->findByPk($cat);
     $DeliveryDate = false;
     $dpProducts = false;
     $Location = $BoxoCart->Location;
     if ($Location) {
         if (!$BoxoCart->DeliveryDate) {
             $DeliveryDate = $BoxoCart->getNextDeliveryDate();
         } else {
             $DeliveryDate = $BoxoCart->DeliveryDate;
         }
         $BoxoCart->setDelivery_date_id($DeliveryDate->id);
         $products = SupplierProduct::getAvailableItems($DeliveryDate->id, $cat);
         $dpProducts = new CActiveDataProvider('SupplierProduct');
         $dpProducts->setData($products);
     }
     $this->render('index', array('dpProducts' => $dpProducts, 'DeliveryDate' => $DeliveryDate, 'Category' => $Category, 'Customer' => $User, 'curCat' => $cat, 'BoxoCart' => $BoxoCart, 'Location' => $Location));
 }