private static function cartCheck()
 {
     //Only check if the total amount is match
     $app = \Slim\Slim::getInstance();
     $data = $app->request->post();
     $data['items'] = json_decode($data['items']);
     if (!$data['items'] || !is_array($data['items'])) {
         //if cart item is empty
         $app->halt(400, json_encode('Cart Info is invalid.'));
     }
     $coupons = [];
     if (isset($data['coupons'])) {
         $coupons = json_decode($data['coupons']);
     }
     $sum = 0;
     foreach ($data['items'] as $key => $value) {
         //validate shopping cart object is valid
         StoreController::isValid($value);
         $backEndPrice = StoreController::applyCoupon($value->id, $coupons)->price;
         if ($backEndPrice != $value->price) {
             $app->halt(409, json_encode('Price is invalid.'));
         }
         $sum = $sum + $backEndPrice * $value->qty;
     }
     if ($sum != $data['amount']) {
         $app->halt(409, json_encode('Total price is wrong.'));
     }
 }
 public static function shoppingCartRecommend()
 {
     $app = \Slim\Slim::getInstance();
     $data = $app->request->post();
     if (!isset($data['items']) || is_null($data['items']) || empty($data['items'])) {
         $app->halt('400');
     }
     $cartArr = json_decode($data['items']);
     $courseArr = [];
     foreach ($cartArr as $key => $value) {
         StoreController::isValid($value);
         array_push($courseArr, $value->course_id);
     }
     return self::getArrRecommend($courseArr);
 }
 /**
  * @api {post} /store/update Update Shopping cart info (amount/coupon)
  * @apiName Update Shopping cart info
  * @apiGroup Manager
  * @apiHeader (Header) {String} X_Authorization Authorization value.
  * @apiParam  (url Parameter) {Number} idUser User unique ID.
  * @apiParam  {Number} idBin Bin's unique ID.
  * @apiParam  {Number} idUser User's unique ID. The change will apply to this user.
  * 
  * @apiError 400 Input Invalid. This will happen if the param is missing or not the valid format.
  * @apiError 404 Not found. This will happen if the bin id/user id/course id/sale id is not in our system.
  * @apiError 401 Not authorized. This will happen if the header value is not attached.
  * @apiError 409 User already enrolled.
  *
  *
  */
 public static function update()
 {
     $app = \Slim\Slim::getInstance();
     $data = $app->request->post();
     if (!isset($data['items']) || !isset($data['coupons'])) {
         $app->halt(400, 'Invalid Input');
     }
     $items = json_decode($data['items']);
     $coupons = json_decode($data['coupons']);
     foreach ($items as $key => &$value) {
         StoreController::isValid($value);
         $price_code = StoreController::applyCoupon($value->id, $coupons);
         $value->price = $price_code->price;
         if (isset($price_code->old_price)) {
             $value->orig_price = $price_code->old_price;
         }
         $value->coupon = $price_code->coupon;
     }
     return json_encode($items);
 }
Example #4
0
 public function init()
 {
     self::$config = $this->folder->config = array_merge(self::$config, $this->folder->config);
     $this->model = new $this->_model($this->folder);
 }