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();
}
}
}
}
}
}
}