Exemplo n.º 1
0
 /**
  * @param CustomerCore $customer
  *
  * @return mixed
  * @throws PrestaShopExceptionCustomerCore
  */
 public static function getToken($customer)
 {
     if ($customer->validateFields() && !ShopgateCustomerPrestashop::hasCustomerToken($customer->id)) {
         $customerItem = new ShopgateCustomerPrestashop();
         $customerItem->customer_token = md5($customer->id . $customer->email . microtime());
         $customerItem->id_customer = $customer->id;
         $customerItem->add();
     }
     if ($id = ShopgateCustomerPrestashop::hasCustomerToken($customer->id)) {
         $shopgateCustomer = new ShopgateCustomerPrestashop($id);
         return $shopgateCustomer->customer_token;
     }
     return null;
 }
 /**
  * Soft logout, delete everything links to the customer
  * but leave there affiliate's informations
  *
  * @since 1.5.0
  */
 public function mylogout()
 {
     if (file_exists(_PS_ROOT_DIR_ . '/modules/fbconnect_psb/fb_sdk/facebook.php')) {
         include _PS_ROOT_DIR_ . '/modules/fbconnect_psb/fb_sdk/facebook.php';
         $facebook = new Facebook(array('appId' => Configuration::get('FB_CONNECT_APPID'), 'secret' => Configuration::get('FB_CONNECT_APPKEY')));
         $facebook->destroySession();
     }
     parent::mylogout();
 }
 /**
  * login method - forward to either login or create account
  * --
  */
 public function loginToStore()
 {
     $this->auth_user = $this->service->userinfo->get();
     $i_customer_id = CustomerCore::customerExists($this->auth_user->email, true);
     if ($i_customer_id) {
         $this->login($i_customer_id);
     } else {
         $this->createAccount();
     }
 }
Exemplo n.º 4
0
 public static function customerHasAddress($id_customer, $id_address)
 {
     if (!self::isOpcModuleActive()) {
         return parent::customerHasAddress($id_customer, $id_address);
     }
     if (!Tools::isSubmit('delete')) {
         return true;
     } else {
         return parent::customerHasAddress($id_customer, $id_address);
     }
 }
Exemplo n.º 5
0
 public static function customerHasAddress($id_customer, $id_address)
 {
     // fix requirement for customer address when it wasn't required (updating in pre_Save in OPCKT)
     if (!self::isOpcModuleActive()) {
         return parent::customerHasAddress($id_customer, $id_address);
     }
     if (!Tools::isSubmit('delete')) {
         return true;
     } else {
         return parent::customerHasAddress($id_customer, $id_address);
     }
 }
