0

I create a configurable product programmatically and after creating it shows enable field of price and stock.But when i hit save button in admin, the price and quantity become non editable.Which table its saving this change.

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager
        $product_configurable = $objectManager->create('\Magento\Catalog\Model\Product');
        $product_configurable->setData('name', rand(30, 230));
        $product_configurable->setData('sku', rand(5, 340));
        $product_configurable->setAttributeSetId($set);
        $product_configurable->setTypeId('configurable');
        $product_configurable->setStatus(1);
        $product_configurable->setVisibility(4);
        $product_configurable->setPrice($wholedata['product']['price']);
        $product_configurable->setWeight($wholedata['product']['weight']);
        $product_configurable->setShortDescription($wholedata['product']['shortdes']);
        $product_configurable->setDescription($wholedata['product']['descrip']);
        $product_configurable->setWebsiteIds(array(1));
        $product_configurable->setCategoryIds(array($cat_id));
        $qty = $wholedata['product']['stock'];
        $product_configurable->setStockData(array(
                'use_config_manage_stock' => 0,
                'manage_stock' => 1,
                'min_sale_qty' => 1,
                'max_sale_qty' => 1002,
                'is_in_stock' => 0,
                'qty' => 0
            )
        );
        $product_configurable->save();
$productId = 501; // Configurable Product Id
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId); // Load Configurable Product
            $attributeModel = $objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute');
            $position = 0;
            $attributes = array(90); // Super Attribute Ids Used To Create Configurable Product
            $associatedProductIds = array(456); //Product Ids Of Associated Products


            foreach ($attributes as $attributeId) {
                $data = array('attribute_id' => $attributeId, 'product_id' => $productId, 'position' => $position);
                $position++;
                $attributeModel->setData($data)->save();
            }
            $product->setTypeId("configurable"); // Setting Product Type As Configurable
            $product->setAffectConfigurableProductAttributes(4);
            $objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable')->setUsedProductAttributeIds($attributes, $product);
            $product->setNewVariationsAttributeSetId(4); // Setting Attribute Set Id
            $product->setAssociatedProductIds($associatedProductIds);// Setting Associated Products
            $product->setCanSaveConfigurableAttributes(true);
            $product->save();

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.