VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: kiasati on July 23, 2017, 17:31:50 PM

Title: not to list products that are not in stock
Post by: kiasati on July 23, 2017, 17:31:50 PM
Hi

i have a module that shows categories of products in front page.
I dont want the products that are not in stock available to be shown.

there is a function in the module code to select the products:


public static function _CountProduct($catids, $params)
{
if ($catids == '*') {
$_catids = $params->get('catid');
$catids = self::_getChildCategories($_catids, $params);
$catids = self::_getPublishCategories($catids);
}
if (empty($catids)) return;

$limitation = 999;
$source_group = null;
$ordering_direction = $params->get('product_ordering_direction');
$source_order = $params->get('source_order', 'group.featured');
$p_special = $params->get('show_front');
$categoryModel = VmModel::getModel('Category');
$categoryModel->_noLimit = true;

$list = array();
if (!empty($catids)) {
$productModel = VmModel::getModel('Product');
$productModel = new VirtuemartModelProductExtend();
$productModel->filter_order = $source_order;
$productModel->specail_product = $p_special;
$productModel->ordering_direction = $ordering_direction;
$desc_maxlength = $params->get('item_des_maxlength');
$items = $productModel->getProductListing($source_group, $limitation, true, true, false, true, $catids);
$productModel->addImages($items);
$ratingModel = VmModel::getModel('ratings');
foreach ($items as $item) {
$item->title = $item->product_name;
$item->id = $item->virtuemart_product_id;
$item->description = $item->product_desc;
self::getVmImages($item, $params);
$item->short_desc = self::_cleanText($item->product_s_desc);
$item->_description = self::_cleanText($item->description);
$item->_description = ($item->_description != '') ? self::truncate($item->_description, $desc_maxlength) : self::truncate($item->short_desc, $desc_maxlength);
$item->vote = $ratingModel->getVoteByProduct($item->virtuemart_product_id);
$item->rating = $ratingModel->getRatingByProduct($item->virtuemart_product_id);
$list[] = $item;
}
}


return count($list);
}




how should i change this function to do so?

any help would be appreciated.
thanks
Title: Re: not to list products that are not in stock
Post by: technext2k on August 01, 2017, 23:03:33 PM
I think there should an API function to get stock but if none is there, you can directly get product_in_stock field from products table.
Title: Re: not to list products that are not in stock
Post by: kiasati on August 05, 2017, 16:52:49 PM
Quote from: technext2k on August 01, 2017, 23:03:33 PM
I think there should an API function to get stock but if none is there, you can directly get product_in_stock field from products table.
i didnt get it. :/

ANY HELP EVERYBODY??!
Title: Re: not to list products that are not in stock
Post by: jjk on August 05, 2017, 18:44:12 PM
Did you try 'Action when a Product is Out of Stock' > 'Do not Display Product' in 'VM configuration' > 'Shopfront' tab?
Title: Re: not to list products that are not in stock
Post by: kiasati on August 06, 2017, 12:19:07 PM
Quote from: jjk on August 05, 2017, 18:44:12 PM
Did you try 'Action when a Product is Out of Stock' > 'Do not Display Product' in 'VM configuration' > 'Shopfront' tab?
I do want to display the products that are out of stock. but i don't want them to display only in a specific module.
so i have to edit this part of code in the module