pageFactory = $pageFactory; $this->messageManager = $messageManager; $this->resultFactory = $context->getResultFactory(); $this->inlineTranslation = $inlineTranslation; $this->escaper = $escaper; $this->transportBuilder = $transportBuilder; $this->logger = $helperContext->getLogger(); $this->quoteInApi = $quoteInApi; $this->logHelper = $logHelper; parent::__construct($context); } private function preparePostData($data){ if (!array_key_exists('items', $data)) { return null; } for ($x = 0; $x < count($data["items"]); $x++) { $data["items"][$x]["productId"] = "test"; if (!array_key_exists('quote_ins', $data["items"][$x])) { $data["items"][$x]["quote_ins"] = array(); } $quote_ins_custom = array(); foreach ($data["items"][$x]["quote_ins"] as $quote_in) { $quote_in_custom = array(); foreach ($quote_in as $key => $value) { $quote_in_custom[$key] = $value; } array_push($quote_ins_custom, $quote_in_custom) ; } $data["items"][$x]["quote_ins"] = $quote_ins_custom; } return $data; } private function getCustomer(){ $om = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $om->get('Magento\Customer\Model\Session'); $customer = $customerSession->getCustomer(); return $customer; } public function execute() { $customer = $this->getCustomer(); $data = $this->getRequest()->getPostValue(); if (!empty($data)) { $this->logHelper->setName(self::LOG_FILE); $this->quoteInApi->setLogHelper($this->logHelper); $post_data_to_erp = array( "urlAPI" => "/api/magento/quotein-save", "data" => $data["data"] ); $response = $this->quoteInApi->login(); if ($response) { //$this->logHelper->write($this->quoteInApi->getToken()); $rep = $this->quoteInApi->saveQuoteInToERP($post_data_to_erp); if ($rep) { $this->messageManager->addSuccess(__("Thank you. We'll get back to you very soon.")); } else { $this->messageManager->addError(__("Error, Please try again")); } } else { $this->messageManager->addError(__("Error, Please try again")); } } return $this->pageFactory->create(); } }