I want to programmatically update product information, such as quantity, price, etc.
(from outside of the Magento source directory.)
How can I do that?
I want to programmatically update product information, such as quantity, price, etc.
(from outside of the Magento source directory.)
How can I do that?
2
Answers
Magento is pretty easy to bootstrap. If you want a standalone script where you can access all your functions, just add the following at the top of your PHP file :
After that you can load all your models. To update your products I suggest you two ways. The regular one :
Or the API model usage :
I’d highly recommend leveraging the REST APIs available in M2x to Create/Update products and its attributes.
Note: You have the option of using OAuth or Bearer Tokens in Magento 2 to Authenticate/Authorize your API invocations.
You can find additional information on all the APIs available in Magento 2.1 here –
http://devdocs.magento.com/swagger/index_21.html
You’ll find specifics of the APIs you need under the grouping titled
catalogProductRepositoryV1
GET /V1/products
GET /V1/products/{sku}
POST /V1/products
PUT /V1/products/{sku}
I haven’t tested the code, but I think something like this should do the trick: