Magento 2: Column is exists but throwing Column not found: 1054 Unknown column 'so.event_id' in 'where clause' while inserting into sales_orderSQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause'Column not found: 1054 Unknown column 'ca.sort_order' in 'order clause' errorThe requested Payment Method is not available When creating an orderMagento2 : How to get guest email address after shipping address and before placeorder?Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'marca_filter.value' in 'where clause'Column not found: 1054 Unknown column 'catalog_product_entity_varchar.ebay_template_new' in 'field list'Column not found: 1054 Unknown column 'at_status_default.value'Address Information And Customer address are not showing in magento 2Column not found: 1054 Unknown column 'billing_telephone'Magento 2: Payment Method Not Capturing Shipping Address From Payment Page

Where does the Z80 processor start executing from?

What is paid subscription needed for in Mortal Kombat 11?

Roman Numeral Treatment of Suspensions

Do sorcerers' Subtle Spells require a skill check to be unseen?

What does "I’d sit this one out, Cap," imply or mean in the context?

Integer addition + constant, is it a group?

Opposite of a diet

What can we do to stop prior company from asking us questions?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Large drywall patch supports

How can I kill an app using Terminal?

Closest Prime Number

Applicability of Single Responsibility Principle

Are student evaluations of teaching assistants read by others in the faculty?

CREATE opcode: what does it really do?

Different result between scanning in Epson's "color negative film" mode and scanning in positive -> invert curve in post?

How does it work when somebody invests in my business?

Is the destination of a commercial flight important for the pilot?

You cannot touch me, but I can touch you, who am I?

System.debug(JSON.Serialize(o)) Not longer shows full string

How does Loki do this?

Is there a good way to store credentials outside of a password manager?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Proof of work - lottery approach



Magento 2: Column is exists but throwing Column not found: 1054 Unknown column 'so.event_id' in 'where clause' while inserting into sales_order


SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause'Column not found: 1054 Unknown column 'ca.sort_order' in 'order clause' errorThe requested Payment Method is not available When creating an orderMagento2 : How to get guest email address after shipping address and before placeorder?Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'marca_filter.value' in 'where clause'Column not found: 1054 Unknown column 'catalog_product_entity_varchar.ebay_template_new' in 'field list'Column not found: 1054 Unknown column 'at_status_default.value'Address Information And Customer address are not showing in magento 2Column not found: 1054 Unknown column 'billing_telephone'Magento 2: Payment Method Not Capturing Shipping Address From Payment Page













1















I have event_id column in my sales_order table. I want to place an order & I am not sending event_id because its zero by default. When am trying to place an order, Its throwing me the error Column not found: 1054 Unknown column 'so.event_id' in 'where clause', query was: INSERT INTO sales_order ...



enter image description here



I have already run all cache & upgrade commands many times but I don't know why its doing this. Here is my code:



public function createMageOrder($orderData) 
$store = $this->_storeManager->getStore();
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($orderData["entity"]["customer_email"]); // load customet by email address
if (!$customer->getEntityId())
echo "Customer does not exist. please create here...";
exit;
//If not avilable then create this customer
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($orderData['shipping_address']['firstname'])
->setLastname($orderData['shipping_address']['lastname'])
->setEmail($orderData['email'])
->setPassword($orderData['email']);
$customer->save();

$quote = $this->quote->create(); //Create object of quote
$quote->setStore($store); //set store for which you create quote
// if you have allready buyer id then you can load customer directly
$customer = $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
foreach ($orderData["entity"]["items"] as $item)
$product = $this->_product->load($item['product_id']);
$product->setPrice($item['price']);
$quote->addProduct(
$product, intval($item['qty_ordered'])
);


//Set Address to quote
$quote->getBillingAddress()->addData($orderData["entity"]["billing_address"]);
$quote->getShippingAddress()->addData($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]);

// Collect Rates and Set Shipping & Payment Method
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"]); //shipping method
$quote->setPaymentMethod($orderData["entity"]["payment"]["method"]); //payment method
$quote->setInventoryProcessed(false); //not effetc inventory
$quote->save(); //Now Save quote and your quote is ready
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $orderData["entity"]["payment"]["method"]]);
// $quote->setData('event_id', $orderData["entity"]["event_id"]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();

// Create Order From Quote
$order = $this->quoteManagement->submit($quote);

