Exemplo n.º 1
0
 public function getGlobalCartOrder($createIfNone = false)
 {
     if (Cookie::has('goprop_order_id') && !isset($this->_currentOrder)) {
         $order = Order::where('id', Cookie::get('goprop_order_id'))->where('status', Order::STATUS_CART)->whereNull('property_id')->first();
         $this->_currentOrder = $order;
     }
     if (empty($this->_currentOrder)) {
         if ($createIfNone) {
             $order = new Order();
             $order->status = Order::STATUS_CART;
             $order->save();
             $this->_currentOrder = $order;
             $cookie = Cookie::make('goprop_order_id', $order->id, 25200);
             Cookie::queue($cookie);
         }
     }
     return $this->_currentOrder;
 }
Exemplo n.º 2
0
 public function postPropertyPackages(PropertyFormRequest $request, $id)
 {
     $user = Auth::user();
     $property = Property::findOrFail($id);
     $propertyCartOrder = $property->getCartOrder();
     if (empty($propertyCartOrder)) {
         $order = new Order(['status' => Order::STATUS_CART]);
         $order->property()->associate($property);
         $order->user()->associate($user);
         $order->save();
     } else {
         $order = $propertyCartOrder;
     }
     //Clear Order Item first
     $order->items()->delete();
     $property->packages()->detach();
     $orderTempAddons = [];
     foreach ($request->input('action', []) as $idx => $action) {
         $package = Package::findOrFail($action);
         $features = $request->input('features.' . $package->id, []);
         $addons = [];
         if ($package->isExclusive) {
             $exclusiveCategory = 'level_' . $package->category->slug;
         } else {
             $exclusiveCategory = FALSE;
         }
         foreach ($features as $idy => $feature) {
             $featureObj = $package->features->find($feature);
             $addons[] = $featureObj->id;
             if (!in_array($featureObj->id, $orderTempAddons)) {
                 $orderTempAddons[] = $featureObj->id;
                 $orderItem = new OrderItem(['item' => $featureObj->id, 'item_type' => 'feature', 'quantity' => 1, 'price' => $featureObj->pivot->price, 'net_price' => $featureObj->pivot->price, 'sort_order' => $idy + 1]);
                 $order->items()->save($orderItem);
             }
         }
         //Associate first package to Order temporarily
         if ($idx == 0) {
             $order->package()->associate($package);
         }
         $property->packages()->attach([$package->id => ['addons' => implode('|', $addons)]]);
     }
     $order->calculate();
     $order->save();
     return redirect()->route('frontend.property.review', ['id' => $property->id]);
 }