Sort and filter by product_sort_price

  • Posts: 410
  • Thank you received: 15
3 years 4 months ago #325773

-- HikaShop version -- : 4.4.0

Hello, very much please add support for sorting and filtering via product_sort_price.This is what I need to sort and filter products without a main price. Is there a trigger that can do this?

Please Log in or Create an account to join the conversation.

  • Posts: 410
  • Thank you received: 15
3 years 4 months ago #325774

I seem to be confused with that again - www.hikashop.com/forum/filters-search/90...r-does-not-work.html . Is there possible by the trigger after save variant to take the lowest price of the variants and recorded as the main product price?

Last edit: 3 years 4 months ago by neo191987.

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13036
  • MODERATOR
3 years 4 months ago #325803

Hi,

I've made a patch on our end for the next version so you'll have a hidden setting to change that in the future where you'll just have to enter an entry with the namekey sort_price_select_mode and the value cheapest in the hikashop_config table and it will do it.
For now, what you can do is change the line:
if($price->price_min_quantity <= 1)
to:
if(empty($selectedPrice) || $selectedPrice->price_value < $price->price_value)
in the file administrator/components/com_hikashop/classes/product.php

The following user(s) said Thank You: neo191987

Please Log in or Create an account to join the conversation.

  • Posts: 410
  • Thank you received: 15
3 years 4 months ago #326256

Hi, I was able to fix the problem with this code. If you can add such a feature it will be fine. In case we use only variants created by other vendors without a basic price entered and we want to take the lowest price of the variant so that the sorting and filtering of products works properly. In this case, it will be very difficult to monitor and update all product prices manually, and if we do not, sorting and filtering will not be correct, so I needed this option.

public function onHikashopBeforeDisplayView(&$view) {
if(!$this->app->isAdmin()) {
$ctrl = hikaInput::get()->getCmd('ctrl', '');
$task = hikaInput::get()->getCmd('task', '');
if($ctrl != 'category' && $task != 'listing' || $ctrl != 'product' && $task != 'listing') return;
$db = JFactory::getDBO();
$product_class = hikashop_get('class.product');
if(!empty($view->rows)) {
foreach($view->rows as $key => $value) { if(isset($value->product_published) && $value->product_published == 1) { $products[$key] = $value; } } }
if(!empty($products)) {
foreach($products as $data) {
$product_class->getProducts($data->product_id);
foreach($product_class->products as $product) {
$product_class->orderVariants($product);
if(!empty($product->variants)) {
$variants = array_slice($product->variants, 0, 1);
foreach($variants as $variant) {
$price_id = (int)$product->prices[0]->price_id;
$price_product_id = (int)$variant->product_parent_id;
$price_currency_id = (int)$variant->prices[0]->price_currency_id;
$price_min_quantity = (int)$variant->prices[0]->price_min_quantity;
$price_start_date = (int)$variant->prices[0]->price_start_date;
$price_end_date = (int)$variant->prices[0]->price_end_date;
$price_value = (float)$variant->prices[0]->price_value;
$price_site_id = $db->Quote($variant->prices[0]->price_site_id);
$price_access = $db->Quote($variant->prices[0]->price_access);
$price_users = $db->Quote($variant->prices[0]->price_users);
if($price_id != 0) {
$query = 'UPDATE '.hikashop_table('price').' SET price_currency_id = '.$price_currency_id.', price_product_id = '.$price_product_id.', price_min_quantity = '.$price_min_quantity.', price_value = '.$price_value.', price_site_id = '.$price_site_id.', price_access = '.$price_access.', price_users = '.$price_users.', price_start_date = '.$price_start_date.', price_end_date = '.$price_end_date.' WHERE price_id = '.$price_id.' AND price_value != '.$price_value;
}
else {
$insert = array();
$insert[] = '('.$price_currency_id.','.$price_product_id.','.$price_min_quantity.','.$price_value.','.$price_site_id.','.$price_access.','.$price_users.','.$price_start_date.','.$price_end_date.')'; $select = 'price_currency_id, price_product_id, price_min_quantity, price_value, price_site_id, price_access, price_users, price_start_date, price_end_date'; $query = 'REPLACE '.hikashop_table('price').' ('.$select.') VALUES '.implode(',',$insert).';';
}
$db->setQuery($query);
$db->execute();
}
}
}
}
}
}
}

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13036
  • MODERATOR
3 years 4 months ago #326279

Hi,

The patch will be in the next version of HikaShop. Make sure you have the entry with the namekey sort_price_select_mode and the value "cheapest" in the hikashop_config table of your database so that when you update your HikaShop, you'll keep the sorting_price selection working as with this patch.

The following user(s) said Thank You: neo191987

Please Log in or Create an account to join the conversation.

Time to create page: 0.064 seconds
Powered by Kunena Forum