Exemple #1
0
    public function getContent()
    {
        if (Tools::isSubmit('submitUpdate')) {
            Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool) Tools::getValue('NW_CONFIRMATION_EMAIL'));
            Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool) Tools::getValue('NW_VERIFICATION_EMAIL'));
            $voucher = Tools::getValue('NW_VOUCHER_CODE');
            if ($voucher && !Validate::isDiscountName($voucher)) {
                $this->_html .= $this->displayError($this->l('The voucher code is invalid.'));
            } else {
                Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher));
                $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
            }
        } elseif (Tools::isSubmit('subscribedmerged')) {
            $id = Tools::getValue('id');
            if (preg_match('/(^N)/', $id)) {
                $id = (int) substr($id, 1);
                $sql = 'UPDATE ' . _DB_PREFIX_ . 'newsletter SET active = 0 WHERE id = ' . $id;
                Db::getInstance()->execute($sql);
            } else {
                $c = new Customer((int) $id);
                $c->newsletter = (int) (!$c->newsletter);
                $c->update();
            }
            Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
        } elseif (Tools::isSubmit('exportSubscribers')) {
            $header = array('id', 'shop_name', 'gender', 'lastname', 'firstname', 'email', 'subscribed', 'subscribed_on');
            // TODO
            $array_to_export = array_merge(array($header), $this->getSubscribers());
            $file_name = time() . '.csv';
            $fd = fopen($this->getLocalPath() . $file_name, 'w+');
            foreach ($array_to_export as $tab) {
                $line = implode(';', $tab);
                $line .= "\n";
                fwrite($fd, $line, 4096);
            }
            fclose($fd);
            Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name);
        } elseif (Tools::isSubmit('exportOnlyBlockNews')) {
            $array_to_export = $this->getBlockNewsletterSubscriber();
            $file_name = time() . '.csv';
            $fd = fopen($this->getLocalPath() . $file_name, 'w+');
            foreach ($array_to_export as $tab) {
                $line = implode(';', $tab);
                $line .= "\n";
                fwrite($fd, $line, 4096);
            }
            fclose($fd);
            Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name);
        } elseif (Tools::isSubmit('searchEmail')) {
            $this->_searched_email = Tools::getValue('searched_email');
        }
        $this->_html .= $this->renderForm();
        $this->_html .= $this->renderSearchForm();
        $this->_html .= $this->renderList();
        $this->_html .= '<div class="panel"><a href="' . $this->context->link->getAdminLink('AdminModules', false) . '&exportSubscribers&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '">
    <button class="btn btn-default btn-lg"><span class="icon icon-share"></span> ' . $this->l('Export as CSV') . '</button>
</a></div>';
        $this->_html .= $this->renderExportForm();
        return $this->_html;
    }
