Answer the question
In order to leave comments, you need to log in
Simplacms how to make it so that it does not show product options in the filter with a quantity of 0?
In simple 2.1, there is no functionality for filters by product variants, I installed a filter , on top of a fresh system, everything works, but if a product variant has a quantity of 0, and even a price of 0, then it still shows this variant in the filter, while in the options goods everything works.
Tell me how to remove unnecessary options from the filters. All code is in the file above. But I will give the code in which I think you can change it so that everything works out) Thank you!
veiw/ProductsView.php
if(!empty($category) || !empty($brand)) {
$variant_products = array();
foreach($this->products->get_id_products($filter) as $p)
$variant_products[$p->id] = $p;
$variant_products_ids = array_keys($variant_products);
$features_variants = array();
$temp_variants = $this->variants->get_value_variants(array('product_id'=>$variant_products_ids, 'stock'=>true));
foreach($temp_variants as &$variant)
$features_variants[$variant->name] = $variant->name;
asort($features_variants);
$this->design->assign('features_variants', $features_variants);
veiw/ProductsView.php
if(!empty($category) || !empty($brand)) {
$variant_products = array();
foreach($this->products->get_id_products($filter) as $p)
$variant_products[$p->id] = $p;
$variant_products_ids = array_keys($variant_products);
$features_variants = array();
$temp_variants = $this->variants->get_value_variants(array('product_id'=>$variant_products_ids, 'stock'=>true));
foreach($temp_variants as &$variant)
$features_variants[$variant->name] = $variant->name;
asort($features_variants);
$this->design->assign('features_variants', $features_variants);
api/Variants.php
public function get_value_variants($filter = array())
{
$product_id_filter = '';
$instock_filter = '';
if(!empty($filter['product_id']))
$product_id_filter = $this->db->placehold('AND v.product_id in([email protected])', (array)$filter['product_id']);
if(!empty($filter['in_stock']) && $filter['in_stock'])
$instock_filter = $this->db->placehold('AND (v.stock>0 OR v.stock IS NULL)');
if(!$product_id_filter)
return array();
$query = $this->db->placehold("SELECT v.name
FROM __variants AS v
WHERE
v.name <> ''
$product_id_filter
$instock_filter
GROUP BY v.name
");
$this->db->query($query);
return $this->db->results();
}
{if $features_variants|count > 1}
<tr>
<td class="feature_name">Варианты:</td>
<td class="feature_values">
{foreach $features_variants as $o}
<label><input type="checkbox" name="v[]" value="{$o}"{if $smarty.get.v && $o|in_array:$smarty.get.v} checked{/if}>
{$o|escape}{$o|count|escape}
{/foreach}
</label>
</td>
</tr>
{/if}
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