В моей таблице sales_order есть столбец event_id.Я хочу разместить заказ, и я не отправляю event_id, потому что по умолчанию он равен нулю.Когда я пытаюсь разместить заказ, он выдает мне ошибку Столбец не найден: 1054 Неизвестный столбец 'so.event_id' в 'где предложение', запрос был: INSERT INTO sales_order
...
Вот ошибка, получаемая в INSERT Query:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'event_id' in 'where clause', query was: INSERT INTO `sales_order` (`state`, `status`, `protect_code`, `shipping_description`, `is_virtual`, `store_id`, `customer_id`, `base_discount_amount`, `base_grand_total`, `base_shipping_amount`, `base_shipping_tax_amount`, `base_subtotal`, `base_tax_amount`, `base_to_global_rate`, `base_to_order_rate`, `discount_amount`, `grand_total`, `shipping_amount`, `shipping_tax_amount`, `store_to_base_rate`, `store_to_order_rate`, `subtotal`, `tax_amount`, `total_qty_ordered`, `customer_is_guest`, `customer_note_notify`, `customer_group_id`, `quote_id`, `base_shipping_discount_amount`, `base_subtotal_incl_tax`, `base_total_due`, `shipping_discount_amount`, `subtotal_incl_tax`, `total_due`, `weight`, `increment_id`, `applied_rule_ids`, `base_currency_code`, `customer_email`, `customer_firstname`, `customer_lastname`, `customer_middlename`, `discount_description`, `global_currency_code`, `order_currency_code`, `shipping_method`, `store_currency_code`, `store_name`, `total_item_count`, `discount_tax_compensation_amount`, `base_discount_tax_compensation_amount`, `shipping_discount_tax_compensation_amount`, `base_shipping_discount_tax_compensation_amnt`, `shipping_incl_tax`, `base_shipping_incl_tax`, `gift_message_id`, `has_ambassador`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Я уже запустил весь кеш& обновить команды много раз, но я не знаю, почему это делает это.Вот мой код:
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;
}
Я вызываю эту функцию в функции placeGTOrder ($ post) , где $ post - это мои $ orderData.Вот функция, по которой я отправляю мой запрос как действие:
public function placeGTOrder($post) {
$formData = $this->_helper->unserializeForm($post['formData']);
$order = array();
//fill cart items to order items
$cart = $this->_objectManager->get('\Magento\Checkout\Model\Cart');
$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 Website\nMain Website Store\n";
$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;
}
Вот таблица: