Beispiel #1
0
$new_address->phone = $telephone_no;
$new_address->id_country = $id_country;
$new_address->id_state = $id_state;
$new_address->id_customer = (int) $current_cart->id_customer;
$new_address->id_manufacturer = 0;
$new_address->id_supplier = 0;
$new_address->id_warehouse = 0;
if (!$new_address->add()) {
    die('<script language="javascript" type="text/javascript">top.location.href = "' . $context->link->getPageLink('order') . '?step=1" ;</script>');
}
/*
 * Save shipto data in shipto cart object.
 */
$shipto_cart = ShiptomyidCart::getByIdCart($current_cart->id);
if (!$shipto_cart) {
    $shipto_cart = new ShiptomyidCart();
    $shipto_cart->id_cart = $current_cart->id;
}
$shipto_cart->receiver_email = $email;
$shipto_cart->receiver_lastname = $lastname;
$shipto_cart->receiver_firstname = $firstname;
$shipto_cart->receiver_city = $city;
$shipto_cart->receiver_postcode = $postcode;
$shipto_cart->receiver_id_country = $id_country;
$shipto_cart->receiver_id_state = $id_state;
$shipto_cart->receiver_phone = $telephone_no;
$shipto_cart->receiver_type = $receiver_type;
$shipto_cart->receiver_linkedin_id = $receiver_linkedin_id;
$shipto_cart->receiver_facebook_id = $receiver_facebook_id;
if (!$shipto_cart->save()) {
    die('<script language="javascript" type="text/javascript">top.location.href = "' . $context->link->getPageLink('order') . '?step=1" ;</script>');
 /**
  * Send order to shiptomyid.
  */
 public function sendOrderToAPI($order)
 {
     $this->on_process = true;
     $delivery_address = new Address((int) $order->id_address_delivery);
     $invoice_address = new Address((int) $order->id_address_invoice);
     $customer = new Customer((int) $order->id_customer);
     $shipto_cart = ShiptomyidCart::getByIdCart((int) $order->id_cart);
     if (!Validate::isLoadedObject($delivery_address) || !Validate::isLoadedObject($invoice_address) || !Validate::isLoadedObject($customer) || !Validate::isLoadedObject($shipto_cart)) {
         ShiptomyidLog::addLog('invalid order object or address object in order', $order->id);
         return false;
     }
     $gift_msg = !empty($order->gift_message) ? $order->gift_message : 'Brought to you by Ship2MyID';
     $data_to_send = array('vendor_order_id' => $order->id, 'sender_email_address' => $customer->email, 'sender_first_name' => $invoice_address->firstname, 'sender_last_name' => $invoice_address->lastname, 'sender_message' => $gift_msg, 'receiver_email_address' => $shipto_cart->receiver_email, 'receiver_first_name' => $shipto_cart->receiver_firstname, 'receiver_last_name' => $shipto_cart->receiver_lastname, 'receiver_telephone' => $shipto_cart->receiver_phone, 'receiver_type' => $shipto_cart->receiver_type, 'receiver_linkedin_id' => '', 'receiver_facebook_id' => '', 'marketplace_order_data' => $this->getOrderData($order));
     switch ($shipto_cart->receiver_type) {
         case 'facebook':
             $data_to_send['receiver_facebook_id'] = $shipto_cart->receiver_facebook_id;
             break;
         case 'linkedin':
             $data_to_send['receiver_linkedin_id'] = $shipto_cart->receiver_linkedin_id;
             break;
     }
     $result = $this->api->sendOrder(array('ExternalOrder' => $data_to_send));
     if (isset($result['ExternalOrder'])) {
         $result_data = $result['ExternalOrder'];
         $new_shipto_order = new ShiptomyidOrder();
         $new_shipto_order->id_order = $order->id;
         $new_shipto_order->id_shiptomyid = $result_data['id'];
         $new_shipto_order->state_send = 1;
         if ($new_shipto_order->add()) {
             ShiptomyidOrder::changeOrderStatus($order->id, self::$os_waiting);
             ShiptomyidOrder::addMessageToOrder($order->id, $this->l('Add order in Ship2MyId : #' . $new_shipto_order->id_shiptomyid));
             $this->checkOrderStatus($new_shipto_order->id_order, $result);
             return true;
         }
         ShiptomyidLog::addLog('Error in save shiptotmyid_order object.', $order->id, $new_shipto_order->id_shiptomyid);
     } else {
         ShiptomyidOrder::changeOrderStatus($order->id, self::$os_error);
         ShiptomyidOrder::addMessageToOrder($order->id, ShiptoAPI::getErrorMessage($result));
     }
     return false;
 }