本文整理匯總了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());
}