$order->setEmailSent(0);
$increment_id = $order->getRealOrderId();
if ($order->getEntityId())
$result['order_id'] = $order->getRealOrderId();
else
$result = ['error' => 1, 'msg' => 'Your custom message'];

return $result;



I am calling this function in placeGTOrder($post) function where $post is my $orderData. Here is the function on which am sending my request as an action:



public function placeGTOrder($post) 
$formData = $this->_helper->unserializeForm($post['formData']);
$order = array();

//fill cart items to order items
$cart = $this->_objectManager->get('MagentoCheckoutModelCart');
$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();
$getItems = [];
foreach ($items as $item)
$collect = array();
$collect["base_original_price"] = 45;
$collect["base_price"] = 45;
$collect["base_price_incl_tax"] = 45;
$collect["base_row_invoiced"] = 0;
$collect["base_row_total"] = 45;
$collect["base_tax_amount"] = 0;
$collect["base_tax_invoiced"] = 0;
$collect["discount_amount"] = 4.5;
$collect["discount_percent"] = 10;
$collect["free_shipping"] = 0;
$collect["is_virtual"] = 0;
$collect["name"] = $item->getName();
$collect["original_price"] = 45;
$collect["price"] = 45;
$collect["price_incl_tax"] = 45;
$collect["product_id"] = $item->getProductId();
$collect["product_type"] = "simple";
$collect["qty_ordered"] = $item->getQty();
$collect["row_total"] = 45;
$collect["row_total_incl_tax"] = 45;
$collect["sku"] = $item->getSku();
$collect["store_id"] = 1;
$getItems[] = $collect;



// $order["entity"]["event_id"] = $formData["eventID"];
$order["entity"]["base_currency_code"] = "USD";
$order["entity"]["base_discount_amount"] = -4.5;
$order["entity"]["base_grand_total"] = 45.5;
$order["entity"]["base_shipping_amount"] = 5;
$order["entity"]["base_subtotal"] = 45;
$order["entity"]["base_tax_amount"] = 0;
$order["entity"]["customer_email"] = urldecode($formData['Email']);
$order["entity"]["customer_firstname"] = $formData['FirstName'];
$order["entity"]["customer_group_id"] = 3;
$order["entity"]["customer_id"] = $formData['selected_customer_id'];
$order["entity"]["customer_is_guest"] = 0;
$order["entity"]["customer_lastname"] = $formData['LastName'];
$order["entity"]["customer_note_notify"] = 1;
$order["entity"]["discount_amount"] = -4.5;
$order["entity"]["email_sent"] = 1;
$order["entity"]["coupon_code"] = "";
$order["entity"]["discount_description"] = "Test1";
$order["entity"]["grand_total"] = 45.5;
$order["entity"]["is_virtual"] = 0;
$order["entity"]["order_currency_code"] = "USD";
$order["entity"]["shipping_amount"] = 5;
$order["entity"]["shipping_description"] = "Flat Rate - Fixed";
$order["entity"]["state"] = "new";
$order["entity"]["status"] = "pending";
$order["entity"]["store_currency_code"] = "USD";
$order["entity"]["store_id"] = 1;
$order["entity"]["store_name"] = "Main WebsitenMain Website Storen";
$order["entity"]["subtotal"] = 45;
$order["entity"]["subtotal_incl_tax"] = 45;
$order["entity"]["tax_amount"] = 0;
$order["entity"]["total_item_count"] = 1;
$order["entity"]["total_qty_ordered"] = 1;
$order["entity"]["weight"] = 1;
$order["entity"]["items"] = $getItems;
$order["entity"]["billing_address"]["address_type"] = "billing";
$order["entity"]["billing_address"]["city"] = urldecode($formData['MainAddress.City']);
$order["entity"]["billing_address"]["company"] = "";
$order["entity"]["billing_address"]["country_id"] = urldecode($formData["MainAddress.Country"]);
$order["entity"]["billing_address"]["email"] = urldecode($formData['Email']);
$order["entity"]["billing_address"]["firstname"] = urldecode($formData['FirstName']);
$order["entity"]["billing_address"]["lastname"] = urldecode($formData['LastName']);
$order["entity"]["billing_address"]["postcode"] = urldecode($formData['MainAddress.Zip']);
$order["entity"]["billing_address"]["region"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_code"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_id"] = 19;
$order["entity"]["billing_address"]["street"] = array(urldecode($formData["MainAddress.Address1"]), urldecode($formData["MainAddress.Address2"]));
$order["entity"]["billing_address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["payment"]["method"] = "checkmo";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["address_type"] = "shipping";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["city"] = urldecode($formData["MailingAddress.City"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["company"] = "";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["country_id"] = urldecode($formData["MailingAddress.Country"]);
// $order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["customer_address_id"] = 2;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["email"] = urldecode($formData["Email"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["firstname"] = urldecode($formData["FirstName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["lastname"] = urldecode($formData["LastName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["postcode"] = urldecode($formData["MainAddress.Zip"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_code"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_id"] = 19;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["street"] = array(urldecode($formData["MailingAddress.Address1"]), urldecode($formData["MailingAddress.Address2"]));
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"] = "flatrate_flatrate";

$result = $this->createMageOrder($order);
echo json_encode($result); exit;
// $ApiResponse = $this->_helper->placeOrderByAPI($order);
// print_r($ApiResponse);
exit;
exit;










share|improve this question
























  • your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

    – Knight017
    yesterday











  • In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

    – Abdulrehman Sheikh
    yesterday











  • Okay, then this blog may help you atwix.com/magento-2/…

    – Knight017
    yesterday












  • There shouldn't be an exit anywhere in your code. It should be handled differently.

    – Shawn Abramson
    22 hours ago











  • Exit is not an issue. I just want to insert an order

    – Abdulrehman Sheikh
    20 hours ago















1















I have event_id column in my sales_order table. I want to place an order & I am not sending event_id because its zero by default. When am trying to place an order, Its throwing me the error Column not found: 1054 Unknown column 'so.event_id' in 'where clause', query was: INSERT INTO sales_order ...



enter image description here



I have already run all cache & upgrade commands many times but I don't know why its doing this. Here is my code:



public function createMageOrder($orderData) 
$store = $this->_storeManager->getStore();
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($orderData["entity"]["customer_email"]); // load customet by email address
if (!$customer->getEntityId())
echo "Customer does not exist. please create here...";
exit;
//If not avilable then create this customer
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($orderData['shipping_address']['firstname'])
->setLastname($orderData['shipping_address']['lastname'])
->setEmail($orderData['email'])
->setPassword($orderData['email']);
$customer->save();

$quote = $this->quote->create(); //Create object of quote
$quote->setStore($store); //set store for which you create quote
// if you have allready buyer id then you can load customer directly
$customer = $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
foreach ($orderData["entity"]["items"] as $item)
$product = $this->_product->load($item['product_id']);
$product->setPrice($item['price']);
$quote->addProduct(
$product, intval($item['qty_ordered'])
);


//Set Address to quote
$quote->getBillingAddress()->addData($orderData["entity"]["billing_address"]);
$quote->getShippingAddress()->addData($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]);

