示例#1
0
 public function displayMain()
 {
     global $smarty, $link, $cookie;
     $errors = false;
     if (!$cookie->logged || !User::checkPassword($cookie->id_user, $cookie->passwd)) {
         Tools::redirect($link->getPage('userView'));
     }
     $referer = Tools::Q('referer') ? $link->getPage(Tools::Q('referer')) : $link->getPage('MyAddressesView');
     if ($id_address = Tools::Q('id')) {
         $address = new Address((int) $id_address);
         if (Tools::isSubmit('saveAddress')) {
             $address->copyFromPost();
             if ($address->update()) {
                 Tools::redirect($referer);
             } else {
                 $errors = $address->_errors;
             }
         }
         $smarty->assign('address', $address);
     } elseif (Tools::isSubmit('saveAddress')) {
         $address = new Address();
         $address->copyFromPost();
         $address->id_user = $cookie->id_user;
         if ($address->add()) {
             Tools::redirect($referer);
         } else {
             $errors = $address->_errors;
         }
     }
     $countrys = Country::loadData(1, 1000, 'position', 'asc', array('active' => true));
     $smarty->assign(array('referer' => Tools::Q('referer'), 'countrys' => $countrys, 'errors' => $errors));
     return $smarty->fetch('address.tpl');
 }
示例#2
0
function updateProcess($id)
{
    $send = Request::get('send');
    $address = Request::get('address');
    $address['firstname'] = $send['firstname'];
    $address['lastname'] = $send['lastname'];
    Users::update($id, $send);
    Address::update($id, $address);
}
 /**
  * Get location of user
  * @param Address $address location
  */
 public function getAddress()
 {
     $address = null;
     if ($data = $this->getLocationData()) {
         $address = new Address();
         $address->update($data);
         $address->ID = 0;
         //ensure not in db
     }
     return $address;
 }
