Example #1
0
 protected function prepareData($fill)
 {
     if (empty($fill['sites_id'])) {
         $fill['sites_id'] = app('veer')->siteId;
     }
     if (empty($fill['users_id']) && $this->action != 'add') {
         $fill['users_id'] = \Auth::id();
     }
     foreach (['free', 'close', 'hidden', 'archive', 'delivery_free', 'delivery_hold', 'payment_hold', 'payment_done'] as $key) {
         $fill[$key] = isset($fill[$key]) ? 1 : 0;
     }
     if ($fill['close']) {
         $fill['close_time'] = now();
     }
     $fill['progress'] = isset($fill['progress']) ? strtr($fill['progress'], ["%" => ""]) : 5;
     $fill['delivery_plan'] = !empty($fill['delivery_plan']) ? parse_form_date($fill['delivery_plan']) : null;
     $fill['delivery_real'] = !empty($fill['delivery_real']) ? parse_form_date($fill['delivery_real']) : null;
     $fill += ['cluster_oid' => null, 'cluster' => null, 'delivery_method_id' => $this->order->delivery_method_id, 'payment_method_id' => $this->order->payment_method_id, 'status_id' => $this->order->status_id, 'userbook_id' => $this->order->userbook_id];
     if ($this->order->cluster_oid != $fill['cluster_oid'] || $this->order->cluster != $fill['cluster']) {
         $existingOrders = \Veer\Models\Order::where('sites_id', '=', $fill['sites_id'])->where('cluster', '=', $fill['cluster'])->where('cluster_oid', '=', $fill['cluster_oid'])->first();
         // we cannot update cluster ids if they already exist
         if (is_object($existingOrders) || empty($fill['cluster_oid'])) {
             array_forget($fill, ['cluster_oid', 'cluster']);
         }
     }
     if ($this->order->delivery_method_id != $fill['delivery_method_id'] && empty($fill['delivery_method'])) {
         $fill['delivery_method'] = \Veer\Models\OrderShipping::where('id', '=', $fill['delivery_method_id'])->pluck('name');
     }
     if ($this->order->payment_method_id != $fill['payment_method_id'] && empty($fill['payment_method'])) {
         $fill['payment_method'] = \Veer\Models\OrderPayment::where('id', '=', $fill['payment_method_id'])->pluck('name');
     }
     return $fill;
 }
Example #2
0
 public function update($id)
 {
     $p = \Veer\Models\OrderShipping::find($id);
     if (is_object($p)) {
         $this->entity = $p;
         event('veer.message.center', trans('veeradmin.shipping.update'));
     } else {
         event('veer.message.center', trans('veeradmin.shipping.error'));
     }
     return $this;
 }
Example #3
0
 /**
  * recalculate order delivery
  */
 public function recalculateOrderDelivery($order, $delivery = null, $pretend = false)
 {
     if (empty($delivery)) {
         $delivery = \Veer\Models\OrderShipping::find($order->delivery_method_id);
     }
     if (!is_object($delivery)) {
         return $order;
     }
     $order->delivery_method = $delivery->name;
     // change address if it's pickup
     if ($delivery->delivery_type == "pickup" && !empty($delivery->address)) {
         // @todo if we have several address how to choose the right one?
         // now it's just one address!
         $parseAddresses = json_decode($delivery->address);
         $order->country = array_get(head($parseAddresses), 0);
         $order->city = array_get(head($parseAddresses), 1);
         $order->address = array_get(head($parseAddresses), 2);
         $order->userbook_id = 0;
     }
     // 2
     switch ($delivery->payment_type) {
         case "free":
             $order->delivery_price = 0;
             $order->delivery_free = true;
             $order->delivery_hold = false;
             break;
         case "fix":
             $order->delivery_price = $delivery->price;
             $order->delivery_free = false;
             $order->delivery_hold = false;
             break;
     }
     // 3 calculator
     $class = starts_with($delivery->func_name, "\\") ? $delivery->func_name : "\\Veer\\Components\\Ecommerce\\" . $delivery->func_name;
     if (!empty($delivery->func_name) && class_exists($class)) {
         $deliveryFunc = new $class();
         $getData = $deliveryFunc->fire($order, $delivery);
         $order->delivery_price = isset($getData->delivery_price) ? $getData->delivery_price : $delivery->price;
         $order->delivery_free = isset($getData->delivery_free) ? $getData->delivery_free : false;
         $order->delivery_hold = isset($getData->delivery_hold) ? $getData->delivery_hold : true;
         // @todo do we need this
         $delivery->discount_enable = isset($getData->discount_enable) ? $getData->discount_enable : $delivery->discount_enable;
         $delivery->discount_price = isset($getData->discount_price) ? $getData->discount_price : $delivery->discount_price;
         $delivery->discount_conditions = isset($getData->discount_conditions) ? $getData->discount_conditions : $delivery->discount_conditions;
     }
     // 4
     if ($delivery->discount_enable == 1 && $delivery->discount_price > 0) {
         $checkConditions = $this->checkDisountConditions($delivery->discount_conditions, $order);
         if (array_get($checkConditions, 'activate') == true || array_get($checkConditions, 'conditions') == false) {
             if (array_get($checkConditions, 'price') == "total") {
                 $content = new \Veer\Models\OrderProduct();
                 $content->orders_id = $order->id;
                 $content->product = 0;
                 $content->products_id = 0;
                 $content->name = \Lang::get('veeradmin.order.content.delivery.discount') . " (-" . $delivery->discount_price . "%)";
                 $content->original_price = 0 - $order->content_price * ($delivery->discount_price / 100);
                 $content->quantity = 1;
                 $content->attributes = "";
                 $content->comments = \Lang::get('veeradmin.order.content.discount');
                 $content->price_per_one = $content->original_price;
                 $content->price = $content->original_price;
                 if ($pretend == false) {
                     $content->save();
                 }
                 $order->content_price = $order->content_price + $content->price;
             } else {
                 $order->delivery_price = $order->delivery_price * (1 - $delivery->discount_price / 100);
             }
         }
     }
     if ($order->delivery_price <= 0 && $order->delivery_hold != true) {
         $order->delivery_free = true;
     }
     return $order;
 }
Example #4
0
 /**
  * Get all veer shop shipping
  * @return object
  */
 function shipping($siteId = null)
 {
     if (empty($siteId)) {
         $shipping = \Veer\Models\OrderShipping::select();
     } else {
         $shipping = \Veer\Models\OrderShipping::where('sites_id', '=', $siteId);
     }
     return \Cache::remember('listofShippingMethods-' . $siteId, 0.5, function () use($shipping) {
         return $shipping->where('enable', '=', true)->orderBy('manual_order', 'asc')->get();
     });
 }