예제 #1
0
 public function add($data, $relation = null, $attach_id = null, $returnId = true)
 {
     $prefix = 'fl';
     $model = null;
     switch ($relation) {
         case 'products':
             $model = \Veer\Models\Product::find($attach_id);
             $prefix = 'prd';
             break;
         case 'pages':
             $model = \Veer\Models\Page::find($attach_id);
             $prefix = 'pg';
             break;
         case 'categories':
             $model = \Veer\Models\Category::find($attach_id);
             $prefix = 'ct';
             break;
         case 'users':
             $model = \Veer\Models\User::find($attach_id);
             $prefix = 'usr';
             break;
     }
     $id = $this->upload('image', 'uploadImage', $attach_id, $model, $prefix, null, is_object($model) ? false : true, $data);
     return $returnId ? $id : $this;
 }
예제 #2
0
 /**
  * Add page or product to user list
  */
 public function addToList($type = null, $id = null)
 {
     if (!empty($id)) {
         switch ($type) {
             case "product":
                 $e = \Veer\Models\Product::sitevalidation(app('veer')->siteId)->where('id', '=', $id)->checked()->first();
                 break;
             case "page":
                 $e = \Veer\Models\Page::sitevalidation(app('veer')->siteId)->where('id', '=', $id)->excludeHidden()->first();
                 break;
         }
         if (is_object($e)) {
             $this->savingEntity($e, \Auth::id(), \Input::get('name', '[basket]'));
         }
     }
     return $this->showUser->getUserLists(app('veer')->siteId, \Auth::id(), app('session')->getId(), \Input::get('name', '[basket]'));
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * Query Builder: 
  * 
  * - who: List of Products in/across Sites 
  * - with: Images
  * - to whom: ? 
  */
 public function getConnectedProducts($id, $siteId = null)
 {
     $p = \Veer\Models\Product::whereIn('id', $id)->with(array('images' => function ($query) {
         $query->orderBy('pivot_id', 'asc');
     }))->checked();
     if (!empty($siteId)) {
         $p->sitevalidation($siteId);
     }
     return $p->get();
 }
예제 #5
0
 /**
  * Make Product available if it's not.
  *
  * @helper Model update
  * @param int|null $id
  * @param timestamp|null $when
  * @return \Veer\Services\Administration\Elements\Product
  */
 public function available($id = null, $when = null)
 {
     if ($id === false) {
         return $this;
     }
     if (empty($id)) {
         $id = $this->id;
     }
     if (empty($when)) {
         $when = now();
     }
     if ($this->entity instanceof $this->className && $this->entity->id == $id) {
         $this->entity->to_show = $when;
         $this->entity->save();
     } else {
         \Veer\Models\Product::where('id', '=', $id)->update(['to_show' => $when]);
     }
     event('veer.message.center', trans('veeradmin.product.show'));
     return $this;
 }