示例#4
0
 public function getPreviewAddress($log = false)
 {
     // for compatibility
     /** NO LONGER NECESSARY */
     /*
     if($this->name == 'localizedshipping')
     	$name = 'shp';
     else
     */
     $name = $this->name;
     if ($this->context->cookie->postcode && $this->context->cookie->id_country && $this->context->cookie->id_state) {
         $cookie_state = $this->context->cookie->id_state;
     } else {
         $cookie_state = $this->context->cookie->pc_dest_state;
     }
     $cookie_zip = $this->context->cookie->postcode ? $this->context->cookie->postcode : $this->context->cookie->pc_dest_zip;
     $cookie_country = $this->context->cookie->id_country ? $this->context->cookie->id_country : $this->context->cookie->pc_dest_country;
     if ($this->context->customer->logged) {
         if (isset($_POST[$name . '_dest_zip']) && $_POST[$name . '_dest_zip'] != "" || isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country'] != "" || isset($_POST[$name . '_dest_state']) && $_POST[$name . '_dest_state'] != "") {
             $dest_zip = Tools::getValue($name . '_dest_zip');
             $dest_state = Tools::getValue($name . '_dest_state');
             $dest_country = Tools::getValue($name . '_dest_country');
             $dest_city = Tools::getValue($name . '_dest_city') != $this->l('City') ? Tools::getValue($name . '_dest_city') : "";
             if ((int) $this->context->cart->id_address_delivery > 0) {
                 $address = new Address(intval($this->context->cart->id_address_delivery));
                 $address->postcode = $dest_zip;
                 $address->id_country = $dest_country;
                 $address->city = ($dest_city and strlen($dest_city)) ? $dest_city : 0;
                 if ((int) $dest_state > 0) {
                     $address->id_state = $dest_state;
                 }
                 $country = new Country($dest_country);
                 if (!$address->id_state && $country->contains_states) {
                     $id_state = 0;
                     $states = State::getStates($this->context->language->id, true);
                     foreach ($states as $state) {
                         $id_state = $state['id_state'];
                     }
                     $address->id_state = $id_state;
                 } else {
                     if ($address->id_state && !$country->contains_states) {
                         $address->id_state = 0;
                     }
                 }
                 $override_address_name = '_' . $name . '_override_address';
                 if ($this->{$override_address_name}) {
                     $address->update();
                 }
             }
             $state = new State($dest_state);
             $country = new Country($dest_country);
             $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
             $dest_country = $country->iso_code;
         } else {
             if ((int) $this->context->cart->id_address_delivery > 0) {
                 $address = new Address(intval($this->context->cart->id_address_delivery));
                 $dest_zip = $address->postcode;
                 $country = new Country($address->id_country);
                 $dest_country = $country->iso_code;
                 $dest_state = $address->id_state;
                 $dest_city = $address->city;
                 $state = new State($dest_state);
                 $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
                 $country = new Country($dest_country);
                 $state = new State($dest_state);
                 $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
                 $dest_country = $country->iso_code;
             }
         }
     } else {
         /** IF CARRIER IS NOT ROYAL MAIL CARRIER */
         if ($this->name != 'royalmail') {
             if (isset($_POST[$name . '_dest_zip']) && $_POST[$name . '_dest_zip'] || isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country'] || isset($_POST[$name . '_dest_state']) && $_POST[$name . '_dest_state']) {
                 $dest_zip = Tools::getValue($name . '_dest_zip');
                 $dest_state = Tools::getValue($name . '_dest_state');
                 $dest_country = Tools::getValue($name . '_dest_country');
                 $dest_city = isset($_POST[$name . '_dest_city']) && $_POST[$name . '_dest_city'] != $this->l('City') ? $_POST[$name . '_dest_city'] : "";
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
             }
         } else {
             if (isset($_POST[$name . '_dest_country']) && $_POST[$name . '_dest_country']) {
                 $dest_zip = Tools::getValue($name . '_dest_zip');
                 $dest_state = Tools::getValue($name . '_dest_state');
                 $dest_country = Tools::getValue($name . '_dest_country');
                 $dest_city = isset($_POST[$name . '_dest_city']) && $_POST[$name . '_dest_city'] != $this->l('City') ? $_POST[$name . '_dest_city'] : "";
             } else {
                 $dest_zip = $cookie_zip;
                 $dest_state = $cookie_state;
                 $dest_country = $cookie_country;
                 $dest_city = $this->context->cookie->pc_dest_city;
             }
         }
         $country = new Country($dest_country);
         $state = new State($dest_state);
         $id_zone = $state->id_zone > 0 ? $state->id_zone : $country->id_zone;
         $dest_country = $country->iso_code;
     }
     $this->context->cookie->pc_dest_zip = strlen($dest_zip) ? $dest_zip : $cookie_zip;
     $this->context->cookie->pc_dest_state = strlen($dest_state) ? $dest_state : $cookie_state;
     if (strlen($dest_country)) {
         $id_country = Country::getByIso($dest_country);
         $this->context->cookie->pc_dest_country = $id_country ? $id_country : $cookie_country;
     }
     $this->context->cookie->pc_dest_city = strlen($dest_city) ? $dest_city : $this->context->cookie->pc_dest_city;
     $this->context->cookie->write();
     return array('dest_zip' => $dest_zip, 'dest_state' => $dest_state, 'dest_country' => $dest_country, 'dest_city' => $dest_city, 'id_zone' => $id_zone);
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     if (Tools::isSubmit('export_csv')) {
         $this->renderCSV();
     }
     // checks access
     if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError($this->l('You do not have permission to add suppliers.'));
         return parent::postProcess();
     }
     if (Tools::isSubmit('submitAdd' . $this->table)) {
         if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) {
             return;
         }
         // updates/creates address if it does not exist
         if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) {
             $address = new Address((int) Tools::getValue('id_address'));
         } else {
             $address = new Address();
         }
         // creates address
         $address->alias = Tools::getValue('name', null);
         $address->lastname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->firstname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->address1 = Tools::getValue('address', null);
         $address->address2 = Tools::getValue('address2', null);
         $address->postcode = Tools::getValue('postcode', null);
         $address->phone = Tools::getValue('phone', null);
         $address->id_country = Tools::getValue('id_country', null);
         $address->id_state = Tools::getValue('id_state', null);
         $address->city = Tools::getValue('city', null);
         $validation = $address->validateController();
         // checks address validity
         if (count($validation) > 0) {
             foreach ($validation as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError($this->l('The address is not correct. Please make sure all of the required fields are completed.'));
         } else {
             if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) {
                 $address->update();
             } else {
                 $address->save();
                 $_POST['id_address'] = $address->id;
             }
         }
         //--ERP informations
         // updates/creates erp_supplier if it does not exist
         if (Tools::isSubmit('id_erpip_supplier') && (int) Tools::getValue('id_erpip_supplier') > 0) {
             $erp_supplier = new ErpSupplier((int) Tools::getValue('id_erpip_supplier'));
         } else {
             $erp_supplier = new ErpSupplier();
         }
         // creates erp_supplier
         $erp_supplier->email = Tools::getValue('email', null);
         $erp_supplier->fax = Tools::getValue('fax', null);
         $erp_supplier->franco_amount = Tools::getValue('franco_amount', null);
         $erp_supplier->discount_amount = Tools::getValue('discount_amount', null);
         $erp_supplier->shipping_amount = Tools::getValue('shipping_amount', null);
         $erp_supplier->escompte = Tools::getValue('escompte', null);
         $erp_supplier->delivery_time = Tools::getValue('delivery_time', null);
         $erp_supplier->account_number_accounting = Tools::getValue('account_number_accounting', null);
         $validation2 = $erp_supplier->validateController();
         //print_r($validation2);
         // checks erp_supplier validity
         if (count($validation2) > 0) {
             foreach ($validation2 as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError($this->l('The ErpIllicopresta Supplier is not correct. Please make sure all of the required fields are completed.'));
         } else {
             if (Tools::isSubmit('id_erpip_supplier') && Tools::getValue('id_erpip_supplier') > 0) {
                 $erp_supplier->update();
             } else {
                 $erp_supplier->save();
                 $_POST['id_erpip_supplier'] = $erp_supplier->id;
             }
         }
         return parent::postProcess();
     } else {
         if (Tools::isSubmit('delete' . $this->table)) {
             if (!($obj = $this->loadObject(true))) {
                 return;
             } else {
                 if (SupplyOrder::supplierHasPendingOrders($obj->id)) {
                     $this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.');
                 } else {
                     //delete all product_supplier linked to this supplier
                     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'product_supplier` WHERE `id_supplier`=' . (int) $obj->id);
                     $id_address = Address::getAddressIdBySupplierId($obj->id);
                     $address = new Address($id_address);
                     if (Validate::isLoadedObject($address)) {
                         $address->deleted = 1;
                         $address->save();
                     }
                     //delete erp supplier
                     $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($obj->id);
                     $erp_supplier = new ErpSupplier($id_erpip_supplier);
                     if (Validate::isLoadedObject($erp_supplier)) {
                         $erp_supplier->delete();
                     }
                     return parent::postProcess();
                 }
             }
         } else {
             return parent::postProcess();
         }
     }
 }
示例#6
0
 /**
  * 更新国家信息
  * @access public
  */
 function update_save()
 {
     //判断country是否已存在
     $id = get_post_value('id');
     $country = get_post_value('country');
     $region = get_post_value('region');
     $orders = get_post_value('orders');
     $status = get_post_value('status');
     if (!$this->verify_region($id)) {
         echo '<br>大区  ' . $_POST['region'] . ' 已存在,请核对后重新输入。<a href="javascript:history.go(-1)">返回</a><br>';
         return;
     }
     $field = array('country_id' => $country, 'region' => $region, 'orders' => $orders, 'status' => $status == '10000' ? '10000' : '30000');
     $m = new Address();
     $m->clear();
     $m->setTable('vcb_address_region');
     $m->setField($field);
     $m->setWhere('region_id', '=', $id);
     $m->update();
     //返回
     echo '<br>操作成功,<a href="index" >返回</a><br>';
 }
