public function acknowledge_order($order_id, $data) { $xml = simplexml_load_string($data); $acknowledge_arr = array(); $i = 0; foreach ($xml->ProcessedOrder->ProcessedOrderItems->ProcessedOrderItem as $item) { $AmazonOrderItemCode = (string) $item->AmazonOrderItemCode; $product_id = $item->ItemCustomData->Item_product_id; $acknowledge_arr['items'][$i]['AmazonOrderItemCode'] = $AmazonOrderItemCode; $acknowledge_arr['items'][$i]['product_id'] = $product_id; $i++; } // Acknowledge the order in seller central using MWS FEED API $acknowledge_arr['MerchantOrderID'] = $order_id; $obj = new Pwapresta(); $obj->pwa_acknowledge_feed($acknowledge_arr); }
public function update_cart_by_junglee_xml($order_id, $orderdetail) { $prefix = _DB_PREFIX_; $tablename = $prefix . 'orders'; $total_amount = 0; $total_principal = 0; $shipping_amount = 0; $total_promo = 0; $ClientRequestId = 0; $AmazonOrderID = (string) $orderdetail->OrderReport->AmazonOrderID; foreach ($orderdetail->OrderReport->Item as $item) { $SKU = (string) $item->SKU; $Title = (string) $item->Title; $Quantity = (int) $item->Quantity; $Principal_Promotions = 0; $Shipping_Promotions = 0; foreach ($item->ItemPrice->Component as $amount_type) { $item_charge_type = (string) $amount_type->Type; if ($item_charge_type == 'Principal') { $Principal = abs((double) $amount_type->Amount); } if ($item_charge_type == 'Shipping') { $Shipping = abs((double) $amount_type->Amount); } if ($item_charge_type == 'Tax') { $Tax = abs((double) $amount_type->Amount); } if ($item_charge_type == 'ShippingTax') { $ShippingTax = abs((double) $amount_type->Amount); } } if (!empty($item->Promotion)) { foreach ($item->Promotion as $promotions) { foreach ($promotions->Component as $promotion_amount_type) { $promotion_type = (string) $promotion_amount_type->Type; if ($promotion_type == 'Shipping') { $Shipping_Promotions += abs((double) $promotion_amount_type->Amount); } if ($promotion_type == 'Principal') { $Principal_Promotions += abs((double) $promotion_amount_type->Amount); } } } } $total_principal += $Principal; $total_amount += $Principal - $Principal_Promotions + ($Shipping - $Shipping_Promotions); $shipping_amount += $Shipping + $Shipping_Promotions; $total_promo += $Principal_Promotions + $Shipping_Promotions; foreach ($item->CustomizationInfo as $info) { $info_type = (string) $info->Type; if ($info_type == 'url') { $info_array = explode(',', $info->Data); $customerId_array = explode('=', $info_array[0]); $ClientRequestId = $customerId_array[1]; } } } $ShippingServiceLevel = (string) $orderdetail->OrderReport->FulfillmentData->FulfillmentServiceLevel; $sql = 'UPDATE `' . $prefix . 'pwa_orders` set `shipping_service` = "' . $ShippingServiceLevel . '" , `order_type` = "junglee" where `prestashop_order_id` = "' . $order_id . '" '; Db::getInstance()->Execute($sql); $cust_name = (string) $orderdetail->OrderReport->BillingData->BuyerName; $name_arr = explode(' ', $cust_name); if (count($name_arr) > 1) { $firstname = ''; for ($i = 0; $i < count($name_arr) - 2; $i++) { $firstname = $firstname . ' ' . $name_arr[$i]; } $lastname = $name_arr[count($name_arr) - 1]; } else { $firstname = $cust_name; $lastname = ' '; } $email = (string) $orderdetail->OrderReport->BillingData->BuyerEmailAddress; $sql = 'SELECT * from `' . $prefix . 'customer` where email = "' . $email . '" '; $results = Db::getInstance()->ExecuteS($sql); if (empty($results)) { $password = Tools::passwdGen(); $customer = new Customer(); $customer->firstname = trim($firstname); $customer->lastname = $lastname; $customer->email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress; $customer->passwd = md5($password); $customer->active = 1; if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) { $customer->is_guest = 1; } else { $customer->is_guest = 0; } $customer->add(); $customer_id = $customer->id; if (Configuration::get('PS_CUSTOMER_CREATION_EMAIL') && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) { Mail::Send($this->context->language->id, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname); } } else { $customer_id = $results[0]['id_customer']; } $id_country = Country::getByIso((string) $orderdetail->OrderReport->FulfillmentData->Address->CountryCode); if ($id_country == 0 || $id_country == '') { $id_country = 110; } $address = new Address(); $address->id_country = $id_country; $address->id_state = 0; $address->id_customer = $customer_id; $address->alias = 'My Address'; $address->firstname = trim($firstname); $address->lastname = $lastname; $address->address1 = (string) $orderdetail->OrderReport->FulfillmentData->Address->AddressFieldOne; $address->address2 = (string) $orderdetail->OrderReport->FulfillmentData->Address->AddressFieldTwo; $address->postcode = (string) $orderdetail->OrderReport->FulfillmentData->Address->PostalCode; $address->phone_mobile = (string) $orderdetail->OrderReport->FulfillmentData->Address->PhoneNumber; $address->city = (string) $orderdetail->OrderReport->FulfillmentData->Address->City . ' ' . (string) $orderdetail->OrderReport->FulfillmentData->Address->StateOrRegion; $address->active = 1; $address->add(); $address_id = $address->id; $id_order_state = 2; $reference = Order::generateReference(); $order = new Order(); $order->id = $order_id; $order->id_customer = (int) $customer_id; $order->id_address_invoice = (int) $address_id; $carrier = null; $sql = 'SELECT id_carrier from `' . $prefix . 'carrier` where `active` = 1 and `deleted` = 0 limit 0,1'; $result = Db::getInstance()->ExecuteS($sql); $id_carrier = $result[0]['id_carrier']; $sql = 'SELECT id_currency from `' . $prefix . 'currency` where `active` = 1 and `deleted` = 0 and `iso_code` = "INR" limit 0,1'; $result = Db::getInstance()->ExecuteS($sql); $currency_id = $result[0]['id_currency']; $sql = 'UPDATE `' . $tablename . '` set `id_customer` = ' . (int) $customer_id . ', `id_carrier` = ' . $id_carrier . ', `id_address_invoice` = ' . (int) $address_id . ', `id_address_delivery` = ' . (int) $address_id . ', `id_currency` = ' . $currency_id . ', `reference` = "' . $reference . '", `secure_key` = "' . md5(uniqid()) . '", `total_paid` = ' . $total_amount . ', `total_paid_tax_incl` = ' . $total_amount . ', `total_paid_tax_excl` = ' . $total_amount . ', `total_paid_real` = 0, `total_shipping` = ' . $shipping_amount . ', `total_shipping_tax_incl` = ' . $shipping_amount . ', `total_shipping_tax_excl` = ' . $shipping_amount . ', `total_discounts` = ' . (double) $total_promo . ', `total_discounts_tax_incl` = ' . (double) $total_promo . ', `total_discounts_tax_excl` = ' . (double) $total_promo . ', `total_products` = ' . $total_principal . ', `total_products_wt` = ' . $total_principal . ', `invoice_date` = "0000-00-00 00:00:00", `delivery_date` = "0000-00-00 00:00:00" where `id_order` = ' . $order_id . ''; // `round_mode` = '.Configuration::get('PS_PRICE_ROUND_MODE').', Db::getInstance()->Execute($sql); $i = 0; foreach ($orderdetail->OrderReport->Item as $item) { $id_product = (string) $item->SKU; $product = new Product((int) $product_id); $SKU = $product->reference; $AmazonOrderItemCode = (string) $item->AmazonOrderItemCode; $Title = (string) $item->Title; $Quantity = (int) $item->Quantity; foreach ($item->ItemPrice->Component as $amount_type) { $item_charge_type = (string) $amount_type->Type; if ($item_charge_type == 'Principal') { $Amount = (double) $amount_type->Amount; } } $Amount = $Amount / $Quantity; $Amount = round($Amount, 3); $acknowledge_arr['items'][$i]['AmazonOrderItemCode'] = $AmazonOrderItemCode; $acknowledge_arr['items'][$i]['product_id'] = $id_product; $i++; $sql = 'INSERT into `' . $prefix . 'order_detail` set `id_order` = ' . $order_id . ', `product_id` = ' . $id_product . ', `product_name` = "' . $Title . '", `product_quantity` = ' . $Quantity . ', `product_quantity_in_stock` = ' . $Quantity . ', `product_price` = ' . $Amount . ', `product_reference` = "' . $SKU . '", `total_price_tax_incl` = ' . $Amount * $Quantity . ', `total_price_tax_excl` = ' . $Amount * $Quantity . ', `unit_price_tax_incl` = ' . $Amount . ', `unit_price_tax_excl` = ' . $Amount . ', `original_product_price` = ' . $Amount . ' '; Db::getInstance()->Execute($sql); $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $Quantity . ' where `id_product` = ' . $id_product . ' and `id_product_attribute` = 0 '; Db::getInstance()->Execute($sql); /*$sql = 'UPDATE `'.$prefix.'stock_available` set `quantity` = `quantity` - '.$Quantity.' where `id_product` = '.$product_id.' and `id_product_attribute` = '.$product_attribute_id.' '; Db::getInstance()->Execute($sql);*/ $date = date('Y-m-d'); $sql = 'UPDATE `' . $prefix . 'product_sale` set `quantity` = `quantity` + ' . $Quantity . ', `sale_nbr` = `sale_nbr` + ' . $Quantity . ', `date_upd` = ' . $date . ' where `id_product` = ' . $id_product . ' '; Db::getInstance()->Execute($sql); } // Adding an entry in order_carrier table if (!is_null($carrier)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = '0'; $order_carrier->shipping_cost_tax_excl = (double) $shipping_amount; $order_carrier->shipping_cost_tax_incl = (double) $shipping_amount; $order_carrier->add(); } else { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = '0'; $order_carrier->shipping_cost_tax_excl = (double) $shipping_amount; $order_carrier->shipping_cost_tax_incl = (double) $shipping_amount; $order_carrier->add(); } // Acknowledge the order in seller central using MWS FEED API $acknowledge_arr['MerchantOrderID'] = (int) $order->id; $obj = new Pwapresta(); $obj->pwa_acknowledge_feed($acknowledge_arr); $history = new OrderHistory(); $history->id_order = $order->id; $history->changeIdOrderState((int) $id_order_state, $order->id, true); $history->addWithemail(true, array()); }