// Collect Rates and Set Shipping & Payment Method
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"]); //shipping method
$quote->setPaymentMethod($orderData["entity"]["payment"]["method"]); //payment method
$quote->setInventoryProcessed(false); //not effetc inventory
$quote->save(); //Now Save quote and your quote is ready
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $orderData["entity"]["payment"]["method"]]);
// $quote->setData('event_id', $orderData["entity"]["event_id"]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();

// Create Order From Quote
$order = $this->quoteManagement->submit($quote);

$order->setEmailSent(0);
$increment_id = $order->getRealOrderId();
if ($order->getEntityId())
$result['order_id'] = $order->getRealOrderId();
else
$result = ['error' => 1, 'msg' => 'Your custom message'];

return $result;



I am calling this function in placeGTOrder($post) function where $post is my $orderData. Here is the function on which am sending my request as an action:



public function placeGTOrder($post) 
$formData = $this->_helper->unserializeForm($post['formData']);
$order = array();

//fill cart items to order items
$cart = $this->_objectManager->get('MagentoCheckoutModelCart');
$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();
$getItems = [];
foreach ($items as $item)
$collect = array();
$collect["base_original_price"] = 45;
$collect["base_price"] = 45;
$collect["base_price_incl_tax"] = 45;
$collect["base_row_invoiced"] = 0;
$collect["base_row_total"] = 45;
$collect["base_tax_amount"] = 0;
$collect["base_tax_invoiced"] = 0;
$collect["discount_amount"] = 4.5;
$collect["discount_percent"] = 10;
$collect["free_shipping"] = 0;
$collect["is_virtual"] = 0;
$collect["name"] = $item->getName();
$collect["original_price"] = 45;
$collect["price"] = 45;
$collect["price_incl_tax"] = 45;
$collect["product_id"] = $item->getProductId();
$collect["product_type"] = "simple";
$collect["qty_ordered"] = $item->getQty();
$collect["row_total"] = 45;
$collect["row_total_incl_tax"] = 45;
$collect["sku"] = $item->getSku();
$collect["store_id"] = 1;
$getItems[] = $collect;



