/** * Trying to get paramter from Veer instance * */ function db_parameter($param = null, $default = null, $getFromDbSiteId = null) { if (empty($param)) { return null; } $v = app('veer')->siteConfig; if (!empty($getFromDbSiteId)) { $cacheName = 'dbparameter' . $getFromDbSiteId . '-' . $param; $v[$param] = \Cache::remember($cacheName, 0.5, function () use($param, $getFromDbSiteId) { return \Veer\Models\Configuration::where('sites_id', '=', $getFromDbSiteId)->where('conf_key', '=', $param)->value('conf_val'); }); if (empty($v[$param])) { unset($v[$param]); } } return isset($v[$param]) ? $v[$param] : db_parameter_not_found($param, $default); }
/** * 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; }
protected function enableTheme($siteId, $theme) { $c = \Veer\Models\Configuration::firstOrCreate(["conf_key" => "TEMPLATE", "sites_id" => $siteId]); $c->conf_val = $theme; $c->theme = $theme; $c->save(); }
/** * Loading site's configuration from database. * * * */ protected function saveConfiguration($siteDb) { Config::set('veer.mainurl', $siteDb->url); Config::set('veer.site_id', $siteDb->id); $this->siteId = $siteDb->id; $this->cachingQueries->make(\Veer\Models\Configuration::where('sites_id', '=', $siteDb->id)); $this->siteConfig = $this->cachingQueries->lists('conf_val', 'conf_key', 1440); }