本文整理汇总了PHP中Address::getFirstCustomerAddressId方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::getFirstCustomerAddressId方法的具体用法?PHP Address::getFirstCustomerAddressId怎么用?PHP Address::getFirstCustomerAddressId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getFirstCustomerAddressId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login_customer
/**
* Logs a given customer in.
*/
public static function login_customer($id_customer)
{
// Make sure that that the customers exists.
$sql = "SELECT * FROM `" . _DB_PREFIX_ . "customer` WHERE `id_customer` = '" . pSQL($id_customer) . "'";
$result = Db::getInstance()->GetRow($sql);
// The user account has been found!
if (!empty($result['id_customer'])) {
// See => CustomerCore::getByEmail
$customer = new Customer();
$customer->id = $result['id_customer'];
foreach ($result as $key => $value) {
if (key_exists($key, $customer)) {
$customer->{$key} = $value;
}
}
// See => AuthControllerCore::processSubmitLogin
Hook::exec('actionBeforeAuthentication');
$context = Context::getContext();
$context->cookie->id_compare = isset($context->cookie->id_compare) ? $context->cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id);
$context->cookie->id_customer = (int) $customer->id;
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->logged = 1;
$customer->logged = 1;
$context->cookie->is_guest = $customer->isGuest();
$context->cookie->passwd = $customer->passwd;
$context->cookie->email = $customer->email;
// Add customer to the context
$context->customer = $customer;
if (Configuration::get('PS_CART_FOLLOWING') && (empty($context->cookie->id_cart) || Cart::getNbProducts($context->cookie->id_cart) == 0) && ($id_cart = (int) Cart::lastNoneOrderedCart($context->customer->id))) {
$context->cart = new Cart($id_cart);
} else {
$context->cart->id_carrier = 0;
$context->cart->setDeliveryOption(null);
$context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
$context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
}
$context->cart->id_customer = (int) $customer->id;
$context->cart->secure_key = $customer->secure_key;
$context->cart->save();
$context->cookie->id_cart = (int) $context->cart->id;
$context->cookie->update();
$context->cart->autosetProductAddress();
Hook::exec('actionAuthentication');
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($context);
CartRule::autoAddToCart($context);
// Customer is now logged in.
return true;
}
// Invalid customer specified.
return false;
}
示例2: initContent
public function initContent()
{
$cmofie = "module";
parent::initContent();
${$cmofie} = new AgilePaypal();
$this->context->cart = new Cart();
$this->context->cart->id_lang = intval($this->context->cookie->id_lang);
$this->context->cart->id_currency = intval($this->context->cookie->id_currency);
$jpptxpcvjjk = "sl_expresscheckout_id_country";
$this->context->cart->id_guest = intval($this->context->cookie->id_guest);
$llkzpyey = "id_product";
if ($this->context->cookie->id_customer) {
$this->context->cart->id_customer = intval($this->context->cookie->id_customer);
$this->context->cart->id_address_delivery = intval(Address::getFirstCustomerAddressId($this->context->cart->id_customer));
$this->context->cart->id_address_invoice = $this->context->cart->id_address_delivery;
} else {
$this->context->cart->id_address_delivery = 0;
$this->context->cart->id_address_invoice = 0;
}
${"GLOBALS"}["lpampekuqrwh"] = "id_product";
$this->context->cart->add();
if ($this->context->cart->id) {
$this->context->cookie->id_cart = intval($this->context->cart->id);
}
${$llkzpyey} = (int) Tools::getValue("id_product");
if (${${"GLOBALS"}["hvtkfucisp"]}) {
$this->context->cart->updateQty((int) Tools::getValue("qty"), ${${"GLOBALS"}["lpampekuqrwh"]}, 0, false, "up");
}
${$jpptxpcvjjk} = (int) Configuration::get("PS_COUNTRY_DEFAULT");
if ($this->context->cart->id_address_invoice) {
$sgcgklgjd = "countrystate";
${$sgcgklgjd} = Address::getCountryAndState($this->context->cart->id_address_invoice);
${${"GLOBALS"}["ilrsdjvry"]} = (int) ${${"GLOBALS"}["rlrnvyxftps"]}["id_country"];
}
$this->context->cart->id_address_delivery = ${${"GLOBALS"}["ilrsdjvry"]};
$this->context->cart->id_address_invoice = ${${"GLOBALS"}["ilrsdjvry"]};
${${"GLOBALS"}["smzfojqsh"]} = array("sl_agilepaypalexpress_cycle" => Tools::getValue("sl_agilepaypalexpress_cycle"), "sl_agilepaypalexpress_cycle_base" => Tools::getValue("sl_agilepaypalexpress_cycle_base"), "sl_agilepaypalexpress_cycle_num" => Tools::getValue("sl_agilepaypalexpress_cycle_num"), "sl_expresscheckout_id_country" => ${${"GLOBALS"}["ilrsdjvry"]});
if ($this->context->cart->getOrderTotal() <= 0) {
Tools::redirect("index.php?controller=order");
} else {
if (Tools::getValue("sl_agilepaypalexpress_cycle_num") == 1) {
Tools::redirect($this->context->link->getModuleLink("agilepaypal", "redirect", ${${"GLOBALS"}["smzfojqsh"]}, true));
} else {
Tools::redirect($this->context->link->getModuleLink("agilepaypal", "subscribe", ${${"GLOBALS"}["smzfojqsh"]}, true));
}
}
}
示例3: delete
public function delete(Address $address, $token)
{
if (!$this->authorizeChange($address, $token)) {
return false;
}
$id = $address->id;
$ok = $address->delete();
if ($ok) {
if ($this->cart->id_address_invoice == $id) {
unset($this->cart->id_address_invoice);
}
if ($this->cart->id_address_delivery == $id) {
unset($this->cart->id_address_delivery);
$this->cart->updateAddressId($id, Address::getFirstCustomerAddressId($this->customer->id));
}
}
return $ok;
}
示例4: login_customer
/**
* Logs a given customer in.
*/
public static function login_customer($id_customer)
{
global $cart, $cookie;
// Make sure that that the customers exists.
$sql = "SELECT * FROM `" . _DB_PREFIX_ . "customer` WHERE `id_customer` = '" . pSQL($id_customer) . "'";
$result = Db::getInstance()->GetRow($sql);
// The user account has been found!
if (!empty($result['id_customer'])) {
// See => CustomerCore::getByEmail
$customer = new Customer();
$customer->id = $result['id_customer'];
foreach ($result as $key => $value) {
if (key_exists($key, $customer)) {
$customer->{$key} = $value;
}
}
// See => AuthControllerCore
Module::hookExec('beforeAuthentication');
$cookie->id_compare = isset($cookie->id_compare) ? $cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id);
$cookie->id_customer = (int) $customer->id;
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
$cookie->is_guest = $customer->isGuest();
if (Configuration::get('PS_CART_FOLLOWING') and (empty($cookie->id_cart) or Cart::getNbProducts($cookie->id_cart) == 0)) {
$cookie->id_cart = (int) Cart::lastNoneOrderedCart((int) $customer->id);
}
// Update cart address.
$cart->id_carrier = 0;
$cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
$cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
$cart->secure_key = $customer->secure_key;
$cart->update();
Module::hookExec('authentication');
// Customer is now logged in.
return true;
}
// Invalid customer specified.
return false;
}
示例5: init
/**
* Initialize address controller
* @see FrontController::init()
*/
public function init()
{
parent::init();
// Get address ID
$id_address = 0;
if ($this->ajax && Tools::isSubmit('type')) {
if (Tools::getValue('type') == 'delivery' && isset($this->context->cart->id_address_delivery)) {
$id_address = (int) $this->context->cart->id_address_delivery;
} else {
if (Tools::getValue('type') == 'invoice' && isset($this->context->cart->id_address_invoice) && $this->context->cart->id_address_invoice != $this->context->cart->id_address_delivery) {
$id_address = (int) $this->context->cart->id_address_invoice;
}
}
} else {
$id_address = (int) Tools::getValue('id_address', 0);
}
// Initialize address
if ($id_address) {
$this->_address = new Address($id_address);
if (Validate::isLoadedObject($this->_address) && Customer::customerHasAddress($this->context->customer->id, $id_address)) {
if (Tools::isSubmit('delete')) {
if ($this->_address->delete()) {
if ($this->context->cart->id_address_invoice == $this->_address->id) {
unset($this->context->cart->id_address_invoice);
}
if ($this->context->cart->id_address_delivery == $this->_address->id) {
unset($this->context->cart->id_address_delivery);
$this->context->cart->updateAddressId($this->_address->id, (int) Address::getFirstCustomerAddressId(Context::getContext()->customer->id));
}
Tools::redirect('index.php?controller=addresses');
}
$this->errors[] = Tools::displayError('This address cannot be deleted.');
}
} elseif ($this->ajax) {
exit;
} else {
Tools::redirect('index.php?controller=addresses');
}
}
}
示例6: formatEntityToXML
/**
* Convert the entities data into an xml object and return the xml object as a string
*
* @param array $aEntity Entity data
*/
public function formatEntityToXML($aEntity)
{
$dom = new DOMDocument('1.0', 'utf-8');
// Set the root of the XML
$root = $dom->createElement($this->sEntity);
$dom->appendChild($root);
$oCustomer = new Customer((int) $aEntity['id_customer']);
// Check if the customer has visited the website since a specific number of days $this->nbDaysCustomerValid
$aLastConnection = $oCustomer->getLastConnections();
if ($aLastConnection[0]['date_add'] < date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d') - (int) $this->nbDaysCustomerValid, date('Y')))) {
$this->nbEntitiesTreated--;
$this->nbEntities--;
return ' ';
}
unset($aLastConnection);
$id = $dom->createElement('id', (int) $oCustomer->id);
$root->appendChild($id);
if (($sBirthday = strtotime($oCustomer->birthday)) && !empty($sBirthday)) {
$dobyear = $dom->createElement('dobyear', date('Y', $sBirthday));
$root->appendChild($dobyear);
}
$gender = $dom->createElement('gender', (int) $oCustomer->id_gender == 1 ? 'male' : 'female');
$root->appendChild($gender);
$oAddress = new Address((int) Address::getFirstCustomerAddressId((int) $oCustomer->id));
unset($oCustomer);
if (($sLocation = trim($oAddress->city)) && !empty($sLocation)) {
$location = $dom->createElement('location', $sLocation);
$root->appendChild($location);
}
if (($sCountry = Country::getIsoById((int) $oAddress->id_country)) && !empty($sCountry)) {
$country = $dom->createElement('country', $sCountry);
$root->appendChild($country);
}
$sReturn = $dom->saveHTML();
unset($oAddress);
unset($dom);
return $sReturn;
}
示例7: trim
$authentication = $customer->getByemail(trim($email), trim($passwd));
/* Handle brute force attacks */
sleep(1);
if (!$authentication or !$customer->id) {
$errors[] = Tools::displayError('authentication failed');
} else {
$cookie->id_customer = intval($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->logged = 1;
$cookie->passwd = $customer->passwd;
$cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') and (empty($cookie->id_cart) or Cart::getNbProducts($cookie->id_cart) == 0)) {
$cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
}
$id_address = intval(Address::getFirstCustomerAddressId(intval($customer->id)));
$cookie->id_address_delivery = $id_address;
$cookie->id_address_invoice = $id_address;
Module::hookExec('authentication');
if ($back = Tools::getValue('back')) {
Tools::redirect($back);
}
Tools::redirect('my-account.php');
}
}
}
if (isset($create_account)) {
/* Generate years, months and days */
if (isset($_POST['years']) and is_numeric($_POST['years'])) {
$selectedYears = intval($_POST['years']);
}
示例8: preProcess
//.........这里部分代码省略.........
}
if ((int) $country->contains_states and !(int) $address->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;
if (!$address->add()) {
$this->errors[] = Tools::displayError('An error occurred while creating your address.');
} else {
if (!$customer->is_guest) {
if (!Mail::Send((int) self::$cookie->id_lang, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
$this->errors[] = Tools::displayError('Cannot send email');
}
}
self::$smarty->assign('confirmation', 1);
self::$cookie->id_customer = (int) $customer->id;
self::$cookie->customer_lastname = $customer->lastname;
self::$cookie->customer_firstname = $customer->firstname;
self::$cookie->passwd = $customer->passwd;
self::$cookie->logged = 1;
self::$cookie->email = $customer->email;
self::$cookie->is_guest = !Tools::getValue('is_new_customer', 1);
/* Update cart address */
self::$cart->secure_key = $customer->secure_key;
self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
self::$cart->update();
Module::hookExec('createAccount', array('_POST' => $_POST, 'newCustomer' => $customer));
if (Tools::isSubmit('ajax')) {
$return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) self::$cookie->id_customer, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice, 'token' => Tools::getToken(false));
die(Tools::jsonEncode($return));
}
if ($back = Tools::getValue('back')) {
Tools::redirect($back);
}
Tools::redirect('my-account.php');
}
}
}
}
}
if (sizeof($this->errors)) {
if (!Tools::getValue('is_new_customer')) {
unset($_POST['passwd']);
}
if (Tools::isSubmit('ajax')) {
$return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0);
die(Tools::jsonEncode($return));
}
}
}
if (Tools::isSubmit('SubmitLogin')) {
Module::hookExec('beforeAuthentication');
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
if (empty($email)) {
$this->errors[] = Tools::displayError('E-mail address required');
示例9: updateCustomer
/**
* Update context after customer login
* @param Customer $customer Created customer
*/
public function updateCustomer(Customer $customer)
{
$this->customer = $customer;
$this->cookie->id_customer = (int) $customer->id;
$this->cookie->customer_lastname = $customer->lastname;
$this->cookie->customer_firstname = $customer->firstname;
$this->cookie->passwd = $customer->passwd;
$this->cookie->logged = 1;
$customer->logged = 1;
$this->cookie->email = $customer->email;
$this->cookie->is_guest = $customer->isGuest();
$this->cart->secure_key = $customer->secure_key;
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->cookie->id_cart) || Cart::getNbProducts($this->cookie->id_cart) == 0) && ($id_cart = (int) Cart::lastNoneOrderedCart($this->customer->id))) {
$this->cart = new Cart($id_cart);
} else {
$id_carrier = (int) $this->cart->id_carrier;
$this->cart->id_carrier = 0;
$this->cart->setDeliveryOption(null);
$this->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
$this->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
}
$this->cart->id_customer = (int) $customer->id;
if (isset($id_carrier) && $id_carrier) {
$delivery_option = [$this->cart->id_address_delivery => $id_carrier . ','];
$this->cart->setDeliveryOption($delivery_option);
}
$this->cart->save();
$this->cookie->id_cart = (int) $this->cart->id;
$this->cookie->write();
$this->cart->autosetProductAddress();
}
示例10: processSubmitAccount
//.........这里部分代码省略.........
$this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false);
}
$this->processCustomerNewsletter($customer);
$customer->birthday = empty($_POST['years']) ? '' : (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
if (!Validate::isBirthDate($customer->birthday)) {
$this->errors[] = Tools::displayError('Invalid date of birth');
}
if (!count($this->errors)) {
$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 {
foreach ($addresses_types as $addresses_type) {
${$addresses_type}->id_customer = (int) $customer->id;
if ($addresses_type == 'address_invoice') {
foreach ($_POST as $key => &$post) {
if ($tmp = Tools::getValue($key . '_invoice')) {
$post = $tmp;
}
}
}
$this->errors = array_unique(array_merge($this->errors, ${$addresses_type}->validateController()));
if ($addresses_type == 'address_invoice') {
$_POST = $post_back;
}
if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !${$addresses_type}->add()) {
$this->errors[] = Tools::displayError('An error occurred while creating your address.');
}
}
if (!count($this->errors)) {
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('The email cannot be sent.');
}
} 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 = (int) Address::getFirstCustomerAddressId((int) $customer->id);
$this->context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
if (isset($address_invoice) && Validate::isLoadedObject($address_invoice)) {
$this->context->cart->id_address_invoice = (int) $address_invoice->id;
}
if ($this->ajax && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$delivery_option = array((int) $this->context->cart->id_address_delivery => (int) $this->context->cart->id_carrier . ',');
$this->context->cart->setDeliveryOption($delivery_option);
}
// 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));
$this->ajaxDie(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')) && $back == Tools::secureReferrer($back)) {
Tools::redirect(html_entity_decode($back));
}
// 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 = (int) Tools::getValue('multi-shipping') ? '&multi-shipping=' . $multi : ''));
} else {
Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : '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);
$this->ajaxDie(Tools::jsonEncode($return));
}
$this->context->smarty->assign('account_error', $this->errors);
}
}
示例11: intval
if ($cookie->id_customer) {
$cart->id_customer = intval($cookie->id_customer);
}
$cart->id_lang = intval($cookie->id_lang);
$cart->id_currency = intval($cookie->id_currency);
$cart->update();
}
}
if (!isset($cart) or !$cart->id) {
$cart = new Cart();
$cart->id_lang = intval($cookie->id_lang);
$cart->id_currency = intval($cookie->id_currency);
$cart->id_guest = intval($cookie->id_guest);
if ($cookie->id_customer) {
$cart->id_customer = intval($cookie->id_customer);
$cart->id_address_delivery = intval(Address::getFirstCustomerAddressId($cart->id_customer));
$cart->id_address_invoice = $cart->id_address_delivery;
} else {
$cart->id_address_delivery = 0;
$cart->id_address_invoice = 0;
}
}
if (!$cart->nbProducts()) {
$cart->id_carrier = NULL;
}
$ps_language = new Language(intval($cookie->id_lang));
setlocale(LC_COLLATE, strtolower($ps_language->iso_code) . '_' . strtoupper($ps_language->iso_code) . '.UTF-8');
setlocale(LC_CTYPE, strtolower($ps_language->iso_code) . '_' . strtoupper($ps_language->iso_code) . '.UTF-8');
setlocale(LC_TIME, strtolower($ps_language->iso_code) . '_' . strtoupper($ps_language->iso_code) . '.UTF-8');
setlocale(LC_NUMERIC, 'en_EN.UTF-8');
if (is_object($currency)) {
示例12: init
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();
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();
$this->nbProducts = $this->context->cart->nbProducts();
if (Configuration::get('PS_CATALOG_MODE')) {
$this->errors[] = Tools::displayError('This store has not accepted your new 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 (($cart_rule = new CartRule(CartRule::getIdByCode($code))) && Validate::isLoadedObject($cart_rule)) {
if ($error = $cart_rule->checkValidity($this->context, false, true)) {
$this->errors[] = $error;
} else {
$this->context->cart->addCartRule($cart_rule->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');
}
}
if ($this->context->cart->isVirtualCart()) {
$this->setNoCarrier();
}
} else {
Tools::redirect('index.php?controller=order-opc');
}
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
if ($this->nbProducts) {
$this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart());
}
$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);
if ($this->context->cart->nbProducts()) {
if (Tools::isSubmit('ajax')) {
if (Tools::isSubmit('method')) {
switch (Tools::getValue('method')) {
case 'setsession':
$this->context->cookie->amazon_id = Tools::getValue('amazon_id');
$this->context->cookie->amz_access_token = AmzPayments::prepareCookieValueForPrestaShopUse(Tools::getValue('access_token'));
$this->context->cookie->amz_access_token_set_time = time();
if (!$this->context->customer->isLogged() && self::$amz_payments->lpa_mode != 'pay') {
$d = self::$amz_payments->requestTokenInfo(AmzPayments::prepareCookieValueForAmazonPaymentsUse($this->context->cookie->amz_access_token));
if ($d->aud != self::$amz_payments->client_id) {
error_log('auth error LPA');
die('error');
}
$d = self::$amz_payments->requestProfile(AmzPayments::prepareCookieValueForAmazonPaymentsUse($this->context->cookie->amz_access_token));
$customer_userid = $d->user_id;
$customer_name = $d->name;
$customer_email = $d->email;
if ($customers_local_id = AmazonPaymentsCustomerHelper::findByAmazonCustomerId($customer_userid)) {
Hook::exec('actionBeforeAuthentication');
$customer = new Customer();
$authentication = AmazonPaymentsCustomerHelper::getByCustomerID($customers_local_id, true, $customer);
if (isset($authentication->active) && !$authentication->active) {
exit;
} elseif (!$authentication || !$customer->id) {
exit;
} 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);
//.........这里部分代码省略.........
示例13: init
public function init()
{
global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
$css_files = array();
$js_files = array();
if (self::$initialized) {
return;
}
self::$initialized = true;
if ($this->ssl and !(empty($_SERVER['HTTPS']) or strtolower($_SERVER['HTTPS']) != 'off') and Configuration::get('PS_SSL_ENABLED')) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
exit;
}
ob_start();
$cookie = new Cookie('ps');
$link = new Link();
if ($this->auth and !$cookie->isLogged($this->guestAllowed)) {
Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : ''));
}
/* Theme is missing or maintenance */
if (!is_dir(_PS_THEME_DIR_)) {
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
} elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !(int) Configuration::get('PS_SHOP_ENABLE')) {
$this->maintenance = true;
} elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) {
$this->geolocationManagement();
}
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = (int) Language::getIdByIso($iso)) {
$_GET['id_lang'] = $id_lang;
}
Tools::switchLanguage();
Tools::setCookieLanguage();
/* attribute id_lang is often needed, so we create a constant for performance reasons */
if (!defined('_USER_ID_LANG_')) {
define('_USER_ID_LANG_', (int) $cookie->id_lang);
}
if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned((int) $cookie->id_customer)) {
$cookie->logout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
} elseif (isset($_GET['mylogout'])) {
$cookie->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
global $currency;
$currency = Tools::setCurrency();
$_MODULES = array();
if ((int) $cookie->id_cart) {
$cart = new Cart((int) $cookie->id_cart);
if ($cart->OrderExists()) {
unset($cookie->id_cart, $cart);
} elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) and !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) and $cart->nbProducts() and intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1) {
unset($cookie->id_cart, $cart);
} elseif ($cookie->id_customer != $cart->id_customer or $cookie->id_lang != $cart->id_lang or $cookie->id_currency != $cart->id_currency) {
if ($cookie->id_customer) {
$cart->id_customer = (int) $cookie->id_customer;
}
$cart->id_lang = (int) $cookie->id_lang;
$cart->id_currency = (int) $cookie->id_currency;
$cart->update();
}
}
if (!isset($cart) or !$cart->id) {
$cart = new Cart();
$cart->id_lang = (int) $cookie->id_lang;
$cart->id_currency = (int) $cookie->id_currency;
$cart->id_guest = (int) $cookie->id_guest;
if ($cookie->id_customer) {
$cart->id_customer = (int) $cookie->id_customer;
$cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
$cart->id_address_invoice = $cart->id_address_delivery;
} else {
$cart->id_address_delivery = 0;
$cart->id_address_invoice = 0;
}
}
if (!$cart->nbProducts()) {
$cart->id_carrier = NULL;
}
$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8');
setlocale(LC_COLLATE, $locale);
setlocale(LC_CTYPE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_NUMERIC, 'en_US.UTF-8');
if (Validate::isLoadedObject($currency)) {
$smarty->ps_currency = $currency;
}
if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) {
$smarty->ps_language = $ps_language;
}
/* get page name to display it in body id */
$pathinfo = pathinfo(__FILE__);
$page_name = basename($_SERVER['PHP_SELF'], '.' . $pathinfo['extension']);
$page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
$smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name));
$smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */
$navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
$smarty->assign('navigationPipe', $navigationPipe);
//.........这里部分代码省略.........
示例14: init
public function init()
{
global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
if (self::$initialized) {
return;
}
self::$initialized = true;
// If current URL use SSL, set it true (used a lot for module redirect)
if (Tools::usingSecureMode()) {
$useSSL = $this->ssl = true;
}
$css_files = array();
$js_files = array();
if ($this->ssl && !Tools::usingSecureMode() && _PS_SSL_ENABLED_) {
header('HTTP/1.1 301 Moved Permanently');
header('Cache-Control: no-cache');
header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
exit;
} elseif (_PS_SSL_ENABLED_ && Tools::usingSecureMode() && !$this->ssl) {
header('HTTP/1.1 301 Moved Permanently');
header('Cache-Control: no-cache');
header('Location: ' . Tools::getShopDomain(true) . $_SERVER['REQUEST_URI']);
exit;
}
ob_start();
/* Loading default country */
$defaultCountry = new Country((int) _PS_COUNTRY_DEFAULT_, (int) _PS_LANG_DEFAULT_);
$cookie = new Cookie('ps', '', time() + ((int) Configuration::get('PS_COOKIE_LIFETIME_FO') > 0 ? (int) Configuration::get('PS_COOKIE_LIFETIME_FO') : 1) * 3600);
$link = new Link();
if ($this->auth && !$cookie->isLogged($this->guestAllowed)) {
Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : ''));
}
/* Theme is missing or maintenance */
if (!file_exists(_PS_THEME_DIR_)) {
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
} elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' && !(int) Configuration::get('PS_SHOP_ENABLE')) {
$this->maintenance = true;
} elseif (_PS_GEOLOCATION_ENABLED_) {
$this->geolocationManagement();
}
// Switch language if needed and init cookie language
$iso = Tools::getValue('isolang');
if ($iso && Validate::isLanguageIsoCode($iso)) {
$id_lang = (int) Language::getIdByIso($iso);
if ($id_lang) {
$_GET['id_lang'] = $id_lang;
}
}
Tools::switchLanguage();
Tools::setCookieLanguage();
/* attribute id_lang is often needed, so we create a constant for performance reasons */
if (!defined('_USER_ID_LANG_')) {
define('_USER_ID_LANG_', (int) $cookie->id_lang);
}
if (isset($_GET['logout']) || $cookie->logged && Customer::isBanned((int) $cookie->id_customer)) {
$cookie->logout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
} elseif (isset($_GET['mylogout'])) {
$cookie->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
global $currency;
$currency = Tools::setCurrency();
/* Cart already exists */
if ((int) $cookie->id_cart) {
$cart = new Cart((int) $cookie->id_cart);
if ($cart->OrderExists()) {
unset($cookie->id_cart, $cart, $cookie->checkedTOS);
} elseif (_PS_GEOLOCATION_ENABLED_ && !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && (int) Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') != -1 && !self::isInWhitelistForGeolocation()) {
unset($cookie->id_cart, $cart);
} elseif ($cookie->id_customer != $cart->id_customer || $cookie->id_lang != $cart->id_lang || $cookie->id_currency != $cart->id_currency) {
if ($cookie->id_customer) {
$cart->id_customer = (int) $cookie->id_customer;
}
$cart->id_lang = (int) $cookie->id_lang;
$cart->id_currency = (int) $cookie->id_currency;
$cart->update();
}
/* Select an address if not set */
if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $cookie->id_customer) {
$to_update = false;
if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
$to_update = true;
$cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
}
if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
$to_update = true;
$cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
}
if ($to_update) {
$cart->update();
}
}
}
if (!isset($cart) || !$cart->id) {
$cart = new Cart();
$cart->id_lang = (int) $cookie->id_lang;
$cart->id_currency = (int) $cookie->id_currency;
$cart->id_guest = (int) $cookie->id_guest;
if ($cookie->id_customer) {
//.........这里部分代码省略.........
示例15: updateQty
/**
* Update product quantity
*
* @param int $quantity Quantity to add (or substract)
* @param int $id_product Product ID
* @param int $id_product_attribute Attribute ID if needed
* @param string $operator Indicate if quantity must be increased or decreased
*/
public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true)
{
//error_log(__LINE__.'@'.__FILE__);
if (!$shop) {
$shop = Context::getContext()->shop;
}
if (Context::getContext()->customer->id) {
if ($id_address_delivery == 0 && (int) $this->id_address_delivery) {
// The $id_address_delivery is null, use the cart delivery address
$id_address_delivery = $this->id_address_delivery;
} elseif ($id_address_delivery == 0) {
// The $id_address_delivery is null, get the default customer address
$id_address_delivery = (int) Address::getFirstCustomerAddressId((int) Context::getContext()->customer->id);
} elseif (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) {
// The $id_address_delivery must be linked with customer
$id_address_delivery = 0;
}
}
$quantity = (int) $quantity;
$id_product = (int) $id_product;
$id_product_attribute = (int) $id_product_attribute;
$product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $shop->id);
if ($id_product_attribute) {
$combination = new Combination((int) $id_product_attribute);
if ($combination->id_product != $id_product) {
return false;
}
}
/* If we have a product combination, the minimal quantity is set with the one of this combination */
if (!empty($id_product_attribute)) {
$minimal_quantity = (int) Attribute::getAttributeMinimalQty($id_product_attribute);
} else {
$minimal_quantity = (int) $product->minimal_quantity;
}
if (!Validate::isLoadedObject($product)) {
die(Tools::displayError());
}
if (isset(self::$_nbProducts[$this->id])) {
unset(self::$_nbProducts[$this->id]);
}
if (isset(self::$_totalWeight[$this->id])) {
unset(self::$_totalWeight[$this->id]);
}
Hook::exec('actionBeforeCartUpdateQty', array('cart' => $this, 'product' => $product, 'id_product_attribute' => $id_product_attribute, 'id_customization' => $id_customization, 'quantity' => $quantity, 'operator' => $operator, 'id_address_delivery' => $id_address_delivery, 'shop' => $shop, 'auto_add_cart_rule' => $auto_add_cart_rule));
if ((int) $quantity <= 0) {
return $this->deleteProduct($id_product, $id_product_attribute, (int) $id_customization);
} elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE') && !defined('_PS_ADMIN_DIR_')) {
return false;
} else {
/* Check if the product is already in the cart */
$result = $this->containsProduct($id_product, $id_product_attribute, (int) $id_customization, (int) $id_address_delivery);
/* Update quantity if product already exist */
if ($result) {
if ($operator == 'up') {
$sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity
FROM ' . _DB_PREFIX_ . 'product p
' . Product::sqlStock('p', $id_product_attribute, true, $shop) . '
WHERE p.id_product = ' . $id_product;
$result2 = Db::getInstance()->getRow($sql);
$product_qty = (int) $result2['quantity'];
// Quantity for product pack
if (Pack::isPack($id_product)) {
$product_qty = Pack::getQuantity($id_product, $id_product_attribute);
}
$new_qty = (int) $result['quantity'] + (int) $quantity;
$qty = '+ ' . (int) $quantity;
if (!Product::isAvailableWhenOutOfStock((int) $result2['out_of_stock'])) {
if ($new_qty > $product_qty) {
return false;
}
}
} elseif ($operator == 'down') {
$qty = '- ' . (int) $quantity;
$new_qty = (int) $result['quantity'] - (int) $quantity;
if ($new_qty < $minimal_quantity && $minimal_quantity > 1) {
return -1;
}
} else {
return false;
}
/* Delete product from cart */
if ($new_qty <= 0) {
return $this->deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization);
} elseif ($new_qty < $minimal_quantity) {
return -1;
} else {
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `quantity` = `quantity` ' . $qty . ', `date_add` = NOW()
WHERE `id_product` = ' . (int) $id_product . (!empty($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
AND `id_cart` = ' . (int) $this->id . (Configuration::get('PS_ALLOW_MULTISHIPPING') && $this->isMultiAddressDelivery() ? ' AND `id_address_delivery` = ' . (int) $id_address_delivery : '') . '
LIMIT 1');
//.........这里部分代码省略.........