Read More
Read More
Menu Close

    Magento2 – Programmatically Create Product

    Create Product Programatically

    Here we will see how to create product in magento2 with given data.
    Use following code to programmatically create product in magento2.

    Note: There are some points you need to remember when using this code snippet.

    1- If you want to create configurable product then you have to assign associated product to current product otherwise it will create simple product. See here how to add associated products.

    2- If you do not set weight, it will create simple product.

    3- If you want to create downloadable product then you have to add download links to current product otherwise it will create virtual/simple product.

    Searching for an experienced
    Magento 2 Company ?
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    3 comments

  • Amitkumar Magento Developer
    what about categories to assign product?
    • Miroslav Kodet
      use MagentoCatalogApiCategoryLinkManagementInterface;

      $CategoryLinkManagementInterface->assignProductToCategories(
      $product->getSku(),
      [
      $id1,
      $id2,
      $id3…
      ]
      );

  • AlaaGh
    If I want to include this code on a module, should I put it on the block file?
  • Back to Top