public static function getValidatedByIdTab($id_tab) { $advices = new Collection('advice', Context::getContext()->language->id); $advices->where('validated', '=', 1); $advices->where('id_tab', '=', (int) $id_tab); return $advices; }
public static function getShopGroups($active = true) { $groups = new Collection('ShopGroup'); $groups->where('deleted', '=', false); if ($active) { $groups->where('active', '=', true); } return $groups; }
public function renderView() { $badges_feature = new Collection('badge', $this->context->language->id); $badges_feature->where('type', '=', 'feature'); $badges_feature->orderBy('id_group'); $badges_feature->orderBy('group_position'); $badges_achievement = new Collection('badge', $this->context->language->id); $badges_achievement->where('type', '=', 'achievement'); $badges_achievement->orderBy('id_group'); $badges_achievement->orderBy('group_position'); $badges_international = new Collection('badge', $this->context->language->id); $badges_international->where('type', '=', 'international'); $badges_international->orderBy('id_group'); $badges_international->orderBy('group_position'); $groups = array(); $query = new DbQuery(); $query->select('DISTINCT(b.`id_group`), bl.group_name, b.type'); $query->from('badge', 'b'); $query->join(' LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); foreach ($result as $res) { $groups['badges_' . $res['type']][$res['id_group']] = $res['group_name']; } $badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international)); $levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend')); $this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels); return parent::renderView(); }
/** * Get list of shop urls * * @param bool $id_shop * @return Collection */ public static function getShopUrls($id_shop = false) { $urls = new Collection('ShopUrl'); if ($id_shop) { $urls->where('id_shop', '=', $id_shop); } return $urls; }
private function getUserLastCollectionUsed() { $user_id = Auth::user()->id; $coll_id = Collection::where('user_id', $user_id)->where("last_used", 1)->pluck('id'); // dd($coll_id); if ($coll_id) { return $coll_id; } else { return null; } }
protected static function actionDefault() { $products = new Collection('Product', App::currentLang()->getId()); $products->link('cover'); $products->where("`id` IN (" . implode(',', array_keys($_SESSION['cart'])) . ")"); $products = $products->items(); foreach ($products as $product) { $product->quantity = $_SESSION['cart'][$product->getId()]; } self::templateVar('cart_items', $products); return self::displayPage('cart'); }
function submit_products() { $start = 0; while (true) { $inventories = Inventory::whereNull('shopify_id')->orWhere('dirty', 1)->skip($start)->take(100)->get(); $cnt = count($inventories); if ($cnt == 0) { break; } foreach ($inventories as $inventory) { if ($inventory->image == '') { continue; } if ($inventory->shopify_id == NULL) { $amzInfo = AmazonInfo::where("inventory_id", $inventory->id)->first(); $collection = Collection::where("name", $amzInfo->category1)->first(); if ($collection == NULL) { //echo '[', date('Y-m-d H:m:s'), '] Skip - ', $inventory->name, "\r\n"; continue; } $result = create_product($inventory->name, $inventory->description, 'Bellwether', 'Book', $inventory->sku, $inventory->price, $inventory->quantity, $inventory->image, $inventory->isbn); if ($result['success'] == 'true') { /* Check if collection exists and add product & category... */ if ($collection != NULL) { $inventory->dirty = 0; $sid = $result['product']['id']; $inventory->shopify_id = $sid; $inventory->save(); echo '[', date('Y-m-d H:m:s'), '] Added Product - ', "ID ", $sid, ", ", $inventory->name, "\r\n"; add_product_to_collection($result['product']['id'], $collection->shopify_id); echo 'Added to Collection - ' . $collection->name . "\r\n"; } } } else { $result = update_product_content($inventory->shopify_id, $inventory->price, $inventory->quantity, $inventory->sku); if ($result['success'] == 'true') { $inventory->dirty = 0; $inventory->save(); echo 'Updated Product - ' . $inventory->name . "\r\n"; } } } $start += $cnt; } }
protected static function actionDefault() { /* * Если выводиться вся страница то списко товаров передается шаблону products-list таким образом * Controller -> index -> products-list * Если запрос аяксовый то переменные передаются напрямую шаблону products-list * Controller -> products-list * Но при создании этих переменных мы не думаем о том какой шаблон будет выводиться. */ // Заголовок списка товаров self::templateVar('product_list_title', 'Последние товары'); // товары в списке (6 последних добавленных в соотвествии с фильтром цен) $collection = new Collection('Product', App::currentLang()->getId()); $collection->link('cover'); $collection->order("`add` DESC"); $where = "`active` = 1"; if (isset($_POST['submitPriceRange'])) { $where .= " AND `price` >= {$_POST['min']} AND `price` <= {$_POST['max']}"; } $collection->where($where); $collection->limit(6); self::templateVar('product_list_items', $collection->items()); if (App::isAjax()) { // Если это ajax выводим чанк списка товаров return self::displayPage('chunks/product-list'); } // Привязка категорий для табов под списком товаров // Получаем две категории из базы $collection = new Collection('Category', App::currentLang()->getId()); $collection->where("`active` = 1"); $collection->limit(2); $categories = $collection->items(); foreach ($categories as $category) { $collection = new Collection('Product', App::currentLang()->getId()); $collection->where("`id_category` = " . $category->getId() . " AND `active` = 1"); $collection->limit(4); $category->setLink('products', $collection->items()); } foreach ($categories as $index => $category) { if (empty($category->products)) { unset($categories[$index]); } } // Привязываем к шаблону static::templateVar('tab_categories', $categories); return self::displayPage('index'); }
protected static function actionSearch() { // Заголовок над списком твоаров self::templateVar('product_list_title', 'Результаты поиска'); // Товары $products = new Collection('Product', App::currentLang()->getId()); $products->link('cover'); $products->where("`active` = 1 AND `name` LIKE '%{$_GET['q']}%'" . (isset($_POST['submitPriceRange']) ? " AND `price` >= {$_POST['min']} AND `price` <= {$_POST['max']}" : '')); $products->order("`add` DESC"); $products->limit(12); self::templateVar('product_list_items', $products->items()); // Если это ajax выводим только чанк product-list if (App::isAjax()) { return self::displayPage('chunks/product-list'); } return self::displayPage('catalog'); }
public function testWhere() { $this->object[0]; // initialize collection $this->assertTrue($this->object->isLoaded()); // change conditions $this->object->where("[allowed] = %b", false); $this->assertFalse($this->object->isLoaded()); // test result $i = 0; foreach ($this->object as $item) { $this->assertEquals(false, $item->allowed); $i++; } $this->assertEquals(2, $i); // change conditions $this->object->where("[name] = %s", "Article"); $this->assertEquals(1, count($this->object)); }
protected static function init() { parent::init(); /* * Если текущий запрос не ajax * Происходит привязка глобальных данных для левого меню */ if (!App::isAjax()) { // Привязка списка категорий $collection = new Collection('Category', App::currentLang()->getId()); $collection->where("`active` = 1"); static::templateGlobal('aside_categories', $collection->items()); // Привязка списка производителей $collection = new Collection('Brand', App::currentLang()->getId()); $collection->where("`active` = 1"); static::templateGlobal('aside_brands', $collection->items()); // Привязка данных для фильтра цен static::templateGlobal('filter_price', Database::getRow("\n SELECT\n MIN(`price`) AS `min`,\n MAX(`price`) AS `max`\n FROM `product`\n WHERE `active` = 1\n ")); } }
public function getDoctorsListCount($latitude = 0, $longitude = 0, $query = array()) { $this->data = DB::table('doctors'); $this->data->leftJoin('doctors_details AS dhospital', 'doctors.id', '=', 'dhospital.doctor_id'); $this->data->leftJoin('listing_hospitals', 'dhospital.detail_id', '=', 'listing_hospitals.id'); $this->data->leftJoin('doctors_details AS dhmo', 'doctors.id', '=', 'dhmo.doctor_id'); $this->data->leftJoin('listing_hmo', 'dhmo.detail_id', '=', 'listing_hmo.id'); $this->data->leftJoin('doctors_specialization', 'doctors.id', '=', 'doctors_specialization.doctor_id'); $this->data->leftJoin('location_cities', 'listing_hospitals.city', '=', 'location_cities.id'); $this->data->leftJoin('location_provinces', 'listing_hospitals.province', '=', 'location_provinces.id'); $this->data->select(DB::raw("doctors.*, dhospital.detail_id as hospital_id, listing_hospitals.listing_title as hospital_title, listing_hospitals.latitude, listing_hospitals.longitude, listing_hospitals.street, location_cities.city_name, location_provinces.province_name, dhmo.detail_id as hmo_id, listing_hmo.listing_title as hmo_title, doctors_specialization.specialization_id, (6371 * acos (cos ( radians(?) ) * cos( radians( listing_hospitals.latitude ) ) * cos( radians( listing_hospitals.longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( listing_hospitals.latitude ) ))) AS distance"))->setBindings([$latitude, $longitude, $latitude]); $this->data->where('dhospital.detail_type', '=', 1); $this->data->where('dhmo.detail_type', '=', 4); if (isset($query['specializations'])) { $this->data->whereIn('doctors_specialization.specialization_id', $query['specializations']); } if (isset($query['locations'])) { $this->data->whereIn('listing_hospitals.city', $query['locations']); } $this->data->groupBy('doctors.id'); // } return $this->data->get(); }
public static function load_products() { if (!Config::$cart_table) { return; } # create a collection for the products table $col = new Collection(Config::$cart_table); # loop through the products in the cart foreach (self::get_cart() as $id => $qty) { # select those products by their ids # field, value, use_quotes, or $col->where('id', $id, true, true); } # if there is any products in the cart at all if ($_SESSION[Config::$sitename]['cart'][Auth::user_id()]) { # then load them all into the collection $col->get(); } # clear the static products array self::$products = []; # for each item in the collection foreach ($col->items as $product) { # add a quantity property to the model $product->quantity = $_SESSION[Config::$sitename]['cart'][Auth::user_id()][$product->id]; # add the product object into the products array self::$products[] = $product; } }
/** * Return an array of all children of the current category * * @param int $id_lang * @return Collection */ public function getAllChildren($id_lang = null) { if (is_null($id_lang)) { $id_lang = Context::getContext()->language->id; } $categories = new Collection('Category', $id_lang); $categories->where('nleft', '>', $this->nleft); $categories->where('nright', '<', $this->nright); return $categories; }
/** * For a given product, retrieves the stock collection * * @param int $id_product * @param int $id_product_attribute * @param int $id_warehouse Optional * @param int $price_te Optional * @return Collection of Stock */ protected function getStockCollection($id_product, $id_product_attribute, $id_warehouse = null, $price_te = null) { $stocks = new Collection('Stock'); $stocks->where('id_product', '=', $id_product); $stocks->where('id_product_attribute', '=', $id_product_attribute); if ($id_warehouse) { $stocks->where('id_warehouse', '=', $id_warehouse); } if ($price_te) { $stocks->where('price_te', '=', $price_te); } return $stocks; }
/** * Get collection from module name * @static * @param $module string Module name * @param null $id_lang integer Language ID * @return array|Collection Collection of tabs (or empty array) */ public static function getCollectionFromModule($module, $id_lang = null) { if (is_null($id_lang)) { $id_lang = Context::getContext()->language->id; } if (!Validate::isModuleName($module)) { return array(); } $tabs = new Collection('Tab', (int) $id_lang); $tabs->where('module', '=', $module); return $tabs; }
/** * Retrieves the details entries (i.e. products) collection for the current order * * @return Collection of SupplyOrderDetail */ public function getEntriesCollection() { $details = new Collection('SupplyOrderDetail'); $details->where('id_supply_order', '=', $this->id); return $details; }
/** * @static * @param $id_customer * @return bool */ public static function deleteByIdCustomer($id_customer) { $return = true; $cart_rules = new Collection('CartRule'); $cart_rules->where('id_customer', '=', $id_customer); foreach ($cart_rules as $cart_rule) { $return &= $cart_rule->delete(); } return $return; }
/** * Display a listing of the resource. * * @return Response */ public function index() { $collections = Collection::where('user_id', '=', Auth::User()->id)->get(); return view('collections.index', compact('collections')); }
/** * Get all other orders with the same reference * * @since 1.5.0.13 */ public function getBrother() { $collection = new Collection('order'); $collection->where('reference', '=', $this->reference); $collection->where('id_order', '<>', $this->id); return $collection; }
/** * Get a collection of shops * * @param bool $active * @param int $id_shop_group * @return Collection */ public static function getShopsCollection($active = true, $id_shop_group = null) { $shops = new Collection('Shop'); if ($active) { $shops->where('active', '=', 1); } if ($id_shop_group) { $shops->where('id_shop_group', '=', (int) $id_shop_group); } return $shops; }
/** * Get Order Payments By Invoice ID * @static * @param $id_invoice Invoice ID * @return Collection Collection */ public static function getByInvoiceId($id_invoice) { $payments = Db::getInstance()->executeS('SELECT id_order_payment FROM `' . _DB_PREFIX_ . 'order_invoice_payment` WHERE id_order_invoice = ' . (int) $id_invoice); if (!$payments) { return array(); } $payment_list = array(); foreach ($payments as $payment) { $payment_list[] = $payment['id_order_payment']; } $payments = new Collection('OrderPayment'); $payments->where('id_order_payment', 'IN', $payment_list); return $payments; }
/** * Exports CSV */ protected function renderCSV() { // exports orders if (Tools::isSubmit('csv_orders')) { $ids = array(); foreach ($this->_list as $entry) { $ids[] = $entry['id_supply_order']; } if (count($ids) <= 0) { return; } $id_lang = Context::getContext()->language->id; $orders = new Collection('SupplyOrder', $id_lang); $orders->where('is_template', '=', false); $orders->where('id_supply_order', 'in', $ids); $id_warehouse = $this->getCurrentWarehouse(); if ($id_warehouse != -1) { $orders->where('id_warehouse', '=', $id_warehouse); } $orders->getAll(); $csv = new CSV($orders, $this->l('supply_orders')); $csv->export(); } else { if (Tools::isSubmit('csv_orders_details')) { // header header('Content-type: text/csv'); header('Content-Type: application/force-download; charset=UTF-8'); header('Cache-Control: no-store, no-cache'); header('Content-disposition: attachment; filename="' . $this->l('supply_orders_details') . '.csv"'); // echoes details $ids = array(); foreach ($this->_list as $entry) { $ids[] = $entry['id_supply_order']; } if (count($ids) <= 0) { return; } // for each supply order $keys = array('id_product', 'id_product_attribute', 'reference', 'supplier_reference', 'ean13', 'upc', 'name', 'unit_price_te', 'quantity_expected', 'quantity_received', 'price_te', 'discount_rate', 'discount_value_te', 'price_with_discount_te', 'tax_rate', 'tax_value', 'price_ti', 'tax_value_with_order_discount', 'price_with_order_discount_te', 'id_supply_order'); echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $keys))); // overrides keys (in order to add FORMAT calls) $keys = array('sod.id_product', 'sod.id_product_attribute', 'sod.reference', 'sod.supplier_reference', 'sod.ean13', 'sod.upc', 'sod.name', 'FORMAT(sod.unit_price_te, 2)', 'sod.quantity_expected', 'sod.quantity_received', 'FORMAT(sod.price_te, 2)', 'FORMAT(sod.discount_rate, 2)', 'FORMAT(sod.discount_value_te, 2)', 'FORMAT(sod.price_with_discount_te, 2)', 'FORMAT(sod.tax_rate, 2)', 'FORMAT(sod.tax_value, 2)', 'FORMAT(sod.price_ti, 2)', 'FORMAT(sod.tax_value_with_order_discount, 2)', 'FORMAT(sod.price_with_order_discount_te, 2)', 'sod.id_supply_order'); foreach ($ids as $id) { $query = new DbQuery(); $query->select(implode(', ', $keys)); $query->from('supply_order_detail', 'sod'); $query->leftJoin('supply_order', 'so', 'so.id_supply_order = sod.id_supply_order'); $id_warehouse = $this->getCurrentWarehouse(); if ($id_warehouse != -1) { $query->where('so.id_warehouse = ' . (int) $id_warehouse); } $query->where('sod.id_supply_order = ' . (int) $id); $query->orderBy('sod.id_supply_order_detail DESC'); $resource = Db::getInstance()->query($query); // gets details while ($row = Db::getInstance()->nextRow($resource)) { echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row))); } } } else { if (Tools::isSubmit('csv_order_details') && Tools::getValue('id_supply_order')) { $supply_order = new SupplyOrder((int) Tools::getValue('id_supply_order')); if (Validate::isLoadedObject($supply_order)) { $details = $supply_order->getEntriesCollection(); $details->getAll(); $csv = new CSV($details, $this->l('supply_order') . '_' . $supply_order->reference . '_details'); $csv->export(); } } } } }
/** * Return collection of order invoice object linked to the payments of the current order invoice object * * @since 1.5.0.14 */ public function getSibling() { $query = new DbQuery(); $query->select('oip2.id_order_invoice'); $query->from('order_invoice_payment', 'oip1'); $query->innerJoin('order_invoice_payment', 'oip2', 'oip2.id_order_payment = oip1.id_order_payment AND oip2.id_order_invoice <> oip1.id_order_invoice'); $query->where('oip1.id_order_invoice = ' . $this->id); $invoices = Db::getInstance()->executeS($query); if (!$invoices) { return array(); } $invoice_list = array(); foreach ($invoices as $invoice) { $invoice_list[] = $invoice['id_order_invoice']; } $payments = new Collection('OrderInvoice'); $payments->where('id_order_invoice', 'IN', $invoice_list); return $payments; }
public function getDataGeneration() { $datas = array(); $order_to_change_state = array(); $saved_product = array(); $datas_quantity = array(); $customer_concerned = array(); $concerned_id_order_detail = array(); $orders = Db::getInstance()->executeS(' SELECT a.id_order FROM `' . _DB_PREFIX_ . 'orders` a LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`) WHERE a.current_state = ' . (int) $this->generate_order_state . ' ORDER BY a.`id_order` DESC'); $unselected_orders_array = array(); /* if (isset( $this->context->cookie->unselected_orders) && !empty( $this->context->cookie->unselected_orders)) { $unselected_orders_array = Tools::unSerialize( $this->context->cookie->unselected_orders); } */ if (Tools::getValue('unselected_orders_list', false)) { $unselected_orders_array = explode(',', Tools::getValue('unselected_orders_list')); $unselected_orders_array = array_map('trim', $unselected_orders_array); } if (!empty($orders)) { foreach ($orders as $order) { $id_order = (int) $order['id_order']; if (!in_array($id_order, $unselected_orders_array)) { $order = new Order((int) $id_order); if (!Validate::isLoadedObject($order)) { throw new PrestaShopException('object oder simulate can\'t be loaded'); } $order_details = $order->getOrderDetailList(); if (!empty($order_details)) { $order_to_change_state[] = (int) $id_order; foreach ($order_details as $order_detail) { $id_supplier = 0; $product_key = $order_detail['product_id'] . '_' . $order_detail['product_attribute_id']; $product = new Product($order_detail['product_id'], $order_detail['product_attribute_id']); // update selling price to purchase price $order_detail['unit_price_tax_excl'] = ErpStock::getWholesalePrice($order_detail['product_id'], $order_detail['product_attribute_id']); $order_detail['tax_rate'] = Tax::getProductTaxRate($order_detail['product_id']); $order_detail['unit_price_tax_incl'] = $order_detail['unit_price_tax_excl'] * (1 + (double) $order_detail['tax_rate'] / 100); if (empty($product->id_supplier)) { // Get already associated suppliers $associated_suppliers = new Collection('ProductSupplierCore'); $associated_suppliers->where('id_product', '=', (int) $product->id); $associated_suppliers->groupBy('id_supplier'); foreach ($associated_suppliers as $associated_supplier) { $id_supplier = $associated_supplier->id_supplier; } } else { $id_supplier = $product->id_supplier; } if (isset($saved_product[$product_key])) { $datas_quantity[$product_key] += $order_detail['product_quantity']; $customer_concerned[$product_key][] = $order->id_customer; $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer); $order_detail['total_product_quantity'] = $datas_quantity[$product_key]; $order_detail['customer_concerned'] = $customer_concerned[$product_key]; $order_detail['concerned_id_order_detail'] = $concerned_id_order_detail[$product_key]; $datas[$id_supplier][$product_key] = $order_detail; } else { $product_quantity = $order_detail['product_quantity']; $order_detail['total_product_quantity'] = $product_quantity; $order_detail['customer_concerned'][] = $order->id_customer; $order_detail['concerned_id_order_detail'][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer); $datas[$id_supplier][$product_key] = $order_detail; $datas_quantity[$product_key] = $product_quantity; $customer_concerned[$product_key][] = $order->id_customer; $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer); $saved_product[$product_key] = true; } } } } } } $data_return = array(); foreach ($datas as $id_supplier => $data) { if ($id_supplier > 0) { $product_list = array(); foreach ($data as $product_key => $product_info) { $customer_concerned = ''; $customer_concerned_arr = array_unique($product_info['customer_concerned']); foreach ($customer_concerned_arr as $id_customer) { $customer = new Customer($id_customer); $customer_concerned .= $customer->lastname . ' ' . $customer->firstname . ', '; } $total_te = $product_info['unit_price_tax_excl'] * $product_info['total_product_quantity']; $total_ti = $product_info['unit_price_tax_incl'] * $product_info['total_product_quantity']; $product_info['total_price_tax_excl'] = Tools::displayPrice($total_te); $product_info['total_price_tax_incl'] = Tools::displayPrice($total_ti); $product_info['unit_price_tax_excl'] = $product_info['unit_price_tax_excl']; $product_info['customer_concerned'] = Tools::substr($customer_concerned, 0, Tools::strlen($customer_concerned) - 2); $product_info['customer_id'] = $customer_concerned_arr; $product_list[] = $product_info; } $data_return[$id_supplier] = $product_list; } } // for the order, get the orders list that the statuts should be update in provider order if ($this->display == 'ordering') { return array('data_return' => $data_return, 'order_to_change_state' => $order_to_change_state); } else { return $data_return; } }
public function postStore($id = null) { // ---------------------------------------- HANDLE REQUEST ---------------------------------------- // handle id if (!is_null($id)) { $data = $this->model->findorfail($id); } else { $data = $this->model->newInstance(); } // ---------------------------------------- CHECK TAG ---------------------------------------- $tags_in_db = \App\Tag::whereIn('tag', Input::get('tags'))->get(); if (!$tags_in_db) { $tags_in_db = new Collection(); } foreach (Input::get('tags') as $x) { if (!$tags_in_db->where('tag', $x)->first()->id) { $new_tag = new \App\Tag(['tag' => $x]); if (!$new_tag->save()) { dd($new_tag->getErrors()); } $tags_in_db->push($new_tag); } } // ---------------------------------------- HANDLE SAVE ---------------------------------------- $input = Input::all(); if (!empty($input['published_at'])) { $input['published_at'] = \Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['published_at'])->format('Y-m-d H:i:s'); } else { $input['published_at'] = null; } unset($input['longlat']); $input['tag_ids'] = $tags_in_db->pluck('id')->toArray(); $data->fill($input); if ($data->save()) { if (!$this->save_required_images($data, $input)) { return redirect()->back()->withInput()->withErrors($data->getErrors()); } return redirect()->route('admin.' . $this->view_name . '.show', ['id' => $data->id])->with('alert_success', '"' . $data->{$data->getNameField()} . '" has been saved successfully'); } else { return redirect()->back()->withInput()->withErrors($data->getErrors()); } }
/** * For a given product, gets its warehouses * * @param int $id_product * @return Collection The type of the collection is WarehouseProductLocation */ public static function getCollection($id_product) { $collection = new Collection('WarehouseProductLocation'); $collection->where('id_product', '=', (int) $id_product); return $collection; }
public static function __callStatic($name, $arguments) { $collection = new Collection($arguments[0]); switch ($name) { case '_columns': return $collection->columns($arguments[1]); case '_where': return $collection->where($arguments[1]); case '_join': return $collection->join($arguments[1]); case '_order': return $collection->order($arguments[1], $arguments[2]); case '_group': return $collection->group($arguments[1]); case '_limit': return $collection->limit($arguments[1]); case '_offset': return $collection->offset($arguments[1]); case '_all': return $collection->all(); default: throw new \Bacon\Exceptions\MethodNotFound(); } }
/** * Remove all downloadable files for product and its attributes * * @return bool */ public function deleteDownload() { $result = true; $collection_download = new Collection('ProductDownload'); $collection_download->where('id_product', '=', $this->id); foreach ($collection_download as $product_download) { $result &= $product_download->delete(true); } return $result; }
/** * For a given product, retrieves its suppliers * * @param int $id_product * @param int $group_by_supplier * @return Collection */ public static function getSupplierCollection($id_product, $group_by_supplier = true) { $suppliers = new Collection('ProductSupplier'); $suppliers->where('id_product', '=', (int) $id_product); if ($group_by_supplier) { $suppliers->groupBy('id_supplier'); } return $suppliers; }