Exemplo n.º 6
0
 public function getOrders($customerToken, $customerLanguage, $limit, $offset, $orderDateFrom, $sortOrder)
 {
     $shopgateCustomerModel = new ShopgateCustomerPrestashop();
     $this->_currentCustomer = $shopgateCustomerModel->getCustomerByToken($customerToken);
     if (!$this->_currentCustomer->validateFields(false)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_CUSTOMER_TOKEN_INVALID);
     }
     $orders = $this->getCustomerOrders($this->_currentCustomer->id, $limit, $offset, $orderDateFrom, $sortOrder);
     foreach ($orders as $orderItem) {
         /** @var OrderCore $orderCore */
         $orderCore = new Order($orderItem['id_order']);
         $order = new ShopgateExternalOrder();
         $order->setOrderNumber($orderCore->id);
         $order->setExternalOrderNumber($orderCore->reference);
         $order->setExternalOrderId($orderCore->id);
         /** @var OrderStateCore $orderStatus */
         $orderStatus = new OrderState($orderCore->getCurrentState());
         $order->setStatusName($orderStatus->name[$this->getPlugin()->getLanguageId()]);
         $order->setStatusColor($orderStatus->color);
         $order->setCreatedTime($orderCore->date_add);
         $order->setMail($this->_currentCustomer->email);
         $order->setDeliveryAddress($this->_getAddress($orderCore->id_address_delivery, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setInvoiceAddress($this->_getAddress($orderCore->id_address_invoice, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setItems($this->_getOrderItems($orderCore));
         $order->setExternalCoupons($this->_getCartRules($orderCore));
         /** @var CurrencyCore $currency */
         $currency = Currency::getCurrency($orderCore->id_currency);
         $order->setCurrency($currency['iso_code']);
         $order->setAmountComplete(isset($orderCore->total_paid_tax_incl) ? $orderCore->total_paid_tax_incl : $orderCore->total_paid);
         $order->setIsPaid($orderCore->hasBeenPaid());
         $order->setPaymentMethod($orderCore->payment);
         $order->setIsShippingCompleted($orderCore->hasBeenShipped());
         $order->setShippingCompletedTime($orderCore->hasBeenShipped() ? $orderCore->delivery_date : null);
         $order->setDeliveryNotes($this->_getDeliveryNotes($orderCore));
         $order->setExtraCosts($this->_getExtraCost($orderCore));
         $order->setOrderTaxes($this->_getOrderTaxes());
         $this->_result[] = $order;
     }
     return $this->_result;
 }
Exemplo n.º 7
0
 public function delete()
 {
     $ret = parent::delete();
     if (Module::isInstalled('agilemultipleseller')) {
         include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php";
         $id_seller = SellerInfo::getSellerIdByCustomerId($this->id);
         $emp = new Employee($id_seller);
         if (Validate::isLoadedObject($emp)) {
             $emp->delete();
         }
     }
     return $ret;
 }
Exemplo n.º 8
0
 public static function customerHasAddress($id_customer, $id_address)
 {
     if (!Module::isInstalled('agilepaypal')) {
         return parent::customerHasAddress($id_customer, $id_address);
     }
     $address = new Address($id_address);
     if (Validate::isLoadedObject($address)) {
         if ($address->alias == 'agileexpress' and $address->id_customer == 0 and $address->id_manufacturer == 0 and $address->id_supplier == 0) {
             return true;
         }
     }
     return parent::customerHasAddress($id_customer, $id_address);
 }
Exemplo n.º 9
0
 /**
  * Creates a new customer based on the given data.
  */
 public static function create_customer_from_data(array $data, $send_email_to_admin = false, $send_email_to_customer = false)
 {
     if (is_array($data) && !empty($data['user_token']) && !empty($data['identity_token'])) {
         $password = Tools::passwdGen();
         // Build customer fields.
         $customer = new CustomerCore();
         $customer->firstname = $data['user_first_name'];
         $customer->lastname = $data['user_last_name'];
         $customer->id_gender = $data['user_gender'];
         $customer->birthday = $data['user_birthdate'];
         $customer->active = true;
         $customer->deleted = false;
         $customer->is_guest = false;
         $customer->passwd = Tools::encrypt($password);
         // We could get the email.
         if (!empty($data['user_email'])) {
             // It already exists.
             if (self::get_id_customer_for_email_address($data['user_email']) !== false) {
                 // Create a new one.
                 $customer->email = self::generate_random_email_address();
                 $customer->newsletter = false;
             } else {
                 $customer->email = $data['user_email'];
                 $customer->newsletter = true;
             }
         } else {
             // Create a new one.
             $customer->email = self::generate_random_email_address();
             $customer->newsletter = false;
         }
         // Create a new user account.
         if ($customer->add()) {
             // Tie the tokens to the newly created member.
             if (self::link_tokens_to_id_customer($customer->id, $data['user_token'], $data['identity_token'], $data['identity_provider'])) {
                 //Send an email to the customer
                 if ($send_email_to_customer === true) {
                     self::send_confirmation_to_customer($customer, $password, $data['identity_provider']);
                 }
                 //Send an email to the administratos
                 if ($send_email_to_admin === true) {
                     self::send_confirmation_to_administrators($customer, $data['identity_provider']);
                 }
                 //Done
                 return $customer->id;
             }
         }
     }
     //Error
     return false;
 }
Exemplo n.º 10
0
 /**
  *  This method is used to fetch all subsribed users from the default customer table to list
  * them in the SendinBlue PS plugin.
  */
 public function geSubstMobileNumber()
 {
     $customer_data = $this->getAllCustomers();
     $address_mobilephone = array();
     foreach ($customer_data as $customer_detail) {
         $temp = 0;
         if (count($customer_detail) > 0 && !empty($customer_detail['id_customer']) && $customer_detail['newsletter_date_add'] > 0) {
             $id_customer = $customer_detail['id_customer'];
             $customer = new CustomerCore((int) $id_customer);
             $customer_address = $customer->getAddresses((int) $this->context->language->id);
             // Check if user have address data
             if ($customer_address && count($customer_address) > 0) {
                 // Code to get latest phone number of logged in user
                 $count_address = count($customer_address);
                 for ($i = $count_address; $i >= 0; $i--) {
                     foreach ($customer_address as $select_address) {
                         if ($temp < $select_address['date_upd'] && !empty($select_address['phone_mobile'])) {
                             $temp = $select_address['date_upd'];
                             $address_mobilephone[$select_address['id_customer']] = $select_address;
                         }
                     }
                 }
             }
         }
     }
     return $address_mobilephone;
 }
Exemplo n.º 11
0
 protected function processSubmitAccount()
 {
     if (!$this->isOpcModuleActive()) {
         return parent::processSubmitAccount();
     }
     // Entire override is here just because of rigid address set-up. Original PS do not expect
     // address being set to cart prior to processSubmitAccount call and thus always creates new Address
     $inv_first_on = Configuration::get('OPC_INVOICE_FIRST') == "1";
     Hook::exec('actionBeforeSubmitAccount');
     $this->create_account = true;
     if (Tools::isSubmit('submitAccount')) {
         $this->context->smarty->assign('email_create', 1);
     }
     // New Guest customer
     if (!Tools::getValue('is_new_customer', 1) && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
         $this->errors[] = Tools::displayError('You cannot create a guest account.');
     }
     // Customer (not-guest) checkout, password field is hidden and password is automatically generated
     if ((!Tools::getIsset('passwd') || trim($_POST['passwd']) == "") && trim(Tools::getValue('email')) != "" && Configuration::get('OPC_CREATE_CUSTOMER_PASSWORD') && !CustomerCore::customerExists(Tools::getValue('email'))) {
         $_POST['is_new_customer'] = 1;
         $_POST['passwd'] = Tools::passwdGen(5);
     } elseif (!Tools::getValue('is_new_customer', 1)) {
         $_POST['passwd'] = md5(time() . _COOKIE_KEY_);
     }
     if (Tools::getIsset('guest_email') && $_POST['guest_email']) {
         $_POST['email'] = $_POST['guest_email'];
     }
     // Checked the user address in case he changed his email address
     if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) {
         if (Customer::customerExists($email)) {
             $this->errors[] = Tools::displayError('An account is already registered with this e-mail.', false);
         }
     }
     // Preparing customer
     $customer = new Customer();
     $_POST['lastname'] = Tools::getValue('customer_lastname');
     $_POST['firstname'] = Tools::getValue('customer_firstname');
     //        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') &&
     //            (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || Configuration::get('PS_GUEST_CHECKOUT_ENABLED')))
     //            $this->errors[] = Tools::displayError('You must register at least one phone number');
     $error_phone = false;
     if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) {
         $inv_suffix = $inv_first_on ? "_invoice" : "";
         if (Tools::isSubmit('submitGuestAccount') || !Tools::getValue('is_new_customer')) {
             if (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix)) {
                 $error_phone = true;
             }
         } elseif ((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || Configuration::get('PS_ORDER_PROCESS_TYPE')) && (Configuration::get('PS_ORDER_PROCESS_TYPE') && !Tools::getValue('email_create')) && (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix))) {
             $error_phone = true;
         } elseif (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE') && Tools::getValue('email_create') && (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix))) {
             $error_phone = true;
         }
     }
     if ($error_phone) {
         $this->errors[] = Tools::displayError('You must register at least one phone number.');
     }
     $this->errors = array_unique(array_merge($this->errors, $customer->validateController()));
     // Check the requires fields which are settings in the BO
     $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase());
     if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
         if (!count($this->errors)) {
             if (Tools::isSubmit('newsletter')) {
                 $this->processCustomerNewsletter($customer);
             }
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             if (!Validate::isBirthDate($customer->birthday)) {
                 $this->errors[] = Tools::displayError('Invalid birthday.');
             }
             $customer->active = 1;
             // New Guest customer
             if (Tools::isSubmit('is_new_customer')) {
                 $customer->is_guest = !Tools::getValue('is_new_customer', 1);
             } else {
                 $customer->is_guest = 0;
             }
             if (!count($this->errors)) {
                 if (!$customer->add()) {
                     $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                 } else {
                     if (!$customer->is_guest) {
                         if (!$this->sendConfirmationMail($customer)) {
                             $this->errors[] = Tools::displayError('Cannot send e-mail');
                         }
                     }
                     $this->updateContext($customer);
                     $this->context->cart->update();
                     Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                     if ($this->ajax) {
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                         die(Tools::jsonEncode($return));
                     }
                     // redirection: if cart is not empty : redirection to the cart
                     if (count($this->context->cart->getProducts(true)) > 0) {
                         Tools::redirect('index.php?controller=order&multi-shipping=' . (int) Tools::getValue('multi-shipping'));
                     } else {
                         Tools::redirect('index.php?controller=my-account');
                     }
                 }
             }
         }
     } else {
         $lastnameAddress = $inv_first_on ? $_POST['lastname_invoice'] : $_POST['lastname'];
         $firstnameAddress = $inv_first_on ? $_POST['firstname_invoice'] : $_POST['firstname'];
         // Preparing address
         $id_address = isset($this->context->cart->id_address_delivery) ? (int) $this->context->cart->id_address_delivery : 0;
         if ($id_address > 0) {
             $address = new Address($id_address);
         } else {
             $address = new Address();
         }
         $_POST['lastname'] = $lastnameAddress;
         $_POST['firstname'] = $firstnameAddress;
         $address->id_customer = 1;
         $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
         // US customer: normalize the address
         if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
             include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
             $normalize = new AddressStandardizationSolution();
             $address->address1 = $normalize->AddressLineStandardization($address->address1);
             $address->address2 = $normalize->AddressLineStandardization($address->address2);
         }
         $inv_suffix = $inv_first_on ? "_invoice" : "";
         $country = new Country((int) Tools::getValue('id_country' . $inv_suffix));
         if ($country->need_zip_code) {
             if (($postcode = Tools::getValue('postcode' . $inv_suffix)) && $country->zip_code_format) {
                 if (!$country->checkZipCode($postcode)) {
                     $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                 }
             } elseif ($country->zip_code_format && !$this->context->cart->isVirtualCart()) {
                 $this->errors[] = Tools::displayError('Zip/Postal code is required.');
             } elseif ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                 $this->errors[] = Tools::displayError('Zip/Postal code is invalid.');
             }
         }
         /*if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
                     $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
                 elseif (!$country->need_identification_number)
           $address->dni = null;*/
     }
     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');
     }
     if (!count($this->errors)) {
         if (Customer::customerExists(Tools::getValue('email'))) {
             $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please enter your password or request a new one.', false);
         }
         if (Tools::isSubmit('newsletter')) {
             $this->processCustomerNewsletter($customer);
         }
         $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
         if (!Validate::isBirthDate($customer->birthday)) {
             $this->errors[] = Tools::displayError('Invalid birthday.');
         }
         if (!count($this->errors)) {
             // if registration type is in one step, we save the address
             if (Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) {
                 if (!($country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT'))) || !Validate::isLoadedObject($country)) {
                     die(Tools::displayError());
                 }
             }
             $contains_state = isset($country) && is_object($country) ? (int) $country->contains_states : 0;
             $id_state = isset($address) && is_object($address) ? (int) $address->id_state : 0;
             if ($contains_state && !$id_state) {
                 $this->errors[] = Tools::displayError('This country requires a state selection.');
             } else {
                 $customer->active = 1;
                 // New Guest customer
                 if (Tools::isSubmit('is_new_customer')) {
                     $customer->is_guest = !Tools::getValue('is_new_customer', 1);
                 } else {
                     $customer->is_guest = 0;
                 }
                 if (!$customer->add()) {
                     $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                 } else {
                     $address->id_customer = (int) $customer->id;
                     $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
                     if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount'))) {
                         if ($address->id > 0 && !$address->update() || !($address->id > 0) && !$address->add()) {
                             $this->errors[] = Tools::displayError('An error occurred while creating your address.');
                         } else {
                             if (!$customer->is_guest) {
                                 $this->context->customer = $customer;
                                 $customer->cleanGroups();
                                 // we add the guest customer in the default customer group
                                 $customer->addGroups(array((int) Configuration::get('PS_CUSTOMER_GROUP')));
                                 if (!$this->sendConfirmationMail($customer)) {
                                     $this->errors[] = Tools::displayError('Cannot send e-mail');
                                 }
                             } else {
                                 $customer->cleanGroups();
                                 // we add the guest customer in the guest customer group
                                 $customer->addGroups(array((int) Configuration::get('PS_GUEST_GROUP')));
                             }
                             $this->updateContext($customer);
                             $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
                             if ($this->context->cart->id_address_invoice == 0) {
                                 $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
                             }
                             // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
                             $this->context->cart->update();
                             // Avoid articles without delivery address on the cart
                             $this->context->cart->autosetProductAddress();
                             Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                             if ($this->ajax) {
                                 $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                                 die(Tools::jsonEncode($return));
                             }
                             // if registration type is in two steps, we redirect to register address
                             if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
                                 Tools::redirect('index.php?controller=address');
                             }
                             if ($back = Tools::getValue('back')) {
                                 Tools::redirect($back);
                             }
                             Tools::redirect('index.php?controller=my-account');
                             // redirection: if cart is not empty : redirection to the cart
                             if (count($this->context->cart->getProducts(true)) > 0) {
                                 Tools::redirect('index.php?controller=order&multi-shipping=' . (int) Tools::getValue('multi-shipping'));
                             } else {
                                 Tools::redirect('index.php?controller=my-account');
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($this->errors)) {
         //for retro compatibility to display guest account creation form on authentication page
         if (Tools::getValue('submitGuestAccount')) {
             $_GET['display_guest_checkout'] = 1;
         }
         if (!Tools::getValue('is_new_customer')) {
             unset($_POST['passwd']);
         }
         if ($this->ajax) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0);
             die(Tools::jsonEncode($return));
         }
         $this->context->smarty->assign('account_error', $this->errors);
     }
 }
Exemplo n.º 12
0
<?php

/**
 * validation
 *
 * @category   PayIntelligent
 * @copyright  Copyright (c) 2013 PayIntelligent GmbH (http://payintelligent.de)
 */
include_once dirname(__FILE__) . '/../../../../config/config.inc.php';
include dirname(__FILE__) . '/../../../../header.php';
include dirname(__FILE__) . '/../../validation.php';
$paymentController = new PigmbhpaymillValidationModuleFrontController();
global $cart;
foreach (CustomerCore::getCustomers() as $customer) {
    if ($customer['id_customer'] == $cart->id_customer) {
        $currentUser = $customer;
        break;
    }
}
$paymentController->initContent($cart, $currentUser, Configuration::get('PS_SHOP_NAME'));
include dirname(__FILE__) . '/../../../../footer.php';
Exemplo n.º 13
0
    public function delete()
    {
        if (!count(Order::getCustomerOrders((int) $this->id))) {
            $addresses = $this->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
            foreach ($addresses as $address) {
                $obj = new Address((int) $address['id_address']);
                $obj->delete();
            }
        }
        Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'customer_group` WHERE `id_customer` = ' . (int) $this->id);
        Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'message WHERE id_customer=' . (int) $this->id);
        Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'specific_price WHERE id_customer=' . (int) $this->id);
        Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'compare WHERE id_customer=' . (int) $this->id);
        $carts = Db::getInstance()->executes('SELECT id_cart
			FROM ' . _DB_PREFIX_ . 'cart
			WHERE id_customer=' . (int) $this->id);
        if ($carts) {
            foreach ($carts as $cart) {
                Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'cart WHERE id_cart=' . (int) $cart['id_cart']);
                Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart=' . (int) $cart['id_cart']);
            }
        }
        $cts = Db::getInstance()->executes('SELECT id_customer_thread
			FROM ' . _DB_PREFIX_ . 'customer_thread
			WHERE id_customer=' . (int) $this->id);
        if ($cts) {
            foreach ($cts as $ct) {
                Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customer_thread WHERE id_customer_thread=' . (int) $ct['id_customer_thread']);
                Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customer_message WHERE id_customer_thread=' . (int) $ct['id_customer_thread']);
            }
        }
        CartRule::deleteByIdCustomer((int) $this->id);
        // start of implementation of the module code - taxamo
        Taxamoeuvat::deleteCCPrefix($this->id);
        // end of code implementation module - taxamo
        return parent::delete();
    }
