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:
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); }
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'.
As I said, without using object manager. I can't figure out how to do it without using object manager.. :\
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();