public function init() { self::$amz_payments = new AmzPayments(); $this->isLogged = (bool) $this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer); parent::init(); /* Disable some cache related bugs on the cart/order */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); $this->display_column_left = false; $this->display_column_right = false; $this->service = self::$amz_payments->getService(); }
/** * Initialize parent order controller * @see FrontController::init() */ public function init() { $this->isLogged = (bool) ($this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer)); parent::init(); /* Disable some cache related bugs on the cart/order */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); $this->nbProducts = $this->context->cart->nbProducts(); if (!$this->context->customer->isLogged(true) && $this->context->getMobileDevice() && Tools::getValue('step')) { Tools::redirect($this->context->link->getPageLink('authentication', true, (int) $this->context->language->id, $params)); } // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 && Dispatcher::getInstance()->getController() != 'order') { Tools::redirect('index.php?controller=order'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 && Dispatcher::getInstance()->getController() != 'orderopc') { if (isset($_GET['step']) && $_GET['step'] == 3) { Tools::redirect('index.php?controller=order-opc&isPaymentStep=true'); } Tools::redirect('index.php?controller=order-opc'); } if (Configuration::get('PS_CATALOG_MODE')) { $this->errors[] = Tools::displayError('This store has not accepted your new order.'); } if (Tools::isSubmit('submitReorder') && ($id_order = (int) Tools::getValue('id_order'))) { $oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id)); $duplication = $oldCart->duplicate(); if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = Tools::displayError('Sorry. We cannot renew your order.'); } else { if (!$duplication['success']) { $this->errors[] = Tools::displayError('Some items are no longer available, and we are unable to renew your order.'); } else { $this->context->cookie->id_cart = $duplication['cart']->id; $this->context->cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc'); } Tools::redirect('index.php?controller=order'); } } } if ($this->nbProducts) { if (CartRule::isFeatureActive()) { if (Tools::isSubmit('submitAddDiscount')) { if (!($code = trim(Tools::getValue('discount_name')))) { $this->errors[] = Tools::displayError('You must enter a voucher code.'); } elseif (!Validate::isCleanHtml($code)) { $this->errors[] = Tools::displayError('The voucher code is invalid.'); } else { if (($cartRule = new CartRule(CartRule::getIdByCode($code))) && Validate::isLoadedObject($cartRule)) { if ($error = $cartRule->checkValidity($this->context, false, true)) { $this->errors[] = $error; } else { $this->context->cart->addCartRule($cartRule->id); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc&addingCartRule=1'); } Tools::redirect('index.php?controller=order&addingCartRule=1'); } } else { $this->errors[] = Tools::displayError('This voucher does not exists.'); } } $this->context->smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($code))); } elseif (($id_cart_rule = (int) Tools::getValue('deleteDiscount')) && Validate::isUnsignedId($id_cart_rule)) { $this->context->cart->removeCartRule($id_cart_rule); Tools::redirect('index.php?controller=order-opc'); } } /* Is there only virtual product in cart */ if ($isVirtualCart = $this->context->cart->isVirtualCart()) { $this->setNoCarrier(); } } $this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); }
protected function addressImportOne($info, $force_ids, $validateOnly = false) { AdminImportController::setDefaultValues($info); if ($force_ids && isset($info['id']) && (int) $info['id']) { $address = new Address((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Address::addressExists((int) $info['id'])) { $address = new Address((int) $info['id']); } else { $address = new Address(); } } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address); if (isset($address->country) && is_numeric($address->country)) { if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) { $address->id_country = (int) $address->country; } } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) { if ($id_country = Country::getIdByName(null, $address->country)) { $address->id_country = (int) $id_country; } else { $country = new Country(); $country->active = 1; $country->name = AdminImportController::createMultiLangField($address->country); $country->id_zone = 0; // Default zone for country to create $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2)); // Default iso for country to create $country->contains_states = 0; // Default value for country to create $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true); if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) { $address->id_country = (int) $country->id; } else { if (!$validateOnly) { $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT'); $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } if (isset($address->state) && is_numeric($address->state)) { if (State::getNameById((int) $address->state)) { $address->id_state = (int) $address->state; } } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) { if ($id_state = State::getIdByName($address->state)) { $address->id_state = (int) $id_state; } else { $state = new State(); $state->active = 1; $state->name = $address->state; $state->id_country = isset($country->id) ? (int) $country->id : 0; $state->id_zone = 0; // Default zone for state to create $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2)); // Default iso for state to create $state->tax_behavior = 0; if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) { $address->id_state = (int) $state->id; } else { if (!$validateOnly) { $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } if (isset($address->customer_email) && !empty($address->customer_email)) { if (Validate::isEmail($address->customer_email)) { // a customer could exists in different shop $customer_list = Customer::getCustomersByEmail($address->customer_email); if (count($customer_list) == 0) { $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); } } else { $this->errors[] = sprintf($this->trans('"%s" is not a valid email address.', array(), 'Admin.Parameters.Notification'), $address->customer_email); return; } } elseif (isset($address->id_customer) && !empty($address->id_customer)) { if (Customer::customerIdExistsStatic((int) $address->id_customer)) { $customer = new Customer((int) $address->id_customer); // a customer could exists in different shop $customer_list = Customer::getCustomersByEmail($customer->email); if (count($customer_list) == 0) { $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer); } } else { $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), $address->id_customer); } } else { $customer_list = array(); $address->id_customer = 0; } if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) { $address->id_manufacturer = (int) $address->manufacturer; } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) { if ($manufacturerId = Manufacturer::getIdByName($address->manufacturer)) { $address->id_manufacturer = $manufacturerId; } else { $manufacturer = new Manufacturer(); $manufacturer->name = $address->manufacturer; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) { $address->id_manufacturer = (int) $manufacturer->id; } else { if (!$validateOnly) { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } if (isset($address->supplier) && is_numeric($address->supplier) && Supplier::supplierExists((int) $address->supplier)) { $address->id_supplier = (int) $address->supplier; } elseif (isset($address->supplier) && is_string($address->supplier) && !empty($address->supplier)) { if ($supplierId = Supplier::getIdByName($address->supplier)) { $address->id_supplier = $supplierId; } else { $supplier = new Supplier(); $supplier->name = $address->supplier; if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) { $address->id_supplier = (int) $supplier->id; } else { if (!$validateOnly) { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } $res = false; if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $address->force_id = (bool) $force_ids; if (isset($customer_list) && count($customer_list) > 0) { $filter_list = array(); foreach ($customer_list as $customer) { if (in_array($customer['id_customer'], $filter_list)) { continue; } $filter_list[] = $customer['id_customer']; $address->id_customer = $customer['id_customer']; } } if ($address->id && $address->addressExists($address->id)) { $res = $validateOnly || $address->update(); } if (!$res) { $res = $validateOnly || $address->add(); } } if (!$res) { if (!$validateOnly) { $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } }
public function customerIdExists($id_customer) { return Customer::customerIdExistsStatic((int) $id_customer); }
protected function _getPaymentMethods() { if (!$this->isLogged) { return '<p class="warning">' . Tools::displayError('Please sign in to see payment methods') . '</p>'; } if (self::$cart->OrderExists()) { return '<p class="warning">' . Tools::displayError('Error: this order is already validated') . '</p>'; } if (!self::$cart->id_customer or !Customer::customerIdExistsStatic(self::$cart->id_customer) or Customer::isBanned(self::$cart->id_customer)) { return '<p class="warning">' . Tools::displayError('Error: no customer') . '</p>'; } $address_delivery = new Address(self::$cart->id_address_delivery); $address_invoice = self::$cart->id_address_delivery == self::$cart->id_address_invoice ? $address_delivery : new Address(self::$cart->id_address_invoice); if (!self::$cart->id_address_delivery or !self::$cart->id_address_invoice or !Validate::isLoadedObject($address_delivery) or !Validate::isLoadedObject($address_invoice) or $address_invoice->deleted or $address_delivery->deleted) { return '<p class="warning">' . Tools::displayError('Error: please choose an address') . '</p>'; } if (!self::$cart->id_carrier and !self::$cart->isVirtualCart()) { return '<p class="warning">' . Tools::displayError('Error: please choose a carrier') . '</p>'; } elseif (self::$cart->id_carrier != 0) { $carrier = new Carrier((int) self::$cart->id_carrier); if (!Validate::isLoadedObject($carrier) or $carrier->deleted or !$carrier->active) { return '<p class="warning">' . Tools::displayError('Error: the carrier is invalid') . '</p>'; } } if (!self::$cart->id_currency) { return '<p class="warning">' . Tools::displayError('Error: no currency has been selected') . '</p>'; } if (!self::$cookie->checkedTOS and Configuration::get('PS_CONDITIONS')) { return '<p class="warning">' . Tools::displayError('Please accept Terms of Service') . '</p>'; } /* If some products have disappear */ if (!self::$cart->checkQuantities()) { return '<p class="warning">' . Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order.') . '</p>'; } /* Check minimal amount */ $currency = Currency::getCurrency((int) self::$cart->id_currency); $minimalPurchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if (self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) { return '<p class="warning">' . Tools::displayError('A minimum purchase total of') . ' ' . Tools::displayPrice($minimalPurchase, $currency) . ' ' . Tools::displayError('is required in order to validate your order.') . '</p>'; } /* Bypass payment step if total is 0 */ if (self::$cart->getOrderTotal() <= 0) { return '<p class="center"><input type="button" class="exclusive_large" name="confirmOrder" id="confirmOrder" value="' . Tools::displayError('I confirm my order') . '" onclick="confirmFreeOrder();" /></p>'; } $return = Module::hookExecPayment(); if (!$return) { return '<p class="warning">' . Tools::displayError('No payment method is available') . '</p>'; } return $return; }
protected function _getPaymentMethods() { if (!$this->isLogged) { return '<p class="warning">' . Tools::displayError('Please sign in to see payment methods.') . '</p>'; } if ($this->context->cart->OrderExists()) { return '<p class="warning">' . Tools::displayError('Error: This order has already been validated.') . '</p>'; } if (!$this->context->cart->id_customer || !Customer::customerIdExistsStatic($this->context->cart->id_customer) || Customer::isBanned($this->context->cart->id_customer)) { return '<p class="warning">' . Tools::displayError('Error: No customer.') . '</p>'; } $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = $this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice); if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { return '<p class="warning">' . Tools::displayError('Error: Please select an address.') . '</p>'; } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { return '<p class="warning">' . Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you\'ve selected.') . '</p>'; } else { return '<p class="warning">' . Tools::displayError('Error: None of your chosen carriers deliver to the address you\'ve selected.') . '</p>'; } } if (!$this->context->cart->getDeliveryOption(null, false) && !$this->context->cart->isVirtualCart()) { return '<p class="warning">' . Tools::displayError('Error: Please choose a carrier.') . '</p>'; } if (!$this->context->cart->id_currency) { return '<p class="warning">' . Tools::displayError('Error: No currency has been selected.') . '</p>'; } if (!$this->context->cookie->checkedTOS && Configuration::get('PS_CONDITIONS')) { return '<p class="warning">' . Tools::displayError('Please accept the Terms of Service.') . '</p>'; } /* If some products have disappear */ if (!$this->context->cart->checkQuantities()) { return '<p class="warning">' . Tools::displayError('An item in your cart is no longer available. You cannot proceed with your order.') . '</p>'; } /* Check minimal amount */ $currency = Currency::getCurrency((int) $this->context->cart->id_currency); $minimal_purchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase) { return '<p class="warning">' . sprintf(Tools::displayError('A minimum purchase total of %1s (tax excl.) is required in order to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency)) . '</p>'; } /* Bypass payment step if total is 0 */ if ($this->context->cart->getOrderTotal() <= 0) { return '<p class="center"><button class="button btn btn-default button-medium" name="confirmOrder" id="confirmOrder" onclick="confirmFreeOrder();" type="submit"> <span>' . Tools::displayError('I confirm my order.') . '</span></button></p>'; } $return = Hook::exec('displayPayment'); if (!$return) { return '<p class="warning">' . Tools::displayError('No payment method is available for use at this time. ') . '</p>'; } return $return; }
public function addressImport() { $this->receiveTab(); $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT'); $handle = $this->openCsvFile(); AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); AdminImportController::setDefaultValues($info); $address = new Address(); AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address); if (isset($address->country) && is_numeric($address->country)) { if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) { $address->id_country = (int) $address->country; } } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) { if ($id_country = Country::getIdByName(null, $address->country)) { $address->id_country = (int) $id_country; } else { $country = new Country(); $country->active = 1; $country->name = AdminImportController::createMultiLangField($address->country); $country->id_zone = 0; // Default zone for country to create $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2)); // Default iso for country to create $country->contains_states = 0; // Default value for country to create $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true); if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $country->add()) { $address->id_country = (int) $country->id; } else { $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $country->name[$default_language_id]); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } if (isset($address->state) && is_numeric($address->state)) { if (State::getNameById((int) $address->state)) { $address->id_state = (int) $address->state; } } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) { if ($id_state = State::getIdByName($address->state)) { $address->id_state = (int) $id_state; } else { $state = new State(); $state->active = 1; $state->name = $address->state; $state->id_country = isset($country->id) ? (int) $country->id : 0; $state->id_zone = 0; // Default zone for state to create $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2)); // Default iso for state to create $state->tax_behavior = 0; if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $state->add()) { $address->id_state = (int) $state->id; } else { $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $state->name); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } if (isset($address->customer_email) && !empty($address->customer_email)) { if (Validate::isEmail($address->customer_email)) { // a customer could exists in different shop $customer_list = Customer::getCustomersByEmail($address->customer_email); if (count($customer_list) == 0) { $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); } } else { $this->errors[] = sprintf(Tools::displayError('"%s" is not a valid email address.'), $address->customer_email); continue; } } elseif (isset($address->id_customer) && !empty($address->id_customer)) { if (Customer::customerIdExistsStatic((int) $address->id_customer)) { $customer = new Customer((int) $address->id_customer); // a customer could exists in different shop $customer_list = Customer::getCustomersByEmail($customer->email); if (count($customer_list) == 0) { $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer); } } else { $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be saved.'), $address->id_customer); } } else { $customer_list = array(); $address->id_customer = 0; } if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) { $address->id_manufacturer = (int) $address->manufacturer; } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) { $manufacturer = new Manufacturer(); $manufacturer->name = $address->manufacturer; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) { $address->id_manufacturer = (int) $manufacturer->id; } else { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } if (isset($address->supplier) && is_numeric($address->supplier) && Supplier::supplierExists((int) $address->supplier)) { $address->id_supplier = (int) $address->supplier; } elseif (isset($address->supplier) && is_string($address->supplier) && !empty($address->supplier)) { $supplier = new Supplier(); $supplier->name = $address->supplier; if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) { $address->id_supplier = (int) $supplier->id; } else { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $res = false; if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { if (isset($customer_list) && count($customer_list) > 0) { $filter_list = array(); foreach ($customer_list as $customer) { if (in_array($customer['id_customer'], $filter_list)) { continue; } $filter_list[] = $customer['id_customer']; unset($address->id); $address->id_customer = $customer['id_customer']; $res = $address->add(); if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); } } } else { $address->force_id = (bool) Tools::getValue('forceIDs'); if ($address->id && $address->addressExists($address->id)) { $res = $address->update(); } if (!$res) { $res = $address->add(); } } } if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }
public function init() { if (!$this->isOpcModuleActive()) { return parent::init(); } if (Tools::getIsset('id_carrier') && strpos(Tools::getValue('id_carrier'), ",") > 0) { $_POST['id_carrier'] = Cart::intifier(Tools::getValue('id_carrier')); } $this->opc_templates_path = _PS_MODULE_DIR_ . 'onepagecheckout/views/templates/front'; $this->origInit(); $this->_assignOpcSettings(); if ($this->opc_config != null && $this->opc_config['goods_return_cms'] > 0) { $cms = new CMS((int) $this->opc_config['goods_return_cms'], (int) $this->context->language->id); $link_goods_return = $this->context->link->getCMSLink($cms, $cms->link_rewrite, true); if (!strpos($link_goods_return, '?')) { $link_goods_return .= '?content_only=1'; } else { $link_goods_return .= '&content_only=1'; } $this->context->smarty->assign("link_goods_return", $link_goods_return); } $this->_setInfoBlockContent(); $this->_setExtraDivPaymentBlock(); if ($this->nbProducts) { $this->context->smarty->assign('virtual_cart', false); } $this->context->smarty->assign('is_multi_address_delivery', $this->context->cart->isMultiAddressDelivery() || (int) Tools::getValue('multi-shipping') == 1); $this->context->smarty->assign('open_multishipping_fancybox', (int) Tools::getValue('multi-shipping') == 1); $this->context->smarty->assign('order_process_type', Configuration::get('PS_ORDER_PROCESS_TYPE')); $this->context->smarty->assign('one_phone_at_least', (int) Configuration::get('PS_ONE_PHONE_AT_LEAST')); $this->inv_first_on = isset($this->opc_config) && isset($this->opc_config["invoice_first"]) && $this->opc_config["invoice_first"] == "1"; $this->default_ps_carriers = isset($this->opc_config) && isset($this->opc_config["default_ps_carriers"]) && $this->opc_config["default_ps_carriers"] == "1"; if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) { $this->isLogged = (bool) ($this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer)); } if ($this->context->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 (count($this->errors)) { die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}'); } die(true); } break; case 'updateCarrierAndGetPayments': if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) && Tools::isSubmit('recyclable') && Tools::isSubmit('gift') && Tools::isSubmit('gift_message')) { $this->_assignWrappingAndTOS(); CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if ($this->_processCarrier()) { $carriers = $this->context->cart->simulateCarriersOutput(); $return = array_merge(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'carrier_data' => $this->_getCarrierList(), 'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array('carriers' => $carriers))), $this->getFormatedSummaryDetail()); Cart::addExtraCarriers($return); die(Tools::jsonEncode($return)); } else { $this->errors[] = Tools::displayError('Error occurred while updating cart.'); } if (count($this->errors)) { die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}'); } exit; } break; case 'updateTOSStatusAndGetPayments': if (Tools::isSubmit('checked')) { $this->context->cookie->checkedTOS = (int) Tools::getValue('checked'); die(Tools::jsonEncode(array())); } break; case 'updatePaymentsOnly': die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => self::_getPaymentMethods()))); break; case 'getCarrierList': $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart()); $result = $this->_getCarrierList(); $result = array_merge($result, array('HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods()), $this->getFormatedSummaryDetail()); die(Tools::jsonEncode($result)); break; case 'editCustomer': if (!$this->isLogged) { exit; } if (Tools::getValue('years')) { $this->context->customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days'); } if (trim(Tools::getValue('customer_lastname')) == "") { $_POST['customer_lastname'] = $this->inv_first_on ? Tools::getValue('lastname_invoice') : Tools::getValue('lastname'); } if (trim(Tools::getValue('customer_firstname')) == "") { $_POST['customer_firstname'] = $this->inv_first_on ? Tools::getValue('firstname_invoice') : Tools::getValue('firstname'); } $this->errors = $this->context->customer->validateController(); $this->context->customer->newsletter = (int) Tools::isSubmit('newsletter'); $this->context->customer->optin = (int) Tools::isSubmit('optin'); $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) $this->context->customer->id, 'token' => Tools::getToken(false)); if (!count($this->errors)) { $return['isSaved'] = (bool) $this->context->customer->update(); } else { $return['isSaved'] = false; } die(Tools::jsonEncode($return)); break; case 'getAddressBlockAndCarriersAndPayments': if ($this->context->customer->isLogged()) { if (!Customer::getAddressesTotalById($this->context->customer->id)) { 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(); } $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart()); $customer = $this->context->customer; $customer_info = array("id" => $customer->id, "email" => $customer->email, "id_gender" => $customer->id_gender, "birthday" => $customer->birthday, "newsletter" => $customer->newsletter, "optin" => $customer->optin, "is_guest" => $customer->is_guest); $this->_processAddressFormat(); $this->_assignAddress(); $address_delivery = $this->context->smarty->tpl_vars['delivery']->value; $address_invoice = $this->context->smarty->tpl_vars['invoice']->value; if (Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && !class_exists("VatNumber", false)) { include_once _PS_MODULE_DIR_ . '/vatnumber/vatnumber.php'; } if (isset($address_delivery) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_delivery->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_delivery->id_country) { $allow_eu_vat_delivery = 1; } else { $allow_eu_vat_delivery = 0; } if (isset($address_invoice) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_invoice->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_invoice->id_country) { $allow_eu_vat_invoice = 1; } else { $allow_eu_vat_invoice = 0; } $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX')); if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) { $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE'); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100); } else { $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); } $return = array_merge(array('customer_info' => $customer_info, 'allow_eu_vat_delivery' => $allow_eu_vat_delivery, 'allow_eu_vat_invoice' => $allow_eu_vat_invoice, 'customer_addresses' => $this->context->smarty->tpl_vars['addresses']->value, 'block_user_info' => isset($blockUserInfo) ? method_exists($blockUserInfo, 'hookTop') ? $blockUserInfo->hookTop(array()) : $blockUserInfo->hookDisplayTop(array()) : '', 'carrier_data' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), '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) $this->context->cookie->id_currency)))), $this->getFormatedSummaryDetail()); die(Tools::jsonEncode($return)); } die(Tools::displayError("Customer is not logged in, while he should be. Check please AuthController and cookies.")); break; case 'makeFreeOrder': if (($id_order = $this->_checkFreeOrder()) && $id_order) { $order = new Order((int) $id_order); $email = $this->context->customer->email; if ($this->context->customer->is_guest) { $this->context->customer->logout(); } // If guest we clear the cookie for security reason die('freeorder:' . $order->reference . ':' . $email); } exit; break; case 'updateAddressesSelected': $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 (Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && !class_exists("VatNumber", false)) { include_once _PS_MODULE_DIR_ . '/vatnumber/vatnumber.php'; } if (isset($address_delivery) && Configuration::get('VATNUMBER_MANAGEMENT') && file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_delivery->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_delivery->id_country) { $allow_eu_vat_delivery = 1; } else { $allow_eu_vat_delivery = 0; } if (isset($address_invoice) && Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(_PS_MODULE_DIR_ . '/vatnumber/vatnumber.php') && VatNumber::isApplicable($address_invoice->id_country) && Configuration::get('VATNUMBER_COUNTRY') != $address_invoice->id_country) { $allow_eu_vat_invoice = 1; } else { $allow_eu_vat_invoice = 0; } $address_delivery = new Address((int) Tools::getValue('id_address_delivery')); $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart()); $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 && $address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer && $address_invoice->id_customer != $this->context->customer->id) { $this->errors = "not_your_address"; } if (!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) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { $this->errors[] = Tools::displayError('This address is invalid.'); } else { $this->context->cart->id_address_delivery = (int) Tools::getValue('id_address_delivery'); $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int) Tools::getValue('id_address_invoice'); if (!$this->context->cart->update()) { $this->errors[] = Tools::displayError('An error occurred while updating your cart.'); } CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); $this->context->cart->setNoMultishipping(); // As the cart is no multishipping, set each delivery address lines with the main delivery address if (!count($this->errors)) { $result = $this->_getCarrierList(); $wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX')); if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) { $wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE'); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100); } else { $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); } $result = array_merge($result, array('allow_eu_vat_delivery' => $allow_eu_vat_delivery, 'allow_eu_vat_invoice' => $allow_eu_vat_invoice, 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency))), 'carrier_data' => $this->_getCarrierList()), $this->getFormatedSummaryDetail()); die(Tools::jsonEncode($result)); } } if (count($this->errors)) { die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); } break; case 'multishipping': $this->_assignSummaryInformations(); $this->context->smarty->assign('product_list', $this->context->cart->getProducts()); if ($this->context->customer->id) { $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id)); } else { $this->context->smarty->assign('address_list', array()); } $this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping-products.tpl'); $this->display(); die; break; case 'cartReload': $this->_assignSummaryInformations(); if ($this->context->customer->id) { $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id)); } else { $this->context->smarty->assign('address_list', array()); } $this->context->smarty->assign('opc', true); $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl'); $this->display(); die; break; case 'noMultiAddressDelivery': $this->context->cart->setNoMultishipping(); die; break; case 'emailCheck': if (Tools::isSubmit('cust_email')) { $customer_email = Tools::getValue('cust_email'); $is_registered = Validate::isEmail($customer_email) ? Customer::customerExists($customer_email) : 0; $return = array('is_registered' => $is_registered); die(Tools::jsonEncode($return)); } break; case 'zipCheck': if (Tools::isSubmit('id_country')) { $id_country = Tools::getValue('id_country'); if ($id_country > 0) { $errors = array(); $country = new Country($id_country); $zip_code_format = $country->zip_code_format; if ($country->need_zip_code) { if ($postcode = Tools::getValue('postcode') and $zip_code_format) { $zip_regexp = '/^' . $zip_code_format . '$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', $country->iso_code, $zip_regexp); if (!preg_match($zip_regexp, $postcode)) { $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } } elseif ($zip_code_format) { $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.'); } elseif ($postcode and !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) { $errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } } } //if($id_country>0) $return = array('is_ok' => empty($errors), 'errors' => $errors); die(Tools::jsonEncode($return)); } break; default: throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"'); } } else { throw new PrestaShopException('Method is not defined'); } } } elseif (Tools::isSubmit('ajax')) { throw new PrestaShopException('Method is not defined'); } }
public function init() { self::$amz_payments = new AmzPayments(); $this->isLogged = (bool) $this->context->customer->id && Customer::customerIdExistsStatic((int) $this->context->cookie->id_customer); parent::init(); /* Disable some cache related bugs on the cart/order */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); $this->display_column_left = false; $this->display_column_right = false; // Service initialisieren $this->service = self::$amz_payments->getService(); if (Tools::isSubmit('ajax')) { if (Tools::isSubmit('method')) { switch (Tools::getValue('method')) { case 'redirectAuthentication': case 'setusertoshop': if (Tools::getValue('access_token')) { $this->context->cookie->amz_access_token = AmzPayments::prepareCookieValueForPrestaShopUse(Tools::getValue('access_token')); $this->context->cookie->amz_access_token_set_time = time(); } else { if (Tools::getValue('method') == 'redirectAuthentication') { Tools::redirect('index'); } else { error_log('Error, method not submitted and no token'); die('error'); } } if (Tools::getValue('action') == 'fromCheckout') { $accessTokenValue = AmzPayments::prepareCookieValueForAmazonPaymentsUse(Tools::getValue('access_token')); } else { $accessTokenValue = Tools::getValue('access_token'); } $d = self::$amz_payments->requestTokenInfo($accessTokenValue); if ($d->aud != self::$amz_payments->client_id) { if (Tools::getValue('method') == 'redirectAuthentication') { Tools::redirect('index'); } else { error_log('auth error LPA'); die('error'); } } $d = self::$amz_payments->requestProfile($accessTokenValue); $customer_userid = $d->user_id; $customer_name = $d->name; $customer_email = $d->email; // $postcode = $d->postal_code; if ($customers_local_id = AmazonPaymentsCustomerHelper::findByAmazonCustomerId($customer_userid)) { // Customer already exists - login Hook::exec('actionBeforeAuthentication'); $customer = new Customer(); $authentication = AmazonPaymentsCustomerHelper::getByCustomerID($customers_local_id, true, $customer); if (isset($authentication->active) && !$authentication->active) { $this->errors[] = Tools::displayError('Your account isn\'t available at this time, please contact us'); } elseif (!$authentication || !$customer->id) { $this->errors[] = Tools::displayError('Authentication failed.'); } else { $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 (Tools::getValue('action') == 'fromCheckout' && isset($this->context->cookie->amz_connect_order)) { AmzPayments::switchOrderToCustomer($this->context->customer->id, $this->context->cookie->amz_connect_order, true); } if (Tools::getValue('action') == 'checkout') { $goto = $this->context->link->getModuleLink('amzpayments', 'amzpayments'); } elseif (Tools::getValue('action') == 'fromCheckout') { $goto = 'index.php?controller=history'; } elseif ($this->context->cart->nbProducts()) { $goto = 'index.php?controller=order'; } else { if (Configuration::get('PS_SSL_ENABLED')) { $goto = _PS_BASE_URL_SSL_ . __PS_BASE_URI__; } else { $goto = _PS_BASE_URL_ . __PS_BASE_URI__; } } if (Tools::getValue('method') == 'redirectAuthentication') { Tools::redirect($goto); } else { echo $goto; } } } else { if (AmazonPaymentsCustomerHelper::findByEmailAddress($customer_email)) { $this->context->cookie->amzConnectEmail = $customer_email; $this->context->cookie->amzConnectCustomerId = $customer_userid; $goto = $this->context->link->getModuleLink('amzpayments', 'connect_accounts'); if (Tools::getValue('action') && Tools::getValue('action') == 'checkout') { if (strpos($goto, '?') > 0) { $goto .= '&checkout=1'; } else { $goto .= '?checkout=1'; } } if (Tools::getValue('method') == 'redirectAuthentication') { Tools::redirect($goto); } else { echo $goto; } } else { // Customer does not exist - Create account Hook::exec('actionBeforeSubmitAccount'); $this->create_account = true; $_POST['passwd'] = md5(time() . _COOKIE_KEY_); $firstname = ''; $lastname = ''; $customer_name = preg_replace("/[0-9]/", "", $customer_name); if (strpos(trim($customer_name), ' ') !== false) { list($firstname, $lastname) = explode(' ', trim($customer_name)); } elseif (strpos(trim($customer_name), '-') !== false) { list($firstname, $lastname) = explode('-', trim($customer_name)); } else { $firstname = trim($customer_name); $lastname = 'Placeholder'; } $customer = new Customer(); $customer->email = $customer_email; $lastname_address = $lastname; $firstname_address = $firstname; $_POST['lastname'] = Tools::getValue('customer_lastname', $lastname_address); $_POST['firstname'] = Tools::getValue('customer_firstname', $firstname_address); // $addresses_types = array('address'); $this->errors = array_unique(array_merge($this->errors, $customer->validateController())); // Check the requires fields which are settings in the BO $this->errors = $this->errors + $customer->validateFieldsRequiredDatabase(); if (!count($this->errors)) { $customer->firstname = Tools::ucwords($customer->firstname); $customer->is_guest = 0; $customer->active = 1; if (!count($this->errors)) { if ($customer->add()) { if (!$customer->is_guest) { if (!$this->sendConfirmationMail($customer)) { $this->errors[] = Tools::displayError('The email cannot be sent.'); } } AmazonPaymentsCustomerHelper::saveCustomersAmazonReference($customer, $customer_userid); $this->updateContext($customer); $this->context->cart->update(); Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if (Tools::getValue('action') == 'fromCheckout' && isset($this->context->cookie->amz_connect_order)) { AmzPayments::switchOrderToCustomer($customer->id, $this->context->cookie->amz_connect_order, true); } if (Tools::getValue('action') == 'checkout') { $goto = $this->context->link->getModuleLink('amzpayments', 'amzpayments'); } elseif (Tools::getValue('action') == 'fromCheckout') { $goto = 'index.php?controller=history'; } elseif ($this->context->cart->nbProducts()) { $goto = 'index.php?controller=order'; } else { if (Configuration::get('PS_SSL_ENABLED')) { $goto = _PS_BASE_URL_SSL_ . __PS_BASE_URI__; } else { $goto = _PS_BASE_URL_ . __PS_BASE_URI__; } } if (Tools::getValue('method') == 'redirectAuthentication') { Tools::redirect($goto); } else { echo $goto; } } else { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } } } else { error_log('Error validating customers informations'); die('error'); } } } die; } } } }
public function ajax_getPaymentMethods() { $val = Context::getContext()->cookie->ulozenka; if (empty($val)) { return '<p class="warning">' . Tools::displayError('Prosím vyberte pobočku') . '</p>'; } $isLogged = (bool) (Context::getContext()->customer->id && Customer::customerIdExistsStatic((int) Context::getContext()->cookie->id_customer)); if (!$isLogged) { return '<p class="warning">' . Tools::displayError('Please sign in to see payment methods.') . '</p>'; } if (Context::getContext()->cart->OrderExists()) { return '<p class="warning">' . Tools::displayError('Error: This order has already been validated.') . '</p>'; } if (!Context::getContext()->cart->id_customer || !Customer::customerIdExistsStatic(Context::getContext()->cart->id_customer) || Customer::isBanned(Context::getContext()->cart->id_customer)) { return '<p class="warning">' . Tools::displayError('Error: No customer.') . '</p>'; } $address_delivery = new Address(Context::getContext()->cart->id_address_delivery); $address_invoice = Context::getContext()->cart->id_address_delivery == Context::getContext()->cart->id_address_invoice ? $address_delivery : new Address(Context::getContext()->cart->id_address_invoice); if (!Context::getContext()->cart->id_address_delivery || !Context::getContext()->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) { return '<p class="warning">' . Tools::displayError('Error: Please select an address.') . '</p>'; } /* if (count(Context::getContext()->cart->getDeliveryOptionList()) == 0 && !Context::getContext()->cart->isVirtualCart()) { if (Context::getContext()->cart->isMultiAddressDelivery()) return '<p class="warning">'.Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you\'ve selected.').'</p>'; else return '<p class="warning">'.Tools::displayError('Error: None of your chosen carriers deliver to the address you\'ve selected.').'</p>'; } if (!Context::getContext()->cart->getDeliveryOption(null, false) && !Context::getContext()->cart->isVirtualCart()) return '<p class="warning">'.Tools::displayError('Error: Please choose a carrier.').'</p>'; */ if (!Context::getContext()->cart->id_currency) { return '<p class="warning">' . Tools::displayError('Error: No currency has been selected.') . '</p>'; } if (!Context::getContext()->cookie->checkedTOS && Configuration::get('PS_CONDITIONS')) { return '<p class="warning">' . Tools::displayError('Please accept the Terms of Service.') . '</p>'; } /* If some products have disappear */ if (!Context::getContext()->cart->checkQuantities()) { return '<p class="warning">' . Tools::displayError('An item in your cart is no longer available. You cannot proceed with your order.') . '</p>'; } /* Check minimal amount */ $currency = Currency::getCurrency((int) Context::getContext()->cart->id_currency); $minimalPurchase = Tools::convertPrice((double) Configuration::get('PS_PURCHASE_MINIMUM'), $currency); if (Context::getContext()->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) { return '<p class="warning">' . sprintf(Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'), Tools::displayPrice($minimalPurchase, $currency)) . '</p>'; } /* Bypass payment step if total is 0 */ if (Context::getContext()->cart->getOrderTotal() <= 0) { return '<p class="center"><input type="button" class="exclusive_large" name="confirmOrder" id="confirmOrder" value="' . Tools::displayError('I confirm my order.') . '" onclick="confirmFreeOrder();" /></p>'; } $return = Hook::exec('displayPayment'); if (!$return) { return '<p class="warning">' . Tools::displayError('No payment method is available for use at this time. ') . '</p>'; } return $return; }
public function customerImport() { $customer_exist = false; $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); AdminImportController::setDefaultValues($info); if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $customer = new Customer((int) $info['id']); $current_id_customer = $customer->id; $current_id_shop = $customer->id_shop; $current_id_shop_group = $customer->id_shop_group; $customer_exist = true; $customer_groups = $customer->getGroups(); $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); foreach ($customer_groups as $key => $group) { if ($group == $customer->id_default_group) { unset($customer_groups[$key]); } } } else { $customer = new Customer(); } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer); if ($customer->passwd) { $customer->passwd = Tools::encrypt($customer->passwd); } $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop); $customers_shop = array(); $customers_shop['shared'] = array(); $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); if (Shop::isFeatureActive() && $id_shop_list) { foreach ($id_shop_list as $id_shop) { $shop = new Shop((int) $id_shop); $group_shop = $shop->getGroup(); if ($group_shop->share_customer) { if (!in_array($group_shop->id, $customers_shop['shared'])) { $customers_shop['shared'][(int) $id_shop] = $group_shop->id; } } else { $customers_shop[(int) $id_shop] = $group_shop->id; } } } else { $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); $default_shop->getGroup(); $customers_shop[$default_shop->id] = $default_shop->getGroup()->id; } //set temporally for validate field $customer->id_shop = $default_shop->id; $customer->id_shop_group = $default_shop->getGroup()->id; $res = true; if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { foreach ($customers_shop as $id_shop => $id_group) { if ($id_shop == 'shared') { foreach ($id_group as $key => $id) { $customer->id_shop = (int) $key; $customer->id_shop_group = (int) $id; if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { unset($customer->id); $res &= $customer->add(); if (isset($customer_groups)) { $customer->addGroups($customer_groups); } if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } } } else { $customer->id_shop = $id_shop; $customer->id_shop_group = $id_group; if ($customer_exist && $id_shop == $current_id_shop) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { unset($customer->id); $res &= $customer->add(); if (isset($customer_groups)) { $customer->addGroups($customer_groups); } if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } } } } $customer_exist = false; if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . ($lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }