Change the code:
if($this->row->product_quantity == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK')
$text = JText::sprintf('X_ITEM_IN_STOCK', $this->row->product_quantity);
else
$text = JText::sprintf('X_ITEMS_IN_STOCK', $this->row->product_quantity);
to:
if(!empty($this->element->product_id)){ if($this->row->product_quantity == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK')
$text = JText::sprintf('X_ITEM_IN_STOCK', $this->row->product_quantity);
else
$text = JText::sprintf('X_ITEMS_IN_STOCK', $this->row->product_quantity); }
in the file "quantity" of the view "product" via the menu Display>Views and that should do it.