- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to create ConfigurableProduct?
How do I create a configurable product? I am looking at Magento\ConfigurableProduct\Api and still have no idea how to actually create a configurable product... Looking at StackOverflow, seems like lots of people are using object manager, and I also read that using object manager isn't recommended now, so how do I do this?
Is there any documentation and code examples how to create configurable product in codes, without using object manager?
About the Api folder, these also confuses me:
- LinkManagementInterface has addChild, but ConfigurableProductManagementInterface has generateVariation, both seems to do the same thing - that is, add a variation to a simple product. So what do I need to use, in what order, how?
- Then, what about OptionRepositoryInterface? I assume we need to use this to create a configurable product since it has the most similar functionality to ProductRepositoryInterface used to create product, but it's taking in OptionInterface which doesn't have any fields related to attribute??
tldr: This is all so confusing, can someone just show how to create a configurable product?
Below is as far as my understanding managed to take me in creating a simple product, I'm still clueless how to create a configurable product.
public function __construct(ProductInterfaceFactory $factory, ProductRepositoryInterface $repository) { $this->repository = $repository; $this->factory = $factory; } public function setEntity($source) { $product = $this->factory->create(); $product->setSku($source->getId()); $product->setName($source->getDescription()); $product->setPrice($source->getUnitPrice()); $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); $product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); $this->repository->save($product); }
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to create ConfigurableProduct?
Hey,
You might want to have a look here:
Did it work for you?
---------------------------------------------------------
If you've found one of our answers useful, please give 'Kudos' or 'Accept as Solution'.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to create ConfigurableProduct?
As I said, without using object manager. I can't figure out how to do it without using object manager.. :\
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to create ConfigurableProduct?
public function __construct( \Magento\Catalog\Model\ProductFactory $productFactory ) { $this->productFactory = $productFactory; } Now instead of using objectManager, You can use as below way, $configproduct = $this->productFactory->create(); $configproduct->setPrice(); $configproduct->setSku();
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content