function show_Address()
{
    return displayAddress();
}
Example #2
0
function processAddress()
{
    global $cart, $smarty;
    $errors = array();
    if (!isset($_POST['id_address_delivery']) or !Address::isCountryActiveById(intval($_POST['id_address_delivery']))) {
        $errors[] = 'this address is not in a valid area';
    } else {
        $cart->id_address_delivery = intval(Tools::getValue('id_address_delivery'));
        $cart->id_address_invoice = Tools::isSubmit('same') ? $cart->id_address_delivery : intval(Tools::getValue('id_address_invoice'));
        if (!$cart->update()) {
            $errors[] = Tools::displayError('an error occured while updating your cart');
        }
        if (Tools::isSubmit('message') and !empty($_POST['message'])) {
            if (!Validate::isMessage($_POST['message'])) {
                $errors[] = Tools::displayError('invalid message');
            } elseif ($oldMessage = Message::getMessageByCartId(intval($cart->id))) {
                $message = new Message(intval($oldMessage['id_message']));
                $message->message = htmlentities($_POST['message'], ENT_COMPAT, 'UTF-8');
                $message->update();
            } else {
                $message = new Message();
                $message->message = htmlentities($_POST['message'], ENT_COMPAT, 'UTF-8');
                $message->id_cart = intval($cart->id);
                $message->id_customer = intval($cart->id_customer);
                $message->add();
            }
        }
    }
    if (sizeof($errors)) {
        if (Tools::getValue('ajax')) {
            die('{\'hasError\' : true, errors : [\'' . implode('\',\'', $errors) . '\']}');
        }
        $smarty->assign('errors', $errors);
        displayAddress();
        include_once dirname(__FILE__) . '/footer.php';
        exit;
    }
    if (Tools::getValue('ajax')) {
        die(true);
    }
}