Exemple #2
0
 public function index()
 {
     $obj = new Customer('1');
     $obj->fname = 'Altaf';
     $obj->update();
     //echo "<pre>";print_r($obj->getData);die;
 }
 public function preProcess()
 {
     parent::preProcess();
     $customer = new Customer((int) self::$cookie->id_customer);
     if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) {
         $customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
     }
     if (Tools::isSubmit('submitIdentity')) {
         if (Module::getInstanceByName('blocknewsletter')->active) {
             if (!isset($_POST['optin'])) {
                 $customer->optin = 0;
             }
             if (!isset($_POST['newsletter'])) {
                 $customer->newsletter = 0;
             }
         }
         if (!isset($_POST['id_gender'])) {
             $_POST['id_gender'] = 9;
         }
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         } else {
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             $id_customer_exists = (int) Customer::customerExists(Tools::getValue('email'), true, false);
             if ($id_customer_exists && $id_customer_exists != (int) self::$cookie->id_customer) {
                 $this->errors[] = Tools::displayError('An account is already registered with this e-mail.');
             }
             $_POST['old_passwd'] = trim($_POST['old_passwd']);
             if (empty($_POST['old_passwd']) || Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
                 $this->errors[] = Tools::displayError('Your password is incorrect.');
             } elseif ($_POST['passwd'] != $_POST['confirmation']) {
                 $this->errors[] = Tools::displayError('Password and confirmation do not match');
             } else {
                 $prev_id_default_group = $customer->id_default_group;
                 $this->errors = array_unique(array_merge($this->errors, $customer->validateController(true, true)));
             }
             if (!count($this->errors)) {
                 $customer->id_default_group = (int) $prev_id_default_group;
                 $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
                 if (Tools::getValue('passwd')) {
                     self::$cookie->passwd = $customer->passwd;
                 }
                 if ($customer->update()) {
                     self::$cookie->customer_lastname = $customer->lastname;
                     self::$cookie->customer_firstname = $customer->firstname;
                     self::$smarty->assign('confirmation', 1);
                 } else {
                     $this->errors[] = Tools::displayError('Cannot update information');
                 }
             }
         }
     } else {
         $_POST = array_map('stripslashes', $customer->getFields());
     }
     $birthday = $customer->birthday ? explode('-', $customer->birthday) : array('-', '-', '-');
     /* Generate years, months and days */
     self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
     self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
 }
 public function testCustomerUpdateFromCard()
 {
     $token = 'cus_FaWhNhFT5gEAAv5BArjJSIIq';
     $this->mockResponse($this->success_customer_update_card_response());
     $params = array('card_number' => '4908440000000003', 'expiration_month' => '01', 'expiration_year' => date('Y') + 1, 'cvv' => '123', 'holder_name' => 'John Doe');
     $customer = Customer::update($token, $params);
     $this->assertEquals(substr($params['card_number'], -4), $customer->card->last_four);
 }
 public function testCustomerUpdate()
 {
     $token = 'cus_zDdjHBuNW3do8G3jaTqApzsI';
     $this->mockResponse($this->success_customer_update_response());
     $params = array('email' => '*****@*****.**', 'full_name' => 'John Doe');
     $customer = Customer::update($token, $params);
     $this->assertNotNull($customer->email);
     $this->assertNotNull($customer->full_name);
 }
 public function preProcess()
 {
     parent::preProcess();
     $customer = new Customer((int) self::$cookie->id_customer);
     if (sizeof($_POST)) {
         $exclusion = array('secure_key', 'old_passwd', 'passwd', 'active', 'date_add', 'date_upd', 'last_passwd_gen', 'newsletter_date_add', 'id_default_group');
         $fields = $customer->getFields();
         foreach ($fields as $key => $value) {
             if (!in_array($key, $exclusion)) {
                 $customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0;
             }
         }
     }
     if (isset($_POST['years']) and isset($_POST['months']) and isset($_POST['days'])) {
         $customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
     }
     if (Tools::isSubmit('submitIdentity')) {
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         } else {
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             $_POST['old_passwd'] = trim($_POST['old_passwd']);
             if (empty($_POST['old_passwd']) or Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
                 $this->errors[] = Tools::displayError('Your password is incorrect.');
             } elseif ($_POST['passwd'] != $_POST['confirmation']) {
                 $this->errors[] = Tools::displayError('Password and confirmation do not match');
             } else {
                 $prev_id_default_group = $customer->id_default_group;
                 $this->errors = $customer->validateControler();
             }
             if (!sizeof($this->errors)) {
                 $customer->id_default_group = (int) $prev_id_default_group;
                 $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
                 if (Tools::getValue('passwd')) {
                     self::$cookie->passwd = $customer->passwd;
                 }
                 if ($customer->update()) {
                     self::$cookie->customer_lastname = $customer->lastname;
                     self::$cookie->customer_firstname = $customer->firstname;
                     self::$smarty->assign('confirmation', 1);
                 } else {
                     $this->errors[] = Tools::displayError('Cannot update information');
                 }
             }
         }
     } else {
         $_POST = array_map('stripslashes', $customer->getFields());
     }
     if ($customer->birthday) {
         $birthday = explode('-', $customer->birthday);
     } else {
         $birthday = array('-', '-', '-');
     }
     /* Generate years, months and days */
     self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
     self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
 }
 /**
  * Start forms process
  * @see FrontController::postProcess()
  */
 public function postProcess()
 {
     if (Tools::isSubmit('email')) {
         if (!($email = Tools::getValue('email')) || !Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('Invalid e-mail address');
         } else {
             $customer = new Customer();
             $customer->getByemail($email);
             if (!Validate::isLoadedObject($customer)) {
                 $this->errors[] = Tools::displayError('There is no account registered to this e-mail address.');
             } else {
                 if (strtotime($customer->last_passwd_gen . '+' . (int) ($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time() > 0) {
                     $this->errors[] = sprintf(Tools::displayError('You can regenerate your password only every %d minute(s)'), (int) $min_time);
                 } else {
                     if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{url}' => $this->context->link->getPageLink('password', true, null, 'token=' . $customer->secure_key . '&id_customer=' . (int) $customer->id)), $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
                         $this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email));
                     } else {
                         $this->errors[] = Tools::displayError('Error occurred while sending the e-mail.');
                     }
                 }
             }
         }
     } else {
         if (($token = Tools::getValue('token')) && ($id_customer = (int) Tools::getValue('id_customer'))) {
             $email = Db::getInstance()->getValue('SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer=' . (int) $id_customer);
             if ($email) {
                 $customer = new Customer();
                 $customer->getByemail($email);
                 if (strtotime($customer->last_passwd_gen . '+' . (int) ($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time() > 0) {
                     Tools::redirect('index.php?controller=authentication&error_regen_pwd');
                 } else {
                     $customer->passwd = Tools::encrypt($password = Tools::passwdGen(MIN_PASSWD_LENGTH));
                     $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
                     if ($customer->update()) {
                         Hook::exec('actionPasswordRenew', array('customer' => $customer, 'password' => $password));
                         if (Mail::Send($this->context->language->id, 'password', Mail::l('Your new password'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
                             $this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email));
                         } else {
                             $this->errors[] = Tools::displayError('Error occurred while sending the e-mail.');
                         }
                     } else {
                         $this->errors[] = Tools::displayError('An error occurred with your account and your new password cannot be sent to your e-mail. Please report your problem using the contact form.');
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted');
             }
         } else {
             if (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) {
                 $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted');
             }
         }
     }
 }
 public static function update_models($action, array $fromData, Customer $toMember)
 {
     $updateData = [];
     foreach ($fromData as $fieldName => $value) {
         // TODO what if we have a field with an underscore?
         $updateData[str_replace('_', '.', $fieldName)] = $value;
     }
     $updateData = self::filter_data($action, $updateData);
     $toMember->update($updateData);
     $toMember->write();
     return $fromData;
 }
function customer_edit()
{
    $customer = new Customer();
    $customerid = isset($_POST['customerid']) ? $_POST['customerid'] : "";
    $customer->id = $customerid;
    $customer->name = isset($_POST['name']) ? $_POST['name'] : "";
    $customer->address = isset($_POST['address']) ? $_POST['address'] : "";
    $customer->phone = isset($_POST['phone']) ? $_POST['phone'] : "";
    $customer->cell = isset($_POST['cell']) ? $_POST['cell'] : "";
    $customer->active = isset($_POST['active']) ? $_POST['active'] : 0;
    $customer->email = isset($_POST['email']) ? $_POST['email'] : "";
    $customer->nit = isset($_POST['nit']) ? $_POST['nit'] : "";
    return $customer->update();
}
Exemple #10
0
 public static function anonimize_customers()
 {
     $customers = Customer::getCustomers();
     foreach ($customers as $customer) {
         // print_r($customer);
         $anon_customer = new Customer($customer["id_customer"]);
         $anon_customer->email = md5($customer['email']) . '@example.com';
         $res = $anon_customer->update();
         if ($res) {
             echo "Successfully updated user " . $anon_customer->id . "\n";
         } else {
             echo "Error, could not update user " . $customer['id_customer'] . "\n";
             return false;
         }
     }
 }
Exemple #11
0
<?php

session_start();
require "../deny/connector.php";
require "../administrator/process/class/class.Customer.php";
require "../administrator/includes/injection.php";
$cid = $_SESSION['user_id'];
$fullname = sqlInjection($_POST['fullname']);
$phone = sqlInjection($_POST['phone']);
$address = sqlInjection($_POST['address']);
$gender = sqlInjection($_POST['gender']);
//echo $cid." ".$fullname." ".$phone." ".$address." ".$gender;
$cus = new Customer();
$cus->update($cid, $fullname, $gender, $address, $phone);
echo "<meta http-equiv='refresh' content='0;url=../index.php?page=profile'>";
//header("location: ../index.php?page=profile");
//exit();
    public function addWithemail($autodate = true, $templateVars = false)
    {
        $lastOrderState = $this->getLastOrderState($this->id_order);
        if (!parent::add($autodate)) {
            return false;
        }
        $result = Db::getInstance()->getRow('
			SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`
			FROM `' . _DB_PREFIX_ . 'order_history` oh
				LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON oh.`id_order` = o.`id_order`
				LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON o.`id_customer` = c.`id_customer`
				LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON oh.`id_order_state` = os.`id_order_state`
				LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
			WHERE oh.`id_order_history` = ' . (int) $this->id . '
				AND os.`send_email` = 1');
        $order = new Order((int) $this->id_order);
        if (isset($result['template']) and Validate::isEmail($result['email'])) {
            $topic = $result['osname'];
            $data = array('{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int) $this->id_order);
            if ($templateVars) {
                $data = array_merge($data, $templateVars);
            }
            $data['{total_paid}'] = Tools::displayPrice((double) $order->total_paid, new Currency((int) $order->id_currency), false);
            $data['{order_name}'] = sprintf("#%06d", (int) $order->id);
            // An additional email is sent the first time a virtual item is validated
            if ($virtualProducts = $order->getVirtualProducts() and (!$lastOrderState or !$lastOrderState->logable) and $newOrderState = new OrderState($this->id_order_state, Configuration::get('PS_LANG_DEFAULT')) and $newOrderState->logable) {
                global $smarty;
                $assign = array();
                foreach ($virtualProducts as $key => $virtualProduct) {
                    $id_product_download = ProductDownload::getIdFromIdProduct($virtualProduct['product_id']);
                    $product_download = new ProductDownload($id_product_download);
                    $assign[$key]['name'] = $product_download->display_filename;
                    $dl_link = $product_download->getTextLink(false, $virtualProduct['download_hash']) . '&id_order=' . $order->id . '&secure_key=' . $order->secure_key;
                    $assign[$key]['link'] = $dl_link;
                    if ($virtualProduct['download_deadline'] != '0000-00-00 00:00:00') {
                        $assign[$key]['deadline'] = Tools::displayDate($virtualProduct['download_deadline'], $order->id_lang);
                    }
                    if ($product_download->nb_downloadable != 0) {
                        $assign[$key]['downloadable'] = $product_download->nb_downloadable;
                    }
                }
                $smarty->assign('virtualProducts', $assign);
                $smarty->assign('id_order', $order->id);
                $iso = Language::getIsoById((int) $order->id_lang);
                $links = $smarty->fetch(_PS_MAIL_DIR_ . $iso . '/download-product.tpl');
                $tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
                $data = array_merge($data, $tmpArray);
                global $_LANGMAIL;
                Mail::Send((int) $order->id_lang, 'download_product', Mail::l('Virtual product to download'), $data, $result['email'], $result['firstname'] . ' ' . $result['lastname']);
            }
            //custom subjects
            $emailSubject = $topic;
            $smsText = '';
            $delivery = new Address((int) $order->id_address_delivery);
            if ($this->id_order_state == _PS_OS_CANCELED_) {
                $emailSubject = 'Your order #' . $order->id . ' with IndusDiva.com has been cancelled';
                $smsText = 'Dear customer, your order #' . $order->id . ' with IndusDiva.com has been cancelled. www.indusdiva.com';
                Tools::sendSMS($delivery->phone_mobile, $smsText);
            } else {
                if ($this->id_order_state == _PS_OS_REFUND_) {
                    $emailSubject = 'Refund of your payment at IndusDiva.com';
                    $smsText = 'Dear customer, an amount of ' . Tools::displayPrice((double) $order->total_paid) . ' has been credited to your account against your order #' . $order->id . ' at IndusDiva.com. www.indusdiva.com';
                    Tools::sendSMS($delivery->phone_mobile, $smsText);
                }
            }
            if (Validate::isLoadedObject($order)) {
                Mail::Send((int) $order->id_lang, $result['template'], $emailSubject, $data, $result['email'], $result['firstname'] . ' ' . $result['lastname']);
            }
        }
        /* Send loyalty rules message */
        if ($this->id_order_state == _PS_OS_DELIVERED_) {
            $customer = new Customer($order->id_customer);
            $customer->total_delivered++;
            $customer->update();
            Tools::sendSQSRuleMessage(EVENT_ORDER_DELIVERED, $order->id, $order->id_customer, $this->date_add);
        } else {
            if ($this->id_order_state == _PS_OS_CANCELED_) {
                $order_cart = new Cart($order->id_cart);
                $points_redeemed = $order_cart->getPoints();
                if ($points_redeemed) {
                    VBRewards::addRewardPoints($order->id_customer, EVENT_ORDER_CANCELLED, 0, $points_redeemed, 'Redemption order cancelled - Order no ' . $order->id, $order->id, $order->date_add);
                }
                /*
                			//if online payment bonus awarded
                			$reward = rule_base::getReward($order->id_customer, ONLINE_ORDER, 0, $order->id);
                if($reward)
                {
                    $points_removed = $reward['points_awarded'];
                    VBRewards::removeRewardPoints($order->id_customer, EVENT_ORDER_CANCELLED, 0, $points_removed, 'Order Cancellation - Bonus coins reverted - Order no ' . $order->id, $order->id, $this->date_add);
                }
                */
                //if the order was delivered
                if ($lastOrderState->id == _PS_OS_DELIVERED_) {
                    $customer = new Customer($order->id_customer);
                    $customer->total_delivered--;
                    $customer->update();
                    Tools::sendSQSRuleMessage(EVENT_ORDER_CANCELLED, $order->id, $order->id_customer, $this->date_add);
                }
            } else {
                if ($this->id_order_state == _PS_OS_PREPARATION_) {
                    if ($lastOrderState->id == _PS_OS_CANCELED_) {
                        $order_cart = new Cart($order->id_cart);
                        $points_redeemed = $order_cart->getPoints();
                        if ($points_redeemed > 0) {
                            VBRewards::removeRewardPoints($order->id_customer, EVENT_POINTS_REDEEMED, 0, $points_redeemed, 'Coins redeemed - Order no ' . $order->id, $order->id, $order->date_add);
                        }
                    }
                }
            }
        }
        return true;
    }
Exemple #13
0
    die($pdoException->getMessage());
}
$customer = new Customer($dirt, 4);
echo "Number of columns: " . (string) $customer->getColumnCount() . "\n";
for ($i = 1; $i <= 1225; $i++) {
    $isLoaded = $customer->retrieve(['Id' => $i]);
    if ($isLoaded) {
        echo 'Pharmacy Id: ' . (string) $customer->PharmacyId . "\n";
        echo 'First Name: ' . $customer->FirstName . "\n";
        echo 'Last Name: ' . $customer->LastName . "\n";
        echo 'Email: ' . $customer->Email . "\n";
    }
}
exit;
$customer->FirstName = 'Marge';
$updateWorked = $customer->update();
echo "Update: " . (string) $updateWorked;
exit;
$customer->FirstName = 'Ralph';
$customer->LastName = 'Bednar';
echo "Last Name: " . $customer->LastName;
$customer->bogus = 'ee';
exit;
/*


$dirtLite = $dirt->sqlite('/home/ryan/blah.db');
//$stmt = $dirtLite->query("CREATE TABLE Test (id int, firstname char(10))");
//$stmt->execute();

$stmt = $dirtLite->query("INSERT INTO Test (id, firstname) values(1,'ryan')");
 public function preProcess()
 {
     parent::preProcess();
     if ($this->nbProducts) {
         self::$smarty->assign('virtual_cart', false);
     }
     $this->isLogged = (bool) ((int) self::$cookie->id_customer and Customer::customerIdExistsStatic((int) self::$cookie->id_customer));
     if (self::$cart->nbProducts()) {
         if (Tools::isSubmit('ajax')) {
             if (Tools::isSubmit('method')) {
                 switch (Tools::getValue('method')) {
                     case 'updateMessage':
                         if (Tools::isSubmit('message')) {
                             $txtMessage = urldecode(Tools::getValue('message'));
                             $this->_updateMessage($txtMessage);
                             if (sizeof($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             die(true);
                         }
                         break;
                     case 'updateCarrierAndGetPayments':
                         if (Tools::isSubmit('id_carrier') and Tools::isSubmit('recyclable') and Tools::isSubmit('gift') and Tools::isSubmit('gift_message')) {
                             if ($this->_processCarrier()) {
                                 $return = array('summary' => self::$cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods());
                                 die(Tools::jsonEncode($return));
                             } else {
                                 $this->errors[] = Tools::displayError('Error occurred updating cart.');
                             }
                             if (sizeof($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                             exit;
                         }
                         break;
                     case 'updateTOSStatusAndGetPayments':
                         if (Tools::isSubmit('checked')) {
                             self::$cookie->checkedTOS = (int) Tools::getValue('checked');
                             die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods())));
                         }
                         break;
                     case 'getCarrierList':
                         die(Tools::jsonEncode($this->_getCarrierList()));
                         break;
                     case 'editCustomer':
                         if (!$this->isLogged) {
                             exit;
                         }
                         $customer = new Customer((int) self::$cookie->id_customer);
                         if (Tools::getValue('years')) {
                             $customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
                         }
                         $_POST['lastname'] = $_POST['customer_lastname'];
                         $_POST['firstname'] = $_POST['customer_firstname'];
                         $this->errors = $customer->validateControler();
                         $customer->newsletter = (int) Tools::isSubmit('newsletter');
                         $customer->optin = (int) Tools::isSubmit('optin');
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) self::$cookie->id_customer, 'token' => Tools::getToken(false));
                         if (!sizeof($this->errors)) {
                             $return['isSaved'] = (bool) $customer->update();
                         } else {
                             $return['isSaved'] = false;
                         }
                         die(Tools::jsonEncode($return));
                         break;
                     case 'getAddressBlockAndCarriersAndPayments':
                         if (self::$cookie->isLogged()) {
                             // check if customer have addresses
                             if (!Customer::getAddressesTotalById((int) self::$cookie->id_customer)) {
                                 die(Tools::jsonEncode(array('no_address' => 1)));
                             }
                             if (file_exists(_PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php')) {
                                 include_once _PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php';
                                 $blockUserInfo = new BlockUserInfo();
                             }
                             self::$smarty->assign('isVirtualCart', self::$cart->isVirtualCart());
                             $this->_processAddressFormat();
                             $this->_assignAddress();
                             // Wrapping fees
                             $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
                             $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
                             $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
                             $return = array('summary' => self::$cart->getSummaryDetails(), 'order_opc_adress' => self::$smarty->fetch(_PS_THEME_DIR_ . 'order-address.tpl'), 'block_user_info' => isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : '', 'carrier_list' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) self::$cookie->id_currency))));
                             die(Tools::jsonEncode($return));
                         }
                         die(Tools::displayError());
                         break;
                     case 'makeFreeOrder':
                         /* Bypass payment step if total is 0 */
                         if ($id_order = $this->_checkFreeOrder() and $id_order) {
                             $email = self::$cookie->email;
                             if (self::$cookie->is_guest) {
                                 self::$cookie->logout();
                             }
                             // If guest we clear the cookie for security reason
                             die('freeorder:' . $id_order . ':' . $email);
                         }
                         exit;
                         break;
                     case 'updateAddressesSelected':
                         if (self::$cookie->isLogged(true)) {
                             $id_address_delivery = (int) Tools::getValue('id_address_delivery');
                             $id_address_invoice = (int) Tools::getValue('id_address_invoice');
                             $address_delivery = new Address((int) Tools::getValue('id_address_delivery'));
                             $address_invoice = (int) Tools::getValue('id_address_delivery') == (int) Tools::getValue('id_address_invoice') ? $address_delivery : new Address((int) Tools::getValue('id_address_invoice'));
                             if ($address_delivery->id_customer != self::$cookie->id_customer || $address_invoice->id_customer != self::$cookie->id_customer) {
                                 $this->errors[] = Tools::displayError('This address is not yours.');
                             } elseif (!Address::isCountryActiveById((int) Tools::getValue('id_address_delivery'))) {
                                 $this->errors[] = Tools::displayError('This address is not in a valid area.');
                             } elseif (!Validate::isLoadedObject($address_delivery) or !Validate::isLoadedObject($address_invoice) or $address_invoice->deleted or $address_delivery->deleted) {
                                 $this->errors[] = Tools::displayError('This address is invalid.');
                             } else {
                                 self::$cart->id_address_delivery = (int) Tools::getValue('id_address_delivery');
                                 self::$cart->id_address_invoice = Tools::isSubmit('same') ? self::$cart->id_address_delivery : (int) Tools::getValue('id_address_invoice');
                                 if (!self::$cart->update()) {
                                     $this->errors[] = Tools::displayError('An error occurred while updating your cart.');
                                 }
                                 if (!sizeof($this->errors)) {
                                     if (self::$cookie->id_customer) {
                                         $customer = new Customer((int) self::$cookie->id_customer);
                                         $groups = $customer->getGroups();
                                     } else {
                                         $groups = array(1);
                                     }
                                     $result = $this->_getCarrierList();
                                     // Wrapping fees
                                     $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
                                     $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
                                     $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
                                     $result = array_merge($result, array('summary' => self::$cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) self::$cookie->id_currency)))));
                                     die(Tools::jsonEncode($result));
                                 }
                             }
                             if (sizeof($this->errors)) {
                                 die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
                             }
                         }
                         die(Tools::displayError());
                         break;
                     default:
                         exit;
                 }
             }
             exit;
         }
     } elseif (Tools::isSubmit('ajax')) {
         exit;
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Customer $customer)
 {
     $input = array_except(Input::all(), array('_method', 'password', 'password_confirmation'));
     $customer->fill($input);
     $validation_rules = array_except(Customer::$validation_rules, array('password', 'password_confirmation'));
     $validation_rules['email'] = $validation_rules['email'] . ',' . $customer->id;
     Log::debug('customer - update - validation rule', $validation_rules);
     $validator = Validator::make($input, $validation_rules);
     if ($validator->passes()) {
         if ($customer->update()) {
             return Redirect::route('customers.show', $customer->id)->with('message', 'Customer updated.');
         } else {
             return Redirect::route('customers.edit', array_get($customer->getOriginal(), 'id'))->withInput()->withErrors($customer->errors());
         }
     } else {
         return Redirect::route('customers.edit', array_get($customer->getOriginal(), 'id'))->withInput()->withErrors($validator->errors());
     }
 }
Exemple #16
0
<?php
    $action = $_REQUEST['action'];
    $handler->loadModel('customer_m');
    $customer = new Customer;

    switch ($action){
        case 'read':
            echo $customer->read($_POST);
            break;
        case 'create':
            echo $customer->create($_POST['data']);
            break;
        case 'update':
            echo $customer->update($_POST['data']);
            break;
        case 'destroy':
            echo $customer->destroy($_POST['data']);
            break;            
    }
?>
Exemple #17
0
 /**
  * Start forms process
  * @see FrontController::postProcess()
  */
 public function postProcess()
 {
     $origin_newsletter = (bool) $this->customer->newsletter;
     if (Tools::isSubmit('submitIdentity')) {
         $email = trim(Tools::getValue('email'));
         if (Tools::getValue('months') != '' && Tools::getValue('days') != '' && Tools::getValue('years') != '') {
             $this->customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
         } elseif (Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '') {
             $this->customer->birthday = null;
         } else {
             $this->errors[] = Tools::displayError('Invalid date of birth.');
         }
         if (Tools::getIsset('old_passwd')) {
             $old_passwd = trim(Tools::getValue('old_passwd'));
         }
         if (!Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('This email address is not valid');
         } elseif ($this->customer->email != $email && Customer::customerExists($email, true)) {
             $this->errors[] = Tools::displayError('An account using this email address has already been registered.');
         } elseif (!Tools::getIsset('old_passwd') || Tools::encrypt($old_passwd) != $this->context->cookie->passwd) {
             $this->errors[] = Tools::displayError('The password you entered is incorrect.');
         } elseif (Tools::getValue('passwd') != Tools::getValue('confirmation')) {
             $this->errors[] = Tools::displayError('The password and confirmation do not match.');
         } else {
             $prev_id_default_group = $this->customer->id_default_group;
             // Merge all errors of this file and of the Object Model
             $this->errors = array_merge($this->errors, $this->customer->validateController());
         }
         if (!count($this->errors)) {
             $this->customer->id_default_group = (int) $prev_id_default_group;
             $this->customer->firstname = Tools::ucwords($this->customer->firstname);
             if (Configuration::get('PS_B2B_ENABLE')) {
                 $this->customer->website = Tools::getValue('website');
                 // force update of website, even if box is empty, this allows user to remove the website
                 $this->customer->company = Tools::getValue('company');
             }
             if (!Tools::getIsset('newsletter')) {
                 $this->customer->newsletter = 0;
             } elseif (!$origin_newsletter && Tools::getIsset('newsletter')) {
                 if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
                     /** @var Blocknewsletter $module_newsletter */
                     if ($module_newsletter->active) {
                         $module_newsletter->confirmSubscription($this->customer->email);
                     }
                 }
             }
             if (!Tools::getIsset('optin')) {
                 $this->customer->optin = 0;
             }
             if (Tools::getValue('passwd')) {
                 $this->context->cookie->passwd = $this->customer->passwd;
             }
             if ($this->customer->update()) {
                 $this->context->cookie->customer_lastname = $this->customer->lastname;
                 $this->context->cookie->customer_firstname = $this->customer->firstname;
                 $this->context->smarty->assign('confirmation', 1);
             } else {
                 $this->errors[] = Tools::displayError('The information cannot be updated.');
             }
         }
     } else {
         $_POST = array_map('stripslashes', $this->customer->getFields());
     }
     return $this->customer;
 }
 /**
  * Process login
  */
 protected function processSubmitLogin()
 {
     Hook::exec('actionBeforeAuthentication');
     $passwd = trim(Tools::getValue('passwd'));
     $email = trim(Tools::getValue('email'));
     if (empty($email)) {
         $this->errors[] = Tools::displayError('An email address required.');
     } elseif (!Validate::isEmail($email)) {
         $this->errors[] = Tools::displayError('Invalid email address.');
     } elseif (empty($passwd)) {
         $this->errors[] = Tools::displayError('Password is required.');
     } elseif (!Validate::isPasswd($passwd)) {
         $this->errors[] = Tools::displayError('Invalid password.');
     } else {
         $customer = new Customer();
         $authentication = $customer->getByEmail(trim($email), trim($passwd));
         if (!$authentication || !$customer->id) {
             $this->errors[] = Tools::displayError('Authentication failed.');
         } else {
             $customer->update();
             $address = new Address((int) Address::getFirstCustomerAddressId((int) $customer->id));
             if (!count($this->errors) && is_object($address) && isset($address->id_customer)) {
                 $address->address1 = $_POST['city'] . ' ' . $_POST['street'] . ' ' . $_POST['house'];
                 $address->city = $_POST['city'];
                 $address->firstname = $_POST['firstname'];
                 $address->phone_mobile = $_POST['phone_mobile'];
                 $delivery_pickup = array('delivery_city' => $_POST['city'], 'delivery_street' => $_POST['street'], 'delivery_house' => $_POST['house'], 'delivery_date' => isset($_POST['delivery_date']) ? $_POST['delivery_date'] : '');
                 $address->other = $delivery_pickup['delivery_date'];
                 foreach ($delivery_pickup as $k => $v) {
                     $this->context->cookie->{$k} = $v;
                 }
                 $address->save();
             }
             $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id);
             $this->context->cookie->id_customer = (int) $customer->id;
             $this->context->cookie->customer_lastname = $customer->lastname;
             $this->context->cookie->customer_firstname = $customer->firstname;
             $this->context->cookie->logged = 1;
             $customer->logged = 1;
             $this->context->cookie->is_guest = $customer->isGuest();
             $this->context->cookie->passwd = $customer->passwd;
             $this->context->cookie->email = $customer->email;
             // Add customer to the context
             $this->context->customer = $customer;
             if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && ($id_cart = (int) Cart::lastNoneOrderedCart($this->context->customer->id))) {
                 $this->context->cart = new Cart($id_cart);
             } else {
                 $id_carrier = (int) $this->context->cart->id_carrier;
                 $this->context->cart->id_carrier = 0;
                 $this->context->cart->setDeliveryOption(null);
                 $this->context->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
                 $this->context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
             }
             $this->context->cart->id_customer = (int) $customer->id;
             $this->context->cart->secure_key = $customer->secure_key;
             if ($this->ajax && isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                 $delivery_option = array($this->context->cart->id_address_delivery => $id_carrier . ',');
                 $this->context->cart->setDeliveryOption($delivery_option);
             }
             $this->context->cart->save();
             $this->context->cookie->id_cart = (int) $this->context->cart->id;
             $this->context->cookie->write();
             $this->context->cart->autosetProductAddress();
             Hook::exec('actionAuthentication');
             // Login information have changed, so we check if the cart rules still apply
             CartRule::autoRemoveFromCart($this->context);
             CartRule::autoAddToCart($this->context);
             if (!$this->ajax) {
                 if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) {
                     Tools::redirect(html_entity_decode($back));
                 }
                 Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : 'my-account'));
             }
         }
     }
     if ($this->ajax) {
         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false));
         die(Tools::jsonEncode($return));
     } else {
         $this->context->smarty->assign('authentification_error', $this->errors);
     }
 }
 public function getContent()
 {
     if (Tools::isSubmit('submitUpdate')) {
         Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool) Tools::getValue('NW_CONFIRMATION_EMAIL'));
         Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool) Tools::getValue('NW_VERIFICATION_EMAIL'));
         $voucher = Tools::getValue('NW_VOUCHER_CODE');
         if ($voucher && !Validate::isDiscountName($voucher)) {
             $this->_html .= $this->displayError($this->l('The voucher code is invalid.'));
         } else {
             Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher));
             $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
         }
     } elseif (Tools::isSubmit('subscribedmerged')) {
         $id = Tools::getValue('id');
         if (preg_match('/(^N)/', $id)) {
             $id = (int) substr($id, 1);
             $sql = 'UPDATE ' . _DB_PREFIX_ . 'newsletter SET active = 0 WHERE id = ' . $id;
             Db::getInstance()->execute($sql);
         } else {
             $c = new Customer((int) $id);
             $c->newsletter = (int) (!$c->newsletter);
             $c->update();
         }
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
     } elseif (Tools::isSubmit('submitExport') && ($action = Tools::getValue('action'))) {
         $this->export_csv();
     } elseif (Tools::isSubmit('searchEmail')) {
         $this->_searched_email = Tools::getValue('searched_email');
     }
     $this->_html .= $this->renderForm();
     $this->_html .= $this->renderSearchForm();
     $this->_html .= $this->renderList();
     $this->_html .= $this->renderExportForm();
     return $this->_html;
 }
<?php

require_once "util.php";
require_once "DataBase/Customer.php";
require_once "DataBase/Tour.php";
require_once "DataBase/Priceset.php";
$db_action = var_get_post("db_action", "");
$customer = new Customer();
$tour = new Tour();
$priceset = new Priceset();
switch ($db_action) {
    case "new":
        $customer->create(var_post("customer_number", ""), array(var_post("password", ""), var_post("prename", ""), var_post("postname", ""), var_post("street", ""), var_post("streetnumber", ""), var_post("plz", ""), var_post("city", ""), var_post("telephone", ""), var_post("telefax", ""), var_post("email", ""), var_post("pricelist_id", ""), var_post("tour_id", ""), var_post("rabatt", ""), var_post("details", ""), var_post("bank_name", ""), var_post("bank_account", ""), var_post("blz", "")));
        break;
    case "edit":
        $customer->update(var_post("customer_number", ""), array(var_post("password", ""), var_post("prename", ""), var_post("postname", ""), var_post("street", ""), var_post("streetnumber", ""), var_post("plz", ""), var_post("city", ""), var_post("telephone", ""), var_post("telefax", ""), var_post("email", ""), var_post("pricelist_id", ""), var_post("tour_id", ""), var_post("rabatt", ""), var_post("details", ""), var_post("bank_name", ""), var_post("bank_account", ""), var_post("blz", "")));
        break;
    case "delete":
        $customer->delete(var_get("customer_id", ""));
        break;
}
 public function setPayment($type)
 {
     $address_invoice = new Address((int) $this->context->cart->id_address_invoice);
     $country = new Country((int) $address_invoice->id_country);
     $currency = new Currency((int) $this->context->cart->id_currency);
     if (!$this->verifCountryAndCurrency($country, $currency)) {
         return false;
     }
     $klarna = new Klarna();
     $klarnaInt = new KlarnaIntegration($klarna);
     $klarna->config(Configuration::get('KLARNA_STORE_ID_' . $this->countries[$country->iso_code]['name']), Configuration::get('KLARNA_SECRET_' . $this->countries[$country->iso_code]['name']), $this->countries[$country->iso_code]['code'], $this->countries[$country->iso_code]['langue'], $this->countries[$country->iso_code]['currency'], Configuration::get('KLARNA_MOD'), 'mysql', $this->_getDb());
     if ($type == 'invoice' && Configuration::get('KLARNA_INVOICE_FEE_' . $this->countries[$country->iso_code]['name']) > 0 && !$this->isInCart($this->context->cart, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']))) {
         $this->context->cart->updateQty(1, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
         $productInvoicefee = new Product((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
         $productInvoicefee->addStockMvt(1, 1);
         $productInvoicefee->update();
     }
     $this->initReservation($klarna, $this->context->cart, $this->context->customer, isset($_POST['klarna_house_number']) ? htmlentities($_POST['klarna_house_number'], ENT_QUOTES, 'ISO-8859-1') : null, isset($_POST['klarna_house_ext']) ? htmlentities($_POST['klarna_house_ext'], ENT_QUOTES, 'ISO-8859-1') : null);
     if (Tools::isSubmit('klarna_pno')) {
         $pno = Tools::safeOutput(Tools::getValue('klarna_pno'));
     } else {
         $day = $_POST['klarna_pno_day'] < 10 ? '0' . (int) $_POST['klarna_pno_day'] : (int) $_POST['klarna_pno_day'];
         $month = $_POST['klarna_pno_month'] < 10 ? '0' . (int) $_POST['klarna_pno_month'] : (int) $_POST['klarna_pno_month'];
         $pno = Tools::safeOutput($day . $month . Tools::getValue('klarna_pno_year'));
     }
     $pclass = $type == 'invoice' ? KlarnaPClass::INVOICE : (int) Tools::getValue('paymentAccount');
     try {
         if ($country->iso_code == 'DE' || $country->iso_code == 'NL') {
             if ($this->context->customer->id_gender != 1 && $this->context->customer->id_gender != 2 && $this->context->customer->id_gender != 3) {
                 $gender = (int) $_POST['klarna_gender'];
                 $customer = new Customer($this->context->customer->id);
                 $customer->id_gender = (int) $_POST['klarna_gender'];
                 $Customer->birthday = (int) $_POST['klarna_pno_year'] . '-' . $month . '-' . $day;
                 $customer->update();
             } else {
                 $gender = $this->context->customer->id_gender == 1 ? 1 : 0;
             }
         } else {
             $gender = null;
         }
         $result = $klarnaInt->reserve($pno, $gender, -1, KlarnaFlags::NO_FLAG, (int) $pclass);
         // Here we get the reservation number or invoice number
         $rno = $result[0];
         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'klarna_rno', array('id_cart' => (int) $this->context->cart->id, 'rno' => pSQL($rno), 'pno' => pSQL($pno), 'house_number' => isset($_POST['klarna_house_number']) ? pSQL($_POST['klarna_house_number']) : null, 'house_ext' => isset($_POST['klarna_house_ext']) ? pSQL($_POST['klarna_house_ext']) : null, 'state' => self::RESERVED, 'type' => pSQL($type), 'pclass' => $type == 'invoice' ? null : (int) Tools::getValue('paymentAccount')), 'INSERT');
         $updateResult = $klarnaInt->updateOrderNo($rno, (int) $this->context->cart->id);
         if ($result[1] == KlarnaFlags::PENDING) {
             $this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_PENDING'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key);
         } else {
             if ($result[1] == KlarnaFlags::ACCEPTED) {
                 $this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_ACCEPTED'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key);
             }
         }
         $redirect = __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . (int) $this->context->cart->id . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder . '&key=' . $this->context->cart->secure_key;
         header('Location: ' . $redirect);
         exit;
     } catch (Exception $e) {
         /*remove invoiceFee if existe*/
         $this->context->cart->deleteProduct((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
         return array('error' => true, 'message' => Tools::safeOutput(utf8_encode($e->getMessage())));
     }
 }
 public function processSubmitLogin($provider)
 {
     $social_customer = $this->socialNetworkList[$provider]->processSubmitLogin();
     if (!$social_customer || !$social_customer->id_user) {
         FSLTools::returnError(Tools::displayError('Invalid social account'));
     }
     $customer = null;
     if ($social_customer->id_customer) {
         // If social customer already exist, just login
         $customer = new Customer($social_customer->id_customer);
     } else {
         if (Tools::getValue('createAccount') == 'on' || Tools::getValue('createAccount') == 'true' || Tools::getValue('createAccount') == '1') {
             if (Customer::customerExists($social_customer->email)) {
                 // Social customer not exist, but customer prestashop already exist. Update it.
                 $customer = new Customer();
                 $authentication = $customer->getByEmail($social_customer->email);
                 if (isset($authentication->active) && !$authentication->active) {
                     FSLTools::returnError(Tools::displayError('Your account isn\'t available at this time, please contact us'));
                 } else {
                     if (!$authentication || !$customer->id) {
                         FSLTools::returnError(Tools::displayError('Authentication failed.'));
                     } else {
                         if ($this->context->customer->isLogged() && $customer->id != $this->context->customer->id) {
                             FSLTools::returnError(Tools::displayError('Your current Prestashop account not corresponding to your Social account.'));
                         } else {
                             if (!$customer->birthday && $social_customer->birthday) {
                                 // Update customer if needed
                                 $customer->birthday = $social_customer->birthday;
                                 $customer->update();
                             }
                         }
                     }
                 }
             } else {
                 // Create both social and prestashop customers.
                 $customer = new Customer();
                 $customer->id_shop = $this->context->shop->id;
                 $customer->firstname = $social_customer->firstname;
                 $customer->lastname = $social_customer->lastname;
                 $customer->email = $social_customer->email;
                 $customer->id_gender = $social_customer->id_gender;
                 $customer->newsletter = (bool) Configuration::get('FSL_CUSTOMER_NWSL');
                 $customer->optin = (bool) Configuration::get('FSL_CUSTOMER_OPTIN');
                 $passwd = Tools::passwdGen();
                 $customer->passwd = Tools::encrypt($passwd);
                 if ($social_customer->birthday) {
                     $customer->birthday = $social_customer->birthday;
                 }
                 if (!$customer->add()) {
                     FSLTools::returnError(Tools::displayError('Error during account creation.'));
                 }
                 if ($customer->newsletter) {
                     FSLTools::processCustomerNewsletter($customer);
                 }
                 Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                 if (!FSLTools::sendConfirmationMail($social_customer, $passwd)) {
                     FSLTools::returnError(Tools::displayError('The email cannot be sent.'));
                 }
             }
             if ($customer != null && $customer->id) {
                 $social_customer->id_customer = $customer->id;
                 $social_customer->id_shop = $customer->id_shop;
                 $social_customer->add();
                 // Add social customer
             }
         } else {
             FSLTools::returnAjax();
         }
     }
     if (!$this->context->customer->isLogged() && $customer != null) {
         $this->processLogin($customer);
     }
     if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) {
         $redirect_url = html_entity_decode($back);
     }
     // redirection: if cart is not empty : redirection to the cart
     if (isset(Context::getContext()->cart) && count(Context::getContext()->cart->getProducts(true)) > 0) {
         $redirect_url = Context::getContext()->link->getPageLink('order' . ($multi = (int) Tools::getValue('multi-shipping') ? '&multi-shipping=' . $multi : ''));
     } else {
         $redirect_url = Context::getContext()->link->getPageLink('my-account');
     }
     FSLTools::returnAjax($redirect_url, $social_customer);
 }
 /**
  * @depends testCustomerCreate
  * @group   ecommerce
  */
 public function testAddDefaultCustomerCardFromCardDetails($customer)
 {
     $this->mockResponse($this->successAddDefaultCustomerCardFromCardDetailsResponse());
     $customerToken = $customer->token;
     $params = array('card_number' => '5309707106499343', 'expiration_month' => '01', 'expiration_year' => date('Y') + 1, 'cvv' => '123', 'holder_name' => 'John Doe', 'default_card' => 1);
     $customer = Customer::update($customerToken, $params);
     $this->assertEquals(substr($params['card_number'], -4), $customer->card->last_four);
     $this->assertTrue(isset($customer->cvv_required));
     return $customer;
 }
Exemple #24
0
            $errors[] = Tools::displayError('your current password is not that one');
        } elseif ($_POST['passwd'] != $_POST['confirmation']) {
            $errors[] = Tools::displayError('password and confirmation do not match');
        } elseif ($need_identification_number and Tools::getValue('dni') != NULL and !Validate::isDni(Tools::getValue('dni'))) {
            $errors[] = Tools::displayError('identification number is incorrect or already used');
        } else {
            $prev_id_default_group = $customer->id_default_group;
            $errors = $customer->validateControler();
        }
        if (!sizeof($errors)) {
            $customer->id_default_group = intval($prev_id_default_group);
            $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
            if (Tools::getValue('passwd')) {
                $cookie->passwd = $customer->passwd;
            }
            if ($customer->update()) {
                $cookie->customer_lastname = $customer->lastname;
                $cookie->customer_firstname = $customer->firstname;
                $smarty->assign('confirmation', 1);
            } else {
                $errors[] = Tools::displayError('impossible to update information');
            }
        }
    }
} else {
    $_POST = array_map('stripslashes', $customer->getFields());
}
if ($customer->birthday) {
    $birthday = explode('-', $customer->birthday);
} else {
    $birthday = array('-', '-', '-');
    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)));
    }