Jump to content
rifaia

Webservice - Get Product Quantity in the product itselt

Recommended Posts

Hi,

 

I am  new to Prestashop. Currently i am able to access my store through webservice and do all the CRUD operations successfully with the help of this official tutorial.

 

 

I need a custom option of receiving the product (or) product list with the quantity of stock_availables in the product itself, without the need to query again with the stock_available id of the product. 

 

Thanks in Advance.

Share this post


Link to post
Share on other sites

Anyone have idea or suggestions? Please write.

 

Thanks

Share this post


Link to post
Share on other sites

After some trial and error, i found the below way to get the product quantity in the product itself on webservice if you don't have combinations. 

 

Go to file /classes/Product.php

 

Search around line 387 for 

 

           'quantity' => array(

                'getter' => 'false',
                'setter' => false
            ),

 

and change it to 

 

           'quantity' => array(

                'getter' => 'getMyStockforWebService',
                'setter' => false
            ),
 
Then add the following method.
 
 public function getMyStockforWebService(){
    return StockAvailable::getQuantityAvailableByProduct($this->id, 0);
  }
 
 
This might help someone

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More