// $order["entity"]["event_id"] = $formData["eventID"];
$order["entity"]["base_currency_code"] = "USD";
$order["entity"]["base_discount_amount"] = -4.5;
$order["entity"]["base_grand_total"] = 45.5;
$order["entity"]["base_shipping_amount"] = 5;
$order["entity"]["base_subtotal"] = 45;
$order["entity"]["base_tax_amount"] = 0;
$order["entity"]["customer_email"] = urldecode($formData['Email']);
$order["entity"]["customer_firstname"] = $formData['FirstName'];
$order["entity"]["customer_group_id"] = 3;
$order["entity"]["customer_id"] = $formData['selected_customer_id'];
$order["entity"]["customer_is_guest"] = 0;
$order["entity"]["customer_lastname"] = $formData['LastName'];
$order["entity"]["customer_note_notify"] = 1;
$order["entity"]["discount_amount"] = -4.5;
$order["entity"]["email_sent"] = 1;
$order["entity"]["coupon_code"] = "";
$order["entity"]["discount_description"] = "Test1";
$order["entity"]["grand_total"] = 45.5;
$order["entity"]["is_virtual"] = 0;
$order["entity"]["order_currency_code"] = "USD";
$order["entity"]["shipping_amount"] = 5;
$order["entity"]["shipping_description"] = "Flat Rate - Fixed";
$order["entity"]["state"] = "new";
$order["entity"]["status"] = "pending";
$order["entity"]["store_currency_code"] = "USD";
$order["entity"]["store_id"] = 1;
$order["entity"]["store_name"] = "Main WebsitenMain Website Storen";
$order["entity"]["subtotal"] = 45;
$order["entity"]["subtotal_incl_tax"] = 45;
$order["entity"]["tax_amount"] = 0;
$order["entity"]["total_item_count"] = 1;
$order["entity"]["total_qty_ordered"] = 1;
$order["entity"]["weight"] = 1;
$order["entity"]["items"] = $getItems;
$order["entity"]["billing_address"]["address_type"] = "billing";
$order["entity"]["billing_address"]["city"] = urldecode($formData['MainAddress.City']);
$order["entity"]["billing_address"]["company"] = "";
$order["entity"]["billing_address"]["country_id"] = urldecode($formData["MainAddress.Country"]);
$order["entity"]["billing_address"]["email"] = urldecode($formData['Email']);
$order["entity"]["billing_address"]["firstname"] = urldecode($formData['FirstName']);
$order["entity"]["billing_address"]["lastname"] = urldecode($formData['LastName']);
$order["entity"]["billing_address"]["postcode"] = urldecode($formData['MainAddress.Zip']);
$order["entity"]["billing_address"]["region"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_code"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_id"] = 19;
$order["entity"]["billing_address"]["street"] = array(urldecode($formData["MainAddress.Address1"]), urldecode($formData["MainAddress.Address2"]));
$order["entity"]["billing_address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["payment"]["method"] = "checkmo";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["address_type"] = "shipping";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["city"] = urldecode($formData["MailingAddress.City"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["company"] = "";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["country_id"] = urldecode($formData["MailingAddress.Country"]);
// $order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["customer_address_id"] = 2;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["email"] = urldecode($formData["Email"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["firstname"] = urldecode($formData["FirstName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["lastname"] = urldecode($formData["LastName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["postcode"] = urldecode($formData["MainAddress.Zip"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_code"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_id"] = 19;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["street"] = array(urldecode($formData["MailingAddress.Address1"]), urldecode($formData["MailingAddress.Address2"]));
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"] = "flatrate_flatrate";

$result = $this->createMageOrder($order);
echo json_encode($result); exit;
// $ApiResponse = $this->_helper->placeOrderByAPI($order);
// print_r($ApiResponse);
exit;
exit;










share|improve this question
























  • your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

    – Knight017
    yesterday











  • In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

    – Abdulrehman Sheikh
    yesterday











  • Okay, then this blog may help you atwix.com/magento-2/…

    – Knight017
    yesterday












  • There shouldn't be an exit anywhere in your code. It should be handled differently.

    – Shawn Abramson
    22 hours ago











  • Exit is not an issue. I just want to insert an order

    – Abdulrehman Sheikh
    20 hours ago













1












1








1








I have event_id column in my sales_order table. I want to place an order & I am not sending event_id because its zero by default. When am trying to place an order, Its throwing me the error Column not found: 1054 Unknown column 'so.event_id' in 'where clause', query was: INSERT INTO sales_order ...



enter image description here



I have already run all cache & upgrade commands many times but I don't know why its doing this. Here is my code:



public function createMageOrder($orderData) 
$store = $this->_storeManager->getStore();
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($orderData["entity"]["customer_email"]); // load customet by email address
if (!$customer->getEntityId())
echo "Customer does not exist. please create here...";
exit;
//If not avilable then create this customer
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($orderData['shipping_address']['firstname'])
->setLastname($orderData['shipping_address']['lastname'])
->setEmail($orderData['email'])
->setPassword($orderData['email']);
$customer->save();

$quote = $this->quote->create(); //Create object of quote
$quote->setStore($store); //set store for which you create quote
// if you have allready buyer id then you can load customer directly
$customer = $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
foreach ($orderData["entity"]["items"] as $item)
$product = $this->_product->load($item['product_id']);
$product->setPrice($item['price']);
$quote->addProduct(
$product, intval($item['qty_ordered'])
);


//Set Address to quote
$quote->getBillingAddress()->addData($orderData["entity"]["billing_address"]);
$quote->getShippingAddress()->addData($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]);

