1) Файл api/Variants.php
1.1.) В функции get_variants после
Код: Выделить всё
$instock_filter = '';
добавим
Код: Выделить всё
$order = 'v.position, v.id';
if(!empty($filter['sort_stock'])) {
$order = 'stock DESC, '.$order;
}
1.2) В той же функции ниже в SQL запросе вместо
Код: Выделить всё
ORDER BY v.position, v.id
пишем
Код: Выделить всё
ORDER BY $order
2) Файл view/ProductView.php
Вместо
Код: Выделить всё
foreach($this->variants->get_variants(array('product_id'=>$product->id)) as $v) {
$variants[$v->id] = $v;
}
пишем
Код: Выделить всё
foreach($this->variants->get_variants(array('product_id'=>$product->id, 'sort_stock'=>1)) as $v) {
$variants[$v->id] = $v;
}
3) Файл view/ProductsView.php
Вместо
Код: Выделить всё
$variants = $this->variants->get_variants(array('product_id'=>$products_ids));
пишем
Код: Выделить всё
$variants = $this->variants->get_variants(array('product_id'=>$products_ids, 'sort_stock'=>1));
4) В файле view/BlogView.php
вместо
Код: Выделить всё
$related_products_variants = $this->variants->get_variants(array('product_id'=>array_keys($related_products)));
пишем
Код: Выделить всё
$related_products_variants = $this->variants->get_variants(array('product_id'=>array_keys($related_products), 'sort_stock'=>1));
5) В файле view/WishlistView.php
Вместо
Код: Выделить всё
foreach ($this->variants->get_variants(array('product_id' => $products_ids)) as $variant) {
пишем
Код: Выделить всё
foreach ($this->variants->get_variants(array('product_id' => $products_ids, 'sort_stock'=>1)) as $variant) {
6) Убираем уже ненужный нам код из design/ВАШ_ШАБЛОН/html/scripts.tpl
Код: Выделить всё
{if $smarty.get.module == "MainView" || $smarty.get.module == "ProductsView" || $smarty.get.module == "ProductView" || $smarty.get.module == "ComparisonView" || $smarty.get.module == "WishlistView" || $smarty.get.module == "BlogView"}
$(document).ready(function(){
$('select[name=variant]').each(function(){
var first_in_stock = $(this).find('option[data-stock!="0"]').first();
first_in_stock.prop('selected',true);
first_in_stock.trigger('change');
});
});
{/if}