Answer the question
In order to leave comments, you need to log in
Related products to the product, how to implement the search for related products?
Hello, I decided to finalize related products, the range is very large, about 2000 products, go to the product, then press the button add related products, then there is a list of products, a list of all products, put a tick on the product that will be attached to this product, the product will be related .
It is necessary to implement a search by the name of the goods, so that it is easier to find the goods.
Also implement pagination.
Display a photo of the product, display the category of the product. and the cost of the goods.
All this is in the products, photos, price, product category, everything is shown and working, there is also pagination, I want to implement all this in related products.
promotion of related products.
public function action_related()
{
$id = (int) $this->request->param('id');
$products = ORM::factory('product')->where('id','!=',$id)->order_by("sorts","ASC")->find_all();
$ralated = ORM::factory('related')->where('product_id','=',$id)->find_all()->as_array('id','rproduct_id');
$pArray = array();
foreach ($products as $product):
$pArray[$product->id]['prname'] = $product->prname;
if (in_array($product->id, $ralated))
{
$pArray[$product->id]['related'] = true;
}
else
{
$pArray[$product->id]['related'] = false;
}
endforeach;
$product = ORM::factory('product', $id);
if(!$product->loaded()) {
$this->request->redirect('admin/products');
}
$content = View::factory('admin/product/related', array(
'products' => $pArray,
'id' => $id,
'product' => $product,
));
$this->template->page_title = 'Сопутствующие товары';
$this->template->content = $content;
}
public function action_setrelated()
{
$id = $_POST['data']['rproduct_id'];
$ralated = ORM::factory('related')->where('rproduct_id','=',$id)->find();
$item = ORM::factory('related', $ralated->id);
if($item->loaded())
{
$item->delete();
}
else
{
$data = $_POST['data'];
$products = ORM::factory('related');
$products->values($data);
$products->save();
}
die;
}
<div class="control-group" style="display:inline-block">
<label class="control-label"><strong>Поиск по названию товара</strong></label>
<form method=post action="/admin/products/related">
<input name=cat type=hidden value="<?=$id?>">
<input name=keyword type=text value='' style="width:350px" placeholder="Поиск по названию товара">
<input style="margin-top:-11px;" type='submit' value='Найти' class="btn btn-success" name="submit">
</form></div>
<form method=post action="/admin/products/"> я заменил на <form method=post action="/admin/products/related">
<?php
if($product->category)
{
foreach($category as $cat)
{
if($cat->id == $product->category){
?><a href="/admin/products/index/<?php echo $product->category ?>"><?php echo $cat->name ?></a><?
break;
} else {
}
}
}
?>
<img src="/media/uploads/<?=isset($product->main_img->image) ? $product->main_img->image : 'noimage.jpg' ?>" style="width:100px">
<?php echo Helper_Cenaot::get_cenaot_name($product->cenaot);?>
<?php if($product->price):?>
<strong>
<?php /*echo $product->price;*/ echo number_format($product->price, 0, ' ', '.')?>
</strong> <span>руб</span>
<?php else:?>
<div style="display:none"><p style="font-size:14px; margin: 0; padding: 0;" title="Цена Договорная">ДОГОВОРНАЯ</p></div>
<?php endif;?>
public function action_index() {
$id = (int) $this->request->param('id');
$settings_limit = $setting =ORM::factory('setting')->where('id', '=', '1')->find()->admin_per_page;
$limit = Session::instance()->get('limit', $settings_limit);
$category = ORM::factory('category')->order_by('id','ASC')->find_all();
if($category){
$categories = array();
foreach($category as $cat){
$categories[$cat->id] = $cat->name;
}
}
if(empty($id))
{
$count = ORM::factory('product')->count_all();
$pagination = Pagination::factory(array('total_items' => $count, 'items_per_page' => $settings_limit));
$products = ORM::factory('product')->limit($pagination->items_per_page)->offset($pagination->offset)->order_by("sorts", "DESC")->find_all();
if(isset($_POST['submit'])){
$data = Arr::extract($_POST, array('cat','keyword'));
$key = $data['keyword'];
if(!empty($data['cat'])){
$products = ORM::factory('product')->where('category','=',$data['cat'])->and_where('prname','LIKE',"%$key%")->order_by("sorts", "DESC")->find_all();
}else{
$products = ORM::factory('product')->where('prname','LIKE',"%$key%")->order_by("sorts", "DESC")->find_all();
}
$id = $data['cat'];
$pagination = "";
}
$content = View::factory('admin/product/v_product_index', array(
'products' => $products,
'pagination' => $pagination,
'category' => $category,
'categories' => $categories,
'id' => $id,
));
}
else
{
$selected_cat = ORM::factory('category', $id);
$this->_get_tree($selected_cat);
$products = DB::select()->from('products');
foreach ($this->_tree as $cat_id)
{
$products->or_where('category', '=', $cat_id);
}
$count = (count($products->execute()->as_array()));
$pagination = Pagination::factory(array('total_items' => $count, 'items_per_page' => $limit));
$products->limit($pagination->items_per_page)->offset($pagination->offset)->order_by("sorts", "DESC");
$products = $products->execute()->as_array();
$content = View::factory('admin/product/v_product_index_category', array(
'products' => $products,
'pagination' => $pagination,
'category' => $category,
'count' => $count,
'categories' => $categories,
'id' => $id,
));
}
$this->template->page_title = 'Товары';
$this->template->content = $content;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question