Exemple #1
0
 /**
  * delete User Role
  * @param type $id
  */
 protected function deleteUserRole($id)
 {
     $u = \Veer\Models\UserRole::find($id);
     if (is_object($u)) {
         $u->users()->update(['roles_id' => null]);
         $u->delete();
         return true;
     }
     return false;
 }
Exemple #2
0
 /**
  * edit Order Content
  */
 public function editOrderContent($content, $ordersProducts, $order, $jsonSkip = false)
 {
     $productsId = array_get($ordersProducts, 'products_id');
     $attributes = array_pull($ordersProducts, 'attributes');
     $oldQuantity = isset($content->quantity) ? $content->quantity : 1;
     $content->orders_id = $order->id;
     $content->attributes = $jsonSkip == true ? $attributes : json_encode(explode(",", $attributes));
     $content->quantity = array_pull($ordersProducts, 'quantity', 1);
     if ($content->quantity < 1) {
         $content->quantity = 1;
     }
     \Eloquent::unguard();
     if (empty($productsId)) {
         $content->product = 0;
         $content->fill($ordersProducts);
         $content->price = $content->quantity * $content->price_per_one;
         return $content;
     }
     $content->product = 1;
     $content->name = array_get($ordersProducts, 'name');
     $content->original_price = array_get($ordersProducts, 'original_price');
     $content->price_per_one = array_get($ordersProducts, 'price_per_one');
     if ($content->quantity != $oldQuantity) {
         $content->weight = array_get($ordersProducts, 'weight') / $oldQuantity * $content->quantity;
     } else {
         $content->weight = array_get($ordersProducts, 'weight');
     }
     if ($content->products_id != array_get($ordersProducts, 'products_id') || !empty($content->attributes)) {
         $product = \Veer\Models\Product::find(array_get($ordersProducts, 'products_id'));
         $shopCurrency = \Cache::remember('shopcurrency' . $order->sites_id, 0.5, function () use($order) {
             return \Veer\Models\Configuration::where('sites_id', '=', $order->sites_id)->where('conf_key', '=', 'SHOP_CURRENCY')->pluck('conf_val');
         });
         $shopCurrency = !empty($shopCurrency) ? $shopCurrency : null;
     }
     // use attributes
     if (!empty($content->attributes) && is_object($product)) {
         $attributesParsed = $this->parseAttributes($content->attributes, $content->id, $product);
         if (is_array($attributesParsed)) {
             foreach ($attributesParsed as $attr) {
                 $content->price_per_one = $attr['pivot']['product_new_price'] > 0 ? $this->currency($attr['pivot']['product_new_price'], $product['currency'], array("forced_currency" => $shopCurrency)) : $content->price_per_one;
             }
         }
     }
     if ($content->products_id != array_get($ordersProducts, 'products_id') && is_object($product)) {
         $content->products_id = $product->id;
         $content->original_price = empty($content->original_price) ? $this->currency($product->price, $product->currency, array("forced_currency" => $shopCurrency)) : $content->original_price;
         $content->name = $product->title;
         $content->weight = $product->weight * $content->quantity;
         if (empty($content->price_per_one)) {
             $this->flushRememberedDiscounts();
             $pricePerOne = $this->calculator($product, false, array("sites_id" => $order->sites_id, "users_id" => $order->users_id, "roles_id" => \Veer\Models\UserRole::where('role', '=', $order->user_type)->pluck('id'), "discount_id" => $order->userdiscount_id, "forced_currency" => $shopCurrency));
             $content->price_per_one = $pricePerOne;
         }
     }
     $content->price = $content->quantity * $content->price_per_one;
     $content->comments = array_get($ordersProducts, 'comments', '');
     return $content;
 }
Exemple #3
0
 public function detachRole($role_id)
 {
     \Veer\Models\UserRole::where('roles_id', $role_id)->update(['roles_id' => 0]);
     return $this;
 }