示例#7
0
 private function _postProcessShipping()
 {
     Configuration::updateValue('GOINTERPAY_RECIPIENT_LASTNAME', pSQL(Tools::getValue('recipientLastName')));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_FIRSTNAME', pSQL(Tools::getValue('recipientFirstName')));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_ADDRESS', pSQL(Tools::getValue('recipientAddress')));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_ZIPCODE', pSQL(Tools::getValue('recipientZipCode')));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_CITY', pSQL(Tools::getValue('recipientCity')));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_COUNTRY', (int) Tools::getValue('recipientCountry'));
     Configuration::updateValue('GOINTERPAY_RECIPIENT_STATE', !isset($_POST['recipientState']) ? 0 : (int) Tools::getValue('recipientState'));
     if (Configuration::get('GOINTERPAY_SHIPPING_ADDRESS_ID')) {
         $address = new Address((int) Configuration::get('GOINTERPAY_SHIPPING_ADDRESS_ID'));
         $address->id_country = (int) $_POST['recipientCountry'];
         if (isset($_POST['recipientState'])) {
             $address->id_state = (int) $_POST['recipientState'];
         } else {
             $address->id_state = 0;
         }
         $address->alias = 'gointerpay';
         $address->lastname = pSQL(Tools::getValue('recipientLastName'));
         $address->firstname = isset($_POST['recipientFirstName']) && $_POST['recipientFirstName'] != '' ? pSQL(Tools::getValue('recipientFirstName')) : 'Go Interpay';
         $address->address1 = pSQL(Tools::getValue('recipientAddress'));
         $address->city = pSQL(Tools::getValue('recipientCity'));
         $address->postcode = pSQL(Tools::getValue('recipientZipCode'));
         $address->update();
     } else {
         $address = new Address();
         $address->id_country = (int) $_POST['recipientCountry'];
         if (Tools::getValue('recipientState')) {
             $address->id_state = (int) $_POST['recipientState'];
         } else {
             $address->id_state = 0;
         }
         $address->alias = 'gointerpay';
         $address->lastname = pSQL(Tools::getValue('recipientLastName'));
         $address->firstname = isset($_POST['recipientFirstName']) && $_POST['recipientFirstName'] != '' ? pSQL(Tools::getValue('recipientFirstName')) : 'Go Interpay';
         $address->address1 = pSQL(Tools::getValue('recipientAddress'));
         $address->city = pSQL(Tools::getValue('recipientCity'));
         $address->postcode = pSQL(Tools::getValue('recipientZipCode'));
         if ($address->add()) {
             Configuration::updateValue('GOINTERPAY_SHIPPING_ADDRESS_ID', (int) $address->id);
         }
     }
 }