Exemplo n.º 14
0
 /**
  * Creates a new customer based on the given data.
  */
 public static function create_customer_from_data(array $data, $send_email_to_admin = false, $send_email_to_customer = false)
 {
     if (is_array($data) && !empty($data['user_token']) && !empty($data['identity_token'])) {
         $password = Tools::passwdGen();
         // Build customer fields.
         $customer = new CustomerCore();
         $customer->firstname = $data['user_first_name'];
         $customer->lastname = $data['user_last_name'];
         $customer->id_gender = $data['user_gender'];
         $customer->birthday = $data['user_birthdate'];
         $customer->active = true;
         $customer->deleted = false;
         $customer->is_guest = false;
         $customer->passwd = Tools::encrypt($password);
         //Opted for the newsletter?
         if (!empty($data['user_newsletter'])) {
             $customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
             $customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
             $customer->newsletter = true;
         } else {
             $customer->newsletter = false;
         }
         // We could get the email.
         if (!empty($data['user_email'])) {
             // It already exists.
             if (self::get_id_customer_for_email_address($data['user_email']) !== false) {
                 // Create a new one.
                 $customer->email = self::generate_random_email_address();
                 $customer->newsletter = false;
             } else {
                 $customer->email = $data['user_email'];
             }
         } else {
             // Create a new one.
             $customer->email = self::generate_random_email_address();
             $customer->newsletter = false;
         }
         // Create a new user account.
         if ($customer->add()) {
             // Tie the tokens to the newly created member.
             if (self::link_tokens_to_id_customer($customer->id, $data['user_token'], $data['identity_token'], $data['identity_provider'])) {
                 //Send an email to the customer.
                 if ($send_email_to_customer === true) {
                     self::send_confirmation_to_customer($customer, $password, $data['identity_provider']);
                 }
                 //Send an email to the administrators
                 if ($send_email_to_admin === true) {
                     self::send_confirmation_to_administrators($customer, $data['identity_provider']);
                 }
                 //Process the newletter settings
                 if ($customer->newsletter === true) {
                     if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
                         if ($module_newsletter->active) {
                             $module_newsletter->confirmSubscription($customer->email);
                         }
                     }
                 }
                 //Done
                 return $customer->id;
             }
         }
     }
     //Error
     return false;
 }