本文整理汇总了PHP中app\models\Product::getProducts方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getProducts方法的具体用法?PHP Product::getProducts怎么用?PHP Product::getProducts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::getProducts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildIndex
/**
* @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);
}
示例2: api
public function api()
{
return response()->json(Product::getProducts());
}