示例#8
0
 // Vérification si nom adresse est déjà présent
 $addressNameExist = $address->verifAddressExist($addressNewName);
 if ($categorieCount === 0) {
     echo "categorieDoesntExist";
 } else {
     if ($addressCount === 0) {
         echo "addressDosentExist";
     } else {
         if ($addressNameExist !== 0) {
             echo "addressAlreadyExist";
         } else {
             echo "succesChangeAddress";
             if (!empty($addressNewName)) {
                 $elem = "name";
                 $nameElem = $addressNewName;
                 $address->update($elem, $nameElem, $addressName);
                 $addressList->update($elem, $nameElem, $addressName);
                 echo "Name";
             }
             if (!empty($newCategorieName)) {
                 $adressNameChangeCategorie = $addressName;
                 if (!empty($addressNewName)) {
                     $adressNameChangeCategorie = $addressNewName;
                 }
                 $elem = "categorie";
                 $nameElem = $newCategorieName;
                 $address->update($elem, $nameElem, $adressNameChangeCategorie);
                 echo "Categorie";
             }
             if (!empty($phone)) {
                 $adressNameChangePhone = $addressName;
示例#9
0
 /**
  * 更新国家信息
  * @access public
  */
 function update_save()
 {
     $id = get_post_value('id');
     $country = get_post_value('country');
     if (!$this->verify($id)) {
         echo '<br>大区  ' . $country . ' 已存在,请核对后重新输入。<a href="javascript:history.go(-1)">返回</a><br>';
         return;
     }
     $status = get_post_value('status');
     $field = array('country' => trim($country), 'orders' => get_post_value('orders'), 'status' => $status == '10000' ? '10000' : '30000');
     //判断country是否已存在
     $m = new Address();
     $m->clear();
     $m->setTable('vcb_address_country');
     //设置表名
     $m->setField($field);
     ///设置更新字段及值,(键值数组)
     $m->setWhere('country_id', '=', $id);
     //设置Where条件
     $m->update();
     //返回
     echo '<br>操作成功,<a href="index" >返回</a><br>';
 }
                 exit;
             } elseif ($origin == 'shipment') {
                 header("Location: ../expedition/fiche.php?id=" . $originid);
                 exit;
             } else {
                 header("Location: " . $_SERVER['PHP_SELF'] . "?socid=" . $socid);
                 exit;
             }
         }
     } else {
         $mesg = $object->error;
         $action = 'create';
     }
 } else {
     if ($action == 'update') {
         $result = $object->update($id, $socid, $user);
         if ($result >= 0) {
             if (!empty($backtopage)) {
                 header("Location: " . $backtopage);
                 exit;
             } else {
                 if ($origin == 'commande') {
                     header("Location: ../commande/contact.php?id=" . $originid);
                     exit;
                 } elseif ($origin == 'propal') {
                     header("Location: ../comm/propal/contact.php?id=" . $originid);
                     exit;
                 } elseif ($origin == 'shipment') {
                     header("Location: ../expedition/fiche.php?id=" . $originid);
                     exit;
                 } else {
 public function update_detail($order_id, $data)
 {
     $xml = simplexml_load_string($data);
     $prefix = _DB_PREFIX_;
     $sql = 'SELECT id_address_delivery from `' . $prefix . 'orders` where `id_order` = ' . $order_id . ' ';
     $result = Db::getInstance()->ExecuteS($sql);
     $address_id = $result[0]['id_address_delivery'];
     $address = new Address($address_id);
     $address->phone_mobile = (string) $xml->ProcessedOrder->ShippingAddress->PhoneNumber;
     $address->update();
 }
示例#12
0
文件: main.php 项目: rhalf/app_track
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('POST /v1/main/address', function () {
    try {
        $object = Address::insert();
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('PUT /v1/main/address/@id', function ($id) {
    try {
        $object = Address::update($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('DELETE /v1/main/address/@id', function ($id) {
    try {
        $object = Address::delete($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
//=============================================================================
//Collection
示例#13
0
 private function saveAddress($cart_id_address, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $address1)
 {
     $dummy = "dummyvalue";
     if ($cart_id_address > 0) {
         // update existing one
         $tmp_addr = new Address($cart_id_address);
         $tmp_addr->deleted = 0;
     } else {
         // create a new address
         $tmp_addr = new Address();
         $tmp_addr->alias = "My Address";
         $tmp_addr->lastname = $dummy;
         $tmp_addr->firstname = $dummy;
         $tmp_addr->address1 = $dummy;
         $tmp_addr->postcode = $postcode;
         $tmp_addr->city = $dummy;
     }
     if (trim($postcode) != "") {
         $tmp_addr->postcode = $postcode;
     }
     if (trim($city) != "") {
         $tmp_addr->city = $city;
     }
     if (trim($firstname) != "") {
         $tmp_addr->firstname = $firstname;
     }
     if (trim($lastname) != "") {
         $tmp_addr->lastname = $lastname;
     }
     if (trim($address1) != "") {
         $tmp_addr->address1 = $address1;
     }
     if (trim($id_country) == "") {
         $id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
     }
     if (trim($id_country) != "") {
         $tmp_addr->id_country = $id_country;
         if (trim($id_state) != "") {
             $tmp_addr->id_state = $id_state;
         } else {
             $tmp_addr->id_state = 0;
         }
         if (Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && !VatNumber::isApplicable($id_country)) {
             $tmp_addr->vat_number = "";
         }
         if ($cart_id_address > 0) {
             $tmp_addr->update();
         } else {
             $tmp_addr->add();
         }
         return $tmp_addr->id;
     } else {
         return 0;
     }
 }
示例#14
0
        		exit;
        	}
        }
        else
        {
            $mesg = $address->error;
            $_GET["action"]='create';
        }
    }

    if ($_POST["action"] == 'update')
    {
        $socid		= $_POST["socid"];
        $origin		= $_POST["origin"];
        $originid 	= $_POST["originid"];
        $result 	= $address->update($_POST["id"], $socid, $user);

        if ($result >= 0)
        {
        	if ($origin == commande)
        	{
        		Header("Location: ../commande/fiche.php?id=".$originid);
        		exit;
        	}
        	elseif ($origin == propal)
        	{
        		Header("Location: ../comm/propal.php?id=".$originid);
        		exit;
        	}
        	elseif ($origin == shipment)
        	{
示例#15
0
 private function saveAddress($cart_id_address, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $address1)
 {
     $dummy = "dummyvalue";
     if ($cart_id_address > 0) {
         // update existing one
         /* @var $tmp_addr AddressCore */
         $tmp_addr = new Address($cart_id_address);
         $tmp_addr->deleted = 0;
     } else {
         // create a new address
         $tmp_addr = new Address();
         $tmp_addr->alias = "My Address";
         $tmp_addr->lastname = $dummy;
         $tmp_addr->firstname = $dummy;
         $tmp_addr->address1 = $dummy;
         $tmp_addr->postcode = $postcode;
         $tmp_addr->city = $dummy;
     }
     if (trim($postcode) != "") {
         $tmp_addr->postcode = $postcode;
     }
     // For carrier module which depend on city field
     if (trim($city) != "") {
         $tmp_addr->city = $city;
     }
     if (trim($firstname) != "") {
         $tmp_addr->firstname = $firstname;
     }
     if (trim($lastname) != "") {
         $tmp_addr->lastname = $lastname;
     }
     if (trim($address1) != "") {
         $tmp_addr->address1 = $address1;
     }
     // kvoli virtual produktom, ked online country bola skryta a teda id_country bolo prazdne
     if (trim($id_country) == "") {
         $id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
     }
     if (trim($id_country) != "") {
         $tmp_addr->id_country = $id_country;
         if (trim($id_state) != "") {
             $tmp_addr->id_state = $id_state;
         } else {
             $tmp_addr->id_state = 0;
         }
         // Reset VAT number when address is non-EU (otherwise, taxes won't be added when VAT address changes to non-VAT!)
         if (Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && !VatNumber::isApplicable($id_country)) {
             $tmp_addr->vat_number = "";
         }
         if ($cart_id_address > 0) {
             $tmp_addr->update();
         } else {
             $tmp_addr->add();
             // $opckt_helper->addAddressIdAndCartId($tmp_addr->id, $this->context->cookie->id_cart);
         }
         return $tmp_addr->id;
     } else {
         return 0;
     }
 }
 protected function updateAddress()
 {
     // updates/creates address if it does not exist
     if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) {
         $address = new Address((int) Tools::getValue('id_address'));
     } else {
         $address = new Address();
     }
     // creates address
     // sets the address
     $address->alias = Tools::getValue('reference', null);
     $address->lastname = 'warehouse';
     // skip problem with numeric characters in warehouse name
     $address->firstname = 'warehouse';
     // skip problem with numeric characters in warehouse name
     $address->address1 = Tools::getValue('address', null);
     $address->address2 = Tools::getValue('address2', null);
     $address->postcode = Tools::getValue('postcode', null);
     $address->phone = Tools::getValue('phone', null);
     $address->id_country = Tools::getValue('id_country', null);
     $address->id_state = Tools::getValue('id_state', null);
     $address->city = Tools::getValue('city', null);
     // validates the address
     $validation = $address->validateController();
     // checks address validity
     if (count($validation) > 0) {
         foreach ($validation as $item) {
             $this->errors[] = $item;
         }
         $this->errors[] = Tools::displayError('The address is not correct. Please make sure all of the required fields are completed.');
     } else {
         if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) {
             $address->update();
         } else {
             $address->save();
             $_POST['id_address'] = $address->id;
         }
     }
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     // checks access
     if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError('You do not have permission to add suppliers.');
         return parent::postProcess();
     }
     if (Tools::isSubmit('submitAdd' . $this->table)) {
         if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) {
             return;
         }
         // updates/creates address if it does not exist
         if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) {
             $address = new Address((int) Tools::getValue('id_address'));
         } else {
             $address = new Address();
         }
         // creates address
         $address->alias = Tools::getValue('name', null);
         $address->lastname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->firstname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->address1 = Tools::getValue('address', null);
         $address->address2 = Tools::getValue('address2', null);
         $address->postcode = Tools::getValue('postcode', null);
         $address->phone = Tools::getValue('phone', null);
         $address->phone_mobile = Tools::getValue('phone_mobile', null);
         $address->id_country = Tools::getValue('id_country', null);
         $address->id_state = Tools::getValue('id_state', null);
         $address->city = Tools::getValue('city', null);
         $validation = $address->validateController();
         // checks address validity
         if (count($validation) > 0) {
             foreach ($validation as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError('The address is not correct. Please make sure all of the required fields are completed.');
         } else {
             if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) {
                 $address->update();
             } else {
                 $address->save();
                 $_POST['id_address'] = $address->id;
             }
         }
         return parent::postProcess();
     } elseif (Tools::isSubmit('delete' . $this->table)) {
         if (!($obj = $this->loadObject(true))) {
             return;
         } elseif (SupplyOrder::supplierHasPendingOrders($obj->id)) {
             $this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.');
         } else {
             //delete all product_supplier linked to this supplier
             Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'product_supplier` WHERE `id_supplier`=' . (int) $obj->id);
             $id_address = Address::getAddressIdBySupplierId($obj->id);
             $address = new Address($id_address);
             if (Validate::isLoadedObject($address)) {
                 $address->deleted = 1;
                 $address->save();
             }
             return parent::postProcess();
         }
     } else {
         return parent::postProcess();
     }
 }
示例#18
0
                 exit;
             } elseif ($origin == 'shipment') {
                 Header("Location: ../expedition/fiche.php?id=" . $originid);
                 exit;
             } else {
                 Header("Location: " . $_SERVER['PHP_SELF'] . "?socid=" . $socid);
                 exit;
             }
         }
     } else {
         $mesg = $object->error;
         $action = 'create';
     }
 } else {
     if ($action == 'update') {
         $result = $object->update($_POST["id"], $socid, $user);
         if ($result >= 0) {
             if (!empty($backtopage)) {
                 Header("Location: " . $backtopage);
                 exit;
             } else {
                 if ($origin == 'commande') {
                     Header("Location: ../commande/contact.php?id=" . $originid);
                     exit;
                 } elseif ($origin == 'propal') {
                     Header("Location: ../comm/propal/contact.php?id=" . $originid);
                     exit;
                 } elseif ($origin == 'shipment') {
                     Header("Location: ../expedition/fiche.php?id=" . $originid);
                     exit;
                 } else {
 /**
  * Helper function that populates a form with data and submits it.
  */
 protected function placeOrder($firstname, $surname, $email, $address1, $address2 = null, $city = null, $state = null, $postcode = null, $country = null, $password = null, $confirmpassword = null, $member = null)
 {
     $data = array('FirstName' => $firstname, 'Surname' => $surname, 'Email' => $email, 'Address' => $address1, 'City' => $city, 'State' => $state);
     if ($address2) {
         $data['AddressLine2'] = $address2;
     }
     if ($postcode) {
         $data['PostalCode'] = $postcode;
     }
     if ($country) {
         $data['Country'] = $country;
     }
     if ($password) {
         $data['Password[_Password]'] = $password;
     }
     if ($confirmpassword) {
         $data['Password[_ConfirmPassword]'] = $confirmpassword;
     }
     $order = $this->shoppingcart->current();
     $order->update($data);
     $address = new Address();
     $address->update($data);
     $address->write();
     $order->ShippingAddressID = $address->ID;
     $order->BillingAddressID = $address->ID;
     //same (for now)
     if ($member) {
         $order->MemberID = $member->ID;
     }
     $order->write();
     $this->processor = OrderProcessor::create($order);
     return $this->processor->placeOrder();
 }
示例#20
0
 /**
  * 更新国家信息
  * @access public
  */
 function update_save()
 {
     //判断country是否已存在
     $id = get_post_value('id');
     $province = get_post_value('province');
     $city = get_post_value('city');
     $orders = get_post_value('orders');
     $status = get_post_value('status');
     if (!$this->verify($id)) {
         echo '<br>市  ' . $city . ' 已存在,请核对后重新输入。<a href="javascript:history.go(-1)">返回</a><br>';
         return;
     }
     //保存新增数据(设置column及值)
     $field = array('province_id' => $province, 'city' => $city, 'orders' => $orders, 'status' => $status == '10000' ? '10000' : '30000');
     $m = new Address();
     $m->clear();
     $m->setField($field);
     $m->setWhere('city_id', '=', $id);
     $m->setTable('vcb_address_city');
     $data = $m->update();
     //返回
     echo '<br>操作成功,<a href="index" >返回</a><br>';
 }
    private function _getAddress($addressNode, $id_customer, $type)
    {
        //alias is limited
        $type = Tools::substr($type, 0, 32);
        $id_address = (int) Db::getInstance()->getValue('SELECT `id_address`
			FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `alias` = \'' . pSQL($type) . '\'');
        if ($id_address) {
            $address = new Address((int) $id_address);
        } else {
            $address = new Address();
        }
        $customer = new Customer((int) $id_customer);
        $street1 = '';
        $street2 = '';
        $line2 = false;
        $streets = Explode(' ', (string) $addressNode->Street);
        foreach ($streets as $street) {
            if (Tools::strlen($street1) + Tools::strlen($street) + 1 < 32 && !$line2) {
                $street1 .= $street . ' ';
            } else {
                $line2 = true;
                $street2 .= $street . ' ';
            }
        }
        $lastname = (string) $addressNode->LastName;
        $firstname = (string) $addressNode->FirstName;
        $address->id_customer = (int) $id_customer;
        $address->id_country = (int) Country::getByIso(trim($addressNode->Country));
        $address->alias = pSQL($type);
        $address->lastname = !empty($lastname) ? pSQL($lastname) : $customer->lastname;
        $address->firstname = !empty($firstname) ? pSQL($firstname) : $customer->firstname;
        $address->address1 = pSQL($street1);
        $address->address2 = pSQL($street2);
        $address->company = pSQL($addressNode->Company);
        $address->postcode = pSQL($addressNode->PostalCode);
        $address->city = pSQL($addressNode->Town);
        $address->phone = Tools::substr(pSQL($addressNode->Phone), 0, 16);
        $address->phone_mobile = Tools::substr(pSQL($addressNode->PhoneMobile), 0, 16);
        if ($id_address) {
            $address->update();
        } else {
            $address->add();
        }
        return $address->id;
    }
    public function ajaxProcessSaveOrder()
    {
        $products = Tools::getValue('products');
        $delivery_date = Tools::getValue('delivery_date');
        $delivery_time_from = Tools::getValue('delivery_time_from');
        $delivery_time_to = Tools::getValue('delivery_time_to');
        $id_employee = Tools::getValue('employees');
        if (!empty($id_employee) && is_array($id_employee)) {
            $id_employee = $id_employee[0];
        }
        $other = Tools::getValue('other');
        if (empty($products)) {
            PrestaShopLogger::addLog('AphCalendar::saveOrder - Products to be select', 1, null, 'AphCalendar', 0, true);
            die(Tools::jsonEncode(array('result' => false, 'error' => 'Non e\' stato selezionato nessun prodotto. Prego selezionarle almeno uno.')));
        }
        $id_customer = (int) Tools::getValue('id_customer');
        if ($id_customer < 1) {
            $customer = new Customer();
            $customer->firstname = Tools::getValue('firstname');
            $customer->lastname = Tools::getValue('lastname');
            $customer->email = Tools::getValue('email');
            $customer->phone = Tools::getValue('phone');
            $customer->id_gender = Tools::getValue('id_gender');
            $customer->id_shop = (int) Context::getContext()->shop->id;
            $customer->passwd = strtoupper(Tools::passwdGen(10));
            $customer->newsletter = 1;
            if ($customer->validateFields(false, true) !== true) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Fields of customer not valid', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione del cliente. Prego riprovare.')));
            }
            $result = $customer->add();
            if (!$result) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Address of customer is to be added', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione del cliente. Prego riprovare.')));
            }
            $stores = Db::getInstance()->executeS('
			SELECT st.id_country,st.id_state,st.city
			FROM ' . _DB_PREFIX_ . 'store_shop ss
			LEFT JOIN `' . _DB_PREFIX_ . 'store` st 
				ON (ss.`id_store` = st.`id_store`)
			WHERE ss.`id_shop` = ' . (int) Context::getContext()->shop->id);
            $address = new Address();
            $address->id_customer = $customer->id;
            $address->alias = 'indirizzo';
            $address->firstname = $customer->firstname;
            $address->lastname = $customer->lastname;
            $address->address1 = '-';
            $address->postcode = '00000';
            $address->phone = $customer->phone;
            $address->phone_mobile = $customer->phone;
            $address->id_country = $stores[0]['id_country'];
            $address->id_state = $stores[0]['id_state'];
            $address->city = $stores[0]['city'];
            if ($address->validateFields(false, true) !== true) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Fields of address of customer not valid', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione del cliente. Prego riprovare.')));
            }
            $address->add();
            $customer->id_address_delivery = $address->id;
            $customer->id_address_invoice = $address->id;
            if (!$result) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Customer is to be added', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione del cliente. Prego riprovare.')));
            }
            $id_customer = $customer->id;
        } else {
            $customer = new Customer($id_customer);
            $customer->firstname = Tools::getValue('firstname');
            $customer->lastname = Tools::getValue('lastname');
            $customer->email = Tools::getValue('email');
            $customer->phone = Tools::getValue('phone');
            $customer->id_gender = Tools::getValue('id_gender');
            $customer->id_shop = (int) Context::getContext()->shop->id;
            $customer->update();
            $addresses = $customer->getAddresses((int) Context::getContext()->language->id);
            if (empty($addresses)) {
                $customer->id_address_delivery = $customer->id_address_invoice = 0;
            } else {
                $customer->id_address_delivery = $addresses[0]['id_address'];
                $customer->id_address_invoice = $addresses[0]['id_address'];
                $address = new Address($addresses[0]['id_address'], (int) Context::getContext()->language->id);
                $address->firstname = $customer->firstname;
                $address->lastname = $customer->lastname;
                $address->phone = $customer->phone;
                $address->phone_mobile = $customer->phone;
                $address->update();
            }
        }
        $id_order = (int) Tools::getValue('id_order');
        $feature_duration = Configuration::get('APH_FEATURE_DURATION');
        $services_duration = json_decode(Configuration::get('APH_SERVICES_DURATION'), true);
        $reservation_offline_status = Configuration::get('APH_RESERVATION_OFFLINE_STATUS');
        // always add taxes even if there are not displayed to the customer
        $use_taxes = true;
        // Total method
        $total_method = Cart::BOTH_WITHOUT_SHIPPING;
        //TODO ajaxProcessAddProductOnOrder() in AdminOrdersController
        if ($id_order < 1) {
            do {
                $reference = Order::generateReference();
            } while (Order::getByReference($reference)->count());
            $order = new Order();
            $order->id_customer = (int) $customer->id;
            $order->secure_key = $customer->secure_key;
            $order->id_address_invoice = $customer->id_address_delivery;
            $order->id_address_delivery = $customer->id_address_invoice;
            $order->id_currency = (int) Context::getContext()->currency->id;
            $order->id_lang = (int) Context::getContext()->language->id;
            $order->reference = $reference;
            $order->id_shop = (int) Context::getContext()->shop->id;
            $order->id_shop_group = (int) Context::getContext()->shop->id_shop_group;
            $order->id_cart = 0;
            $order->id_carrier = 0;
            $order->payment = 'Pagamento alla consegna';
            $order->module = 'cashondelivery';
            $order->total_paid = 0;
            $order->total_paid_real = 0;
            $order->total_products = 0;
            $order->total_products_wt = 0;
            $order->conversion_rate = 1;
            $order->delivery_number = 1;
            $order->delivery_date = $delivery_date . ' ' . $delivery_time_from;
            $order->current_state = $reservation_offline_status;
            if ($order->validateFields(false, true) !== true) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Fields of order not valid', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione dell\'appuntamento. Prego riprovare.')));
            }
            $result = $order->add();
            if (!$result) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Order is about to be added', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante la creazione dell\'appuntamento. Prego riprovare.')));
            }
            // Create new cart
            $cart = new Cart();
            $cart->id_shop_group = $order->id_shop_group;
            $cart->id_shop = $order->id_shop;
            $cart->id_customer = $order->id_customer;
            $cart->id_carrier = $order->id_carrier;
            $cart->id_address_delivery = $order->id_address_delivery;
            $cart->id_address_invoice = $order->id_address_invoice;
            $cart->id_currency = $order->id_currency;
            $cart->id_lang = $order->id_lang;
            $cart->secure_key = $order->secure_key;
            // Save new cart
            $cart->add();
            // Save context (in order to apply cart rule)
            $this->context->cart = $cart;
            $this->context->customer = new Customer($order->id_customer);
            // calculate prices of products
            $products_detail = array();
            foreach ($products as &$product_id) {
                $product = new Product($product_id, false, $order->id_lang, $order->id_shop);
                $products_detail[$product_id] = array();
                $products_detail[$product_id]['id'] = $products_detail[$product_id]['id_product'] = $product_id;
                $products_detail[$product_id]['name'] = $product->name;
                $products_detail[$product_id]['ean13'] = $product->ean13;
                $products_detail[$product_id]['upc'] = $product->upc;
                $products_detail[$product_id]['reference'] = $product->reference;
                $products_detail[$product_id]['cart_quantity'] = 1;
                $products_detail[$product_id]['id_product_attribute'] = 0;
                $products_detail[$product_id]['id_shop'] = $order->id_shop;
                $products_detail[$product_id]['id_supplier'] = 0;
                $products_detail[$product_id]['weight'] = $product->weight;
                $products_detail[$product_id]['height'] = $product->height;
                $products_detail[$product_id]['depth'] = $product->depth;
                $products_detail[$product_id]['ecotax'] = $product->ecotax;
                $products_detail[$product_id]['price_without_reduction'] = Product::getPriceStatic((int) $product_id, true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                $products_detail[$product_id]['price_with_reduction'] = Product::getPriceStatic((int) $product_id, true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                $products_detail[$product_id]['price'] = $products_detail[$product_id]['price_with_reduction_without_tax'] = Product::getPriceStatic((int) $product_id, false, $products_detail[$product_id]['id_product_attribute'], 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                switch (Configuration::get('PS_ROUND_TYPE')) {
                    case Order::ROUND_TOTAL:
                        $products_detail[$product_id]['total'] = $products_detail[$product_id]['price_with_reduction_without_tax'] * (int) $products_detail[$product_id]['cart_quantity'];
                        $products_detail[$product_id]['total_wt'] = $products_detail[$product_id]['price_with_reduction'] * (int) $products_detail[$product_id]['cart_quantity'];
                        break;
                    case Order::ROUND_LINE:
                        $products_detail[$product_id]['total'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction_without_tax'] * (int) $products_detail[$product_id]['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                        $products_detail[$product_id]['total_wt'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction'] * (int) $products_detail[$product_id]['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                        break;
                    case Order::ROUND_ITEM:
                    default:
                        $products_detail[$product_id]['total'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction_without_tax'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $products_detail[$product_id]['cart_quantity'];
                        $products_detail[$product_id]['total_wt'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $products_detail[$product_id]['cart_quantity'];
                        break;
                }
                $products_detail[$product_id]['price_wt'] = $products_detail[$product_id]['price_with_reduction'];
                $products_detail[$product_id]['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
                $products_detail[$product_id]['wholesale_price'] = $product->wholesale_price;
                $products_detail[$product_id]['additional_shipping_cost'] = $product->additional_shipping_cost;
                // Add product to cart
                $update_quantity = $cart->updateQty($products_detail[$product_id]['cart_quantity'], $product->id, $products_detail[$product_id]['id_product_attribute'], null, 'up', 0, new Shop($cart->id_shop));
                $order_detail = new AphOrderDetail();
                $order_detail->createList($order, $cart, $order->current_state, array($products_detail[$product_id]), 0, $use_taxes, 0);
                // update totals amount of order
                $order->total_products += (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
                $order->total_products_wt += (double) $cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
                $order->total_paid += Tools::ps_round((double) $cart->getOrderTotal(true, $total_method), 2);
                $order->total_paid_tax_excl += Tools::ps_round((double) $cart->getOrderTotal(false, $total_method), 2);
                $order->total_paid_tax_incl += Tools::ps_round((double) $cart->getOrderTotal($use_taxes, $total_method), 2);
                // discount
                $order->total_discounts += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
                $order->total_discounts_tax_excl += (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
                $order->total_discounts_tax_incl += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
                // Save changes of order
                $order->id_cart = $cart->id;
                $order->update();
                // Update Tax lines
                $order_detail->updateTaxAmount($order);
                // duration event
                $features = $product->getFeatures();
                foreach ($features as &$feature) {
                    if ($feature_duration == $feature['id_feature']) {
                        $products_detail[$product_id]['duration'] = (int) $services_duration[$feature['id_feature_value']];
                    }
                }
                $order_detail->id_employee = $id_employee;
                $order_detail->delivery_date = $delivery_date;
                $order_detail->delivery_time_from = $delivery_time_from;
                if (!empty($products_detail[$product_id]['duration'])) {
                    $time = new DateTime($delivery_date . ' ' . $delivery_time_from);
                    $time->add(new DateInterval('PT' . $products_detail[$product_id]['duration'] . 'M'));
                    $time_to = $time->format('H:i');
                    if ($time_to > $delivery_time_to) {
                        $delivery_time_to = $time_to;
                    }
                }
                $order_detail->delivery_time_to = $delivery_time_to;
                $order_detail->note = $other;
                $order_detail->update();
            }
        } else {
            $order = new Order($id_order);
            $order->id_customer = (int) $customer->id;
            $order->secure_key = $customer->secure_key;
            $order->id_address_invoice = $customer->id_address_delivery;
            $order->id_address_delivery = $customer->id_address_invoice;
            $order->id_currency = (int) Context::getContext()->currency->id;
            $order->id_lang = (int) Context::getContext()->language->id;
            $order->total_paid = 0;
            $order->total_paid_real = 0;
            $order->total_products = 0;
            $order->total_products_wt = 0;
            $order->conversion_rate = 1;
            $order->delivery_number = 1;
            $order->delivery_date = $delivery_date . ' ' . $delivery_time_from;
            if ($order->validateFields(false, true) !== true) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Fields of order not valid', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante l\'aggiornamento dell\'appuntamento. Prego riprovare.')));
            }
            $result = $order->update();
            if (!$result) {
                PrestaShopLogger::addLog('AphCalendar::saveOrder - Order is about to be added', 1, null, 'AphCalendar', 0, true);
                die(Tools::jsonEncode(array('result' => false, 'error' => 'Si e\' verificato un problema durante l\'aggiornamento dell\'appuntamento. Prego riprovare.')));
            }
            // Create new cart
            $cart = new Cart($order->id_cart);
            // Save context (in order to apply cart rule)
            $this->context->cart = $cart;
            $this->context->customer = new Customer($order->id_customer);
            $id_order_detail = Tools::getValue('id_order_detail');
            $order_detail = new AphOrderDetail($id_order_detail);
            if (empty($products_detail[$order_detail->product_id])) {
                $order_detail->delete();
            }
            // calculate prices of products
            $products_detail = array();
            $is_to_update = false;
            foreach ($products as &$product_id) {
                $is_to_update = $product_id == $order_detail->product_id;
                $product = new Product($product_id, false, $order->id_lang, $order->id_shop);
                $products_detail[$product_id] = array();
                $products_detail[$product_id]['id'] = $products_detail[$product_id]['id_product'] = $product_id;
                $products_detail[$product_id]['name'] = $product->name;
                $products_detail[$product_id]['ean13'] = $product->ean13;
                $products_detail[$product_id]['upc'] = $product->upc;
                $products_detail[$product_id]['reference'] = $product->reference;
                $products_detail[$product_id]['cart_quantity'] = 1;
                $products_detail[$product_id]['id_product_attribute'] = 0;
                $products_detail[$product_id]['id_shop'] = $order->id_shop;
                $products_detail[$product_id]['id_supplier'] = 0;
                $products_detail[$product_id]['weight'] = $product->weight;
                $products_detail[$product_id]['height'] = $product->height;
                $products_detail[$product_id]['depth'] = $product->depth;
                $products_detail[$product_id]['ecotax'] = $product->ecotax;
                $products_detail[$product_id]['price_without_reduction'] = Product::getPriceStatic((int) $product_id, true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                $products_detail[$product_id]['price_with_reduction'] = Product::getPriceStatic((int) $product_id, true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                $products_detail[$product_id]['price'] = $products_detail[$product_id]['price_with_reduction_without_tax'] = Product::getPriceStatic((int) $product_id, false, $products_detail[$product_id]['id_product_attribute'], 6, null, false, true, $products_detail[$product_id]['cart_quantity'], false, $order->id_customer, (int) $cart->id, $order->id_address_invoice, $specific_price_output, true, true, $this->context);
                switch (Configuration::get('PS_ROUND_TYPE')) {
                    case Order::ROUND_TOTAL:
                        $products_detail[$product_id]['total'] = $products_detail[$product_id]['price_with_reduction_without_tax'] * (int) $products_detail[$product_id]['cart_quantity'];
                        $products_detail[$product_id]['total_wt'] = $products_detail[$product_id]['price_with_reduction'] * (int) $products_detail[$product_id]['cart_quantity'];
                        break;
                    case Order::ROUND_LINE:
                        $products_detail[$product_id]['total'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction_without_tax'] * (int) $products_detail[$product_id]['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                        $products_detail[$product_id]['total_wt'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction'] * (int) $products_detail[$product_id]['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                        break;
                    case Order::ROUND_ITEM:
                    default:
                        $products_detail[$product_id]['total'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction_without_tax'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $products_detail[$product_id]['cart_quantity'];
                        $products_detail[$product_id]['total_wt'] = Tools::ps_round($products_detail[$product_id]['price_with_reduction'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $products_detail[$product_id]['cart_quantity'];
                        break;
                }
                $products_detail[$product_id]['price_wt'] = $products_detail[$product_id]['price_with_reduction'];
                $products_detail[$product_id]['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
                $products_detail[$product_id]['wholesale_price'] = $product->wholesale_price;
                $products_detail[$product_id]['additional_shipping_cost'] = $product->additional_shipping_cost;
                // Add product to cart
                $update_quantity = $cart->updateQty($products_detail[$product_id]['cart_quantity'], $product->id, $products_detail[$product_id]['id_product_attribute'], null, 'up', 0, new Shop($cart->id_shop));
                $order_detail = new AphOrderDetail();
                $order_detail->createList($order, $cart, $order->current_state, array($products_detail[$product_id]), 0, $use_taxes, 0);
                // update totals amount of order
                $order->total_products += (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
                $order->total_products_wt += (double) $cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
                $order->total_paid += Tools::ps_round((double) $cart->getOrderTotal(true, $total_method), 2);
                $order->total_paid_tax_excl += Tools::ps_round((double) $cart->getOrderTotal(false, $total_method), 2);
                $order->total_paid_tax_incl += Tools::ps_round((double) $cart->getOrderTotal($use_taxes, $total_method), 2);
                // discount
                $order->total_discounts += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
                $order->total_discounts_tax_excl += (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
                $order->total_discounts_tax_incl += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
                // Save changes of order
                $order->id_cart = $cart->id;
                $order->update();
                // Update Tax lines
                $order_detail->updateTaxAmount($order);
                // duration event
                $features = $product->getFeatures();
                foreach ($features as &$feature) {
                    if ($feature_duration == $feature['id_feature']) {
                        $products_detail[$product_id]['duration'] = (int) $services_duration[$feature['id_feature_value']];
                    }
                }
                $order_detail->id_employee = $id_employee;
                $order_detail->delivery_date = $delivery_date;
                $order_detail->delivery_time_from = $delivery_time_from;
                if (!empty($products_detail[$product_id]['duration'])) {
                    $time = new DateTime($delivery_date . ' ' . $delivery_time_from);
                    $time->add(new DateInterval('PT' . $products_detail[$product_id]['duration'] . 'M'));
                    $time_to = $time->format('H:i');
                    if ($time_to > $delivery_time_to) {
                        $delivery_time_to = $time_to;
                    }
                }
                $order_detail->delivery_time_to = $delivery_time_to;
                $order_detail->note = $other;
                if ($is_to_update) {
                    $order_detail->update();
                } else {
                    $order_detail->add();
                }
            }
        }
        $send_memo = (bool) Tools::getValue('send_memo');
        if (!empty($send_memo)) {
            $shop = new AphStore($products_detail[$product_id]['id_shop']);
            $topic = 'Promemoria appuntamento';
            $data = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => (int) $order->id, '{order_name}' => $order->getUniqReference(), '{product_name}' => $products_detail[$product_id]['name'], '{delivery_date}' => $order_detail->delivery_date, '{delivery_time_from}' => $order_detail->delivery_time_from, '{shop_name}' => $shop->name, '{shop_address}' => $shop->shop_address1 . (!empty($shop->shop_address2) ? ' ' . $shop->shop_address2 : ''), '{shop_city}' => $shop->shop_city, '{shop_link_rewrite}' => $shop->shop_link_rewrite, '{shop_phone}' => $shop->phone);
            if (Validate::isLoadedObject($order)) {
                !Mail::Send((int) $order->id_lang, 'order_memo', $topic, $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, false, null, _PS_MAIL_DIR_, false, (int) $order->id_shop);
            }
        }
        die(Tools::jsonEncode(array('result' => true)));
    }