// Collect Rates and Set Shipping & Payment Method
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"]); //shipping method
$quote->setPaymentMethod($orderData["entity"]["payment"]["method"]); //payment method
$quote->setInventoryProcessed(false); //not effetc inventory
$quote->save(); //Now Save quote and your quote is ready
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $orderData["entity"]["payment"]["method"]]);
// $quote->setData('event_id', $orderData["entity"]["event_id"]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();

// Create Order From Quote
$order = $this->quoteManagement->submit($quote);

$order->setEmailSent(0);
$increment_id = $order->getRealOrderId();
if ($order->getEntityId())
$result['order_id'] = $order->getRealOrderId();
else
$result = ['error' => 1, 'msg' => 'Your custom message'];

return $result;



I am calling this function in placeGTOrder($post) function where $post is my $orderData. Here is the function on which am sending my request as an action:



public function placeGTOrder($post) 
$formData = $this->_helper->unserializeForm($post['formData']);
$order = array();

//fill cart items to order items
$cart = $this->_objectManager->get('MagentoCheckoutModelCart');
$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();
$getItems = [];
foreach ($items as $item)
$collect = array();
$collect["base_original_price"] = 45;
$collect["base_price"] = 45;
$collect["base_price_incl_tax"] = 45;
$collect["base_row_invoiced"] = 0;
$collect["base_row_total"] = 45;
$collect["base_tax_amount"] = 0;
$collect["base_tax_invoiced"] = 0;
$collect["discount_amount"] = 4.5;
$collect["discount_percent"] = 10;
$collect["free_shipping"] = 0;
$collect["is_virtual"] = 0;
$collect["name"] = $item->getName();
$collect["original_price"] = 45;
$collect["price"] = 45;
$collect["price_incl_tax"] = 45;
$collect["product_id"] = $item->getProductId();
$collect["product_type"] = "simple";
$collect["qty_ordered"] = $item->getQty();
$collect["row_total"] = 45;
$collect["row_total_incl_tax"] = 45;
$collect["sku"] = $item->getSku();
$collect["store_id"] = 1;
$getItems[] = $collect;



