model = $model; } public function order($data) { $this->shopApiOrderCart = new ShopApiOrderCart(); $this->performOrderActionList($data, 0); return $this->shopApiOrderCart; } public function remove($data){ $this->performActionList($data, 5); return true; } public function reset($data){ $this->performActionList($data, 0); return true; } public function checkout($data){ $this->shopApiOrderCart = new ShopApiOrderCart(); $this->performOrderCheckoutList($data, 1); return $this->shopApiOrderCart; } private function performActionList($data, $status){ if(isset($data['api_action_list'])){ foreach($data['api_action_list'] as $orderItemId=>$v){ $ShoppingOrder = ShoppingOrder::findOrFail($orderItemId); $ShoppingOrder->api_status = $status; $ShoppingOrder->save(); } } } private function performOrderActionList($data, $status){ if(isset($data['api_action_list'])){ foreach($data['api_action_list'] as $orderItemId=>$v){ $ShoppingOrder = ShoppingOrder::findOrFail($orderItemId); $this->shopApiOrderCart->add($ShoppingOrder); $ShoppingOrder->api_status = $status; //<- no status change is the show list $ShoppingOrder->save(); } $this->shopApiOrderCart->calculate(); return $this->shopApiOrderCart; } } private function performOrderCheckoutList($data, $status){ if(isset($data['api_action_list'])){ foreach($data['api_action_list'] as $k=>$orderItemId){ $ShoppingOrder = ShoppingOrder::findOrFail($orderItemId); $this->shopApiOrderCart->add($ShoppingOrder); $ShoppingOrder->api_status = $status; $ShoppingOrder->save(); } $this->shopApiOrderCart->calculate(); $this->shopApiOrderCart->store(); return $this->shopApiOrderCart; } } }