/** * createOrder * -- * @param $woo_commerce_order_id */ public function createOrder($woo_commerce_order_id) { // Fetch order from WC. $woo_order = new WC_Order($woo_commerce_order_id); // Contact Information $contact_infomation = $this->buildContactInformation($woo_order->billing_company, $woo_order->billing_first_name . " " . $woo_order->billing_last_name, "WC", $woo_order->billing_phone, $woo_order->shipping_first_name . " " . $woo_order->shipping_last_name, $woo_order->billing_email, "", ""); // Transaction Information $transaction_information = $this->buildTransactionInformation(new DateTime(), new DateTime(), new DateTime(), $woo_order->get_order_number(), $woo_order->get_order_number() . "-" . $woo_order->billing_last_name); // Address Information $address_information = $this->buildAddressInformation($woo_order->shipping_address_1, $woo_order->shipping_address_2, $woo_order->shipping_city, $woo_order->shipping_state, $woo_order->shipping_country, $woo_order->shipping_postcode); // Shipping Instructions $shipping_instructions = $this->buildShippingInstructionInformation($woo_order->customer_user, $woo_order->billing_postcode, $this::CARRIER, $this::CARRIER_DESC, $this::CARRIER_MODE, $woo_order->shipping_method_title, $woo_order->customer_note, $woo_order->shipping_postcode, $this::SCAC_CODE); // Extraneous Information. $shipping_info = null; // - not needed in this instance $fulfillment_info = null; // - not needed in this instance // Create new Order for API. $order = new Order(1); // Ship to, Transaction Info, Customer Notes $order->setShipTo($contact_infomation); $order->setTransInfo($transaction_information); $order->setNotes($woo_order->customer_note); // Shipping instructions $order->setShippingInstructions($shipping_instructions); // Order line item array $order_line_item_arr = []; // Loop over woo_commerce_order items, and // fetch products & product information out of every item. foreach ($woo_order->get_items() as $item) { // Retrieve product $product = $woo_order->get_product_from_item($item); // Build new order line item $arr_order = $this->buildOrderLineLitem($product->get_sku(), "", $product->get_stock_quantity(), "", $product->get_dimensions(), new DateTime(), $product->sale_price, "", ""); // Push order line item to [line item arr] array_push($order_line_item_arr, $arr_order); } // Set order line items $order->setOrderLineItems($order_line_item_arr); // Create an ArrayOfOrder object. $aoOrder = new ArrayOfOrder(); $aoOrder->setOrder([$order]); // Execute and return the order action return $this->apiHandler->getClient()->CreateOrders($this->apiHandler->getExtLoginData(), $aoOrder); }
$shipping_instructions->setShipService("FedEx"); $shipping_instructions->setShippingNotes("Shipping Notes"); $shipping_instructions->setShipPointZip("33327"); $shipping_instructions->setSCACCode("2135"); // etc. information $shipping_info = new ShipmentInfoExt(1, 1, 1.0, 1, 25.0, 23.0); $fulfillment_info = new FulfillInvInfo(24.0, 26.88, 12.99); // set shipping information $order->setShippingInstructions($shipping_instructions); // set shipment information $order->setShipmentInfo($shipping_info); $order->setShipTo($contact_info); // order line item ( new up & instantiate ) $order_line_item = new OrderLineItem(1.0, 1.0, 2.0, new DateTime(), 29.99, 1.0, 1.0); $order_line_item->setQty(2.0); $order_line_item->setSKU("Test1"); // array of order line items $order_line_items = new ArrayOfOrderLineItem(); $order_line_items->setOrderLineItem([$order_line_item]); // set order line items to be order line items $order->setOrderLineItems($order_line_items); // new up & instantiate a new ArrayOfOrder object, and set the main order to the order above. $aoOrders = new ArrayOfOrder(); $aoOrders->setOrder([$order]); // let's echo out all functions. try { // let's execute an order with the integrated soap client. echo "<pre>" . var_export($b->CreateOrders($external_login_infomation, $aoOrders), 1) . " </pre > "; } catch (Exception $e) { error_log($e->getCode() . "-" . $e->getMessage() . "-" . $e->getTraceAsString()); }