// $order["entity"]["event_id"] = $formData["eventID"];
$order["entity"]["base_currency_code"] = "USD";
$order["entity"]["base_discount_amount"] = -4.5;
$order["entity"]["base_grand_total"] = 45.5;
$order["entity"]["base_shipping_amount"] = 5;
$order["entity"]["base_subtotal"] = 45;
$order["entity"]["base_tax_amount"] = 0;
$order["entity"]["customer_email"] = urldecode($formData['Email']);
$order["entity"]["customer_firstname"] = $formData['FirstName'];
$order["entity"]["customer_group_id"] = 3;
$order["entity"]["customer_id"] = $formData['selected_customer_id'];
$order["entity"]["customer_is_guest"] = 0;
$order["entity"]["customer_lastname"] = $formData['LastName'];
$order["entity"]["customer_note_notify"] = 1;
$order["entity"]["discount_amount"] = -4.5;
$order["entity"]["email_sent"] = 1;
$order["entity"]["coupon_code"] = "";
$order["entity"]["discount_description"] = "Test1";
$order["entity"]["grand_total"] = 45.5;
$order["entity"]["is_virtual"] = 0;
$order["entity"]["order_currency_code"] = "USD";
$order["entity"]["shipping_amount"] = 5;
$order["entity"]["shipping_description"] = "Flat Rate - Fixed";
$order["entity"]["state"] = "new";
$order["entity"]["status"] = "pending";
$order["entity"]["store_currency_code"] = "USD";
$order["entity"]["store_id"] = 1;
$order["entity"]["store_name"] = "Main WebsitenMain Website Storen";
$order["entity"]["subtotal"] = 45;
$order["entity"]["subtotal_incl_tax"] = 45;
$order["entity"]["tax_amount"] = 0;
$order["entity"]["total_item_count"] = 1;
$order["entity"]["total_qty_ordered"] = 1;
$order["entity"]["weight"] = 1;
$order["entity"]["items"] = $getItems;
$order["entity"]["billing_address"]["address_type"] = "billing";
$order["entity"]["billing_address"]["city"] = urldecode($formData['MainAddress.City']);
$order["entity"]["billing_address"]["company"] = "";
$order["entity"]["billing_address"]["country_id"] = urldecode($formData["MainAddress.Country"]);
$order["entity"]["billing_address"]["email"] = urldecode($formData['Email']);
$order["entity"]["billing_address"]["firstname"] = urldecode($formData['FirstName']);
$order["entity"]["billing_address"]["lastname"] = urldecode($formData['LastName']);
$order["entity"]["billing_address"]["postcode"] = urldecode($formData['MainAddress.Zip']);
$order["entity"]["billing_address"]["region"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_code"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_id"] = 19;
$order["entity"]["billing_address"]["street"] = array(urldecode($formData["MainAddress.Address1"]), urldecode($formData["MainAddress.Address2"]));
$order["entity"]["billing_address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["payment"]["method"] = "checkmo";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["address_type"] = "shipping";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["city"] = urldecode($formData["MailingAddress.City"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["company"] = "";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["country_id"] = urldecode($formData["MailingAddress.Country"]);
// $order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["customer_address_id"] = 2;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["email"] = urldecode($formData["Email"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["firstname"] = urldecode($formData["FirstName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["lastname"] = urldecode($formData["LastName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["postcode"] = urldecode($formData["MainAddress.Zip"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_code"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_id"] = 19;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["street"] = array(urldecode($formData["MailingAddress.Address1"]), urldecode($formData["MailingAddress.Address2"]));
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"] = "flatrate_flatrate";

$result = $this->createMageOrder($order);
echo json_encode($result); exit;
// $ApiResponse = $this->_helper->placeOrderByAPI($order);
// print_r($ApiResponse);
exit;
exit;










share|improve this question
















I have event_id column in my sales_order table. I want to place an order & I am not sending event_id because its zero by default. When am trying to place an order, Its throwing me the error Column not found: 1054 Unknown column 'so.event_id' in 'where clause', query was: INSERT INTO sales_order ...



enter image description here



I have already run all cache & upgrade commands many times but I don't know why its doing this. Here is my code:



public function createMageOrder($orderData) 
$store = $this->_storeManager->getStore();
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($orderData["entity"]["customer_email"]); // load customet by email address
if (!$customer->getEntityId())
echo "Customer does not exist. please create here...";
exit;
//If not avilable then create this customer
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($orderData['shipping_address']['firstname'])
->setLastname($orderData['shipping_address']['lastname'])
->setEmail($orderData['email'])
->setPassword($orderData['email']);
$customer->save();

$quote = $this->quote->create(); //Create object of quote
$quote->setStore($store); //set store for which you create quote
// if you have allready buyer id then you can load customer directly
$customer = $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
foreach ($orderData["entity"]["items"] as $item)
$product = $this->_product->load($item['product_id']);
$product->setPrice($item['price']);
$quote->addProduct(
$product, intval($item['qty_ordered'])
);


//Set Address to quote
$quote->getBillingAddress()->addData($orderData["entity"]["billing_address"]);
$quote->getShippingAddress()->addData($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]);

