Exemplo n.º 1
0
 /**
  * @param bool $type
  * @param bool $type_id
  * @param bool $chain
  * @param bool $strSearch
  * @return $this
  */
 public function buildIndex($type = false, $type_id = false, $chain = false, $strSearch = false)
 {
     //pr($this->_glob['_curr']);
     $productModel = new Product();
     $purchaseModel = new Purchase();
     $categoryModel = new Category();
     $brandModel = new Brand();
     $labelModel = new Label();
     $userModel = new User();
     //$categoryModel = new Category();
     //$brandModel = new Brand();
     $count = $this->_glob['_countProductsOfPage'];
     //количество товаров на странице по умолчанию
     if (isset($_GET['show']) and $_GET['show'] == 'all') {
         $count = $this->_glob['_maxCountProductsOfPage'];
     }
     $products = $productModel->getProducts($type, $type_id, $count, $strSearch);
     //получаем товары
     /*pr($products,true);
       return view('welcome');*/
     $productsIds = $products->pluck('id');
     $productsIds = $productsIds->toArray();
     $terms = $purchaseModel->getVendorTerms($productsIds);
     //получаем условия поставщиков по выбранным товарам
     $labels = $labelModel->getLabelsByProductsId($productsIds);
     foreach ($products as &$product) {
         //pr($product);
         if (count($terms) > 0) {
             $arTerms = [];
             //$terms = $terms->sortBy('base_price');
             $terms = $terms->sortBy('sort');
             /*pr($terms);*/
             $i = 1;
             foreach ($terms as $term) {
                 if ($product->id == $term->product_id) {
                     $term->zakup = toFloat($term->base_price * ((100 - $term->discount_price) / 100) * ($this->_glob['_curr'][$term->currency]['RATE'] * (1 + $term->raise / 100)) * ((100 - $term->discount_bulk) / 100));
                     //та самая ебанутая формула расчета закупа
                     $arTerms[] = $term;
                     if ($i == 3) {
                         break;
                     }
                     $i++;
                 }
             }
             $product->terms = $arTerms;
         }
         if (count($labels) > 0) {
             $arLabel = [];
             foreach ($labels as $label) {
                 if ($product->id == $label->product_id) {
                     $arLabel[] = $label;
                 }
             }
             $product->labels = $arLabel;
         }
     }
     //pr($products);
     $categories_list = $categoryModel->getFullCategoriesList();
     $brands_list = $brandModel->getFullBrandsList();
     $userTemplates = $userModel->getTemplates('products');
     $serializeFields = $userModel->getFields(Auth::User()->template_prod_id, 'products');
     $showFields = false;
     if ($serializeFields != null) {
         $showFields = unserialize($serializeFields->fields);
     }
     $pathToPurchase = '/purchase';
     if ($type == 'category') {
         $pathToPurchase = '/purchase/category/' . $type_id[0];
     }
     if ($type == 'brand') {
         $pathToPurchase = '/purchase/brand/' . $type_id;
     }
     if ($type == 'product') {
         $pathToPurchase = '/purchase/product/' . $type_id;
     }
     if ($type == 'label') {
         $pathToPurchase = '/purchase/label/' . $type_id;
     }
     if ($type == 'flag') {
         $pathToPurchase = '/purchase/flag/';
     }
     if ($strSearch) {
         $pathToPurchase = '/purchase/search/' . $strSearch;
     }
     return view('products.index')->with('title', 'Товары')->with('products', $products)->with('chain', $chain)->with('categories_list', $categories_list)->with('brands_list', $brands_list)->with('pathToPurchase', $pathToPurchase)->with('templates', $userTemplates)->with('fields', $showFields);
 }
Exemplo n.º 2
0
 public function api()
 {
     return response()->json(Product::getProducts());
 }