public function initialize() { parent::initialize(); $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); // Get address ID $address_id = 0; $type = $app->input->get('type'); if ($this->use_ajax && isset($type)) { if ($type == 'delivery' && isset($context->cart->address_delivery_id)) { $address_id = (int) $context->cart->address_delivery_id; } else { if ($type == 'invoice' && isset($context->cart->address_invoice_id) && $context->cart->id_address_invoice != $context->cart->address_delivery_id) { $address_id = (int) $context->cart->address_invoice_id; } } } else { $address_id = (int) $app->input->get('address_id', 0); } // Initialize address if ($address_id) { $address = new JeproshopAddressModelAddress($address_id); $view = $app->input->get('view'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); if (JeproshopTools::isLoadedObject($address, 'address_id') && JeproshopCustomerModelCustomer::customerHasAddress($context->customer->customer_id, $address_id)) { $task = $app->input->get('task'); if (isset($task) && $task == 'delete') { if ($address->delete()) { if ($context->cart->address_invoice_id == $address->address_id) { unset($context->cart->address_invoice_id); } if ($context->cart->id_address_delivery == $address->address_id) { unset($context->cart->id_address_delivery); $context->cart->updateAddressId($address->address_id, (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($context->customer->customer_id)); } $app->redirect('index.php?option=com_jeproshop&view=address'); } $this->has_errors = true; JError::raiseError(500, 'This address cannot be deleted.'); } } elseif ($this->use_ajax) { $app->close; } else { $app->redirect('index.php?option=com_jeproshop&view=address'); } } }
/** * Update product quantity * * @param integer $quantity Quantity to add (or substract) * @param $product_id * @param null $product_attribute_id * @param bool $customization_id * @param string $operator Indicate if quantity must be increased or decreased * @param int $address_delivery_id * @param JeproshopShopModelShop $shop * @param bool $auto_add_cart_rule * @return bool|int * @internal param int $id_product Product ID * @internal param int $id_product_attribute Attribute ID if needed */ public function updateQuantity($quantity, $product_id, $product_attribute_id = null, $customization_id = false, $operator = 'up', $address_delivery_id = 0, JeproshopShopModelShop $shop = null, $auto_add_cart_rule = true) { if (!$shop) { $shop = JeproshopContext::getContext()->shop; } $db = JFactory::getDBO(); if (JeproshopContext::getContext()->customer->customer_id) { if ($address_delivery_id == 0 && (int) $this->address_delivery_id) { // The $id_address_delivery is null, use the cart delivery address $address_delivery_id = $this->address_delivery_id; } elseif ($address_delivery_id == 0) { // The $id_address_delivery is null, get the default customer address $address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) JeproshopContext::getContext()->customer->customer_id); } elseif (!JeproshopCustomerModelCustomer::customerHasAddress(JeproshopContext::getContext()->customer->customer_id, $address_delivery_id)) { // The $id_address_delivery must be linked with customer $address_delivery_id = 0; } } $quantity = (int) $quantity; $product_id = (int) $product_id; $product_attribute_id = (int) $product_attribute_id; $product = new JeproshopProductModelProduct($product_id, false, JeproshopSettingModelSetting::getValue('default_lang'), $shop->shop_id); if ($product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $product_attribute_id); if ($combination->product_id != $product_id) { return false; } } /* If we have a product combination, the minimal quantity is set with the one of this combination */ if (!empty($product_attribute_id)) { $minimal_quantity = (int) JeproshopAttributeModelAttribute::getAttributeMinimalQty($product_attribute_id); } else { $minimal_quantity = (int) $product->minimal_quantity; } if (!JeproshopValidator::isLoadedObject($product, 'product_id')) { die(Tools::displayError()); } if (isset(self::$_nbProducts[$this->cart_id])) { unset(self::$_nbProducts[$this->cart_id]); } if (isset(self::$_totalWeight[$this->cart_id])) { unset(self::$_totalWeight[$this->cart_id]); } if ((int) $quantity <= 0) { return $this->deleteProduct($product_id, $product_attribute_id, (int) $customization_id); } elseif (!$product->available_for_order || JeproshopSettingModelSeting::getValue('catalog_mode')) { return false; } else { /* Check if the product is already in the cart */ $result = $this->containsProduct($product_id, $product_attribute_id, (int) $customization_id, (int) $address_delivery_id); /* Update quantity if product already exist */ if ($result) { if ($operator == 'up') { $query = "SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity FROM " . $db->quoteName('#__jeproshop_product') . " AS product" . JeproshopProductModelProduct::sqlStock('p', $product_attribute_id, true, $shop); $query .= " WHERE product.product_id = " . $product_id; $db->setQuery($query); $result2 = $db->loadObject(); $product_qty = (int) $result2->quantity; // Quantity for product pack if (JeproshopProductPack::isPack($product_id)) { $product_qty = JeproshopProductPack::getQuantity($product_id, $product_attribute_id); } $new_qty = (int) $result->quantity + (int) $quantity; $qty = '+ ' . (int) $quantity; if (!JeproshopProductModelProduct::isAvailableWhenOutOfStock((int) $result2->out_of_stock)) { if ($new_qty > $product_qty) { return false; } } } else { if ($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) $product_id, (int) $product_attribute_id, (int) $customization_id); } else { if ($new_qty < $minimal_quantity) { return -1; } else { $query = "UPDATE " . $db->quoteName('#__jeproshop_cart_product') . " SET " . $db->quoteName('quantity') . " = " . $db->quoteName('quantity') . $qty . ", "; $query .= $db->quoteName('date_add') . " = NOW() WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id; $query .= (!empty($product_attribute_id) ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : "") . " AND " . $db->quoteName('cart_id') . " = " . (int) $this->cart_id; $query .= (JeproshopSettingModelSeting::getValue('allow_multi_shipping') && $this->isMultiAddressDelivery() ? " AND " . $db->quoteName('address_delivery_id') . " = " . (int) $address_delivery_id : "") . " LIMIT 1"; $db->setQuery($query); $db->query(); } } } elseif ($operator == 'up') { $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity FROM ' . _DB_PREFIX_ . 'product p ' . Product::sqlStock('p', $product_attribute_id, true, $shop) . ' WHERE p.id_product = ' . $product_id; $result2 = Db::getInstance()->getRow($sql); // Quantity for product pack if (Pack::isPack($product_id)) { $result2['quantity'] = Pack::getQuantity($product_id, $product_attribute_id); } if (!Product::isAvailableWhenOutOfStock((int) $result2['out_of_stock'])) { if ((int) $quantity > $result2['quantity']) { return false; } } if ((int) $quantity < $minimal_quantity) { return -1; } $result_add = Db::getInstance()->insert('cart_product', array('id_product' => (int) $product_id, 'id_product_attribute' => (int) $product_attribute_id, 'id_cart' => (int) $this->cart_id, 'id_address_delivery' => (int) $address_delivery_id, 'id_shop' => $shop->shop_id, 'quantity' => (int) $quantity, 'date_add' => date('Y-m-d H:i:s'))); if (!$result_add) { return false; } } } // refresh cache of self::_products $this->_products = $this->getProducts(true); $this->update(true); $context = Context::getContext()->cloneContext(); $context->cart = $this; Cache::clean('getContextualValue_*'); if ($auto_add_cart_rule) { CartRule::autoAddToCart($context); } if ($product->customizable) { return $this->updateCustomizationQuantity((int) $quantity, (int) $customization_id, (int) $product_id, (int) $product_attribute_id, (int) $address_delivery_id, $operator); } else { return true; } }
/** * Process submit on an account */ public function register() { $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); $view = $app->input->get('view'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); $input = JRequest::get('get'); $jsonData = array("success" => true); $errors = array(); $task = $app->input->get('task'); if (isset($task) && $task == 'register') { $emailCreate = 1; $viewClass->assign('email_create', 1); } $isNewCustomer = isset($input['is_new_customer']) ? 1 : 0; if (!$isNewCustomer && !JeproshopSettingModelSetting::getValue('enable_guest_checkout')) { $this->has_errors = true; $errors[] = JText::_('You cannot create a guest account..'); } $guestEmail = isset($input['guest_email']) ? $input['guest_email'] : ''; $email = isset($input['email']) ? $input['email'] : ''; if (isset($guestEmail) && $guestEmail) { $email = $guestEmail; } // Checked the user address in case he changed his email address if (JeproshopTools::isEmail($email) && !empty($email)) { if (JeproshopCustomerModelCustomer::customerExists($email)) { $this->has_errors = true; $errors[] = JText::_('An account using this email address has already been registered.'); //, false); } } // Preparing customer $customer = new JeproshopCustomerModelCustomer(); $lastNameAddress = isset($input['lastname']) ? $input['lastname'] : ''; $firstNameAddress = isset($input['firstname']) ? $input['firstname'] : ''; $lastname = isset($input['customer_lastname']) ? $input['customer_lastname'] : $lastNameAddress; $firstname = isset($input['customer_firstname']) ? $input['customer_firstname'] : $firstNameAddress; $addresses_types = array('address'); $inputInvoiceAddress = isset($input['invoice_address']) ? $input['invoice_address'] : 0; if (JeproshopSettingModelSetting::getValue('order_process_type') == 'standard' && JeproshopSettingModelSetting::getValue('enable_guest_checkout') && $inputInvoiceAddress) { $addresses_types[] = 'invoice_address'; } $error_phone = false; $phone = isset($input['phone']) ? $input['phone'] : null; $phone_mobile = isset($input['phone_mobile']) ? $input['phone_mobile'] : null; if (JeproshopSettingModelSetting::getValue('one_phone_at_least')) { if ($task == 'submitGuestAccount' || !$isNewCustomer) { if (!$phone && !$phone_mobile) { $error_phone = true; } } elseif ((JeproshopSettingModelSetting::getValue('registration_process_type') != 'account_only' && JeproshopSettingModelSetting::getValue('order_process_type') != 'standard' || JeproshopSettingModelSetting::getValue('order_process_type') != 'standard' && !$viewClass->email_create || JeproshopSettingModelSetting::getValue('registration_process_type') != 'account_only' && $viewClass->email_create) && (!$phone && !$phone_mobile)) { $error_phone = true; } } if ($error_phone) { $this->has_errors = true; $errors[] = JText::_('You must register at least one phone number.'); } $errors = array_unique(array_merge($errors, $customer->validateController())); if (JeproshopSettingModelSetting::getValue('registration_process_type') == 'account_only' && !$this->use_ajax && !Tools::isSubmit('submitGuestAccount')) { if (!$this->has_errors) { if (isset($input['newsletter']) && $input['newsletter']) { $this->processCustomerNewsletter($customer); } $customer->firstname = JeproshopTools::ucwords($customer->firstname); $customer->birthday = empty($input['year']) ? '' : (int) $input['year'] . '-' . (int) $input['month'] . '-' . (int) $input['day']; if (!JeproshopTools::isBirthDate($customer->birthday)) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth.'); } // New Guest customer $customer->is_guest = isset($isNewCustomer) ? !$isNewCustomer : 0; $customer->published = 1; if (!$this->has_errors) { if ($customer->add()) { if (!$customer->is_guest) { if (!$this->sendConfirmationMail($customer)) { $this->has_errors = true; $errors[] = JText::_('The email cannot be sent.'); } } $this->updateContext($customer); $context->cart->update(); Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => true, 'customer_id' => (int) $context->cookie->customer_id, 'delivery_address_id' => $context->cart->delivery_address_id, 'invoice_address_id' => $context->cart->invoice_address_id, 'token' => Tools::getToken(false)); echo json_encode($return); $app->close(); } if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { $app->redirect(html_entity_decode($back)); } // redirection: if cart is not empty : redirection to the cart if (count($context->cart->getProducts(true)) > 0) { $app->redirect('index.php?option=com_jeproshop&view=order&multi-shipping=' . (int) Tools::getValue('multi-shipping')); } else { Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : 'my-account')); } } else { $this->has_errors = true; JText::_('An error occurred while creating your account.'); } } } } else { // if registration type is in one step, we save the address $input['lastname'] = $lastNameAddress; $input['firstname'] = $firstNameAddress; $post_back = $_POST; // Preparing addresses foreach ($addresses_types as $addresses_type) { $address_type = new JeproshopAddressModelAddress(); $address_type->customer_id = 1; if ($addresses_type == 'invoice_address') { foreach ($input as $key => &$post) { if (isset($input['invoice_' . $key])) { $post = $input['invoice_' . $key]; } } } $this->has_errors = true; $errors = array_unique(array_merge($errors, $address_type->validateController())); if ($addresses_type == 'invoice_address') { $_POST = $post_back; } if (!($country = new JeproshopCountryModelCountry($address_type->country_id)) || !JeproshopTools::isLoadedObject($country, 'country_id')) { $this->has_errors = true; $errors[] = JText::_('Country cannot be loaded with address->id_country'); } if (!$country->published) { $this->has_errors = true; $errors[] = JText::_('This country is not active.'); } $postcode = isset($input['postcode']) ? $input['postcode'] : ''; /* Check zip code format */ if ($country->zip_code_format && !$country->checkZipCode($postcode)) { $this->has_errors = true; $errors[] = JText::_('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'); //, str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)))); } elseif (empty($postcode) && $country->need_zip_code) { $this->has_errors = true; $errors[] = JText::_('A Zip / Postal code is required.'); } elseif ($postcode && !JeproshopTools::isPostCode($postcode)) { $this->has_errors = true; $errors[] = JText::_('The Zip / Postal code is invalid.'); } $identificationNumber = isset($input['dni']) ? $input['dni'] : ''; if ($country->need_identification_number && (!$identificationNumber || !JeproshopTools::isDniLite($identificationNumber))) { $this->has_errors = true; $errors[] = JText::_('The identification number is incorrect or has already been used.'); } elseif (!$country->need_identification_number) { $address_type->dni = null; } if ($task == 'register' || $task == 'submitGuestAccount') { if (!($country = new JeproshopCountryModelCountry($address_type->country_id, JeproshopSettingModelSetting::getValue('default_lang'))) || !JeproshopTools::isLoadedObject($country, 'country_id')) { $this->has_errors = true; $errors[] = JText::_('Country is invalid'); } } $contains_state = isset($country) && is_object($country) ? (int) $country->contains_states : 0; $state_id = isset($address_type) && is_object($address_type) ? (int) $address_type->state_id : 0; if (($task == 'register' || $task == 'submitGuestAccount') && $contains_state && !$state_id) { $this->has_errors = true; $errors[] = JText::_('This country requires you to choose a State.'); } } } $days = isset($input['day']) ? $input['day'] : ''; $months = isset($input['month']) ? $input['month'] : ''; $years = isset($input['year']) ? $input['year'] : ''; if (!@checkdate($months, $days, $years) && !($months == '' && $days == '' && $years == '')) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth'); } if ($this->has_errors) { //todo set negation $email = isset($input['email']) ? $input['email'] : ''; if (JeproshopCustomerModelCustomer::customerExists($email)) { $this->has_errors = true; $errors[] = JText::_('An account using this email address has already been registered. Please enter a valid password or request a new one. '); } if (isset($input['newsletter'])) { $this->processCustomerNewsletter($customer); } $customer->birthday = empty($years) ? '' : (int) $years . '-' . (int) $months . '-' . (int) $days; if (!JeproshopTools::isBirthDate($customer->birthday)) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth'); } echo $input['passwd'] . ' on line ' . __LINE__; if ($this->has_errors) { //todo reset negation $customer->published = 1; // New Guest customer if (isset($isNewCustomer)) { $customer->is_guest = !$isNewCustomer ? 1 : 0; } else { $customer->is_guest = 0; } if (!$customer->add()) { $this->has_errors = true; $errors[] = JText::_('An error occurred while creating your account.'); } else { foreach ($addresses_types as $addresses_type) { $address_type->customer_id = (int) $customer->customer_id; if ($addresses_type == 'invoice_address') { foreach ($input as $key => &$post) { if (isset($input['invoice_' . $key])) { $post = $input['invoice_' . $key]; } } } $errors = array_unique(array_merge($errors, $address_type->validateController())); if ($address_type == 'invoice_address') { $input = $post_back; } if (!$this->has_errors && (JeproshopSettingModelSetting::getValue('registration_process_type') || $this->use_ajax || $task == 'submitGuestAccount') && !$address_type->add()) { $this->has_errors = true; $errors[] = JText::_('An error occurred while creating your address.'); } } if (!$this->has_errors) { if (!$customer->is_guest) { $context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int) JeproshopSettingModelSetting::getValue('customer_group'))); if (!$this->sendConfirmationMail($customer)) { $this->has_errors = true; } $errors[] = JText::_('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int) JeproshopSettingModelSetting::getValue('guest_group'))); } $this->updateContext($customer); $context->cart->delivery_address_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) $customer->customer_id); $context->cart->invice_address_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) $customer->customer_id); if (isset($invoice_address) && JeproshopTools::isLoadedObject($invoice_address, 'address_id')) { $context->cart->invoice_address_id = (int) $invoice_address->address_id; } if ($this->use_ajax && JeproshopSettingModelSetting::getValue('order_process_type') != 'standard') { $delivery_option = array((int) $context->cart->delivery_address_id => (int) $context->cart->carrier_id . ','); $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 $context->cart->update(); // Avoid articles without delivery address on the cart $context->cart->autosetProductAddress(); Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => true, 'customer_id' => (int) $context->cookie->customer_id, 'id_address_delivery' => $context->cart->delivery_address_id, 'id_address_invoice' => $context->cart->invoice_address_id, 'token' => Tools::getToken(false)); echo json_encode($return); $app->close(); } // if registration type is in two steps, we redirect to register address if (JeproshopSettingModelSetting::getValue('registration_process_type') == 'account_only' && !$this->use_ajax && $task != 'submitGuestAccount') { $app->redirect('index.php?option=com_jeproshop&view=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($context->cart->getProducts(true)) > 0) { $app->redirect('index.php?option=com_jeproshop&view=order&multi-shipping=' . (int) $input['multi-shipping']); // else : redirection to the account } else { //todo$app->redirect('index.php?controller=' . (($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } } } if ($this->has_errors) { //for retro compatibility to display guest account creation form on authentication page if ($task == 'guest_account') { $_GET['display_guest_checkout'] = 1; } if (!$isNewCustomer) { unset($_POST['passwd']); } if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => false, 'customer_id' => 0); echo json_encode($return); $app->close(); } $viewClass->assign('account_error', $this->has_errors); } echo json_encode($jsonData); $app->close(); }
public function initialize() { if (self::$initialized) { return; } self::$initialized = true; $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); $view = $app->input->get('view', 'default'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); if (JeproshopTools::usingSecureMode()) { $this->ssl_enabled = true; } if (isset($context->cookie->account_created)) { $accountCreated = true; $viewClass->assignRef('account_created', $accountCreated); $context->cookie->account_created = 0; } JeproshopTools::setCookieLanguage($context->cookie); $cart_id = (int) $this->recoverCart(); if ($cart_id) { $context->cookie->cart_id = $cart_id; } if ($this->authenticated && !$context->customer->isLogged($this->guest_allowed)) { $app->redirect('index.php?option=com_jeproshop&view=authentication'); // todo add retun option } if (JeproshopSettingModelSetting::getValue('enable_geolocation')) { $defaultCountry = $this->geolocationManagement($context->country); if ($defaultCountry && JeproshopTools::isLoadedObject($defaultCountry, 'country_id')) { $context->country = $defaultCountry; } } $currency = JeproshopTools::setCurrency($context->cookie); $logout = $app->input->get('logout'); $myLogout = $app->input->get('mylogout'); if (isset($logout) || $context->customer->logged && JeproshopCustomerModelCustomer::isBanned($context->cutomer->customer_id)) { $context->customer->logout(); //$app->input->get('') } elseif (isset($myLogout)) { $context->customer->mylogout(); } if ((int) $context->cookie->cart_id) { $cart = new JeproshopCartModelCart($context->cookie->cart_id); if ($cart->orderExists()) { $context->cookie->cart_id = null; $context->cookie->check_selling_condition = false; } elseif ((int) JeproshopSettingModelSetting::getValue('enable_geolocation') && !in_array(strtoupper($context->cookie->iso_code_country), explode(';', JeproshopSettingModelSetting::getValue('allowed_countries'))) && $cart->numberOfProducts() && (int) JeproshopSettingModelSetting::getValue('geolocation_behavior') != -1 && !self::isInWhiteListForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) { $context->cookie->cart_id = null; $cart = null; } elseif ($context->cookie->customer_id != $cart->customer_id || $context->cookie->lang_id != $cart->lang_id || $currency->currency_id != $cart->currency_id) { if ($context->cookie->customer_id) { $cart->customer_id = (int) $context->cookie->customer_id; } $cart->lang_id = (int) $context->cookie->lang_id; $cart->currency_id = (int) $currency->currency_id; $cart->update(); } if (isset($cart) && (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0 || !isset($cart->address_invoice_id) || $cart->address_invoice_id) && $context->cookie->customer_id) { $toUpdate = false; if (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0) { $toUpdate = true; $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); } if (!isset($cart->address_invoice_id) || $cart->address_invoice_id == 0) { $toUpdate = true; $cart->address_invoice_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); } if ($toUpdate) { $cart->update(); } } } if (!isset($cart) || $cart->cart_id) { $cart = new JeproshopCartModelCart(); $cart->lang_id = (int) $context->cookie->lang_id; $cart->currency_id = (int) $context->cookie->currency_id; $cart->guest_id = (int) $context->cookie->guest_id; $cart->shop_group_id = (int) $context->shop->shop_group_id; $cart->shop_id = $context->shop->shop_id; if ($context->cookie->customer_id) { $cart->customer_id = (int) $context->cookie->id_customer; $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); $cart->address_invoice_id = $cart->address_delivery_id; } else { $cart->address_delivery_id = 0; $cart->address_invoice_id = 0; } // Needed if the merchant want to give a free product to every visitors $context->cart = $cart; JeproshopCartRuleModelCartRule::autoAddToCart($context); } else { $context->cart = $cart; } JeproshopProductModelProduct::initPricesComputation(); $display_tax_label = $context->country->display_tax_label; if (isset($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) && $cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) { $info = JeproshopAddressModelAddress::getCountryAndState($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $country = new JeproshopCountryModelCountry((int) $info->country_id); $context->country = $country; if (JeproshopTools::isLoadedObject($country, 'country_id')) { $display_tax_label = $country->display_tax_label; } } $languages = JeproshopLanguageModelLanguage::getLanguages(true); $meta_language = array(); foreach ($languages as $lang) { $meta_language[] = $lang->iso_code; } $compared_products = array(); $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item'); if ($comparatorMaxItem && isset($context->cookie->compare_id)) { $compared_products = JeproshopProductComparedModelProductCompared::getComparedProducts($context->cookie->compare_id); } $mobileDevice = $context->getMobileDevice(); $viewClass->assignRef('mobile_device', $mobileDevice); $viewClass->assignRef('cart', $cart); $viewClass->assignRef('currency', $currency); $viewClass->assignRef('display_tax_label', $display_tax_label); $isLogged = (bool) $context->customer->isLogged(); $viewClass->assignRef('is_logged', $isLogged); $isGuest = (bool) $context->customer->isGuest(); $viewClass->assignRef('is_guest', $isGuest); $priceRoundMode = JeproshopSettingModelSetting::getValue('price_round_mode'); $viewClass->assignRef('price_round_mode', $priceRoundMode); $useTax = JeproshopSettingModelSetting::getValue('use_tax'); $viewClass->assignRef('use_taxes', $useTax); $showTax = (int) JeproshopSettingModelSetting::getValue('display_tax') == 1 && JeproshopSettingModelSetting::getValue('use_tax'); $viewClass->assignRef('show_tax', $showTax); $catalogMode = (bool) JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices; $viewClass->assignRef('catalog_mode', $catalogMode); $enableB2bMode = (bool) JeproshopSettingModelSetting::getValue('enable_b2b_mode'); $viewClass->assignRef('enable_b2b_mode', $enableB2bMode); $stockManagement = JeproshopSettingModelSetting::getValue('stock_management'); $viewClass->assignRef('stock_management', $stockManagement); $metaLanguages = implode(',', $meta_language); $viewClass->assignRef('meta_languages', $metaLanguages); $viewClass->assignRef('languages', $languages); $numberOfProducts = $cart->numberOfProducts(); $viewClass->assignRef('cart_quantities', $numberOfProducts); $currencies = JeproshopCurrencyModelCurrency::getCurrencies(); $viewClass->assignRef('currencies', $currencies); $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item'); $viewClass->assignRef('comparator_max_item', $comparatorMaxItem); $quickView = (bool) JeproshopSettingModelSetting::getValue('quick_view'); $viewClass->assignRef('quick_view', $quickView); $restrictedCountryMode = false; $viewClass->assignRef('restricted_country_mode', $restrictedCountryMode); $displayPrice = JeproshopProductModelProduct::getTaxCalculationMethod((int) $context->cookie->customer_id); $viewClass->assignRef('display_price', $displayPrice); /*$viewClass->assignRef(''); $viewClass->assignRef(''); $viewClass->assignRef('');*/ $viewClass->assignRef('compared_products', $compared_products); /*$viewClass->assignRef('comparator_max_item', $comparatorMaxItem); */ }