// Collect Rates and Set Shipping & Payment Method
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($orderData["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"]); //shipping method
$quote->setPaymentMethod($orderData["entity"]["payment"]["method"]); //payment method
$quote->setInventoryProcessed(false); //not effetc inventory
$quote->save(); //Now Save quote and your quote is ready
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $orderData["entity"]["payment"]["method"]]);
// $quote->setData('event_id', $orderData["entity"]["event_id"]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();

// Create Order From Quote
$order = $this->quoteManagement->submit($quote);

$order->setEmailSent(0);
$increment_id = $order->getRealOrderId();
if ($order->getEntityId())
$result['order_id'] = $order->getRealOrderId();
else
$result = ['error' => 1, 'msg' => 'Your custom message'];

return $result;



I am calling this function in placeGTOrder($post) function where $post is my $orderData. Here is the function on which am sending my request as an action:



public function placeGTOrder($post) 
$formData = $this->_helper->unserializeForm($post['formData']);
$order = array();

//fill cart items to order items
$cart = $this->_objectManager->get('MagentoCheckoutModelCart');
$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();
$getItems = [];
foreach ($items as $item)
$collect = array();
$collect["base_original_price"] = 45;
$collect["base_price"] = 45;
$collect["base_price_incl_tax"] = 45;
$collect["base_row_invoiced"] = 0;
$collect["base_row_total"] = 45;
$collect["base_tax_amount"] = 0;
$collect["base_tax_invoiced"] = 0;
$collect["discount_amount"] = 4.5;
$collect["discount_percent"] = 10;
$collect["free_shipping"] = 0;
$collect["is_virtual"] = 0;
$collect["name"] = $item->getName();
$collect["original_price"] = 45;
$collect["price"] = 45;
$collect["price_incl_tax"] = 45;
$collect["product_id"] = $item->getProductId();
$collect["product_type"] = "simple";
$collect["qty_ordered"] = $item->getQty();
$collect["row_total"] = 45;
$collect["row_total_incl_tax"] = 45;
$collect["sku"] = $item->getSku();
$collect["store_id"] = 1;
$getItems[] = $collect;



