Skip to main content
added 213 characters in body
Source Link
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Magento\Checkout\Model\CartFactory $cartFactory
        )
    {
        $this->_pageFactory = $pageFactory;
        $this->cartFactory = $cartFactory;
        return parent::__construct($context);
    }
if (!empty($post)) {
   foreach($post['name'] as $key => $name) {
            $age    = $post['age'][$key];
            $weight = $post['weight'][$key];
            $height = $post['height'][$key];
            $gender = $post['gender'][$key];
            $product_id = $post['product_id'][$key];
            $customer_id = $post['customer_id'][$key];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);

             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
}
            echo $msg;  

            $cartObject = $this->cartFactory->create()->truncate();
            $cartObject->saveQuote();
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory
        )
    {
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);
    }
if (!empty($post)) {
   foreach($post['name'] as $key => $name) {
            $age    = $post['age'][$key];
            $weight = $post['weight'][$key];
            $height = $post['height'][$key];
            $gender = $post['gender'][$key];
            $product_id = $post['product_id'][$key];
            $customer_id = $post['customer_id'][$key];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);

             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
}
            echo $msg; 
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Magento\Checkout\Model\CartFactory $cartFactory
        )
    {
        $this->_pageFactory = $pageFactory;
        $this->cartFactory = $cartFactory;
        return parent::__construct($context);
    }
if (!empty($post)) {
   foreach($post['name'] as $key => $name) {
            $age    = $post['age'][$key];
            $weight = $post['weight'][$key];
            $height = $post['height'][$key];
            $gender = $post['gender'][$key];
            $product_id = $post['product_id'][$key];
            $customer_id = $post['customer_id'][$key];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);

             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
}
            echo $msg;  

            $cartObject = $this->cartFactory->create()->truncate();
            $cartObject->saveQuote();
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }
added 3555 characters in body
Source Link

Step: 1

Please change the code in controller file as below

Step 2:

Change the code in controller section

From =

if (!empty($post)) {
            $name   = $post['name'];
            $age    = $post['age'];
            $weight = $post['weight'];
            $height = $post['height'];
            $gender = $post['gender'];
            $product_id = $post['product_id'];
            $customer_id = $post['customer_id'];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            /* $model->setName($name);
            $model->setAge($age);
            $model->setWeight($weight);
            $model->setHeight($height);
            $model->setGender($gender);
            $model->setGender($product_id);
            $model->setGender($customer_id); */
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);
        
        /* echo "<pre>";
        print_r($model);
        die(); */
            
             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
            echo $msg; 
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }

To=

if (!empty($post)) {
   foreach($post['name'] as $key => $name) {
            $age    = $post['age'][$key];
            $weight = $post['weight'][$key];
            $height = $post['height'][$key];
            $gender = $post['gender'][$key];
            $product_id = $post['product_id'][$key];
            $customer_id = $post['customer_id'][$key];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);

             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
}
            echo $msg; 
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }

Please change the code in controller file as below

Step: 1

Please change the code in controller file as below

Step 2:

Change the code in controller section

From =

if (!empty($post)) {
            $name   = $post['name'];
            $age    = $post['age'];
            $weight = $post['weight'];
            $height = $post['height'];
            $gender = $post['gender'];
            $product_id = $post['product_id'];
            $customer_id = $post['customer_id'];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            /* $model->setName($name);
            $model->setAge($age);
            $model->setWeight($weight);
            $model->setHeight($height);
            $model->setGender($gender);
            $model->setGender($product_id);
            $model->setGender($customer_id); */
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);
        
        /* echo "<pre>";
        print_r($model);
        die(); */
            
             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
            echo $msg; 
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }

To=

if (!empty($post)) {
   foreach($post['name'] as $key => $name) {
            $age    = $post['age'][$key];
            $weight = $post['weight'][$key];
            $height = $post['height'][$key];
            $gender = $post['gender'][$key];
            $product_id = $post['product_id'][$key];
            $customer_id = $post['customer_id'][$key];
        
            $model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');           
            
            $model->setData([
                    "name" => $name,
                    "age" => $age,
                    "weight" => $weight,
                    "height" => $height,
                    "gender" => $gender,
                    "product_id" => $product_id,
                    "customer_id" => $customer_id
                    ]);

             $msg ="";
             $data =  $model->save();
            if($data != ''){ 
                //$model->save(); 
                $this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
            }else{ 
                $this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!'); 
            } 
}
            echo $msg; 
            
            // Redirect to your form page (or anywhere you want...)
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultRedirect->setUrl('/prescription/index');
            return $resultRedirect;
        }
Source Link

Please change the code in controller file as below

From:

protected $_postFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Softadroit\Prescription\Controller\Index $postFactory
        )
    {
        $this->_pageFactory = $pageFactory;
        $this->_postFactory = $postFactory;
        return parent::__construct($context);
    }

To:

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory
        )
    {
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);
    }

After that run php bin/magento setup:upgrade And then you can run php bin/magento setup:di:compile