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; }
/** * @helper Model find * @param int $id * @return \Veer\Models\Product|boolean */ protected function getObject($id) { if (empty($id)) { return false; } $product = $this->entity instanceof $this->className && $this->entity->id == $id ? $this->entity : \Veer\Models\Product::find($id); return is_object($product) ? $product : false; }
/** * 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; }