// $order["entity"]["event_id"] = $formData["eventID"];
$order["entity"]["base_currency_code"] = "USD";
$order["entity"]["base_discount_amount"] = -4.5;
$order["entity"]["base_grand_total"] = 45.5;
$order["entity"]["base_shipping_amount"] = 5;
$order["entity"]["base_subtotal"] = 45;
$order["entity"]["base_tax_amount"] = 0;
$order["entity"]["customer_email"] = urldecode($formData['Email']);
$order["entity"]["customer_firstname"] = $formData['FirstName'];
$order["entity"]["customer_group_id"] = 3;
$order["entity"]["customer_id"] = $formData['selected_customer_id'];
$order["entity"]["customer_is_guest"] = 0;
$order["entity"]["customer_lastname"] = $formData['LastName'];
$order["entity"]["customer_note_notify"] = 1;
$order["entity"]["discount_amount"] = -4.5;
$order["entity"]["email_sent"] = 1;
$order["entity"]["coupon_code"] = "";
$order["entity"]["discount_description"] = "Test1";
$order["entity"]["grand_total"] = 45.5;
$order["entity"]["is_virtual"] = 0;
$order["entity"]["order_currency_code"] = "USD";
$order["entity"]["shipping_amount"] = 5;
$order["entity"]["shipping_description"] = "Flat Rate - Fixed";
$order["entity"]["state"] = "new";
$order["entity"]["status"] = "pending";
$order["entity"]["store_currency_code"] = "USD";
$order["entity"]["store_id"] = 1;
$order["entity"]["store_name"] = "Main WebsitenMain Website Storen";
$order["entity"]["subtotal"] = 45;
$order["entity"]["subtotal_incl_tax"] = 45;
$order["entity"]["tax_amount"] = 0;
$order["entity"]["total_item_count"] = 1;
$order["entity"]["total_qty_ordered"] = 1;
$order["entity"]["weight"] = 1;
$order["entity"]["items"] = $getItems;
$order["entity"]["billing_address"]["address_type"] = "billing";
$order["entity"]["billing_address"]["city"] = urldecode($formData['MainAddress.City']);
$order["entity"]["billing_address"]["company"] = "";
$order["entity"]["billing_address"]["country_id"] = urldecode($formData["MainAddress.Country"]);
$order["entity"]["billing_address"]["email"] = urldecode($formData['Email']);
$order["entity"]["billing_address"]["firstname"] = urldecode($formData['FirstName']);
$order["entity"]["billing_address"]["lastname"] = urldecode($formData['LastName']);
$order["entity"]["billing_address"]["postcode"] = urldecode($formData['MainAddress.Zip']);
$order["entity"]["billing_address"]["region"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_code"] = urldecode($formData['region']);
$order["entity"]["billing_address"]["region_id"] = 19;
$order["entity"]["billing_address"]["street"] = array(urldecode($formData["MainAddress.Address1"]), urldecode($formData["MainAddress.Address2"]));
$order["entity"]["billing_address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["payment"]["method"] = "checkmo";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["address_type"] = "shipping";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["city"] = urldecode($formData["MailingAddress.City"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["company"] = "";
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["country_id"] = urldecode($formData["MailingAddress.Country"]);
// $order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["customer_address_id"] = 2;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["email"] = urldecode($formData["Email"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["firstname"] = urldecode($formData["FirstName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["lastname"] = urldecode($formData["LastName"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["postcode"] = urldecode($formData["MainAddress.Zip"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_code"] = urldecode($formData["region"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["region_id"] = 19;
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["street"] = array(urldecode($formData["MailingAddress.Address1"]), urldecode($formData["MailingAddress.Address2"]));
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["address"]["telephone"] = urldecode($formData["PrimaryPhone"]);
$order["entity"]["extension_attributes"]["shipping_assignments"]["shipping"]["method"] = "flatrate_flatrate";

$result = $this->createMageOrder($order);
echo json_encode($result); exit;
// $ApiResponse = $this->_helper->placeOrderByAPI($order);
// print_r($ApiResponse);
exit;
exit;







magento2 php database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







Abdulrehman Sheikh

















asked yesterday









Abdulrehman SheikhAbdulrehman Sheikh

1337




1337












  • your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

    – Knight017
    yesterday











  • In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

    – Abdulrehman Sheikh
    yesterday











  • Okay, then this blog may help you atwix.com/magento-2/…

    – Knight017
    yesterday












  • There shouldn't be an exit anywhere in your code. It should be handled differently.

    – Shawn Abramson
    22 hours ago











  • Exit is not an issue. I just want to insert an order

    – Abdulrehman Sheikh
    20 hours ago

















  • your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

    – Knight017
    yesterday











  • In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

    – Abdulrehman Sheikh
    yesterday











  • Okay, then this blog may help you atwix.com/magento-2/…

    – Knight017
    yesterday












  • There shouldn't be an exit anywhere in your code. It should be handled differently.

    – Shawn Abramson
    22 hours ago











  • Exit is not an issue. I just want to insert an order

    – Abdulrehman Sheikh
    20 hours ago
















your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

– Knight017
yesterday





your code has exit after "Customer does not exist. please create here..." is this by mistake? and in Magento 2.2.3's table sales_order has not column event_id. Is this your custom column?

– Knight017
yesterday













In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

– Abdulrehman Sheikh
yesterday





In my case customer is already exists so its not by mistake. Its perfectly handled. Yes event_id is my own column I have created custom attributes for orders according to magento and magento created this column in sales_order table

– Abdulrehman Sheikh
yesterday













Okay, then this blog may help you atwix.com/magento-2/…

– Knight017
yesterday






Okay, then this blog may help you atwix.com/magento-2/…

– Knight017
yesterday














There shouldn't be an exit anywhere in your code. It should be handled differently.

– Shawn Abramson
22 hours ago





There shouldn't be an exit anywhere in your code. It should be handled differently.

– Shawn Abramson
22 hours ago













Exit is not an issue. I just want to insert an order

– Abdulrehman Sheikh
20 hours ago





Exit is not an issue. I just want to insert an order

– Abdulrehman Sheikh
20 hours ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267425%2fmagento-2-column-is-exists-but-throwing-column-not-found-1054-unknown-column%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267425%2fmagento-2-column-is-exists-but-throwing-column-not-found-1054-unknown-column%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sum ergo cogito? 1 nng

三茅街道4182Guuntc Dn precexpngmageondP