本文整理汇总了PHP中CartRule::autoRemoveFromCart方法的典型用法代码示例。如果您正苦于以下问题:PHP CartRule::autoRemoveFromCart方法的具体用法?PHP CartRule::autoRemoveFromCart怎么用?PHP CartRule::autoRemoveFromCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CartRule
的用法示例。
在下文中一共展示了CartRule::autoRemoveFromCart方法的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: submit
public function submit()
{
if ($this->validate()) {
Hook::exec('actionAuthenticationBefore');
$customer = new Customer();
$authentication = $customer->getByEmail($this->getValue('email'), $this->getValue('password'));
if (isset($authentication->active) && !$authentication->active) {
$this->errors[''][] = $this->translator->trans('Your account isn\'t available at this time, please contact us', [], 'Shop.Notifications.Error');
} elseif (!$authentication || !$customer->id || $customer->is_guest) {
$this->errors[''][] = $this->translator->trans('Authentication failed.', [], 'Shop.Notifications.Error');
} else {
$this->context->updateCustomer($customer);
Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
}
}
return !$this->hasErrors();
}
示例3: initContent
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
/* id_carrier is not defined in database before choosing a carrier, set it to a default one to match a potential cart _rule */
if (empty($this->context->cart->id_carrier)) {
$checked = $this->context->cart->simulateCarrierSelectedOutput();
$checked = (int) Cart::desintifier($checked);
$this->context->cart->id_carrier = $checked;
$this->context->cart->update();
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
}
// SHOPPING CART
$this->_assignSummaryInformations();
// WRAPPING AND TOS
$this->_assignWrappingAndTOS();
if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
$countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
} else {
$countries = Country::getCountries($this->context->language->id, true);
}
// If a rule offer free-shipping, force hidding shipping prices
$free_shipping = false;
foreach ($this->context->cart->getCartRules() as $rule) {
if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
$free_shipping = true;
break;
}
}
$this->context->smarty->assign(array('free_shipping' => $free_shipping, 'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0, 'countries' => $countries, 'sl_country' => (int) Tools::getCountry(), 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'errorCarrier' => Tools::displayError('You must choose a carrier.', false), 'errorTOS' => Tools::displayError('You must accept the Terms of Service.', false), 'isPaymentStep' => isset($_GET['isPaymentStep']) && $_GET['isPaymentStep'], 'genders' => Gender::getGenders(), 'one_phone_at_least' => (int) Configuration::get('PS_ONE_PHONE_AT_LEAST'), 'HOOK_CREATE_ACCOUNT_FORM' => Hook::exec('displayCustomerAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Hook::exec('displayCustomerAccountFormTop')));
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
$this->context->smarty->assign(array('years' => $years, 'months' => $months, 'days' => $days));
/* Load guest informations */
if ($this->isLogged && $this->context->cookie->is_guest) {
$this->context->smarty->assign('guestInformations', $this->_getGuestInformations());
}
// ADDRESS
if ($this->isLogged) {
$this->_assignAddress();
}
// CARRIER
$this->_assignCarrier();
// PAYMENT
$this->_assignPayment();
Tools::safePostVars();
$newsletter = Configuration::get('PS_CUSTOMER_NWSL') || Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active;
$this->context->smarty->assign('newsletter', $newsletter);
$this->context->smarty->assign('optin', (bool) Configuration::get('PS_CUSTOMER_OPTIN'));
$this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase());
$this->_processAddressFormat();
$link = new Link();
if (Tools::getValue('deleteFromOrderLine')) {
$id_product = Tools::getValue('id_product');
$date_from = Tools::getValue('date_from');
$date_to = Tools::getValue('date_to');
$obj_cart_bk_data = new HotelCartBookingData();
$cart_data_dlt = $obj_cart_bk_data->deleteRoomDataFromOrderLine($this->context->cart->id, $this->context->cart->id_guest, $id_product, $date_from, $date_to);
if ($cart_data_dlt) {
Tools::redirect($link->getPageLink('order', null, $this->context->language->id));
}
}
if ((bool) Configuration::get('PS_ADVANCED_PAYMENT_API')) {
$this->addJS(_THEME_JS_DIR_ . 'advanced-payment-api.js');
$this->setTemplate(_PS_THEME_DIR_ . 'order-opc-advanced.tpl');
} else {
if (Module::isInstalled('hotelreservationsystem')) {
require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
$obj_cart_bk_data = new HotelCartBookingData();
$obj_htl_bk_dtl = new HotelBookingDetail();
$obj_rm_type = new HotelRoomType();
$htl_rm_types = $this->context->cart->getProducts();
if (!empty($htl_rm_types)) {
foreach ($htl_rm_types as $type_key => $type_value) {
$product = new Product($type_value['id_product'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['id_product']);
if (!empty($cover_image_arr)) {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'small_default');
} else {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
}
$unit_price = Product::getPriceStatic($type_value['id_product'], true, null, 6, null, false, true, 1);
if (isset($this->context->customer->id)) {
$cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
} else {
$cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
}
$rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['id_product']);
$cart_htl_data[$type_key]['id_product'] = $type_value['id_product'];
$cart_htl_data[$type_key]['cover_img'] = $cover_img;
$cart_htl_data[$type_key]['name'] = $product->name;
$cart_htl_data[$type_key]['unit_price'] = $unit_price;
$cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
$cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
foreach ($cart_bk_data as $data_k => $data_v) {
//.........这里部分代码省略.........
示例4: processSubmitLogin
/**
* Process login
*/
protected function processSubmitLogin()
{
Hook::exec('actionBeforeAuthentication');
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
if (empty($email)) {
$this->errors[] = Tools::displayError('E-mail address required');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Invalid e-mail address');
} elseif (empty($passwd)) {
$this->errors[] = Tools::displayError('Password is required');
} elseif (!Validate::isPasswd($passwd)) {
$this->errors[] = Tools::displayError('Invalid password');
} else {
$customer = new Customer();
$authentication = $customer->getByEmail(trim($email), trim($passwd));
if (!$authentication || !$customer->id) {
$this->errors[] = Tools::displayError('Authentication failed');
} else {
$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)) {
$this->context->cookie->id_cart = (int) Cart::lastNoneOrderedCart($this->context->customer->id);
}
// Update cart address
$this->context->cart->id = $this->context->cookie->id_cart;
$this->context->cart->setDeliveryOption(null);
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
$this->context->cart->secure_key = $customer->secure_key;
$this->context->cart->update();
$this->context->cart->autosetProductAddress();
Hook::exec('actionAuthentication');
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
if (!$this->ajax) {
if ($back = Tools::getValue('back')) {
Tools::redirect(html_entity_decode($back));
}
Tools::redirect('index.php?controller=my-account');
}
}
}
if ($this->ajax) {
$return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false));
die(Tools::jsonEncode($return));
} else {
$this->context->smarty->assign('authentification_error', $this->errors);
}
}
示例5: processChangeProductInCart
/**
* This process add or update a product in the cart
*/
protected function processChangeProductInCart()
{
$mode = Tools::getIsset('update') && $this->id_product ? 'update' : 'add';
if (Tools::getIsset('group')) {
$this->id_product_attribute = (int) Product::getIdProductAttributesByIdAttributes($this->id_product, Tools::getValue('group'));
}
if ($this->qty == 0) {
$this->errors[] = $this->trans('Null quantity.', array(), 'Shop.Notifications.Error');
} elseif (!$this->id_product) {
$this->errors[] = $this->trans('Product not found', array(), 'Shop.Notifications.Error');
}
$product = new Product($this->id_product, true, $this->context->language->id);
if (!$product->id || !$product->active || !$product->checkAccess($this->context->cart->id_customer)) {
$this->errors[] = $this->trans('This product is no longer available.', array(), 'Shop.Notifications.Error');
return;
}
$qty_to_check = $this->qty;
$cart_products = $this->context->cart->getProducts();
if (is_array($cart_products)) {
foreach ($cart_products as $cart_product) {
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute && $cart_product['id_customization'] == $this->customization_id) && (isset($this->id_product) && $cart_product['id_product'] == $this->id_product)) {
$qty_to_check = $cart_product['cart_quantity'];
if (Tools::getValue('op', 'up') == 'down') {
$qty_to_check -= $this->qty;
} else {
$qty_to_check += $this->qty;
}
break;
}
}
}
// Check product quantity availability
if ($this->id_product_attribute) {
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = $this->trans('There isn\'t enough product in stock', array(), 'Shop.Notifications.Error');
}
} elseif ($product->hasAttributes()) {
$minimumQuantity = $product->out_of_stock == 2 ? !Configuration::get('PS_ORDER_OUT_OF_STOCK') : !$product->out_of_stock;
$this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimumQuantity);
// @todo do something better than a redirect admin !!
if (!$this->id_product_attribute) {
Tools::redirectAdmin($this->context->link->getProductLink($product));
} elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = $this->trans('There isn\'t enough product in stock', array(), 'Shop.Notifications.Error');
}
} elseif (!$product->checkQty($qty_to_check)) {
$this->errors[] = $this->trans('There isn\'t enough product in stock', array(), 'Shop.Notifications.Error');
}
// If no errors, process product addition
if (!$this->errors) {
// Add cart if no cart found
if (!$this->context->cart->id) {
if (Context::getContext()->cookie->id_guest) {
$guest = new Guest(Context::getContext()->cookie->id_guest);
$this->context->cart->mobile_theme = $guest->mobile_theme;
}
$this->context->cart->add();
if ($this->context->cart->id) {
$this->context->cookie->id_cart = (int) $this->context->cart->id;
}
}
// Check customizable fields
if (!$product->hasAllRequiredCustomizableFields() && !$this->customization_id) {
$this->errors[] = $this->trans('Please fill in all of the required fields, and then save your customizations.', array(), 'Shop.Notifications.Error');
}
if (!$this->errors) {
$cart_rules = $this->context->cart->getCartRules();
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart, false, true);
$update_quantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, Tools::getValue('op', 'up'), $this->id_address_delivery);
if ($update_quantity < 0) {
// If product has attribute, minimal quantity is set with minimal quantity of attribute
$minimal_quantity = $this->id_product_attribute ? Attribute::getAttributeMinimalQty($this->id_product_attribute) : $product->minimal_quantity;
$this->errors[] = $this->trans('You must add %d minimum quantity', array($minimal_quantity), 'Shop.Notifications.Error');
} elseif (!$update_quantity) {
$this->errors[] = $this->trans('You already have the maximum quantity available for this product.', array(), 'Shop.Notifications.Error');
}
}
}
$removed = CartRule::autoRemoveFromCart();
CartRule::autoAddToCart();
}
示例6: deleteProduct
/**
* Delete a product from the cart
*
* @param integer $id_product Product ID
* @param integer $id_product_attribute Attribute ID if needed
* @param integer $id_customization Customization id
* @return boolean result
*/
public function deleteProduct($id_product, $id_product_attribute = null, $id_customization = null, $id_address_delivery = 0)
{
if (isset(self::$_nbProducts[$this->id])) {
unset(self::$_nbProducts[$this->id]);
}
if (isset(self::$_totalWeight[$this->id])) {
unset(self::$_totalWeight[$this->id]);
}
if ((int) $id_customization) {
$product_total_quantity = (int) Db::getInstance()->getValue('SELECT `quantity`
FROM `' . _DB_PREFIX_ . 'cart_product`
WHERE `id_product` = ' . (int) $id_product . '
AND `id_cart` = ' . (int) $this->id . '
AND `id_product_attribute` = ' . (int) $id_product_attribute);
$customization_quantity = (int) Db::getInstance()->getValue('
SELECT `quantity`
FROM `' . _DB_PREFIX_ . 'customization`
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_product` = ' . (int) $id_product . '
AND `id_product_attribute` = ' . (int) $id_product_attribute . '
' . ((int) $id_address_delivery ? 'AND `id_address_delivery` = ' . (int) $id_address_delivery : ''));
if (!$this->_deleteCustomization((int) $id_customization, (int) $id_product, (int) $id_product_attribute, (int) $id_address_delivery)) {
return false;
}
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
return $customization_quantity == $product_total_quantity && $this->deleteProduct((int) $id_product, (int) $id_product_attribute, null, (int) $id_address_delivery);
}
/* Get customization quantity */
$result = Db::getInstance()->getRow('
SELECT SUM(`quantity`) AS \'quantity\'
FROM `' . _DB_PREFIX_ . 'customization`
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_product` = ' . (int) $id_product . '
AND `id_product_attribute` = ' . (int) $id_product_attribute);
if ($result === false) {
return false;
}
/* If the product still possesses customization it does not have to be deleted */
if (Db::getInstance()->NumRows() && (int) $result['quantity']) {
return Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `quantity` = ' . (int) $result['quantity'] . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_product` = ' . (int) $id_product . ($id_product_attribute != null ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : ''));
}
/* Product deletion */
$result = Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'cart_product`
WHERE `id_product` = ' . (int) $id_product . '
' . (!is_null($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
AND `id_cart` = ' . (int) $this->id . '
' . ((int) $id_address_delivery ? 'AND `id_address_delivery` = ' . (int) $id_address_delivery : ''));
if ($result) {
$return = $this->update(true);
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
CartRule::autoRemoveFromCart();
CartRule::autoAddToCart();
return $return;
}
return false;
}
示例7: _assignAddress
protected function _assignAddress()
{
//if guest checkout disabled and flag is_guest in cookies is actived
if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 && (int) $this->context->customer->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
$this->context->customer->logout();
Tools::redirect('');
} else {
if (!Customer::getAddressesTotalById($this->context->customer->id)) {
Tools::redirect('index.php?controller=address&back=' . urlencode('order.php?step=1&multi-shipping=' . (int) Tools::getValue('multi-shipping')));
}
}
$customer = $this->context->customer;
if (Validate::isLoadedObject($customer)) {
/* Getting customer addresses */
$customerAddresses = $customer->getAddresses($this->context->language->id);
// Getting a list of formated address fields with associated values
$formatedAddressFieldsValuesList = array();
foreach ($customerAddresses as $i => $address) {
if (!Address::isCountryActiveById((int) $address['id_address'])) {
unset($customerAddresses[$i]);
}
$tmpAddress = new Address($address['id_address']);
$formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']);
$formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues($tmpAddress, $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']);
unset($tmpAddress);
}
if (key($customerAddresses) != 0) {
$customerAddresses = array_values($customerAddresses);
}
if (!count($customerAddresses)) {
$bad_delivery = false;
if (($bad_delivery = (bool) (!Address::isCountryActiveById((int) $this->context->cart->id_address_delivery))) || !Address::isCountryActiveById((int) $this->context->cart->id_address_invoice)) {
$back_url = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, array('step' => Tools::getValue('step'), 'multi-shipping' => (int) Tools::getValue('multi-shipping')));
$params = array('multi-shipping' => (int) Tools::getValue('multi-shipping'), 'id_address' => $bad_delivery ? (int) $this->context->cart->id_address_delivery : (int) $this->context->cart->id_address_invoice, 'back' => $back_url);
Tools::redirect($this->context->link->getPageLink('address', true, (int) $this->context->language->id, $params));
}
}
$this->context->smarty->assign(array('addresses' => $customerAddresses, 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList));
/* Setting default addresses for cart */
if ((!isset($this->context->cart->id_address_delivery) || empty($this->context->cart->id_address_delivery)) && count($customerAddresses)) {
$this->context->cart->id_address_delivery = (int) $customerAddresses[0]['id_address'];
$update = 1;
}
if ((!isset($this->context->cart->id_address_invoice) || empty($this->context->cart->id_address_invoice)) && count($customerAddresses)) {
$this->context->cart->id_address_invoice = (int) $customerAddresses[0]['id_address'];
$update = 1;
}
/* Update cart addresses only if needed */
if (isset($update) && $update) {
$this->context->cart->update();
// Address has changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
}
/* If delivery address is valid in cart, assign it to Smarty */
if (isset($this->context->cart->id_address_delivery)) {
$deliveryAddress = new Address((int) $this->context->cart->id_address_delivery);
if (Validate::isLoadedObject($deliveryAddress) && $deliveryAddress->id_customer == $customer->id) {
$this->context->smarty->assign('delivery', $deliveryAddress);
}
}
/* If invoice address is valid in cart, assign it to Smarty */
if (isset($this->context->cart->id_address_invoice)) {
$invoiceAddress = new Address((int) $this->context->cart->id_address_invoice);
if (Validate::isLoadedObject($invoiceAddress) && $invoiceAddress->id_customer == $customer->id) {
$this->context->smarty->assign('invoice', $invoiceAddress);
}
}
}
if ($oldMessage = Message::getMessageByCartId((int) $this->context->cart->id)) {
$this->context->smarty->assign('oldMessage', $oldMessage['message']);
}
}
示例8: addData
public function addData($data, $add, $type)
{
$delivery = array();
$cart = new Cart();
if ($data->{$type}->currency == 'RUR') {
$currency_id = Currency::getIdByIsoCode('RUB');
} else {
$currency_id = Currency::getIdByIsoCode($data->cart->currency);
}
$def_currency = Configuration::get('PS_CURRENCY_DEFAULT');
$this->context->cookie->id_currency = $def_currency != $currency_id ? $currency_id : $def_currency;
$this->context->cookie->write();
$this->context->currency = new Currency($this->context->cookie->id_currency);
$cart->id_lang = (int) $this->context->cookie->id_lang;
$cart->id_currency = (int) $this->context->cookie->id_currency;
$cart->id_guest = (int) $this->context->cookie->id_guest;
$cart->add();
$this->context->cookie->id_cart = (int) $cart->id;
$this->context->cookie->write();
$buyer = isset($data->{$type}->buyer) ? $data->{$type}->buyer : '';
$b = array();
if ($add) {
$delivery = isset($data->{$type}->delivery->address) ? $data->{$type}->delivery->address : new stdClass();
$street = isset($delivery->street) ? ' Улица: ' . $delivery->street : 'Самовывоз';
$subway = isset($delivery->subway) ? ' Метро: ' . $delivery->subway : '';
$block = isset($delivery->block) ? ' Корпус/Строение: ' . $delivery->block : '';
$floor = isset($delivery->floor) ? ' Этаж: ' . $delivery->floor : '';
$house = isset($delivery->house) ? ' Дом: ' . $delivery->house : '';
$address1 = $street . $subway . $block . $floor . $house;
$customer = new Customer(Configuration::get('YA_POKUPKI_CUSTOMER'));
$address = new Address();
$address->firstname = $customer->firstname;
$address->lastname = $customer->lastname;
$address->phone_mobile = isset($buyer->phone) ? $buyer->phone : 999999;
$address->postcode = isset($delivery->postcode) ? $delivery->postcode : 00;
$address->address1 = $address1;
$address->city = isset($delivery->city) ? $delivery->city : 'Город';
$address->alias = 'pokupki_' . Tools::substr(md5(time() . _COOKIE_KEY_), 0, 7);
$address->id_customer = $customer->id;
$address->id_country = Configuration::get('PS_COUNTRY_DEFAULT');
$address->save();
$cart->id_address_invoice = (int) $address->id;
$cart->id_address_delivery = (int) $address->id;
$cart->update();
$cart->id_customer = (int) $customer->id;
$this->context->cookie->id_customer = (int) $customer->id;
$this->context->cookie->write();
$b = array('address' => $address, 'customer' => $customer);
}
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
$a = array('cart' => $cart);
$dd = array_merge($a, $b);
return $dd;
}
示例9: 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();
/* 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';
//.........这里部分代码省略.........
示例10: initContent
/**
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
$fb_connect_appid = Configuration::get('FB_CONNECT_APPID');
$fb_connect_appkey = Configuration::get('FB_CONNECT_APPKEY');
$this->login_url = $this->context->link->getModuleLink('fbconnect_psb', 'login', array(), TRUE, $this->context->language->id);
require_once _PS_ROOT_DIR_ . '/modules/fbconnect_psb/fb_sdk/facebook.php';
$facebook = new Facebook(array('appId' => $fb_connect_appid, 'secret' => $fb_connect_appkey));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$fb_user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
//die('Error: '.$e);
error_log($e);
$user = null;
}
} else {
// Get new Access tokens
Tools::redirect($facebook->getLoginUrl(array('scope' => 'email')));
}
// current user state Logged In with FB
if ($user) {
//get the user email from DB with FB ID
$sql = 'SELECT c.`email`
FROM `' . _DB_PREFIX_ . 'customer` c
LEFT JOIN `' . _DB_PREFIX_ . 'customer_profile_connect` pc ON pc.id_customer = c.id_customer
WHERE pc.`facebook_id` = ' . (int) $fb_user_profile['id'] . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
$email = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
if (empty($email)) {
Tools::redirect($this->context->link->getModuleLink('fbconnect_psb', 'registration', array(), TRUE, $this->context->language->id));
} else {
$customer = new Customer();
$authentication = $customer->getByEmail(trim($email));
if (!$authentication || !$customer->id) {
$this->errors[] = Tools::displayError('Error: 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 {
$this->context->cart->id_carrier = 0;
$this->context->cart->setDeliveryOption(null);
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
}
$this->context->cart->id_customer = (int) $customer->id;
$this->context->cart->secure_key = $customer->secure_key;
$this->context->cart->save();
$this->context->cookie->id_cart = (int) $this->context->cart->id;
$this->context->cookie->update();
$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 ($back = Tools::getValue('back')) {
Tools::redirect(html_entity_decode($back));
} else {
Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? url_encode($this->authRedirection) : 'my-account'));
}
}
}
$this->context->smarty->assign(array('redirect_uri' => urlencode($this->login_url), 'fb_connect_appid' => $fb_connect_appid, 'fb_connect_error' => $this->errors));
$this->setTemplate('login_fb.tpl');
} else {
if (isset($_GET['error']) && isset($_GET['error_code'])) {
$msg = 'There was error while trying to get information from Facebook.';
$msg .= '<br>' . $_GET['error'] . ' - ' . $_GET['error_code'] . ' - ' . $_GET['error_description'] . ' - ' . $_GET['error_reason'];
$this->errors[] = Tools::displayError($msg);
$this->setTemplate('login_fb.tpl');
} else {
Tools::redirect($facebook->getLoginUrl(array('scope' => 'email')));
}
}
}
示例11: processForm
protected function processForm()
{
if (Tools::getValue('action') == 'tryConnect') {
if (Tools::getValue('email') == $this->context->cookie->amzConnectEmail) {
$customer = new Customer();
$authentication = $customer->getByEmail(trim(Tools::getValue('email')), trim(Tools::getValue('passwd')));
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 {
$authentication->save();
AmazonPaymentsCustomerHelper::saveCustomersAmazonReference($authentication, $this->context->cookie->amzConnectCustomerId);
$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('toCheckout') == '1') {
$goto = $this->context->link->getModuleLink('amzpayments', 'amzpayments');
} elseif (Tools::getValue('fromCheckout') == '1') {
$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__;
}
}
Tools::redirect($goto);
}
}
}
}
示例12: processLogin
private function processLogin($customer)
{
if (!Validate::isLoadedObject($customer)) {
FSLTools::returnError(Tools::displayError('Bad customer object.'));
}
Hook::exec('actionBeforeAuthentication');
$context = $this->context;
$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 (isset($context->cart)) {
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 {
$id_carrier = (int) $context->cart->id_carrier;
$context->cart->id_carrier = 0;
$context->cart->setDeliveryOption(null);
$context->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
$context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
}
$context->cart->id_customer = (int) $customer->id;
$context->cart->secure_key = $customer->secure_key;
if (isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$delivery_option = array($context->cart->id_address_delivery => $id_carrier . ',');
$context->cart->setDeliveryOption($delivery_option);
}
$context->cart->save();
$context->cookie->id_cart = (int) $context->cart->id;
$context->cart->autosetProductAddress();
}
$context->cookie->write();
Hook::exec('actionAuthentication');
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($context);
CartRule::autoAddToCart($context);
}
示例13: _processCarrier
protected function _processCarrier()
{
$this->context->cart->recyclable = (int) Tools::getValue('recyclable');
$this->context->cart->gift = (int) Tools::getValue('gift');
if ((int) Tools::getValue('gift')) {
if (!Validate::isMessage(Tools::getValue('gift_message'))) {
$this->errors[] = Tools::displayError('Invalid gift message.');
} else {
$this->context->cart->gift_message = strip_tags(Tools::getValue('gift_message'));
}
}
if (isset($this->context->customer->id) && $this->context->customer->id) {
$address = new Address((int) $this->context->cart->id_address_delivery);
if (!Address::getZoneById($address->id)) {
$this->errors[] = Tools::displayError('No zone matches your address.');
}
} else {
Country::getIdZone((int) Configuration::get('PS_COUNTRY_DEFAULT'));
}
if (Tools::getIsset('delivery_option')) {
if ($this->validateDeliveryOption(Tools::getValue('delivery_option'))) {
$this->context->cart->setDeliveryOption(Tools::getValue('delivery_option'));
}
} elseif (Tools::getIsset('id_carrier')) {
$delivery_option_list = $this->context->cart->getDeliveryOptionList();
if (count($delivery_option_list) == 1) {
reset($delivery_option_list);
$key = Cart::desintifier(Tools::getValue('id_carrier'));
foreach ($delivery_option_list as $id_address => $options) {
if (isset($options[$key])) {
$this->context->cart->id_carrier = (int) Tools::getValue('id_carrier');
$this->context->cart->setDeliveryOption(array($id_address => $key));
if (isset($this->context->cookie->id_country)) {
unset($this->context->cookie->id_country);
}
if (isset($this->context->cookie->id_state)) {
unset($this->context->cookie->id_state);
}
}
}
}
}
Hook::exec('actionCarrierProcess', array('cart' => $this->context->cart));
if (!$this->context->cart->update()) {
return false;
}
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
return true;
}
示例14: processSubmitLogin
/**
* Process login
*/
protected function processSubmitLogin()
{
Hook::exec('actionBeforeAuthentication');
$passwd = trim(Tools::getValue('passwd'));
$_POST['passwd'] = null;
$email = trim(Tools::getValue('email'));
if (empty($email)) {
$this->errors[] = Tools::displayError('An email address required.');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Invalid email address.');
} elseif (empty($passwd)) {
$this->errors[] = Tools::displayError('Password is required.');
} elseif (!Validate::isPasswd($passwd)) {
$this->errors[] = Tools::displayError('Invalid password.');
} else {
$customer = new Customer();
$authentication = $customer->getByEmail(trim($email), trim($passwd));
if (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', array('customer' => $this->context->customer));
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
if (!$this->ajax) {
$back = Tools::getValue('back', 'my-account');
if ($back == Tools::secureReferrer($back)) {
Tools::redirect(html_entity_decode($back));
}
Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : $back));
}
}
}
if ($this->ajax) {
$return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false));
$this->ajaxDie(Tools::jsonEncode($return));
} else {
$this->context->smarty->assign('authentification_error', $this->errors);
}
}
示例15: processAddress
/**
* Manage address
*/
public function processAddress()
{
$same = Tools::isSubmit('same');
if (!Tools::getValue('id_address_invoice', false) && !$same) {
$same = true;
}
if (!Customer::customerHasAddress($this->context->customer->id, (int) Tools::getValue('id_address_delivery')) || !$same && Tools::getValue('id_address_delivery') != Tools::getValue('id_address_invoice') && !Customer::customerHasAddress($this->context->customer->id, (int) Tools::getValue('id_address_invoice'))) {
$this->errors[] = Tools::displayError('Invalid address', !Tools::getValue('ajax'));
} else {
$this->context->cart->id_address_delivery = (int) Tools::getValue('id_address_delivery');
$this->context->cart->id_address_invoice = $same ? $this->context->cart->id_address_delivery : (int) Tools::getValue('id_address_invoice');
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
if (!$this->context->cart->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating your cart.', !Tools::getValue('ajax'));
}
if (!$this->context->cart->isMultiAddressDelivery()) {
$this->context->cart->setNoMultishipping();
}
// If there is only one delivery address, set each delivery address lines with the main delivery address
if (Tools::isSubmit('message')) {
$this->_updateMessage(Tools::getValue('message'));
}
// Add checking for all addresses
$errors = array();
$address_without_carriers = $this->context->cart->getDeliveryAddressesWithoutCarriers(false, $errors);
if (count($address_without_carriers) && !$this->context->cart->isVirtualCart()) {
$flag_error_message = false;
foreach ($errors as $error) {
if ($error == Carrier::SHIPPING_WEIGHT_EXCEPTION && !$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s): it is too heavy. Please amend your cart to lower its weight.', !Tools::getValue('ajax')));
$flag_error_message = true;
} elseif ($error == Carrier::SHIPPING_PRICE_EXCEPTION && !$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s). Please amend your cart.', !Tools::getValue('ajax')));
$flag_error_message = true;
} elseif ($error == Carrier::SHIPPING_SIZE_EXCEPTION && !$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s): its size does not fit. Please amend your cart to reduce its size.', !Tools::getValue('ajax')));
$flag_error_message = true;
}
}
if (count($address_without_carriers) > 1 && !$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to some addresses you selected.', !Tools::getValue('ajax')));
} elseif ($this->context->cart->isMultiAddressDelivery() && !$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to one of the address you selected.', !Tools::getValue('ajax')));
} elseif (!$flag_error_message) {
$this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to the address you selected.', !Tools::getValue('ajax')));
}
}
}
if ($this->errors) {
if (Tools::getValue('ajax')) {
$this->ajaxDie('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
}
$this->step = 1;
}
if ($this->ajax) {
$this->ajaxDie(true);
}
}