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'); } } }
/** * 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(); }
/** * Return cart products * * @result array Products * @param bool $refresh * @param bool $product_id * @param null $country_id * @return array|null */ public function getProducts($refresh = false, $product_id = false, $country_id = null) { if (!$this->cart_id) { return array(); } // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries if ($this->_products !== null && !$refresh) { // Return product row with specified ID if it exists if (is_int($product_id)) { foreach ($this->_products as $product) { if ($product->product_id == $product_id) { return array($product); } } return array(); } return $this->_products; } $db = JFactory::getDBO(); $select = $leftJoin = ""; if (JeproshopCustomization::isFeaturePublished()) { $select .= 'cu.`id_customization`, cu.`quantity` AS customization_quantity'; $leftJoin .= " LEFT JOIN " . $db->quoteName('#__jeproshop_customization') . " AS customization "; /* 'p.`id_product` = cu.`id_product` AND cart_product.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = '.(int)$this->id); */ } else { $select .= 'NULL AS customization_quantity, NULL AS id_customization'; } if (JeproshopCombinationModelCombination::isFeaturePublished()) { $select .= ' product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr, IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference, (p.`weight`+ pa.`weight`) weight_attribute, IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc, pai.`id_image` as pai_id_image, il.`legend` as pai_legend, IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity '; /*$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cart_product.`id_product_attribute`'); $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cart_product.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)'); $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`'); $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = '.(int)$this->id_lang); */ } else { $select .= 'p.`reference` AS reference, p.`ean13`, p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity'; } $query = "SELECT cart_product." . $db->quoteName('product_attribute_id') . ", cart_product." . $db->quoteName('product_id') . ", cart_product."; $query .= $db->quoteName('quantity') . " AS cart_quantity, cart_product." . $db->quoteName('shop_id') . ", product_lang." . $db->quoteName('name'); $query .= ", product." . $db->quoteName('is_virtual') . ", product_lang." . $db->quoteName('short_description') . ", product_lang." . $db->quoteName('available_now'); $query .= ", product_lang." . $db->quoteName('available_later') . ", product_shop." . $db->quoteName('default_category_id') . ", product."; $query .= $db->quoteName('supplier_id') . ", product." . $db->quoteName('manufacturer_id') . ", product_shop." . $db->quoteName('on_sale') . ", product_shop."; $query .= $db->quoteName('ecotax') . ", product_shop." . $db->quoteName('additional_shipping_cost') . ", product_shop." . $db->quoteName('available_for_order'); $query .= ", product_shop." . $db->quoteName('price') . ", product_shop." . $db->quoteName('published') . ", product_shop." . $db->quoteName('unity'); $query .= ", product_shop." . $db->quoteName('unit_price_ratio') . ", stock." . $db->quoteName('quantity') . " AS quantity_available, product." . $db->quoteName('width'); $query .= ", product." . $db->quoteName('height') . ", product." . $db->quoteName('depth') . ", stock." . $db->quoteName('out_of_stock') . ", product."; $query .= $db->quoteName('weight') . ", product." . $db->quoteName('date_add') . ", product." . $db->quoteName('date_upd') . ", IFNULL(stock.quantity, 0) as quantity, "; $query .= "product_lang." . $db->quoteName('link_rewrite') . ", category_lang." . $db->quoteName('link_rewrite') . " AS category, CONCAT(LPAD(cart_product."; $query .= $db->quoteName('product_id') . ", 10, 0), LPAD(IFNULL(cart_product." . $db->quoteName('product_attribute_id') . ", 0), 10, 0), IFNULL(cart_product."; $query .= $db->quoteName('address_delivery_id') . ", 0)) AS unique_id, cart_product.address_delivery_id, product_shop." . $db->quoteName('wholesale_price'); $query .= ", product_shop.advanced_stock_management, product_supplier.product_supplier_reference supplier_reference, IFNULL(specific_price." . $db->quoteName('reduction_type'); $query .= ", 0) AS reduction_type FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product "; $query .= " ON (product." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . ") INNER JOIN " . $db->quoteName('#__jeproshop_product_shop'); $query .= " AS product_shop ON (product_shop." . $db->quoteName('shop_id') . " = cart_product." . $db->quoteName('shop_id') . " AND product_shop." . $db->quoteName('product_id'); $query .= " = product." . $db->quoteName('product_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON (product." . $db->quoteName('product_id'); $query .= " = product_lang." . $db->quoteName('product_id') . "\tAND product_lang." . $db->quoteName('lang_id') . " = " . (int) $this->lang_id; $query .= JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang', 'cart_product.shop_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang'); $query .= " AS category_lang ON(product_shop." . $db->quoteName('default_category_id') . " = category_lang." . $db->quoteName('category_id') . " AND category_lang." . $db->quoteName('lang_id'); $query .= " = " . (int) $this->lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang', 'cart_product.shop_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_supplier'); $query .= " AS product_supplier ON (product_supplier." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . " AND product_supplier."; $query .= $db->quoteName('product_attribute_id') . " = cart_product." . $db->quoteName('product_attribute_id') . " AND product_supplier." . $db->quoteName('supplier_id'); $query .= " = product." . $db->quoteName('supplier_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_specific_price') . " AS specific_price ON (specific_price."; $query .= $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . ") " . JeproshopProductModelProduct::sqlStock('cart_product'); // AND 'sp.`id_shop` = cart_product.`id_shop` // @todo test if everything is ok, then refactorise call of this method //$sql->join(Product::sqlStock('cart_product', 'cart_product')); $query .= " WHERE cart_product." . $db->quoteName('cart_id') . " = " . (int) $this->cart_id; if ($product_id) { $query .= " AND cart_product." . $db->quoteName('product_id') . " = " . (int) $product_id; } $query .= " AND product." . $db->quoteName('product_id') . " IS NOT NULL GROUP BY unique_id ORDER BY cart_product." . $db->quoteName('date_add'); $query .= ", product." . $db->quoteName('product_id') . ", cart_product." . $db->quoteName('product_attribute_id') . " ASC"; $db->setQuery($query); $result = $db->loadObjectList(); // Reset the cache before the following return, or else an empty cart will add dozens of queries $products_ids = array(); $product_attribute_ids = array(); if ($result) { foreach ($result as $row) { $products_ids[] = $row->product_id; $product_attribute_ids[] = $row->product_attribute_id; } } // Thus you can avoid one query per product, because there will be only one query for all the products of the cart JeproshopProductModelProduct::cacheProductsFeatures($products_ids); JeproshopCartModelCart::cacheSomeAttributesLists($product_attribute_ids, $this->lang_id); $this->_products = array(); if (empty($result)) { return array(); } $cart_shop_context = JeproshopContext::getContext()->cloneContext(); foreach ($result as &$row) { if (isset($row->ecotax_attr) && $row->ecotax_attr > 0) { $row->ecotax = (double) $row->ecotax_attr; } $row->stock_quantity = (int) $row->quantity; // for compatibility with 1.2 themes $row->quantity = (int) $row->cart_quantity; if (isset($row->product_attribute_id) && (int) $row->product_attribute_id && isset($row->weight_attribute)) { $row->weight = (double) $row->weight_attribute; } if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } else { $address_id = (int) $row->address_delivery_id; } if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } if ($cart_shop_context->shop->shop_id != $row->shop_id) { $cart_shop_context->shop = new JeproshopShopModelShop((int) $row->shop_id); } $specific_price_output = null; $null = null; if ($this->_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) { $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context); // Here taxes are computed only once the quantity has been applied to the product price $row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context); $tax_rate = JeproshopTaxModelTax::getProductTaxRate((int) $row->product_id, (int) $address_id); $row->total_wt = JeproshopTools::roundPrice($row->price * (double) $row->cart_quantity * (1 + (double) $tax_rate / 100), 2); $row->total = $row->price * (int) $row->cart_quantity; } else { $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, (int) $row->product_attribute_id, 2, null, false, true, $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context); $row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, (int) $row->product_attribute_id, 2, null, false, true, $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context); // In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals $row->price_wt = JeproshopTools::roundPrice($row->price_wt, 2); $row->total_wt = $row->price_wt * (int) $row->cart_quantity; $row->total = JeproshopTools::roundPrice($row->price * (int) $row->cart_quantity, 2); $row->description_short = JeproshopTools::nl2br($row->short_description); } if (!isset($row->product_attribute_id_image_id) || $row->product_attribute_id_image_id == 0) { $cache_id = 'jeproshop_cart_get_products_product_attribute_id_image_id_' . (int) $row->product_id . '_' . (int) $this->lang_id . '_' . (int) $row->shop_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT image_shop." . $db->quoteName('image_id') . " AS image_id, image_lang." . $db->quoteName('legend') . " FROM "; $query .= $db->quoteName('#__jeproshop_image') . " AS image JOIN " . $db->quoteName('#__jeproshop_image_shop') . " AS image_shop ON ("; $query .= " image.image_id = image_shop.image_id AND image_shop.cover=1 AND image_shop.shop_id = " . (int) $row->shop_id . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image_shop." . $db->quoteName('image_id') . " = image_lang."; $query .= $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $this->lang_id . ") WHERE image."; $query .= $db->quoteName('product_id') . " = " . (int) $row->product_id . " AND image_shop." . $db->quoteName('cover') . " = 1"; $db->setQuery($query); $row2 = $db->loadObject(); JeproshopCache::store($cache_id, $row2); } $row2 = JeproshopCache::retrieve($cache_id); if (!$row2) { $row2 = new JObject(); $row2->image_id = false; $row2->legend = false; } else { $row = array_merge($row, $row2); } } else { $row->image_id = $row->product_attribute_id_image_id; $row->legend = $row->product_attribute_legend; } $row->reduction_applies = $specific_price_output && (double) $specific_price_output->reduction; $row->quantity_discount_applies = $specific_price_output && $row->cart_quantity >= (int) $specific_price_output->from_quantity; $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $this->lang_id); $row->allow_out_of_sp = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock); $row->features = JeproshopProductModelProduct::getStaticFeatures((int) $row->product_id); if (array_key_exists($row->product_attribute_id . '_' . $this->lang_id, self::$_attributesLists)) { $row = array_merge($row, self::$_attributesLists[$row->product_attribute_id . '_' . $this->lang_id]); } $row = JeproshopProductModelProduct::getTaxesInformations($row, $cart_shop_context); $this->_products[] = $row; } return $this->_products; }
public function cacheDatabaseRequiredFields() { if (!is_array(self::$_database_required_fields)) { $fields = JeproshopTools::getDatabaseRequiredFields(true, 'address'); if ($fields) { foreach ($fields as $row) { self::$_database_required_fields[$row->object_name][(int) $row->required_fiel_id] = pSQL($row->field_name); } } else { self::$_database_required_fields = array(); } } }
/** * Return package shipping cost * * @param integer $carrier_id Carrier ID (default : current carrier) * @param boolean $use_tax * @param JeproshopCountryModelCountry $default_country * @param Array $product_list * @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost * * @return float Shipping total */ public function getPackageShippingCost($carrier_id = null, $use_tax = true, JeproshopCountryModelCountry $default_country = null, $product_list = null, $zone_id = null) { if ($this->isVirtualCart()) { return 0; } if (!$default_country) { $default_country = JeproshopContext::getContext()->country; } $complete_product_list = $this->getProducts(); if (is_null($product_list)) { $products = $complete_product_list; } else { $products = $product_list; } if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } elseif (count($product_list)) { $prod = current($product_list); $address_id = (int) $prod->address_delivery_id; } else { $address_id = null; } if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } $cache_id = 'get_package_shipping_cost_' . (int) $this->cart_id . '_' . (int) $address_id . '_' . (int) $carrier_id . '_' . (int) $use_tax . '_' . (int) $default_country->country_id; if ($products) { foreach ($products as $product) { $cache_id .= '_' . (int) $product->product_id . '_' . (int) $product->product_attribute_id; } } if (JeproshopCache::isStored($cache_id)) { return JeproshopCache::retrieve($cache_id); } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if (!count($products)) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } if (!isset($zone_id)) { // Get id zone if (!$this->isMultiAddressDelivery() && isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) { $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id); } else { if (!JeproshopValidator::isLoadedObject($default_country, 'country_id')) { $default_country = new Country(JeproshopSettingModelSeting::getValue('PS_COUNTRY_DEFAULT'), JeproshopSettingModelSeting::getValue('PS_LANG_DEFAULT')); } $zone_id = (int) $default_country->zone_id; } } if ($carrier_id && !$this->isCarrierInRange((int) $carrier_id, (int) $zone_id)) { $carrier_id = ''; } if (empty($carrier_id) && $this->isCarrierInRange((int) JeproshopSettingModelSeting::getValue('default_carrier'), (int) $zone_id)) { $carrier_id = (int) JeproshopSettingModelSeting::getValue('default_carrier'); } $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list); if (empty($carrier_id)) { if ((int) $this->customer_id) { $customer = new JeproshopCustomerModelCustomer((int) $this->customer_id); $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id, $customer->getGroups()); unset($customer); } else { $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id); } foreach ($result as $k => $row) { if ($row->carrier_id == JeproshopSettingModelSeting::getValue('default_carrier')) { continue; } if (!isset(self::$_carriers[$row->carrier_id])) { self::$_carriers[$row->carrier_id] = new JeproshopCarrierModelCarrier((int) $row->carrier_id); } $carrier = self::$_carriers[$row->carrier_id]; // Get only carriers that are compliant with shipping method if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByWeight((int) $zone_id) === false || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByPrice((int) $zone_id) === false) { unset($result[$k]); continue; } // If out-of-range behavior carrier is set on "Deactivated carrier" if ($row->range_behavior) { $check_delivery_price_by_weight = JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($row->carrier_id, $this->getTotalWeight(), (int) $zone_id); $total_order = $total_package_without_shipping_tax_inc; $check_delivery_price_by_price = JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($row->carrier_id, $total_order, (int) $zone_id, (int) $this->currency_id); // Get only carriers that have a range compatible with cart if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !$check_delivery_price_by_price) { unset($result[$k]); continue; } } if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $zone_id); } else { $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $zone_id, (int) $this->currency_id); } if (!isset($min_shipping_price)) { $min_shipping_price = $shipping; } if ($shipping <= $min_shipping_price) { $carrier_id = (int) $row->carrier_id; $min_shipping_price = $shipping; } } } if (empty($carrier_id)) { $carrier_id = JeproshopSettingModelSeting::getValue('default_carrier'); } if (!isset(self::$_carriers[$carrier_id])) { self::$_carriers[$carrier_id] = new JeproshopCarrierModelCarrier((int) $carrier_id, JeproshopSettingModelSeting::getValue('default_lang')); } $carrier = self::$_carriers[$carrier_id]; // No valid Carrier or $carrier_id <= 0 ? if (!JeproshopValidator::isLoadedObject($carrier, 'carrier_id')) { JeproshopCache::store($cache_id, 0); return 0; } if (!$carrier->published) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } // Free fees if free carrier if ($carrier->is_free == 1) { JeproshopCache::store($cache_id, 0); return 0; } // Select carrier tax if ($use_tax && !JeproshopTaxModelTax::excludedTaxOption()) { $address = JeproshopAddressModelAddress::initialize((int) $address_id); $carrier_tax = $carrier->getTaxesRate($address); } $configuration = JeproshopSettingModelSeting::getValueMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT')); // Free fees $free_fees_price = 0; if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) { $free_fees_price = JeproshopValidator::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); } $orderTotalWithDiscounts = $this->getOrderTotal(true, JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING, null, null, false); if ($orderTotalWithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { if (!isset($zone_id)) { // Get id zone if (isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) { $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id); } else { $zone_id = (int) $default_country->zone_id; } } if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $zone_id) || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $zone_id, (int) $this->currency_id)) { $shipping_cost += 0; } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id); } else { // by price $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id); } } } else { if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id); } } // Adding handling charges if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) { $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING']; } // Additional Shipping Cost per product foreach ($products as $product) { if (!$product->is_virtual) { $shipping_cost += $product->additional_shipping_cost * $product->cart_quantity; } } $shipping_cost = JeproshopValidator::convertPrice($shipping_cost, JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); /*/get external shipping cost from module if ($carrier->shipping_external) { $module_name = $carrier->external_module_name; $module = Module::getInstanceByName($module_name); if (JeproshopValidator::isLoadedObject($module)) { if (array_key_exists('carrier_id', $module)) $module->carrier_id = $carrier->id; if ($carrier->need_range) if (method_exists($module, 'getPackageShippingCost')) $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products); else $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost); else $shipping_cost = $module->getOrderShippingCostExternal($this); // Check if carrier is available if ($shipping_cost === false) { JeproshopCache::store($cache_id, false); return false; } } else { JeproshopCache::store($cache_id, false); return false; } } */ // Apply tax if ($use_tax && isset($carrier_tax)) { $shipping_cost *= 1 + $carrier_tax / 100; } $shipping_cost = (double) JeproshopValidator::roundPrice((double) $shipping_cost, 2); JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; }
/** * Get product price * * @param integer $product_id Product id * @param boolean $use_tax With taxes or not (optional) * @param integer $product_attribute_id Product attribute id (optional). * If set to false, do not apply the combination price impact. NULL does apply the default combination price impact. * @param integer $decimals Number of decimals (optional) * @param boolean $only_reduction Returns only the reduction amount * @param boolean $use_reduction Set if the returned amount will include reduction * @param integer $quantity Required for quantity discount application (default value: 1) * @param integer $customer_id Customer ID (for customer group reduction) * @param integer $cart_id Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...) * @param integer $address_id Customer address ID. Required for price (tax included) calculation regarding the guest localization * @param null $specific_price_output * @param boolean $with_ecotax insert ecotax in price output. * @param bool $use_group_reduction * @param JeproshopContext $context * @param bool $use_customer_price * @internal param int $divisor Useful when paying many time without fees (optional) * @internal param \variable_reference $specificPriceOutput . * If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @return float Product price */ public static function getStaticPrice($product_id, $use_tax = true, $product_attribute_id = null, $decimals = 6, $only_reduction = false, $use_reduction = true, $quantity = 1, $customer_id = null, $cart_id = null, $address_id = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, JeproshopContext $context = null, $use_customer_price = true) { if (!$context) { $context = JeproshopContext::getContext(); } $cur_cart = $context->cart; if (!JeproshopTools::isBool($use_tax) || !JeproshopTools::isUnsignedInt($product_id)) { //die(Tools::displayError()); } // Initializations $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; // If there is cart in context or if the specified id_cart is different from the context cart id if (!is_object($cur_cart) || JeproshopTools::isUnsignedInt($cart_id) && $cart_id && $cur_cart->cart_id != $cart_id) { /* * When a user (e.g., guest, customer, Google...) is on Jeproshop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on JeproShop, he does not have already it BUT knows the cart ID * When called from the back office, cart ID can be inexistant */ if (!$cart_id && !isset($context->employee)) { JError::raiseError(500, __FILE__ . ' ' . __LINE__); } $cur_cart = new JeproshopCartModelCart($cart_id); // Store cart in context to avoid multiple instantiations in BO if (!JeproshopTools::isLoadedObject($context->cart, 'cart_id')) { $context->cart = $cur_cart; } } $db = JFactory::getDBO(); $cart_quantity = 0; if ((int) $cart_id) { $cache_id = 'jeproshop_product_model_get_price_static_' . (int) $product_id . '_' . (int) $cart_id; $cart_qty = JeproshopCache::retrieve($cache_id); if (!JeproshopCache::isStored($cache_id) || $cart_qty != (int) $quantity) { $query = "SELECT SUM(" . $db->quoteName('quantity') . ") FROM " . $db->quoteName('#__jeproshop_cart_product'); $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('cart_id'); $query .= " = " . (int) $cart_id; $db->setQuery($query); $cart_quantity = (int) $db->loadResult(); JeproshopCache::store($cache_id, $cart_quantity); } $cart_quantity = JeproshopCache::retrieve($cache_id); } $currency_id = (int) JeproshopTools::isLoadedObject($context->currency, 'currency_id') ? $context->currency->currency_id : JeproshopSettingModelSetting::getValue('default_currency'); // retrieve address information $country_id = (int) $context->country->country_id; $state_id = 0; $zipcode = 0; if (!$address_id && JeproshopTools::isLoadedObject($cur_cart, 'cart_id')) { $address_id = $cur_cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}; } if ($address_id) { $address_info = JeproshopAddressModelAddress::getCountryAndState($address_id); if ($address_info->country_id) { $country_id = (int) $address_info->country_id; $state_id = (int) $address_info->state_id; $zipcode = $address_info->postcode; } } else { if (isset($context->customer->geoloc_country_id)) { $country_id = (int) $context->customer->geoloc_country_id; $state_id = (int) $context->customer->state_id; $zipcode = (int) $context->customer->postcode; } } if (JeproshopTaxModelTax::taxExcludedOption()) { $use_tax = false; } if ($use_tax != false && !empty($address_info->vat_number) && $address_info->country_id != JeproshopSettingModelSetting::getValue('vat_number_country') && JeproshopSettingModelSetting::getValue('vat_number_management')) { $use_tax = false; } if (is_null($customer_id) && JeproshopTools::isLoadedObject($context->customer, 'customer_id')) { $customer_id = $context->customer->customer_id; } return JeproshopProductModelProduct::priceCalculation($context->shop->shop_id, $product_id, $product_attribute_id, $country_id, $state_id, $zipcode, $currency_id, $group_id, $quantity, $use_tax, $decimals, $only_reduction, $use_reduction, $with_ecotax, $specific_price_output, $use_group_reduction, $customer_id, $use_customer_price, $cart_id, $cart_quantity); }
public static function getCurrentCountry($customer_id, JeproshopCartModelCart $cart = null) { if (!$cart) { $cart = JeproshopContext::getContext()->cart; } if (!$cart || !$cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) { $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('address_id') . " FROM " . $db->quoteName('#__jeproshop_address') . " WHERE " . $db->quoteName('customer_id') . " = " . (int) $customer_id . " AND " . $db->quoteName('deleted') . " = 0 ORDER BY " . $db->quoteName('address_id'); $db->setQuery($query); $address_id = (int) $db->loadResult(); } else { $address_id = $cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}; } $address = JeproshopAddressModelAddress::getCountryAndState($address_id); return (int) $address->country_id ? $address->country_id : JeproshopSettingModelSetting::getValue('default_country'); }
/** * For a given {product, warehouse}, gets the carrier available * * @param JeproshopProductModelProduct $product The id of the product, or an array with at least the package size and weight * @param int $warehouse_id * @param int $address_delivery_id * @param int $shop_id * @param $cart * @return array */ public static function getAvailableCarrierList(JeproshopProductModelProduct $product, $warehouse_id, $address_delivery_id = null, $shop_id = null, $cart = null) { if (is_null($shop_id)) { $shop_id = JeproshopContext::getContext()->shop->shop_id; } if (is_null($cart)) { $cart = JeproshopContext::getContext()->cart; } $address_id = (int) (!is_null($address_delivery_id) && $address_delivery_id != 0 ? $address_delivery_id : $cart->address_delivery_id); if ($address_id) { $address = new JeproshopAddressModelAddress($address_id); $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId($address->address_id); // Check the country of the address is activated if (!JeproshopAddressModelAddress::isCountryActiveById($address->address_id)) { return array(); } } else { $country = new JeproshopCountryModelCountry(JeproshopSettingModelSetting::getValue('default_country')); $izone_id = $country->zone_id; } // Does the product is linked with carriers? $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); $query->where('pc.id_product = ' . (int) $product->product_id); $query->where('pc.id_shop = ' . (int) $shop_id); $cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop; if (!Cache::isStored($cache_id)) { $carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $carriers_for_product); } $carriers_for_product = Cache::retrieve($cache_id); $carrier_list = array(); if (!empty($carriers_for_product)) { //the product is linked with carriers foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[] = $carrier['id_carrier']; } } if (empty($carrier_list)) { return array(); } //no linked carrier are available for this zone } // The product is not directly linked with a carrier // Get all the carriers linked to a warehouse if ($warehouse_id) { $warehouse = new JeproshopWarehouseModelWarehouse($warehouse_id); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $customer = new JeproshopCustomerModelCustomer($cart->customer_id); $carriers = JeproshopCarrierModelCarrier::getCarriersForOrder($zone_id, $customer->getGroups(), $cart); foreach ($carriers as $carrier) { $available_carrier_list[] = $carrier->carrier_id; } if ($carrier_list) { $carrier_list = array_intersect($available_carrier_list, $carrier_list); } else { $carrier_list = $available_carrier_list; } if (isset($warehouse_carrier_list)) { $carrier_list = array_intersect($carrier_list, $warehouse_carrier_list); } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) { foreach ($carrier_list as $key => $carrier_id) { $carrier = new JeproshopCarrierModelCarrier($carrier_id); if ($carrier->max_width > 0 && $carrier->max_width < $product->width || $carrier->max_height > 0 && $carrier->max_height < $product->height || $carrier->max_depth > 0 && $carrier->max_depth < $product->depth || $carrier->max_weight > 0 && $carrier->max_weight < $product->weight) { unset($carrier_list[$key]); } } } return $carrier_list; }
private function displaySpecificPriceModificationForm($default_currency, $shops, $currencies, $countries, $groups) { $content = ''; if (!$this->product) { return null; } $specificPrices = JeproshopSpecificPriceModelSpecificPrice::getSpecificPricesByProductId((int) $this->product->product_id); $specificPricePriorities = JeproshopSpecificPriceModelSpecificPrice::getPriority((int) $this->product->product_id); $app = JFactory::getApplication(); $taxRate = $this->product->getTaxesRate(JeproshopAddressModelAddress::initialize()); $tmp = array(); foreach ($shops as $shop) { $tmp[$shop->shop_id] = $shop; } $shops = $tmp; $tmp = array(); foreach ($currencies as $currency) { $tmp[$currency->currency_id] = $currency; } $currencies = $tmp; $tmp = array(); foreach ($countries as $country) { $tmp[$country->country_id] = $country; } $countries = $tmp; $tmp = array(); foreach ($groups as $group) { $tmp[$group->group_id] = $group; } $groups = $tmp; $content .= '<table class="table table-striped" ><thead><tr><th>' . JText::_('COM_JEPROSHOP_RULES_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_COMBINATION_LABEL') . '</th>'; $multi_shop = JeproshopShopModelShop::isFeaturePublished(); if ($multi_shop) { $content .= '<th>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</th>'; } $content .= '<th>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</th><th>'; $content .= JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_GROUP_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_CUSTOMER_LABEL') . '</th><th>'; $content .= JText::_('COM_JEPROSHOP_FIXED_PRICE_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_IMPACT_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_PERIOD_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_FROM_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_ACTIONS_LABEL') . '</th></tr></thead><tbody>'; if (!is_array($specificPrices) || !count($specificPrices)) { $content .= '<tr><td class="text-center" colspan="13" ><i class="icon-warning-sign"></i> '; $content .= JText::_('COM_JEPROSHOP_NO_SPECIFIC_PRICES_MESSAGE') . '</td></tr>'; } else { $i = 0; foreach ($specificPrices as $specificPrice) { $currentSpecificCurrency = $currencies[$specificPrice->currency_id ? $specificPrice->currency_id : $default_currency->currency_id]; if ($specificPrice->reduction_type == 'percentage') { $impact = '- ' . $specificPrice->reduction * 100 . ' %'; } elseif ($specificPrice->reduction > 0) { $impact = '- ' . JeproshopTools::displayPrice(Tools::ps_round($specificPrice->reduction, 2), $currentSpecificCurrency); } else { $impact = '--'; } if ($specificPrice->from == '0000-00-00 00:00:00' && $specificPrice->to == '0000-00-00 00:00:00') { $period = JText::_('COM_JEPROSHOP_UNLIMITED_LABEL'); } else { $period = JText::_('COM_JEPROSHOP_FROM_LABEL') . ' ' . ($specificPrice->from != '0000-00-00 00:00:00' ? $specificPrice['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specificPrice['to'] != '0000-00-00 00:00:00' ? $specificPrice['to'] : '0000-00-00 00:00:00'); } if ($specificPrice->product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $specificPrice->product_attribute_id); $attributes = $combination->getAttributesName((int) $this->context->language->lang_id); $attributes_name = ''; foreach ($attributes as $attribute) { $attributes_name .= $attribute->name . ' - '; } $attributes_name = rtrim($attributes_name, ' - '); } else { $attributes_name = JText::_('COM_JEPROSHOP_ALL_COMBINATIONS_LABEL'); } $rule = new JeproshopSpecificPriceRuleModelSpecificPriceRule((int) $specificPrice->specific_price_rule_id); $rule_name = $rule->specific_price_rule_id ? $rule->name : '--'; if ($specificPrice->customer_id) { $customer = new JeproshopCustomerModelCustomer((int) $specificPrice->customer_id); if (JeproshopTools::isLoadedObject($customer, 'customer_id')) { $customer_full_name = $customer->firstname . ' ' . $customer->lastname; } unset($customer); } if (!$specificPrice->shop_id || in_array($specificPrice->shop_id, JeoroshopShopModelShop::getContextListShopID())) { $content .= '<tr class="row_' . ($i % 2 ? '0' : '1') . '"><td>' . $rule_name . '</td><td>' . $attributes_name . '</td>'; $can_delete_specific_prices = true; if (JeproshopShopModelShop::isFeaturePublished()) { $sp_shop_id = $specificPrice->shop_id; $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$sp_shop_id || $sp_shop_id; $content .= '<td>' . ($sp_shop_id ? $shops[$sp_shop_id]['name'] : JText::_('COM_JEPROSHOP_ALL_SHOPS_LABEL')) . '</td>'; } $price = JeproshopTools::roundPrice($specificPrice->price, 2); $fixed_price = $price == JeproshopTools::roundPrice($this->product->price, 2) || $specificPrice->price == -1 ? '--' : JeproshopTools::displayPrice($price, $current_specific_currency); $content .= '<td>' . ($specificPrice->currency_id ? $currencies[$specificPrice->currency_id]->name : JText::_('COM_JEPROSHOP_ALL_CURRENCIES_LABEL')) . '</td>'; $content .= '<td>' . ($specificPrice->country_id ? $countries[$specificPrice->country_id]->name : JText::_('COM_JEPROSHOP_ALL_COUNTRIES_LABEL')) . '</td>'; $content .= '<td>' . ($specificPrice->group_id ? $groups[$specificPrice->group_id]->name : JText::_('COM_JEPROSHOP_ALL_GROUPS_LABEL')) . '</td>'; $content .= '<td title="' . JText::_('COM_JEPROSHOP_ID_LABEL') . ' ' . $specificPrice->customer_id . '">' . (isset($customer_full_name) ? $customer_full_name : JText::_('COM_JEPROSHOP_ALL_CUSTOMERS_LABEL')) . '</td>'; $content .= '<td>' . $fixed_price . '</td><td>' . $impact . '</td><td>' . $period . '</td><td>' . $specificPrice->from_quantity . '</th>'; $content .= '<td>' . (!$rule->specific_price_rule_id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . JRoute::_('index.php?option=com_jeproshop&view=price&product_id=' . (int) $app->input->get('product_id') . '&task=delete_specific_price&specific_price_id=' . (int) $specificPrice->specific_price_id . '&' . JSession::getFormToken() . '=1') . '"><i class="icon-trash"></i></a>' : '') . '</td>'; $content .= '</tr>'; $i++; unset($customer_full_name); } } } $content .= '</tbody></table>'; // Not use id_customer if ($specificPricePriorities[0] == 'customer_id') { unset($specificPricePriorities[0]); } // Reindex array starting from 0 $specificPricePriorities = array_values($specificPricePriorities); $content .= '<div class="panel"><div class="panel-title" >' . JText::_('Priority management') . '</div><div class="panel-content well" ><div class="alert alert-info">'; $content .= JText::_('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . '</div>'; $content .= '<div class="input-group" ><select id="jform_specific_price_priority_1" name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[0] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[0] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[0] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[0] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select> <span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[1] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[1] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[1] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[1] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select> <span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[2] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[2] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[2] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[2] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select><span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[3] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[3] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[3] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[3] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select></div></div></div>'; $content .= '<p class="checkbox"><label for="jform_specific_price_priority_to_all"><input type="checkbox" name="price_field[specific_price_priority_to_all]" id="jform_specific_'; $content .= 'price_priority_to_all" />' . JText::_('Apply to all products') . '</label></p>'; /*<div class="form-group"> <label class="control-label col-lg-3" for="specificPricePriority1">'.$this->l('Priorities').'</label> col-lg-9"> </div> </div> <div class="form-group"> <div class="col-lg-9 col-lg-offset-3"> </div> </div> <div class="panel-footer"> <a href="'.$this->context->link->getAdminLink('AdminProducts').'" class="btn btn-default"><i class="process-icon-cancel"></i> '.$this->l('Cancel').'</a> <button id="product_form_submit_btn" type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> '.$this->l('Save') .'</button> <button id="product_form_submit_btn" type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> '.$this->l('Save and stay') .'</button> </div> </div> '; */ $content .= '<script type="text/javascript">var currencies = new Array(); currencies[0] = new Array(); '; $content .= 'currencies[0]["sign"] = "' . $default_currency->sign . '"; currencies[0]["format"] = ' . $default_currency->format . '; '; foreach ($currencies as $currency) { $content .= ' currencies[' . $currency->currency_id . '] = new Array(); currencies[' . $currency->currency_id . ']["sign"] = "' . $currency->sign . '"; currencies[' . $currency->currency_id . ']["format"] = ' . $currency->format . ';'; } $content .= '</script>'; return $content; }
/** * Returns the product tax * * @param integer $product_id * @param integer $address_id * @param JeproshopContext $context * @return JeproshopTaxModelTax */ public static function getProductTaxRate($product_id, $address_id = null, JeproshopContext $context = null) { if ($context == null) { $context = JeproshopContext::getContext(); } $address = JeproshopAddressModelAddress::initialize($address_id); $tax_rules_id = (int) JeproshopProductModelProduct::getTaxRulesGroupIdByProductId($product_id, $context); $tax_manager = JeproshopTaxManagerFactory::getManager($address, $tax_rules_id); $tax_calculator = $tax_manager->getTaxCalculator(); return $tax_calculator->getTotalRate(); }
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); */ }