php - how to get stock status in opencart product page

424

I want to show

out of stock

on my product page and I change the status from admin and is updated in admin but on my product page there is also same

In Stock

and product page code is

        if ($product_info['quantity'] <= 0) {
                $this->data['stock'] = $product_info['stock_status'];
            } elseif ($this->config->get('config_stock_display')) {
                $this->data['stock'] = $product_info['quantity'];
            } else{
                $this->data['stock'] = $this->language->get('text_instock');

        }

and language page is

$_['text_outstock']     = 'Out of Stock'; 

Now what condition is used there?

790

Answer

Solution:

As far as I understand your issue, you can set it directly in the Admin to show 'out of stock' message.

You need to set it both in the general settings AND in the invidividual product.

Currently, because you did not set your Admin settings correctly,$product_info['stock_status'] does not display 'out of stock'.

However, if you insist of modifying the code, you need to use the following:

 if ($product_info['quantity'] <= 0) {
      //out of stock message
      $this->data['stock'] = $this->language->get('text_outstock');
  } elseif ($this->config->get('config_stock_display')) {
      //in stock, and displaying exact quantity
      $this->data['stock'] = $product_info['quantity'];
  } else{
      //in stock, but just display a message not exact quantity
      $this->data['stock'] = $this->language->get('text_instock');
  }

Hope this helps!

People are also looking for solutions to the problem: Store array of objects in PHP session

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.