// Context part 18

This commit is contained in:
tDidierjean
2011-07-25 15:19:39 +00:00
parent 9b0b588b09
commit 2c4f27f1be
41 changed files with 611 additions and 638 deletions
+64 -71
View File
@@ -35,10 +35,10 @@ class OrderOpcControllerCore extends ParentOrderController
{
parent::preProcess();
if ($this->nbProducts)
self::$smarty->assign('virtual_cart', false);
$this->isLogged = (bool)((int)(self::$cookie->id_customer) AND Customer::customerIdExistsStatic((int)(self::$cookie->id_customer)));
$this->context->smarty->assign('virtual_cart', false);
$this->isLogged = (bool)($this->context->customer->id AND Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer)));
if (self::$cart->nbProducts())
if ($this->context->cart->nbProducts())
{
if (Tools::isSubmit('ajax'))
{
@@ -62,7 +62,7 @@ class OrderOpcControllerCore extends ParentOrderController
if ($this->_processCarrier())
{
$return = array(
'summary' => self::$cart->getSummaryDetails(),
'summary' => $this->context->cart->getSummaryDetails(),
'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'),
'HOOK_PAYMENT' => $this->_getPaymentMethods()
);
@@ -78,7 +78,7 @@ class OrderOpcControllerCore extends ParentOrderController
case 'updateTOSStatusAndGetPayments':
if (Tools::isSubmit('checked'))
{
self::$cookie->checkedTOS = (int)(Tools::getValue('checked'));
$this->context->cookie->checkedTOS = (int)(Tools::getValue('checked'));
die(Tools::jsonEncode(array(
'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'),
'HOOK_PAYMENT' => $this->_getPaymentMethods()
@@ -91,18 +91,17 @@ class OrderOpcControllerCore extends ParentOrderController
case 'editCustomer':
if (!$this->isLogged)
exit;
$customer = new Customer((int)self::$cookie->id_customer);
if (Tools::getValue('years'))
$customer->birthday = (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days');
$this->context->customer->birthday = (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days');
$_POST['lastname'] = $_POST['customer_lastname'];
$_POST['firstname'] = $_POST['customer_firstname'];
$this->errors = $customer->validateControler();
$customer->newsletter = (int)Tools::isSubmit('newsletter');
$customer->optin = (int)Tools::isSubmit('optin');
$this->errors = $this->context->customer->validateControler();
$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)self::$cookie->id_customer,
'id_customer' => (int)$this->context->customer->id,
'token' => Tools::getToken(false)
);
if (!sizeof($this->errors))
@@ -112,17 +111,17 @@ class OrderOpcControllerCore extends ParentOrderController
die(Tools::jsonEncode($return));
break;
case 'getAddressBlockAndCarriersAndPayments':
if (self::$cookie->isLogged())
if ($this->context->customer->isLogged())
{
// check if customer have addresses
if (!Customer::getAddressesTotalById((int)(self::$cookie->id_customer)))
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();
}
self::$smarty->assign('isVirtualCart', self::$cart->isVirtualCart());
$this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
$this->_processAddressFormat();
$this->_assignAddress();
// Wrapping fees
@@ -130,14 +129,14 @@ class OrderOpcControllerCore extends ParentOrderController
$wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX')));
$wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100)));
$return = array(
'summary' => self::$cart->getSummaryDetails(),
'order_opc_adress' => self::$smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'),
'summary' => $this->context->cart->getSummaryDetails(),
'order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'),
'block_user_info' => (isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : ''),
'carrier_list' => $this->_getCarrierList(),
'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'),
'HOOK_PAYMENT' => $this->_getPaymentMethods(),
'no_address' => 0,
'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency))))
'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency))))
);
die(Tools::jsonEncode($return));
}
@@ -147,21 +146,21 @@ class OrderOpcControllerCore extends ParentOrderController
/* Bypass payment step if total is 0 */
if (($id_order = $this->_checkFreeOrder()) AND $id_order)
{
$email = self::$cookie->email;
if (self::$cookie->is_guest)
self::$cookie->logout(); // If guest we clear the cookie for security reason
$email = $this->context->customer->email;
if ($this->context->customer->is_guest)
$this->context->cookie->logout(); // If guest we clear the cookie for security reason
die('freeorder:'.$id_order.':'.$email);
}
exit;
break;
case 'updateAddressesSelected':
if (self::$cookie->isLogged(true))
if ($this->context->cookie->isLogged(true))
{
$id_address_delivery = (int)(Tools::getValue('id_address_delivery'));
$id_address_invoice = (int)(Tools::getValue('id_address_invoice'));
$address_delivery = new Address((int)(Tools::getValue('id_address_delivery')));
$address_invoice = ((int)(Tools::getValue('id_address_delivery')) == (int)(Tools::getValue('id_address_invoice')) ? $address_delivery : new Address((int)(Tools::getValue('id_address_invoice'))));
if ($address_delivery->id_customer != self::$cookie->id_customer || $address_invoice->id_customer != self::$cookie->id_customer)
if ($address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id)
$this->errors[] = Tools::displayError('This address is not yours.');
elseif (!Address::isCountryActiveById((int)(Tools::getValue('id_address_delivery'))))
$this->errors[] = Tools::displayError('This address is not in a valid area.');
@@ -169,18 +168,15 @@ class OrderOpcControllerCore extends ParentOrderController
$this->errors[] = Tools::displayError('This address is invalid.');
else
{
self::$cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery'));
self::$cart->id_address_invoice = Tools::isSubmit('same') ? self::$cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice'));
if (!self::$cart->update())
$this->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.');
if (!sizeof($this->errors))
{
if (self::$cookie->id_customer)
{
$customer = new Customer((int)(self::$cookie->id_customer));
$groups = $customer->getGroups();
}
if ($this->context->customer->id)
$groups = $this->context->customer->getGroups();
else
$groups = array(1);
$result = $this->_getCarrierList();
@@ -189,10 +185,10 @@ class OrderOpcControllerCore extends ParentOrderController
$wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX')));
$wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100)));
$result = array_merge($result, array(
'summary' => self::$cart->getSummaryDetails(),
'summary' => $this->context->cart->getSummaryDetails(),
'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'),
'HOOK_PAYMENT' => $this->_getPaymentMethods(),
'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency))))
'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency))))
));
die(Tools::jsonEncode($result));
}
@@ -233,10 +229,10 @@ class OrderOpcControllerCore extends ParentOrderController
$this->_assignWrappingAndTOS();
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
$countries = Country::getCountries((int)(self::$cookie->id_lang), true);
self::$smarty->assign(array(
$countries = Country::getCountries($this->context->language->id, true);
$this->context->smarty->assign(array(
'isLogged' => $this->isLogged,
'isGuest' => isset(self::$cookie->is_guest) ? self::$cookie->is_guest : 0,
'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0,
'countries' => $countries,
'sl_country' => isset($selectedCountry) ? $selectedCountry : 0,
'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'),
@@ -247,15 +243,15 @@ class OrderOpcControllerCore extends ParentOrderController
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
self::$smarty->assign(array(
$this->context->smarty->assign(array(
'years' => $years,
'months' => $months,
'days' => $days,
));
/* Load guest informations */
if ($this->isLogged AND self::$cookie->is_guest)
self::$smarty->assign('guestInformations', $this->_getGuestInformations());
if ($this->isLogged AND $this->context->cookie->is_guest)
$this->context->smarty->assign('guestInformations', $this->_getGuestInformations());
if ($this->isLogged)
$this->_assignAddress(); // ADDRESS
@@ -265,7 +261,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->_assignPayment();
Tools::safePostVars();
self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
}
public function displayHeader()
@@ -279,7 +275,7 @@ class OrderOpcControllerCore extends ParentOrderController
parent::displayContent();
$this->_processAddressFormat();
self::$smarty->display(_PS_THEME_DIR_.'order-opc.tpl');
$this->context->smarty->display(_PS_THEME_DIR_.'order-opc.tpl');
}
public function displayFooter()
@@ -290,8 +286,8 @@ class OrderOpcControllerCore extends ParentOrderController
protected function _getGuestInformations()
{
$customer = new Customer((int)(self::$cookie->id_customer));
$address_delivery = new Address((int)self::$cart->id_address_delivery);
$customer = $this->context->customer;
$address_delivery = new Address($this->context->cart->id_address_delivery);
if ($customer->birthday)
$birthday = explode('-', $customer->birthday);
@@ -299,13 +295,13 @@ class OrderOpcControllerCore extends ParentOrderController
$birthday = array('0', '0', '0');
return array(
'id_customer' => (int)(self::$cookie->id_customer),
'id_customer' => (int)$customer->id,
'email' => Tools::htmlentitiesUTF8($customer->email),
'customer_lastname' => Tools::htmlentitiesUTF8($customer->lastname),
'customer_firstname' => Tools::htmlentitiesUTF8($customer->firstname),
'newsletter' => (int)$customer->newsletter,
'optin' => (int)$customer->optin,
'id_address_delivery' => (int)self::$cart->id_address_delivery,
'id_address_delivery' => (int)$this->context->cart->id_address_delivery,
'company' => Tools::htmlentitiesUTF8($address_delivery->company),
'lastname' => Tools::htmlentitiesUTF8($address_delivery->lastname),
'firstname' => Tools::htmlentitiesUTF8($address_delivery->firstname),
@@ -330,7 +326,7 @@ class OrderOpcControllerCore extends ParentOrderController
if (!$this->isLogged)
{
$carriers = Carrier::getCarriersForOrder(Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT')));
self::$smarty->assign(array(
$this->context->smarty->assign(array(
'checked' => $this->_setDefaultCarrierSelection($carriers),
'carriers' => $carriers,
'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT')),
@@ -344,7 +340,7 @@ class OrderOpcControllerCore extends ParentOrderController
protected function _assignPayment()
{
self::$smarty->assign(array(
$this->context->smarty->assign(array(
'HOOK_TOP_PAYMENT' => ($this->isLogged ? Module::hookExec('paymentTop') : ''),
'HOOK_PAYMENT' => $this->_getPaymentMethods()
));
@@ -354,41 +350,41 @@ class OrderOpcControllerCore extends ParentOrderController
{
if (!$this->isLogged)
return '<p class="warning">'.Tools::displayError('Please sign in to see payment methods').'</p>';
if (self::$cart->OrderExists())
if ($this->context->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))
if (!$this->context->cart->id_customer OR !Customer::customerIdExistsStatic($this->context->cart->id_customer) OR Customer::isBanned($this->context->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)
$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 OR !$this->context->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())
if (!$this->context->cart->id_carrier AND !$this->context->cart->isVirtualCart())
return '<p class="warning">'.Tools::displayError('Error: please choose a carrier').'</p>';
elseif (self::$cart->id_carrier != 0)
elseif ($this->context->cart->id_carrier != 0)
{
$carrier = new Carrier((int)(self::$cart->id_carrier));
$carrier = new Carrier((int)($this->context->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)
if (!$this->context->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'))
if (!$this->context->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())
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)self::$cart->id_currency);
$currency = Currency::getCurrency((int)$this->context->cart->id_currency);
$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
if (self::$cart->getOrderTotal(false) < $minimalPurchase)
if ($this->context->cart->getOrderTotal(false) < $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)
if ($this->context->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();
@@ -399,15 +395,12 @@ class OrderOpcControllerCore extends ParentOrderController
protected function _getCarrierList()
{
$address_delivery = new Address(self::$cart->id_address_delivery);
if (self::$cookie->id_customer)
{
$customer = new Customer((int)(self::$cookie->id_customer));
$groups = $customer->getGroups();
}
$address_delivery = new Address($this->context->cart->id_address_delivery);
if ($this->context->customer->id)
$groups = $this->context->customer->getGroups();
else
$groups = array(1);
if (!Address::isCountryActiveById((int)(self::$cart->id_address_delivery)))
if (!Address::isCountryActiveById((int)($this->context->cart->id_address_delivery)))
$this->errors[] = Tools::displayError('This address is not in a valid area.');
elseif (!Validate::isLoadedObject($address_delivery) OR $address_delivery->deleted)
$this->errors[] = Tools::displayError('This address is invalid.');
@@ -433,8 +426,8 @@ class OrderOpcControllerCore extends ParentOrderController
{
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
$address_delivery = new Address((int)self::$cart->id_address_delivery);
$address_invoice = new Address((int)self::$cart->id_address_invoice);
$address_delivery = new Address((int)$this->context->cart->id_address_delivery);
$address_invoice = new Address((int)$this->context->cart->id_address_invoice);
$inv_adr_fields = AddressFormat::getOrderedAddressFields((int)$address_delivery->id_country);
$dlv_adr_fields = AddressFormat::getOrderedAddressFields((int)$address_invoice->id_country);
@@ -448,8 +441,8 @@ class OrderOpcControllerCore extends ParentOrderController
foreach(explode(' ',$fields_line) as $field_item)
${$adr_type.'_all_fields'}[] = trim($field_item);
self::$smarty->assign($adr_type.'_adr_fields', ${$adr_type.'_adr_fields'});
self::$smarty->assign($adr_type.'_all_fields', ${$adr_type.'_all_fields'});
$this->context->smarty->assign($adr_type.'_adr_fields', ${$adr_type.'_adr_fields'});
$this->context->smarty->assign($adr_type.'_all_fields', ${$adr_type.'_all_fields'});
}
}