public function hookPayment($params)
 {
     $cart = $params['cart'];
     $customer = new Customer((int) $cart->id_customer);
     $deliveryAddress = new Address((int) $cart->id_address_delivery);
     $country = new Country((int) $deliveryAddress->id_country);
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     if (!Validate::isLoadedObject($currency)) {
         return false;
     }
     $phone = Tools::safeOutput($deliveryAddress->phone_mobile);
     if (empty($phone)) {
         $phone = Tools::safeOutput($deliveryAddress->phone);
     }
     $public_key = Configuration::get('SIMPLEPAY_LIVE_PUBLIC_KEY');
     if ((int) Configuration::get('SIMPLEPAY_TEST_MODE')) {
         $public_key = Configuration::get('SIMPLEPAY_TEST_PUBLIC_KEY');
     }
     $this->context->smarty->assign('email', $customer->email);
     $this->context->smarty->assign('phone', $phone);
     $this->context->smarty->assign('description', Configuration::get('SIMPLEPAY_PAYMENT_DESCRIPTION') . ' #' . $cart->id);
     $this->context->smarty->assign('address', Tools::safeOutput($deliveryAddress->address1 . ' ' . $deliveryAddress->address2));
     $this->context->smarty->assign('postal_code', Tools::safeOutput($deliveryAddress->postcode));
     $this->context->smarty->assign('city', Tools::safeOutput($deliveryAddress->city));
     $this->context->smarty->assign('country', $country->iso_code);
     $this->context->smarty->assign('amount', $cart->getOrderTotal());
     $this->context->smarty->assign('currency', $currency);
     $this->context->smarty->assign('public_key', $public_key);
     $this->context->smarty->assign('module_dir', $this->_path);
     $this->context->smarty->assign('cart_id', $cart->id);
     $this->context->smarty->assign('cart_id', $cart->id);
     $this->context->smarty->assign('image', Configuration::get('SIMPLEPAY_IMAGE'));
     return $this->display(__FILE__, 'views/templates/hook/payment.tpl');
 }
 public function hookPayment($params)
 {
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     if (!Validate::isLoadedObject($currency)) {
         return false;
     }
     $isFailed = Tools::getValue('paynetzerror');
     $this->context->smarty->assign('x_invoice_num', (int) $params['cart']->id);
     $this->context->smarty->assign('isFailed', $isFailed);
     return $this->display(__FILE__, 'views/templates/hook/paynetz.tpl');
 }
 public function getContent()
 {
     if (Tools::isSubmit('btnSubmit')) {
         $this->postProcess();
     }
     $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));
     $id_lang = Configuration::get('PS_LANG_DEFAULT');
     $carriers = Carrier::getCarriers($id_lang, false, false, false, null, 0);
     $config = Configuration::getMultiple(array('COD_ENABLED', 'COD_SHOW_ZERO', 'COD_TITLE', 'COD_ORDER_STATUS', 'COD_SPECIFIC_COUNTRY', 'COD_COUNTRY', 'COD_MINIMUM_ORDER', 'COD_MAXIMUM_ORDER', 'COD_COST_CALCULATION', 'COD_COST_INLAND', 'COD_COST_FOREIGN', 'COD_FREE_FROM', 'COD_CUSTOM_TEXT', 'COD_DISALLOW_METHODS', 'COD_DISALLOWED_METHODS', 'COD_ORDER_TIME'));
     $this->context->smarty->assign(array('module_name' => $this->name, 'displayName' => $this->displayName, 'order_time' => $config['COD_ORDER_TIME'], 'request_uri' => $_SERVER['REQUEST_URI'], 'enabled' => $config['COD_ENABLED'], 'show_zero' => $config['COD_SHOW_ZERO'], 'title' => $config['COD_TITLE'], 'orders_status' => OrderStateCore::getOrderStates((int) $this->context->language->id), 'order_status' => $config['COD_ORDER_STATUS'], 'specific_country' => $config['COD_SPECIFIC_COUNTRY'], 'country' => ($a = unserialize($config['COD_COUNTRY'])) ? $a : array(), 'all_countrys' => Country::getCountries((int) $this->context->language->id, true), 'minimum_order' => $config['COD_MINIMUM_ORDER'], 'maximum_order' => $config['COD_MAXIMUM_ORDER'], 'cost_calculation' => $config['COD_COST_CALCULATION'], 'cost_inland' => $config['COD_COST_INLAND'], 'cost_foreign' => $config['COD_COST_FOREIGN'], 'free_from' => $config['COD_FREE_FROM'], 'custom_text' => $config['COD_CUSTOM_TEXT'], 'disallow_methods' => $config['COD_DISALLOW_METHODS'], 'carriers' => $carriers, 'disallowed_methods' => ($a = unserialize($config['COD_DISALLOWED_METHODS'])) ? $a : array(), 'currency_sign' => $currency->sign));
     $this->context->controller->addJS($this->local_path . '/views/js/script.js', 'all');
     $output = $this->context->smarty->fetch($this->local_path . '/views/templates/admin/configure.tpl');
     return $output;
 }
Exemple #4
0
 /**
  * Set cookie currency from POST or default currency
  *
  * @param $cookie
  * @return JeproshopCurrencyModelCurrency object
  */
 public static function setCurrency($cookie)
 {
     $app = JFactory::getApplication();
     if ($app->input->get('SubmitCurrency')) {
         if (isset($_POST['currency_id']) && is_numeric($_POST['currency_id'])) {
             $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance($_POST['currency_id']);
             if (is_object($currency, 'currency_id') && $currency->currency_id && !$currency->deleted && $currency->isAssociatedToShop()) {
                 $cookie->currency_id = (int) $currency->currency_id;
             }
         }
     }
     $currency = null;
     if ((int) $cookie->currency_id) {
         $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $cookie->currency_id);
     }
     if (!JeproshopTools::isLoadedObject($currency, 'currency_id') || (bool) $currency->deleted || !(bool) $currency->published) {
         $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance(JeproshopSettingModelSetting::getValue('default_currency'));
     }
     $cookie->currency_id = (int) $currency->currency_id;
     if ($currency->isAssociatedToShop()) {
         return $currency;
     } else {
         // get currency from context
         $currency = JeproshopShopModelShop::getEntityIds('currency', JeproshopContext::getContext()->shop->shop_id, true, true);
         if (isset($currency[0]) && $currency[0]['id_currency']) {
             $cookie->id_currency = $currency[0]['id_currency'];
             return Currency::getCurrencyInstance((int) $cookie->id_currency);
         }
     }
     return $currency;
 }
 protected function geolocationManagement($default_country)
 {
     if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
         /* Check if Maxmind Database exists */
         if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) {
             if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
                 include_once _PS_GEOIP_DIR_ . 'geoipcity.inc';
                 $gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD);
                 $record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
                 if (is_object($record)) {
                     if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
                         if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                             $this->restrictedCountry = true;
                         } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                             $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name));
                         }
                     } else {
                         $has_been_set = !isset($this->context->cookie->iso_code_country);
                         $this->context->cookie->iso_code_country = strtoupper($record->country_code);
                     }
                 }
             }
             if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
                 $this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
             }
             if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
                 /* Update defaultCountry */
                 if ($default_country->iso_code != $this->context->cookie->iso_code_country) {
                     $default_country = new Country($id_country);
                 }
                 if (isset($has_been_set) && $has_been_set) {
                     $this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($default_country->id_currency ? (int) $default_country->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id;
                 }
                 return $default_country;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->restrictedCountry = true;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined'));
             }
         } else {
             Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
         }
     }
     return false;
 }
Exemple #6
0
    public function displayListContent($token = NULL)
    {
        /* Display results in a table
         *
         * align  : determine value alignment
         * prefix : displayed before value
         * suffix : displayed after value
         * image  : object image
         * icon   : icon determined by values
         * active : allow to toggle status
         */
        global $currentIndex, $cookie;
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $id_category = 1;
        // default categ
        $irow = 0;
        if ($this->_list and isset($this->fieldsDisplay['position'])) {
            $positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list);
            sort($positions);
        }
        if ($this->_list) {
            $isCms = false;
            if (preg_match('/cms/Ui', $this->identifier)) {
                $isCms = true;
            }
            $keyToGet = 'id_' . ($isCms ? 'cms_' : '') . 'category' . (in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '');
            foreach ($this->_list as $tr) {
                $id = $tr[$this->identifier];
                echo '<tr' . (array_key_exists($this->identifier, $this->identifiersDnd) ? ' id="tr_' . (($id_category = (int) Tools::getValue('id_' . ($isCms ? 'cms_' : '') . 'category', '1')) ? $id_category : '') . '_' . $id . '_' . $tr['position'] . '"' : '') . ($irow++ % 2 ? ' class="alt_row"' : '') . ' ' . ((isset($tr['color']) and $this->colorOnBackground) ? 'style="background-color: ' . $tr['color'] . '"' : '') . '>
							<td class="center">';
                if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) {
                    echo '<input type="checkbox" name="' . $this->table . 'Box[]" value="' . $id . '" class="noborder" />';
                }
                echo '</td>';
                foreach ($this->fieldsDisplay as $key => $params) {
                    $tmp = explode('!', $key);
                    $key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
                    echo '
					<td ' . (isset($params['position']) ? ' id="td_' . (isset($id_category) and $id_category ? $id_category : 0) . '_' . $id . '"' : '') . ' class="' . ((!isset($this->noLink) or !$this->noLink) ? 'pointer' : '') . ((isset($params['position']) and $this->_orderBy == 'position') ? ' dragHandle' : '') . (isset($params['align']) ? ' ' . $params['align'] : '') . '" ';
                    if (!isset($params['position']) and (!isset($this->noLink) or !$this->noLink)) {
                        echo ' onclick="document.location = \'' . $currentIndex . '&' . $this->identifier . '=' . $id . ($this->view ? '&view' : '&update') . $this->table . '&token=' . ($token != NULL ? $token : $this->token) . '\'">' . (isset($params['prefix']) ? $params['prefix'] : '');
                    } else {
                        echo '>';
                    }
                    if (isset($params['active']) and isset($tr[$key])) {
                        $this->_displayEnableLink($token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product'));
                    } elseif (isset($params['activeVisu']) and isset($tr[$key])) {
                        echo '<img src="../img/admin/' . ($tr[$key] ? 'enabled.gif' : 'disabled.gif') . '"
						alt="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" title="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" />';
                    } elseif (isset($params['position'])) {
                        if ($this->_orderBy == 'position' and $this->_orderWay != 'DESC') {
                            echo '<a' . (!($tr[$key] != $positions[sizeof($positions) - 1]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . '
									&way=1&position=' . (int) ($tr['position'] + 1) . '&token=' . ($token != NULL ? $token : $this->token) . '">
									<img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'down' : 'up') . '.gif"
									alt="' . $this->l('Down') . '" title="' . $this->l('Down') . '" /></a>';
                            echo '<a' . (!($tr[$key] != $positions[0]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . '
									&way=0&position=' . (int) ($tr['position'] - 1) . '&token=' . ($token != NULL ? $token : $this->token) . '">
									<img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'up' : 'down') . '.gif"
									alt="' . $this->l('Up') . '" title="' . $this->l('Up') . '" /></a>';
                        } else {
                            echo (int) ($tr[$key] + 1);
                        }
                    } elseif (isset($params['image'])) {
                        // item_id is the product id in a product image context, else it is the image id.
                        $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
                        // If it's a product image
                        if (isset($tr['id_image'])) {
                            $image = new Image((int) $tr['id_image']);
                            $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $image->getExistingImgPath() . '.' . $this->imageType;
                        } else {
                            $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType;
                        }
                        echo cacheImage($path_to_image, $this->table . '_mini_' . $item_id . '.' . $this->imageType, 45, $this->imageType);
                    } elseif (isset($params['icon']) and (isset($params['icon'][$tr[$key]]) or isset($params['icon']['default']))) {
                        echo '<img src="../img/admin/' . (isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'] . '" alt="' . $tr[$key]) . '" title="' . $tr[$key] . '" />';
                    } elseif (isset($params['price'])) {
                        echo Tools::displayPrice($tr[$key], isset($params['currency']) ? Currency::getCurrencyInstance((int) $tr['id_currency']) : $currency, false);
                    } elseif (isset($params['float'])) {
                        echo rtrim(rtrim($tr[$key], '0'), '.');
                    } elseif (isset($params['type']) and $params['type'] == 'date') {
                        echo Tools::displayDate($tr[$key], (int) $cookie->id_lang);
                    } elseif (isset($params['type']) and $params['type'] == 'datetime') {
                        echo Tools::displayDate($tr[$key], (int) $cookie->id_lang, true);
                    } elseif (isset($tr[$key])) {
                        $echo = $key == 'price' ? round($tr[$key], 2) : isset($params['maxlength']) ? Tools::substr($tr[$key], 0, $params['maxlength']) . '...' : $tr[$key];
                        echo isset($params['callback']) ? call_user_func_array(array($this->className, $params['callback']), array($echo, $tr)) : $echo;
                    } else {
                        echo '--';
                    }
                    echo (isset($params['suffix']) ? $params['suffix'] : '') . '</td>';
                }
                if ($this->edit or $this->delete or $this->view and $this->view !== 'noActionColumn') {
                    echo '<td class="center" style="white-space: nowrap;">';
                    if ($this->view) {
                        $this->_displayViewLink($token, $id);
                    }
                    if ($this->edit) {
                        $this->_displayEditLink($token, $id);
                    }
                    if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) {
                        $this->_displayDeleteLink($token, $id);
                    }
                    if ($this->duplicate) {
                        $this->_displayDuplicate($token, $id);
                    }
                    if ($this->allegro) {
                        $this->_displayAllegroLink($id);
                    }
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
    }
Exemple #7
0
 /**
  * Return price converted
  *
  * @param float $price Product price
  * @param object|array $currency Current currency object
  * @param boolean $to_currency convert to currency or from currency to default currency
  * @param Context $context
  *
  * @return float Price
  */
 public static function convertPrice($price, $currency = null, $to_currency = true, Context $context = null)
 {
     static $default_currency = null;
     if ($default_currency === null) {
         $default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
     }
     if (!$context) {
         $context = Context::getContext();
     }
     if ($currency === null) {
         $currency = $context->currency;
     } elseif (is_numeric($currency)) {
         $currency = Currency::getCurrencyInstance($currency);
     }
     $c_id = is_array($currency) ? $currency['id_currency'] : $currency->id;
     $c_rate = is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate;
     if ($c_id != $default_currency) {
         if ($to_currency) {
             $price *= $c_rate;
         } else {
             $price /= $c_rate;
         }
     }
     return $price;
 }
Exemple #8
0
 public function setCurrency()
 {
     $cookie = $this->context->cookie;
     if (Tools::getValue('id_currency') && is_numeric(Tools::getValue('id_currency'))) {
         $currency = Currency::getCurrencyInstance(Tools::getValue('id_currency'));
         if (is_object($currency) && $currency->id && !$currency->deleted && $currency->isAssociatedToShop()) {
             $cookie->id_currency = (int) $currency->id;
         }
     }
     $currency = null;
     if ((int) $cookie->id_currency) {
         $currency = Currency::getCurrencyInstance((int) $cookie->id_currency);
     }
     if (!Validate::isLoadedObject($currency) || (bool) $currency->deleted || !(bool) $currency->active) {
         $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));
     }
     $cookie->id_currency = (int) $currency->id;
     $this->context->currency->id = $cookie->id_currency;
     if ($currency->isAssociatedToShop()) {
         return $currency;
     } else {
         // get currency from context
         $currency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true);
         if (isset($currency[0]) && $currency[0]['id_currency']) {
             $cookie->id_currency = $currency[0]['id_currency'];
             return Currency::getCurrencyInstance((int) $cookie->id_currency);
         }
     }
     $this->context->currency->id = $cookie->id_currency;
     return $currency;
 }
 public static function getAjaxProduct($id_referrer, $id_product, $employee = null)
 {
     $context = Context::getContext();
     $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'));
     $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));
     $referrer = new Referrer($id_referrer);
     $stats_visits = $referrer->getStatsVisits($id_product, $employee);
     $registrations = $referrer->getRegistrations($id_product, $employee);
     $stats_sales = $referrer->getStatsSales($id_product, $employee);
     // If it's a product and it has no visits nor orders
     if ((int) $id_product && !$stats_visits['visits'] && !$stats_sales['orders']) {
         exit;
     }
     $json_array = array('id_product' => (int) $product->id, 'product_name' => addslashes($product->name), 'uniqs' => (int) $stats_visits['uniqs'], 'visitors' => (int) $stats_visits['visitors'], 'visits' => (int) $stats_visits['visits'], 'pages' => (int) $stats_visits['pages'], 'registrations' => (int) $registrations, 'orders' => (int) $stats_sales['orders'], 'sales' => Tools::displayPrice($stats_sales['sales'], $currency), 'cart' => Tools::displayPrice((int) $stats_sales['orders'] ? $stats_sales['sales'] / (int) $stats_sales['orders'] : 0, $currency), 'reg_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $registrations / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'order_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $stats_sales['orders'] / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'click_fee' => Tools::displayPrice((int) $stats_visits['visits'] * $referrer->click_fee, $currency), 'base_fee' => Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency), 'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency));
     die('[' . Tools::jsonEncode($json_array) . ']');
 }
 public function hookPayment($params)
 {
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     if (!Validate::isLoadedObject($currency) || $currency->iso_code != 'USD') {
         return false;
     }
     if (Configuration::get('PS_SSL_ENABLED') || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
         $isFailed = Tools::getValue('aimerror');
         $cards = array();
         $cards['visa'] = Configuration::get('AUTHORIZE_AIM_CARD_VISA') == 'on';
         $cards['mastercard'] = Configuration::get('AUTHORIZE_AIM_CARD_MASTERCARD') == 'on';
         $cards['discover'] = Configuration::get('AUTHORIZE_AIM_CARD_DISCOVER') == 'on';
         $cards['ax'] = Configuration::get('AUTHORIZE_AIM_CARD_AX') == 'on';
         if (method_exists('Tools', 'getShopDomainSsl')) {
             $url = 'https://' . Tools::getShopDomainSsl() . __PS_BASE_URI__ . '/modules/' . $this->name . '/';
         } else {
             $url = 'https://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/';
         }
         $this->context->smarty->assign('x_invoice_num', (int) $params['cart']->id);
         $this->context->smarty->assign('cards', $cards);
         $this->context->smarty->assign('isFailed', $isFailed);
         $this->context->smarty->assign('new_base_dir', $url);
         return $this->display(__FILE__, 'authorizeaim.tpl');
     }
 }
Exemple #11
0
 public function execPayment($cart)
 {
     // Create invoice
     $currency = Currency::getCurrencyInstance((int) $cart->id_currency);
     $options = $_POST;
     $options['transactionSpeed'] = Configuration::get('bitpay_TXSPEED');
     $options['currency'] = $currency->iso_code;
     $total = $cart->getOrderTotal(true);
     $options['notificationURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/ipn.php';
     if (_PS_VERSION_ <= '1.5') {
         $options['redirectURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $this->currentOrder;
     } else {
         $options['redirectURL'] = Context::getContext()->link->getModuleLink('bitpay', 'validation');
     }
     $options['posData'] = '{"cart_id": "' . $cart->id . '"';
     $options['posData'] .= ', "hash": "' . crypt($cart->id, Configuration::get('bitpay_APIKEY')) . '"';
     $this->key = $this->context->customer->secure_key;
     $options['posData'] .= ', "key": "' . $this->key . '"}';
     $options['orderID'] = $cart->id;
     $options['price'] = $total;
     $options['fullNotifications'] = true;
     $postOptions = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL', 'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone');
     foreach ($postOptions as $o) {
         if (array_key_exists($o, $options)) {
             $post[$o] = $options[$o];
         }
     }
     if (function_exists('json_encode')) {
         $post = json_encode($post);
     } else {
         $post = rmJSONencode($post);
     }
     // Call BitPay
     $curl = curl_init($this->apiurl . '/api/invoice/');
     $length = 0;
     if ($post) {
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
         $length = strlen($post);
     }
     $uname = base64_encode(Configuration::get('bitpay_APIKEY'));
     $header = array('Content-Type: application/json', 'Content-Length: ' . $length, 'Authorization: Basic ' . $uname, 'X-BitPay-Plugin-Info: prestashop0.4');
     curl_setopt($curl, CURLINFO_HEADER_OUT, true);
     curl_setopt($curl, CURLOPT_PORT, $this->sslport);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_TIMEOUT, 10);
     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
     // verify certificate (1)
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
     // check existence of CN and verify that it matches hostname (2)
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     $responseString = curl_exec($curl);
     if (!$responseString) {
         $response = curl_error($curl);
         die(Tools::displayError("Error: no data returned from API server!"));
     } else {
         if (function_exists('json_decode')) {
             $response = json_decode($responseString, true);
         } else {
             $response = rmJSONdecode($responseString);
         }
     }
     curl_close($curl);
     if (isset($response['error'])) {
         bplog($response['error']);
         die(Tools::displayError("Error occurred! (" . $response['error']['type'] . " - " . $response['error']['message'] . ")"));
     } else {
         if (!$response['url']) {
             die(Tools::displayError("Error: Response did not include invoice url!"));
         } else {
             header('Location:  ' . $response['url']);
         }
     }
 }
 private function displayPrice($data, $id_currency, $resume = false)
 {
     $currency = $id_currency;
     if ($resume !== false) {
         if ($id_currency == self::CURRENCY_NOT_SET) {
             $currency = $this->def_currency;
         }
     } elseif ($this->currency_code != self::CURRENCY_NOT_SET) {
         $currency = $this->currency_code;
     }
     return Tools::displayPrice($data, Currency::getCurrencyInstance($currency));
 }
Exemple #13
0
 /**
  * Main
  *
  * @param object $order Order
  * @param string $mode Download or display (optional)
  */
 public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false)
 {
     global $cookie, $ecotax;
     if (!Validate::isLoadedObject($order) or !$cookie->id_employee and (!OrderState::invoiceAvailable($order->getCurrentState()) and !$order->invoice_number)) {
         die('Invalid order or invalid order state');
     }
     self::$order = $order;
     self::$orderSlip = $slip;
     self::$delivery = $delivery;
     self::$_iso = strtoupper(Language::getIsoById(intval(self::$order->id_lang)));
     if ((self::$_priceDisplayMethod = $order->getTaxCalculationMethod()) === false) {
         die(self::l('No price display method defined for the customer group'));
     }
     if (!$multiple) {
         $pdf = new PDF('P', 'mm', 'A4');
     }
     $pdf->SetAutoPageBreak(true, 35);
     $pdf->StartPageGroup();
     self::$currency = Currency::getCurrencyInstance(intval(self::$order->id_currency));
     $pdf->AliasNbPages();
     $pdf->AddPage();
     /* Display address information */
     $invoice_address = new Address(intval($order->id_address_invoice));
     $invoiceState = $invoice_address->id_state ? new State($invoice_address->id_state) : false;
     $delivery_address = new Address(intval($order->id_address_delivery));
     $deliveryState = $delivery_address->id_state ? new State($delivery_address->id_state) : false;
     $shop_country = Configuration::get('PS_SHOP_COUNTRY');
     $invoice_customer = new Customer(intval($invoice_address->id_customer));
     $width = 100;
     $pdf->SetX(10);
     $pdf->SetY(25);
     $pdf->SetFont(self::fontname(), '', 12);
     $pdf->Cell($width, 10, self::l('Delivery'), 0, 'L');
     $pdf->Cell($width, 10, self::l('Invoicing'), 0, 'L');
     $pdf->Ln(5);
     $pdf->SetFont(self::fontname(), '', 9);
     if (!empty($delivery_address->company) or !empty($invoice_address->company)) {
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->company), 0, 'L');
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->company), 0, 'L');
         $pdf->Ln(5);
     }
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->firstname) . ' ' . Tools::iconv('utf-8', self::encoding(), $delivery_address->lastname), 0, 'L');
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->firstname) . ' ' . Tools::iconv('utf-8', self::encoding(), $invoice_address->lastname), 0, 'L');
     $pdf->Ln(5);
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address1), 0, 'L');
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->address1), 0, 'L');
     $pdf->Ln(5);
     if (!empty($invoice_address->address2) or !empty($delivery_address->address2)) {
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address2), 0, 'L');
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->address2), 0, 'L');
         $pdf->Ln(5);
     }
     $pdf->Cell($width, 10, $delivery_address->postcode . ' ' . Tools::iconv('utf-8', self::encoding(), $delivery_address->city), 0, 'L');
     $pdf->Cell($width, 10, $invoice_address->postcode . ' ' . Tools::iconv('utf-8', self::encoding(), $invoice_address->city), 0, 'L');
     $pdf->Ln(5);
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->country . ($deliveryState ? ' - ' . $deliveryState->name : '')), 0, 'L');
     $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->country . ($invoiceState ? ' - ' . $invoiceState->name : '')), 0, 'L');
     $pdf->Ln(5);
     $pdf->Cell($width, 10, $delivery_address->phone, 0, 'L');
     if ($invoice_customer->dni != NULL) {
         $pdf->Cell($width, 10, self::l('Tax ID number:') . ' ' . Tools::iconv('utf-8', self::encoding(), $invoice_customer->dni), 0, 'L');
     }
     if (!empty($delivery_address->phone_mobile)) {
         $pdf->Ln(5);
         $pdf->Cell($width, 10, $delivery_address->phone_mobile, 0, 'L');
     }
     /*
      * display order information
      */
     $carrier = new Carrier(self::$order->id_carrier);
     if ($carrier->name == '0') {
         $carrier->name = Configuration::get('PS_SHOP_NAME');
     }
     $history = self::$order->getHistory(self::$order->id_lang);
     foreach ($history as $h) {
         if ($h['id_order_state'] == _PS_OS_SHIPPING_) {
             $shipping_date = $h['date_add'];
         }
     }
     $pdf->Ln(12);
     $pdf->SetFillColor(240, 240, 240);
     $pdf->SetTextColor(0, 0, 0);
     $pdf->SetFont(self::fontname(), '', 9);
     if (self::$orderSlip) {
         $pdf->Cell(0, 6, self::l('SLIP #') . sprintf('%06d', self::$orderSlip->id) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$orderSlip->date_upd, self::$order->id_lang), 1, 2, 'L', 1);
     } elseif (self::$delivery) {
         $pdf->Cell(0, 6, self::l('DELIVERY SLIP #') . Configuration::get('PS_DELIVERY_PREFIX', intval($cookie->id_lang)) . sprintf('%06d', self::$delivery) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
     } else {
         $pdf->Cell(0, 6, self::l('INVOICE #') . Configuration::get('PS_INVOICE_PREFIX', intval($cookie->id_lang)) . sprintf('%06d', self::$order->invoice_number) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
     }
     $pdf->Cell(55, 6, self::l('Order #') . sprintf('%06d', self::$order->id), 'L', 0);
     $pdf->Cell(70, 6, self::l('Carrier:') . ($order->gift ? ' ' . Tools::iconv('utf-8', self::encoding(), $carrier->name) : ''), 'L');
     $pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
     $pdf->Ln(5);
     $pdf->Cell(55, 6, isset($shipping_date) ? self::l('Shipping date:') . ' ' . Tools::displayDate($shipping_date, self::$order->id_lang) : ' ', 'LB', 0);
     $pdf->Cell(70, 6, $order->gift ? self::l('Gift-wrapped order') : Tools::iconv('utf-8', self::encoding(), $carrier->name), 'LRB');
     $pdf->Cell(0, 6, Tools::iconv('utf-8', self::encoding(), $order->payment), 'LRB');
     $pdf->Ln(15);
     $pdf->ProdTab(self::$delivery ? true : '');
     /* Exit if delivery */
     if (!self::$delivery) {
         if (!self::$orderSlip) {
             $pdf->DiscTab();
         }
         $priceBreakDown = array();
         $pdf->priceBreakDownCalculation($priceBreakDown);
         if (!self::$orderSlip or self::$orderSlip and self::$orderSlip->shipping_cost) {
             $priceBreakDown['totalWithoutTax'] += Tools::ps_round($priceBreakDown['shippingCostWithoutTax'], 2) + Tools::ps_round($priceBreakDown['wrappingCostWithoutTax'], 2);
             $priceBreakDown['totalWithTax'] += self::$order->total_shipping + self::$order->total_wrapping;
         }
         if (!self::$orderSlip) {
             $taxDiscount = self::$order->getTaxesAverageUsed();
             if ($taxDiscount != 0) {
                 $priceBreakDown['totalWithoutTax'] -= Tools::ps_round(self::$order->total_discounts / (1 + self::$order->getTaxesAverageUsed() * 0.01), 2);
             } else {
                 $priceBreakDown['totalWithoutTax'] -= self::$order->total_discounts;
             }
             $priceBreakDown['totalWithTax'] -= self::$order->total_discounts;
         }
         /*
          * Display price summation
          */
         if (Configuration::get('PS_TAX') or $order->total_products_wt != $order->total_products) {
             $pdf->Ln(5);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products (tax excl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithoutTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products (tax incl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
         } else {
             $pdf->Ln(5);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products ') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithoutTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         if (!self::$orderSlip and self::$order->total_discounts != '0.00') {
             $pdf->Cell($width, 0, self::l('Total discounts (tax incl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (!self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_discounts, self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         if (isset(self::$order->total_wrapping) and floatval(self::$order->total_wrapping) > 0) {
             $pdf->Cell($width, 0, self::l('Total wrapping') . ' : ', 0, 0, 'R');
             if (self::$_priceDisplayMethod == PS_TAX_EXC) {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['wrappingCostWithoutTax'], self::$currency, true, false)), 0, 0, 'R');
             } else {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_wrapping, self::$currency, true, false)), 0, 0, 'R');
             }
             $pdf->Ln(4);
         }
         if (self::$order->total_shipping != '0.00' and (!self::$orderSlip or self::$orderSlip and self::$orderSlip->shipping_cost)) {
             $pdf->Cell($width, 0, self::l('Total shipping') . ' : ', 0, 0, 'R');
             if (self::$_priceDisplayMethod == PS_TAX_EXC) {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(Tools::ps_round($priceBreakDown['shippingCostWithoutTax'], 2), self::$currency, true, false)), 0, 0, 'R');
             } else {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_shipping, self::$currency, true, false)), 0, 0, 'R');
             }
             $pdf->Ln(4);
         }
         if (Configuration::get('PS_TAX') or $order->total_products_wt != $order->total_products) {
             $pdf->Cell($width, 0, self::l('Total') . ' ' . (self::$_priceDisplayMethod == PS_TAX_EXC ? self::l(' (tax incl.)') : self::l(' (tax excl.)')) . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$_priceDisplayMethod == PS_TAX_EXC ? $priceBreakDown['totalWithTax'] : $priceBreakDown['totalWithoutTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
             $pdf->Cell($width, 0, self::l('Total') . ' ' . (self::$_priceDisplayMethod == PS_TAX_EXC ? self::l(' (tax excl.)') : self::l(' (tax incl.)')) . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$_priceDisplayMethod == PS_TAX_EXC ? $priceBreakDown['totalWithoutTax'] : $priceBreakDown['totalWithTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
         } else {
             $pdf->Cell($width, 0, self::l('Total') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalWithoutTax'], self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         if ($ecotax != '0.00' and !self::$orderSlip) {
             $pdf->Cell($width, 0, self::l('Eco-participation') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, self::convertSign(Tools::displayPrice($ecotax, self::$currency, true, false)), 0, 0, 'R');
             $pdf->Ln(5);
         }
         $pdf->TaxTab($priceBreakDown);
     }
     Hook::PDFInvoice($pdf, self::$order->id);
     if (!$multiple) {
         return $pdf->Output(sprintf('%06d', self::$order->id) . '.pdf', $mode);
     }
 }
Exemple #14
0
 /**
  * @brief to display the payment option, so the customer will pay by merchant ware
  */
 public function hookPayment($params)
 {
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     if (!Validate::isLoadedObject($currency) || $currency->iso_code != 'USD') {
         return false;
     }
     $demo = 1;
     if ($demo == 1 || Configuration::get('PS_SSL_ENABLED') || !empty($_SERVER['HTTPS']) && Tools::strtolower($_SERVER['HTTPS']) != 'off') {
         $isFailed = Tools::getValue('aimerror');
         $cards = array();
         $achsetting = array();
         $midtype = array();
         $cards['visa'] = Configuration::get('ALLIANCE_CARD_VISA') == 'on';
         $cards['mastercard'] = Configuration::get('ALLIANCE_CARD_MASTERCARD') == 'on';
         $cards['discover'] = Configuration::get('ALLIANCE_CARD_DISCOVER') == 'on';
         $cards['ax'] = Configuration::get('ALLIANCE_CARD_AX') == 'on';
         $achsetting['identity'] = Configuration::get('ALLIANCEACH_IDENTITY');
         $achsetting['driver'] = Configuration::get('ALLIANCEACH_DRIVER');
         $midtype['authnet'] = Configuration::get('ALLIANCE_ENABLE');
         $midtype['achmod'] = Configuration::get('ALLIANCEACH_ENABLE');
         if (method_exists('Tools', 'getShopDomainSsl')) {
             $url = 'https://' . Tools::getShopDomainSsl() . __PS_BASE_URI__ . '/modules/' . $this->name . '/';
         } else {
             $url = 'https://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/';
         }
         $this->context->smarty->assign('x_invoice_num', (int) $params['cart']->id);
         $this->context->smarty->assign('cards', $cards);
         $this->context->smarty->assign('achsetting', $achsetting);
         $this->context->smarty->assign('midtype', $midtype);
         $this->context->smarty->assign('isFailed', $isFailed);
         $this->context->smarty->assign('new_base_dir', $url);
         return $this->display(__FILE__, 'views/templates/front/allianceaim.tpl');
     }
 }
 public function hookPayment($params)
 {
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     $isFailed = Tools::getValue('payfortstarterror');
     if (method_exists('Tools', 'getShopDomainSsl')) {
         $url = 'https://' . Tools::getShopDomainSsl() . __PS_BASE_URI__ . '/modules/' . $this->name . '/';
     } else {
         $url = 'https://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/';
     }
     if (Tools::safeOutput(Configuration::get('PAYFORT_START_TEST_MODE'))) {
         $configuration_open_key = Tools::safeOutput(Configuration::get('PAYFORT_START_TEST_OPEN_KEY'));
     } else {
         $configuration_open_key = Tools::safeOutput(Configuration::get('PAYFORT_START_LIVE_OPEN_KEY'));
     }
     $this->context->smarty->assign('configuration_open_key', $configuration_open_key);
     $cart = Context::getContext()->cart;
     $customer = new Customer((int) $cart->id_customer);
     $invoiceAddress = new Address((int) $cart->id_address_invoice);
     $currency = new Currency((int) $cart->id_currency);
     $amount = number_format((double) $cart->getOrderTotal(true, 3), 2, '.', '');
     $amount_in_cents = $amount * 100;
     $this->context->smarty->assign('email', $customer->email);
     $this->context->smarty->assign('currency', $currency->iso_code);
     $this->context->smarty->assign('amount', $amount);
     $this->context->smarty->assign('amount_in_cents', $amount_in_cents);
     $this->context->smarty->assign('isFailed', $isFailed);
     $this->context->smarty->assign('x_invoice_num', (int) $params['cart']->id);
     return $this->display(__FILE__, 'views/templates/hook/payfortstart.tpl');
 }
Exemple #16
0
    /**
     * Return available currencies
     *
     * @return array Currencies
     */
    public static function getCurrencies($object = false, $active = 1)
    {
        $sql = 'SELECT *
				FROM `' . _DB_PREFIX_ . 'currency` c
				' . Shop::addSqlAssociation('currency', 'c') . '
				WHERE `deleted` = 0' . ($active == 1 ? ' AND c.`active` = 1' : '') . '
				GROUP BY c.id_currency
				ORDER BY `name` ASC';
        $tab = Db::getInstance()->executeS($sql);
        if ($object) {
            foreach ($tab as $key => $currency) {
                $tab[$key] = Currency::getCurrencyInstance($currency['id_currency']);
            }
        }
        return $tab;
    }
 /**
  * Initializes front controller: sets smarty variables,
  * class properties, redirects depending on context, etc.
  *
  * @global bool     $useSSL           SSL connection flag
  * @global Cookie   $cookie           Visitor's cookie
  * @global Smarty   $smarty
  * @global Cart     $cart             Visitor's cart
  * @global string   $iso              Language ISO
  * @global Country  $defaultCountry   Visitor's country object
  * @global string   $protocol_link
  * @global string   $protocol_content
  * @global Link     $link
  * @global array    $css_files
  * @global array    $js_files
  * @global Currency $currency         Visitor's selected currency
  *
  * @throws PrestaShopException
  */
 public function init()
 {
     /**
      * Globals are DEPRECATED as of version 1.5.0.1
      * Use the Context object to access objects instead.
      * Example: $this->context->cart
      */
     global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     parent::init();
     // If current URL use SSL, set it true (used a lot for module redirect)
     if (Tools::usingSecureMode()) {
         $useSSL = true;
     }
     // For compatibility with globals, DEPRECATED as of version 1.5.0.1
     $css_files = $this->css_files;
     $js_files = $this->js_files;
     $this->sslRedirection();
     if ($this->ajax) {
         $this->display_header = false;
         $this->display_footer = false;
     }
     // If account created with the 2 steps register process, remove 'account_created' from cookie
     if (isset($this->context->cookie->account_created)) {
         $this->context->smarty->assign('account_created', 1);
         unset($this->context->cookie->account_created);
     }
     ob_start();
     // Init cookie language
     // @TODO This method must be moved into switchLanguage
     Tools::setCookieLanguage($this->context->cookie);
     $protocol_link = Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? 'https://' : 'http://';
     $useSSL = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $link = new Link($protocol_link, $protocol_content);
     $this->context->link = $link;
     if ($id_cart = (int) $this->recoverCart()) {
         $this->context->cookie->id_cart = (int) $id_cart;
     }
     if ($this->auth && !$this->context->customer->isLogged($this->guestAllowed)) {
         Tools::redirect('index.php?controller=authentication' . ($this->authRedirection ? '&back=' . $this->authRedirection : ''));
     }
     /* Theme is missing */
     if (!is_dir(_PS_THEME_DIR_)) {
         throw new PrestaShopException(sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\'))));
     }
     if (Configuration::get('PS_GEOLOCATION_ENABLED')) {
         if (($new_default = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($new_default)) {
             $this->context->country = $new_default;
         }
     } elseif (Configuration::get('PS_DETECT_COUNTRY')) {
         $has_currency = isset($this->context->cookie->id_currency) && (int) $this->context->cookie->id_currency;
         $has_country = isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country;
         $has_address_type = false;
         if ((int) $this->context->cookie->id_cart && ($cart = new Cart($this->context->cookie->id_cart)) && Validate::isLoadedObject($cart)) {
             $has_address_type = isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
         }
         if ((!$has_currency || $has_country) && !$has_address_type) {
             $id_country = $has_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country) ? (int) Country::getByIso(strtoupper($this->context->cookie->iso_code_country)) : (int) Tools::getCountry();
             $country = new Country($id_country, (int) $this->context->cookie->id_lang);
             if (validate::isLoadedObject($country) && $this->context->country->id !== $country->id) {
                 $this->context->country = $country;
                 $this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($country->id_currency ? (int) $country->id_currency : (int) Configuration::get('PS_CURRENCY_DEFAULT'))->id;
                 $this->context->cookie->iso_code_country = strtoupper($country->iso_code);
             }
         }
     }
     $currency = Tools::setCurrency($this->context->cookie);
     if (isset($_GET['logout']) || $this->context->customer->logged && Customer::isBanned($this->context->customer->id)) {
         $this->context->customer->logout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     } elseif (isset($_GET['mylogout'])) {
         $this->context->customer->mylogout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     }
     /* Cart already exists */
     if ((int) $this->context->cookie->id_cart) {
         if (!isset($cart)) {
             $cart = new Cart($this->context->cookie->id_cart);
         }
         if (Validate::isLoadedObject($cart) && $cart->OrderExists()) {
             PrestaShopLogger::addLog('Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart', 1, null, 'Cart', (int) $this->context->cookie->id_cart, true);
             unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
             $this->context->cookie->check_cgv = false;
         } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 && !FrontController::isInWhitelistForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
             PrestaShopLogger::addLog('Frontcontroller::init - GEOLOCATION is deleting a cart', 1, null, 'Cart', (int) $this->context->cookie->id_cart, true);
             unset($this->context->cookie->id_cart, $cart);
         } elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency) {
             if ($this->context->cookie->id_customer) {
                 $cart->id_customer = (int) $this->context->cookie->id_customer;
             }
             $cart->id_lang = (int) $this->context->cookie->id_lang;
             $cart->id_currency = (int) $currency->id;
             $cart->update();
         }
         /* Select an address if not set */
         if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer) {
             $to_update = false;
             if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
                 $to_update = true;
                 $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
                 $to_update = true;
                 $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if ($to_update) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || !$cart->id) {
         $cart = new Cart();
         $cart->id_lang = (int) $this->context->cookie->id_lang;
         $cart->id_currency = (int) $this->context->cookie->id_currency;
         $cart->id_guest = (int) $this->context->cookie->id_guest;
         $cart->id_shop_group = (int) $this->context->shop->id_shop_group;
         $cart->id_shop = $this->context->shop->id;
         if ($this->context->cookie->id_customer) {
             $cart->id_customer = (int) $this->context->cookie->id_customer;
             $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             $cart->id_address_invoice = (int) $cart->id_address_delivery;
         } else {
             $cart->id_address_delivery = 0;
             $cart->id_address_invoice = 0;
         }
         // Needed if the merchant want to give a free product to every visitors
         $this->context->cart = $cart;
         CartRule::autoAddToCart($this->context);
     } else {
         $this->context->cart = $cart;
     }
     /* get page name to display it in body id */
     // Are we in a payment module
     $module_name = '';
     if (Validate::isModuleName(Tools::getValue('module'))) {
         $module_name = Tools::getValue('module');
     }
     if (!empty($this->page_name)) {
         $page_name = $this->page_name;
     } elseif (!empty($this->php_self)) {
         $page_name = $this->php_self;
     } elseif (Tools::getValue('fc') == 'module' && $module_name != '' && Module::getInstanceByName($module_name) instanceof PaymentModule) {
         $page_name = 'module-payment-submit';
     } elseif (preg_match('#^' . preg_quote($this->context->shop->physical_uri, '#') . 'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
         $page_name = 'module-' . $m[1] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[2]);
     } else {
         $page_name = Dispatcher::getInstance()->getController();
         $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
     }
     $this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
     $this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
     /* Breadcrumb */
     $navigation_pipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
     $this->context->smarty->assign('navigationPipe', $navigation_pipe);
     // Automatically redirect to the canonical URL if needed
     if (!empty($this->php_self) && !Tools::getValue('ajax')) {
         $this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
     }
     Product::initPricesComputation();
     $display_tax_label = $this->context->country->display_tax_label;
     if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
         $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $country = new Country((int) $infos['id_country']);
         $this->context->country = $country;
         if (Validate::isLoadedObject($country)) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $languages = Language::getLanguages(true, $this->context->shop->id);
     $meta_language = array();
     foreach ($languages as $lang) {
         $meta_language[] = $lang['iso_code'];
     }
     $compared_products = array();
     if (Configuration::get('PS_COMPARATOR_MAX_ITEM') && isset($this->context->cookie->id_compare)) {
         $compared_products = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
     }
     $this->context->smarty->assign(array('mobile_device' => $this->context->getMobileDevice(), 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'currencyRate' => (double) $currency->getConversationRate(), 'cookie' => $this->context->cookie, 'page_name' => $page_name, 'hide_left_column' => !$this->display_column_left, 'hide_right_column' => !$this->display_column_right, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'force_ssl' => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'), 'content_dir' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__, 'base_uri' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__ . (!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''), 'tpl_dir' => _PS_THEME_DIR_, 'tpl_uri' => _THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $this->context->language->iso_code, 'lang_id' => (int) $this->context->language->id, 'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => $languages, 'meta_language' => implode(',', $meta_language), 'priceDisplay' => Product::getTaxCalculationMethod((int) $this->context->cookie->id_customer), 'is_logged' => (bool) $this->context->customer->isLogged(), 'is_guest' => (bool) $this->context->customer->isGuest(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'show_taxes' => (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX')), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE') || Group::isFeatureActive() && !(bool) Group::getCurrent()->show_prices, 'b2b_enable' => (bool) Configuration::get('PS_B2B_ENABLE'), 'request' => $link->getPaginationLink(false, false, false, true), 'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'), 'quick_view' => (bool) Configuration::get('PS_QUICK_VIEW'), 'shop_phone' => Configuration::get('PS_SHOP_PHONE'), 'compared_products' => is_array($compared_products) ? $compared_products : array(), 'comparator_max_item' => (int) Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'currencySign' => $currency->sign, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank));
     // Add the tpl files directory for mobile
     if ($this->useMobileTheme()) {
         $this->context->smarty->assign(array('tpl_mobile_uri' => _PS_THEME_MOBILE_DIR_));
     }
     // Deprecated
     $this->context->smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $this->context->customer->isLogged(), 'customerName' => $this->context->customer->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : false));
     $assign_array = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     // Add the images directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['img_mobile_dir'] = _THEME_MOBILE_IMG_DIR_;
     }
     // Add the CSS directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['css_mobile_dir'] = _THEME_MOBILE_CSS_DIR_;
     }
     foreach ($assign_array as $assign_key => $assign_value) {
         if (substr($assign_value, 0, 1) == '/' || $protocol_content == 'https://') {
             $this->context->smarty->assign($assign_key, $protocol_content . Tools::getMediaServer($assign_value) . $assign_value);
         } else {
             $this->context->smarty->assign($assign_key, $assign_value);
         }
     }
     /**
      * These shortcuts are DEPRECATED as of version 1.5.0.1
      * Use the Context to access objects instead.
      * Example: $this->context->cart
      */
     self::$cookie = $this->context->cookie;
     self::$cart = $cart;
     self::$smarty = $this->context->smarty;
     self::$link = $link;
     $defaultCountry = $this->context->country;
     $this->displayMaintenancePage();
     if ($this->restrictedCountry) {
         $this->displayRestrictedCountryPage();
     }
     if (Tools::isSubmit('live_edit') && !$this->checkLiveEditAccess()) {
         Tools::redirect('index.php?controller=404');
     }
     $this->iso = $iso;
     $this->context->cart = $cart;
     $this->context->currency = $currency;
 }
Exemple #18
0
 /**
  * Return package shipping cost
  *
  * @param integer $id_carrier Carrier ID (default : current carrier)
  * @param booleal $use_tax
  * @param Country $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($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null)
 {
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::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)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get id zone
     if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
         $id_zone = Address::getZoneById((int) $this->id_address_delivery);
     } else {
         if (!Validate::isLoadedObject($default_country)) {
             $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
         }
         $id_zone = (int) $default_country->id_zone;
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Fatal error: "no default carrier"'));
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(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 = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::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) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             $id_zone = (int) $default_country->id_zone;
         }
         $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->getTotalWeight(), (int) $id_zone);
         // Code Review V&V TO FINISH
         $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list), $id_zone, (int) $this->id_currency);
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // 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 = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $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) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     // Apply tax
     if ($use_tax && isset($carrier_tax)) {
         $shipping_cost *= 1 + $carrier_tax / 100;
     }
     // ###############################################################
     $num = $this->getTotalWeight($product_list);
     $countryAndState = Address::getCountryAndState((int) $this->id_address_delivery);
     $state = $countryAndState['id_state'];
     $pri = false;
     if ($pri) {
         echo "carrierid =>" . $id_carrier . "-";
         echo 'products => ' . $num . '-';
         echo 'state => ' . $state . '-';
     }
     //Ground
     //if( $id_carrier == 21 ){
     if ($id_carrier == 31) {
         //NO CA
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 19.75;
             } elseif ($num == 2) {
                 $shipping_cost = 20.5;
             } elseif ($num == 3) {
                 $shipping_cost = 22.0;
             } elseif ($num == 4) {
                 $shipping_cost = 24.5;
             } elseif ($num == 5) {
                 $shipping_cost = 25.75;
             } elseif ($num == 6) {
                 $shipping_cost = 27.0;
             } elseif ($num == 7) {
                 $shipping_cost = 30.5;
             } elseif ($num == 8) {
                 $shipping_cost = 31.5;
             } elseif ($num == 9) {
                 $shipping_cost = 32.25;
             } elseif ($num == 10) {
                 $shipping_cost = 33.5;
             } elseif ($num == 11) {
                 $shipping_cost = 34.25;
             } else {
                 $shipping_cost = 34.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 19.75;
             } elseif ($num == 2) {
                 $shipping_cost = 20.5;
             } elseif ($num == 3) {
                 $shipping_cost = 22.25;
             } elseif ($num == 4) {
                 $shipping_cost = 25.25;
             } elseif ($num == 5) {
                 $shipping_cost = 26.5;
             } elseif ($num == 6) {
                 $shipping_cost = 28.0;
             } elseif ($num == 7) {
                 $shipping_cost = 32.5;
             } elseif ($num == 8) {
                 $shipping_cost = 33.25;
             } elseif ($num == 9) {
                 $shipping_cost = 34.5;
             } elseif ($num == 10) {
                 $shipping_cost = 35.25;
             } elseif ($num == 11) {
                 $shipping_cost = 36.75;
             } else {
                 $shipping_cost = 38.0;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 22.75;
             } elseif ($num == 2) {
                 $shipping_cost = 23.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.0;
             } elseif ($num == 4) {
                 $shipping_cost = 25.75;
             } elseif ($num == 5) {
                 $shipping_cost = 27.5;
             } elseif ($num == 6) {
                 $shipping_cost = 28.25;
             } elseif ($num == 7) {
                 $shipping_cost = 33.25;
             } elseif ($num == 8) {
                 $shipping_cost = 34.5;
             } elseif ($num == 9) {
                 $shipping_cost = 35.5;
             } elseif ($num == 10) {
                 $shipping_cost = 36.75;
             } elseif ($num == 11) {
                 $shipping_cost = 38.0;
             } else {
                 $shipping_cost = 39.5;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 23.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.5;
             } elseif ($num == 3) {
                 $shipping_cost = 25.75;
             } elseif ($num == 4) {
                 $shipping_cost = 26.5;
             } elseif ($num == 5) {
                 $shipping_cost = 28.0;
             } elseif ($num == 6) {
                 $shipping_cost = 29.5;
             } elseif ($num == 7) {
                 $shipping_cost = 34.75;
             } elseif ($num == 8) {
                 $shipping_cost = 36.75;
             } elseif ($num == 9) {
                 $shipping_cost = 38.25;
             } elseif ($num == 10) {
                 $shipping_cost = 39.5;
             } elseif ($num == 11) {
                 $shipping_cost = 41.25;
             } else {
                 $shipping_cost = 42.5;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 26.25;
             } elseif ($num == 4) {
                 $shipping_cost = 27.75;
             } elseif ($num == 5) {
                 $shipping_cost = 30.25;
             } elseif ($num == 6) {
                 $shipping_cost = 33.25;
             } elseif ($num == 7) {
                 $shipping_cost = 38.5;
             } elseif ($num == 8) {
                 $shipping_cost = 41.25;
             } elseif ($num == 9) {
                 $shipping_cost = 44.0;
             } elseif ($num == 10) {
                 $shipping_cost = 45.75;
             } elseif ($num == 11) {
                 $shipping_cost = 47.75;
             } else {
                 $shipping_cost = 49.5;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 25.25;
             } elseif ($num == 3) {
                 $shipping_cost = 27.5;
             } elseif ($num == 4) {
                 $shipping_cost = 29.75;
             } elseif ($num == 5) {
                 $shipping_cost = 32.75;
             } elseif ($num == 6) {
                 $shipping_cost = 36.25;
             } elseif ($num == 7) {
                 $shipping_cost = 42.25;
             } elseif ($num == 8) {
                 $shipping_cost = 44.75;
             } elseif ($num == 9) {
                 $shipping_cost = 47.0;
             } elseif ($num == 10) {
                 $shipping_cost = 49.75;
             } elseif ($num == 11) {
                 $shipping_cost = 52.0;
             } else {
                 $shipping_cost = 54.0;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = 46.0;
             } elseif ($num == 2) {
                 $shipping_cost = 56.25;
             } elseif ($num == 3) {
                 $shipping_cost = 64.75;
             } elseif ($num == 4) {
                 $shipping_cost = 74.0;
             } elseif ($num == 5) {
                 $shipping_cost = 77.25;
             } elseif ($num == 6) {
                 $shipping_cost = 85.0;
             } elseif ($num == 7) {
                 $shipping_cost = 91.5;
             } elseif ($num == 8) {
                 $shipping_cost = 98.0;
             } elseif ($num == 9) {
                 $shipping_cost = 105.25;
             } elseif ($num == 10) {
                 $shipping_cost = 111.5;
             } elseif ($num == 11) {
                 $shipping_cost = 117.5;
             } else {
                 $shipping_cost = 124.25;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 26.25;
             } elseif ($num == 3) {
                 $shipping_cost = 28.75;
             } elseif ($num == 4) {
                 $shipping_cost = 30.25;
             } elseif ($num == 5) {
                 $shipping_cost = 35.0;
             } elseif ($num == 6) {
                 $shipping_cost = 39.0;
             } elseif ($num == 7) {
                 $shipping_cost = 45.5;
             } elseif ($num == 8) {
                 $shipping_cost = 48.75;
             } elseif ($num == 9) {
                 $shipping_cost = 51.75;
             } elseif ($num == 10) {
                 $shipping_cost = 54.75;
             } elseif ($num == 11) {
                 $shipping_cost = 58.0;
             } else {
                 $shipping_cost = 60.5;
             }
         }
     } elseif ($id_carrier == 30) {
         //NO CA - 302
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.25;
             } elseif ($num == 4) {
                 $shipping_cost = 26.25;
             } elseif ($num == 5) {
                 $shipping_cost = 27.75;
             } elseif ($num == 6) {
                 $shipping_cost = 29.75;
             } elseif ($num == 7) {
                 $shipping_cost = 32.25;
             } elseif ($num == 8) {
                 $shipping_cost = 34.5;
             } elseif ($num == 9) {
                 $shipping_cost = 36.25;
             } elseif ($num == 10) {
                 $shipping_cost = 38.0;
             } elseif ($num == 11) {
                 $shipping_cost = 40.0;
             } else {
                 $shipping_cost = 42.0;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 24.0;
             } elseif ($num == 2) {
                 $shipping_cost = 24.75;
             } elseif ($num == 3) {
                 $shipping_cost = 25.75;
             } elseif ($num == 4) {
                 $shipping_cost = 27.75;
             } elseif ($num == 5) {
                 $shipping_cost = 30.25;
             } elseif ($num == 6) {
                 $shipping_cost = 33.5;
             } elseif ($num == 7) {
                 $shipping_cost = 38.0;
             } elseif ($num == 8) {
                 $shipping_cost = 38.5;
             } elseif ($num == 9) {
                 $shipping_cost = 40.0;
             } elseif ($num == 10) {
                 $shipping_cost = 41.75;
             } elseif ($num == 11) {
                 $shipping_cost = 45.5;
             } else {
                 $shipping_cost = 47.75;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 25.75;
             } elseif ($num == 3) {
                 $shipping_cost = 27.0;
             } elseif ($num == 4) {
                 $shipping_cost = 30.5;
             } elseif ($num == 5) {
                 $shipping_cost = 34.0;
             } elseif ($num == 6) {
                 $shipping_cost = 36.75;
             } elseif ($num == 7) {
                 $shipping_cost = 40.25;
             } elseif ($num == 8) {
                 $shipping_cost = 42.25;
             } elseif ($num == 9) {
                 $shipping_cost = 45.25;
             } elseif ($num == 10) {
                 $shipping_cost = 47.75;
             } elseif ($num == 11) {
                 $shipping_cost = 50.75;
             } else {
                 $shipping_cost = 53.5;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 24.75;
             } elseif ($num == 2) {
                 $shipping_cost = 27.75;
             } elseif ($num == 3) {
                 $shipping_cost = 29.5;
             } elseif ($num == 4) {
                 $shipping_cost = 33.5;
             } elseif ($num == 5) {
                 $shipping_cost = 38.0;
             } elseif ($num == 6) {
                 $shipping_cost = 40.75;
             } elseif ($num == 7) {
                 $shipping_cost = 45.25;
             } elseif ($num == 8) {
                 $shipping_cost = 48.0;
             } elseif ($num == 9) {
                 $shipping_cost = 52.25;
             } elseif ($num == 10) {
                 $shipping_cost = 54.25;
             } elseif ($num == 11) {
                 $shipping_cost = 57.25;
             } else {
                 $shipping_cost = 62.25;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 25.5;
             } elseif ($num == 2) {
                 $shipping_cost = 30.5;
             } elseif ($num == 3) {
                 $shipping_cost = 36.0;
             } elseif ($num == 4) {
                 $shipping_cost = 40.25;
             } elseif ($num == 5) {
                 $shipping_cost = 47.75;
             } elseif ($num == 6) {
                 $shipping_cost = 51.25;
             } elseif ($num == 7) {
                 $shipping_cost = 56.25;
             } elseif ($num == 8) {
                 $shipping_cost = 60.25;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 69.5;
             } elseif ($num == 11) {
                 $shipping_cost = 74.25;
             } else {
                 $shipping_cost = 78.5;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 31.5;
             } elseif ($num == 2) {
                 $shipping_cost = 33.25;
             } elseif ($num == 3) {
                 $shipping_cost = 38.5;
             } elseif ($num == 4) {
                 $shipping_cost = 43.75;
             } elseif ($num == 5) {
                 $shipping_cost = 49.5;
             } elseif ($num == 6) {
                 $shipping_cost = 54.75;
             } elseif ($num == 7) {
                 $shipping_cost = 62.25;
             } elseif ($num == 8) {
                 $shipping_cost = 67.0;
             } elseif ($num == 9) {
                 $shipping_cost = 72.0;
             } elseif ($num == 10) {
                 $shipping_cost = 77.25;
             } elseif ($num == 11) {
                 $shipping_cost = 81.5;
             } else {
                 $shipping_cost = 86.5;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 28.25;
             } elseif ($num == 2) {
                 $shipping_cost = 34.25;
             } elseif ($num == 3) {
                 $shipping_cost = 41.0;
             } elseif ($num == 4) {
                 $shipping_cost = 48.25;
             } elseif ($num == 5) {
                 $shipping_cost = 54.0;
             } elseif ($num == 6) {
                 $shipping_cost = 59.0;
             } elseif ($num == 7) {
                 $shipping_cost = 67.0;
             } elseif ($num == 8) {
                 $shipping_cost = 73.75;
             } elseif ($num == 9) {
                 $shipping_cost = 77.5;
             } elseif ($num == 10) {
                 $shipping_cost = 83.25;
             } elseif ($num == 11) {
                 $shipping_cost = 88.5;
             } else {
                 $shipping_cost = 93.0;
             }
         }
     } elseif ($id_carrier == 32) {
         //NO CA - 202
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 23.75;
             } elseif ($num == 3) {
                 $shipping_cost = 26.0;
             } elseif ($num == 4) {
                 $shipping_cost = 27.5;
             } elseif ($num == 5) {
                 $shipping_cost = 29.25;
             } elseif ($num == 6) {
                 $shipping_cost = 30.75;
             } elseif ($num == 7) {
                 $shipping_cost = 34.75;
             } elseif ($num == 8) {
                 $shipping_cost = 37.5;
             } elseif ($num == 9) {
                 $shipping_cost = 40.0;
             } elseif ($num == 10) {
                 $shipping_cost = 40.75;
             } elseif ($num == 11) {
                 $shipping_cost = 43.25;
             } else {
                 $shipping_cost = 45.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 24.25;
             } elseif ($num == 3) {
                 $shipping_cost = 28.0;
             } elseif ($num == 4) {
                 $shipping_cost = 29.25;
             } elseif ($num == 5) {
                 $shipping_cost = 31.75;
             } elseif ($num == 6) {
                 $shipping_cost = 34.75;
             } elseif ($num == 7) {
                 $shipping_cost = 38.75;
             } elseif ($num == 8) {
                 $shipping_cost = 41.25;
             } elseif ($num == 9) {
                 $shipping_cost = 43.75;
             } elseif ($num == 10) {
                 $shipping_cost = 46.25;
             } elseif ($num == 11) {
                 $shipping_cost = 48.25;
             } else {
                 $shipping_cost = 50.5;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 23.75;
             } elseif ($num == 2) {
                 $shipping_cost = 25.5;
             } elseif ($num == 3) {
                 $shipping_cost = 30.75;
             } elseif ($num == 4) {
                 $shipping_cost = 33.0;
             } elseif ($num == 5) {
                 $shipping_cost = 36.25;
             } elseif ($num == 6) {
                 $shipping_cost = 40.5;
             } elseif ($num == 7) {
                 $shipping_cost = 44.75;
             } elseif ($num == 8) {
                 $shipping_cost = 46.5;
             } elseif ($num == 9) {
                 $shipping_cost = 50.25;
             } elseif ($num == 10) {
                 $shipping_cost = 52.5;
             } elseif ($num == 11) {
                 $shipping_cost = 55.25;
             } else {
                 $shipping_cost = 59.0;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 27.25;
             } elseif ($num == 2) {
                 $shipping_cost = 30.75;
             } elseif ($num == 3) {
                 $shipping_cost = 36.0;
             } elseif ($num == 4) {
                 $shipping_cost = 41.0;
             } elseif ($num == 5) {
                 $shipping_cost = 46.0;
             } elseif ($num == 6) {
                 $shipping_cost = 50.5;
             } elseif ($num == 7) {
                 $shipping_cost = 57.25;
             } elseif ($num == 8) {
                 $shipping_cost = 61.75;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 68.75;
             } elseif ($num == 11) {
                 $shipping_cost = 72.25;
             } else {
                 $shipping_cost = 76.75;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 29.25;
             } elseif ($num == 2) {
                 $shipping_cost = 38.75;
             } elseif ($num == 3) {
                 $shipping_cost = 46.5;
             } elseif ($num == 4) {
                 $shipping_cost = 54.75;
             } elseif ($num == 5) {
                 $shipping_cost = 62.75;
             } elseif ($num == 6) {
                 $shipping_cost = 69.75;
             } elseif ($num == 7) {
                 $shipping_cost = 77.75;
             } elseif ($num == 8) {
                 $shipping_cost = 84.25;
             } elseif ($num == 9) {
                 $shipping_cost = 90.75;
             } elseif ($num == 10) {
                 $shipping_cost = 96.75;
             } elseif ($num == 11) {
                 $shipping_cost = 105.0;
             } else {
                 $shipping_cost = 111.25;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 32.0;
             } elseif ($num == 2) {
                 $shipping_cost = 40.25;
             } elseif ($num == 3) {
                 $shipping_cost = 49.75;
             } elseif ($num == 4) {
                 $shipping_cost = 58.0;
             } elseif ($num == 5) {
                 $shipping_cost = 65.5;
             } elseif ($num == 6) {
                 $shipping_cost = 74.25;
             } elseif ($num == 7) {
                 $shipping_cost = 82.5;
             } elseif ($num == 8) {
                 $shipping_cost = 89.5;
             } elseif ($num == 9) {
                 $shipping_cost = 96.5;
             } elseif ($num == 10) {
                 $shipping_cost = 102.5;
             } elseif ($num == 11) {
                 $shipping_cost = 109.25;
             } else {
                 $shipping_cost = 116.75;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 34.75;
             } elseif ($num == 2) {
                 $shipping_cost = 41.0;
             } elseif ($num == 3) {
                 $shipping_cost = 50.25;
             } elseif ($num == 4) {
                 $shipping_cost = 59.75;
             } elseif ($num == 5) {
                 $shipping_cost = 66.5;
             } elseif ($num == 6) {
                 $shipping_cost = 75.25;
             } elseif ($num == 7) {
                 $shipping_cost = 84.5;
             } elseif ($num == 8) {
                 $shipping_cost = 92.25;
             } elseif ($num == 9) {
                 $shipping_cost = 98.5;
             } elseif ($num == 10) {
                 $shipping_cost = 105.5;
             } elseif ($num == 11) {
                 $shipping_cost = 112.0;
             } else {
                 $shipping_cost = 119.25;
             }
         }
     } elseif ($id_carrier == 29) {
         //NO CA - 102
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 27.25;
             } elseif ($num == 2) {
                 $shipping_cost = 29.0;
             } elseif ($num == 3) {
                 $shipping_cost = 32.75;
             } elseif ($num == 4) {
                 $shipping_cost = 36.25;
             } elseif ($num == 5) {
                 $shipping_cost = 38.75;
             } elseif ($num == 6) {
                 $shipping_cost = 40.75;
             } elseif ($num == 7) {
                 $shipping_cost = 45.25;
             } elseif ($num == 8) {
                 $shipping_cost = 48.25;
             } elseif ($num == 9) {
                 $shipping_cost = 50.5;
             } elseif ($num == 10) {
                 $shipping_cost = 54.75;
             } elseif ($num == 11) {
                 $shipping_cost = 56.25;
             } else {
                 $shipping_cost = 60.5;
             }
         } elseif ($state == 5 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 31.75;
             } elseif ($num == 2) {
                 $shipping_cost = 37.5;
             } elseif ($num == 3) {
                 $shipping_cost = 39.5;
             } elseif ($num == 4) {
                 $shipping_cost = 44.25;
             } elseif ($num == 5) {
                 $shipping_cost = 48.0;
             } elseif ($num == 6) {
                 $shipping_cost = 52.75;
             } elseif ($num == 7) {
                 $shipping_cost = 56.75;
             } elseif ($num == 8) {
                 $shipping_cost = 59.5;
             } elseif ($num == 9) {
                 $shipping_cost = 65.0;
             } elseif ($num == 10) {
                 $shipping_cost = 67.5;
             } elseif ($num == 11) {
                 $shipping_cost = 71.25;
             } else {
                 $shipping_cost = 76.5;
             }
         } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) {
             if ($num == 1) {
                 $shipping_cost = 38.75;
             } elseif ($num == 2) {
                 $shipping_cost = 47.75;
             } elseif ($num == 3) {
                 $shipping_cost = 57.75;
             } elseif ($num == 4) {
                 $shipping_cost = 64.0;
             } elseif ($num == 5) {
                 $shipping_cost = 71.25;
             } elseif ($num == 6) {
                 $shipping_cost = 80.75;
             } elseif ($num == 7) {
                 $shipping_cost = 85.75;
             } elseif ($num == 8) {
                 $shipping_cost = 92.5;
             } elseif ($num == 9) {
                 $shipping_cost = 100.75;
             } elseif ($num == 10) {
                 $shipping_cost = 105.25;
             } elseif ($num == 11) {
                 $shipping_cost = 111.5;
             } else {
                 $shipping_cost = 117.75;
             }
         } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) {
             if ($num == 1) {
                 $shipping_cost = 41.25;
             } elseif ($num == 2) {
                 $shipping_cost = 50.75;
             } elseif ($num == 3) {
                 $shipping_cost = 61.75;
             } elseif ($num == 4) {
                 $shipping_cost = 70.75;
             } elseif ($num == 5) {
                 $shipping_cost = 78.75;
             } elseif ($num == 6) {
                 $shipping_cost = 86.75;
             } elseif ($num == 7) {
                 $shipping_cost = 91.5;
             } elseif ($num == 8) {
                 $shipping_cost = 99.0;
             } elseif ($num == 9) {
                 $shipping_cost = 105.5;
             } elseif ($num == 10) {
                 $shipping_cost = 113.0;
             } elseif ($num == 11) {
                 $shipping_cost = 119.75;
             } else {
                 $shipping_cost = 126.5;
             }
         } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) {
             if ($num == 1) {
                 $shipping_cost = 46.75;
             } elseif ($num == 2) {
                 $shipping_cost = 53.75;
             } elseif ($num == 3) {
                 $shipping_cost = 67.25;
             } elseif ($num == 4) {
                 $shipping_cost = 77.0;
             } elseif ($num == 5) {
                 $shipping_cost = 83.75;
             } elseif ($num == 6) {
                 $shipping_cost = 93.0;
             } elseif ($num == 7) {
                 $shipping_cost = 100.25;
             } elseif ($num == 8) {
                 $shipping_cost = 103.0;
             } elseif ($num == 9) {
                 $shipping_cost = 112.25;
             } elseif ($num == 10) {
                 $shipping_cost = 120.5;
             } elseif ($num == 11) {
                 $shipping_cost = 126.25;
             } else {
                 $shipping_cost = 132.0;
             }
         } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) {
             if ($num == 1) {
                 $shipping_cost = 49.25;
             } elseif ($num == 2) {
                 $shipping_cost = 56.25;
             } elseif ($num == 3) {
                 $shipping_cost = 69.0;
             } elseif ($num == 4) {
                 $shipping_cost = 79.25;
             } elseif ($num == 5) {
                 $shipping_cost = 88.25;
             } elseif ($num == 6) {
                 $shipping_cost = 95.75;
             } elseif ($num == 7) {
                 $shipping_cost = 101.5;
             } elseif ($num == 8) {
                 $shipping_cost = 109.25;
             } elseif ($num == 9) {
                 $shipping_cost = 116.0;
             } elseif ($num == 10) {
                 $shipping_cost = 123.25;
             } elseif ($num == 11) {
                 $shipping_cost = 130.0;
             } else {
                 $shipping_cost = 138.75;
             }
         } elseif ($state == 2 || $state == 11) {
             if ($num == 1) {
                 $shipping_cost = 53.75;
             } elseif ($num == 2) {
                 $shipping_cost = 67.5;
             } elseif ($num == 3) {
                 $shipping_cost = 78.75;
             } elseif ($num == 4) {
                 $shipping_cost = 85.5;
             } elseif ($num == 5) {
                 $shipping_cost = 96.75;
             } elseif ($num == 6) {
                 $shipping_cost = 101.5;
             } elseif ($num == 7) {
                 $shipping_cost = 116.25;
             } elseif ($num == 8) {
                 $shipping_cost = 130.0;
             } elseif ($num == 9) {
                 $shipping_cost = 142.5;
             } elseif ($num == 10) {
                 $shipping_cost = 152.5;
             } elseif ($num == 11) {
                 $shipping_cost = 159.75;
             } else {
                 $shipping_cost = 168.25;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = 50.75;
             } elseif ($num == 2) {
                 $shipping_cost = 60.5;
             } elseif ($num == 3) {
                 $shipping_cost = 70.5;
             } elseif ($num == 4) {
                 $shipping_cost = 81.0;
             } elseif ($num == 5) {
                 $shipping_cost = 90.25;
             } elseif ($num == 6) {
                 $shipping_cost = 98.5;
             } elseif ($num == 7) {
                 $shipping_cost = 104.5;
             } elseif ($num == 8) {
                 $shipping_cost = 113.0;
             } elseif ($num == 9) {
                 $shipping_cost = 119.25;
             } elseif ($num == 10) {
                 $shipping_cost = 127.0;
             } elseif ($num == 11) {
                 $shipping_cost = 133.75;
             } else {
                 $shipping_cost = 139.75;
             }
         }
     } elseif ($id_carrier == 16) {
         //NO CA
         if ($state == 313) {
             if ($num == 1) {
                 $shipping_cost = 11.0;
             } elseif ($num == 2) {
                 $shipping_cost = 12.0;
             } elseif ($num == 3) {
                 $shipping_cost = 12.75;
             } elseif ($num == 4) {
                 $shipping_cost = 14.75;
             } elseif ($num == 5) {
                 $shipping_cost = 15.75;
             } elseif ($num == 6) {
                 $shipping_cost = 16.0;
             } elseif ($num == 7) {
                 $shipping_cost = 19.0;
             } elseif ($num == 8) {
                 $shipping_cost = 19.25;
             } elseif ($num == 9) {
                 $shipping_cost = 20.0;
             } elseif ($num == 10) {
                 $shipping_cost = 20.75;
             } elseif ($num == 11) {
                 $shipping_cost = 22.0;
             } else {
                 $shipping_cost = 22.25;
             }
         } elseif ($state == 314) {
             if ($num == 1) {
                 $shipping_cost = 11.75;
             } elseif ($num == 2) {
                 $shipping_cost = 12.5;
             } elseif ($num == 3) {
                 $shipping_cost = 13.75;
             } elseif ($num == 4) {
                 $shipping_cost = 14.75;
             } elseif ($num == 5) {
                 $shipping_cost = 16.0;
             } elseif ($num == 6) {
                 $shipping_cost = 16.75;
             } elseif ($num == 7) {
                 $shipping_cost = 20.0;
             } elseif ($num == 8) {
                 $shipping_cost = 20.75;
             } elseif ($num == 9) {
                 $shipping_cost = 22.0;
             } elseif ($num == 10) {
                 $shipping_cost = 22.75;
             } elseif ($num == 11) {
                 $shipping_cost = 24.0;
             } else {
                 $shipping_cost = 24.0;
             }
         } elseif ($state == 315) {
             if ($num == 1) {
                 $shipping_cost = 12.25;
             } elseif ($num == 2) {
                 $shipping_cost = 13.75;
             } elseif ($num == 3) {
                 $shipping_cost = 14.5;
             } elseif ($num == 4) {
                 $shipping_cost = 15.75;
             } elseif ($num == 5) {
                 $shipping_cost = 16.5;
             } elseif ($num == 6) {
                 $shipping_cost = 17.0;
             } elseif ($num == 7) {
                 $shipping_cost = 20.5;
             } elseif ($num == 8) {
                 $shipping_cost = 22.0;
             } elseif ($num == 9) {
                 $shipping_cost = 22.75;
             } elseif ($num == 10) {
                 $shipping_cost = 24.0;
             } elseif ($num == 11) {
                 $shipping_cost = 25.25;
             } else {
                 $shipping_cost = 26.0;
             }
         } elseif ($state == 3 || $state == 28) {
             if ($num == 1) {
                 $shipping_cost = 12.25;
             } elseif ($num == 2) {
                 $shipping_cost = 14.0;
             } elseif ($num == 3) {
                 $shipping_cost = 14.75;
             } elseif ($num == 4) {
                 $shipping_cost = 16.25;
             } elseif ($num == 5) {
                 $shipping_cost = 17.75;
             } elseif ($num == 6) {
                 $shipping_cost = 18.75;
             } elseif ($num == 7) {
                 $shipping_cost = 22.5;
             } elseif ($num == 8) {
                 $shipping_cost = 24.0;
             } elseif ($num == 9) {
                 $shipping_cost = 25.25;
             } elseif ($num == 10) {
                 $shipping_cost = 26.75;
             } elseif ($num == 11) {
                 $shipping_cost = 28.25;
             } else {
                 $shipping_cost = 29.0;
             }
         } else {
             if ($num == 1) {
                 $shipping_cost = -1;
             } elseif ($num == 2) {
                 $shipping_cost = -1;
             } elseif ($num == 3) {
                 $shipping_cost = -1;
             } elseif ($num == 4) {
                 $shipping_cost = -1;
             } elseif ($num == 5) {
                 $shipping_cost = -1;
             } elseif ($num == 6) {
                 $shipping_cost = -1;
             } elseif ($num == 7) {
                 $shipping_cost = -1;
             } elseif ($num == 8) {
                 $shipping_cost = -1;
             } elseif ($num == 9) {
                 $shipping_cost = -1;
             } elseif ($num == 10) {
                 $shipping_cost = -1;
             } elseif ($num == 11) {
                 $shipping_cost = -1;
             } else {
                 $shipping_cost = -1;
             }
         }
     }
     //###############################################################
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
Exemple #19
0
 /**
  * Return price converted
  *
  * @param float $price Product price
  * @param object $currency Current currency object
  * @param boolean $to_currency convert to currency or from currency to default currency
  */
 public static function convertPrice($price, $currency = NULL, $to_currency = true)
 {
     if ($currency === NULL) {
         $currency = Currency::getCurrent();
     } elseif (is_numeric($currency)) {
         $currency = Currency::getCurrencyInstance($currency);
     }
     $c_id = is_array($currency) ? $currency['id_currency'] : $currency->id;
     $c_rate = is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate;
     if ($c_id != (int) Configuration::get('PS_CURRENCY_DEFAULT')) {
         if ($to_currency) {
             $price *= $c_rate;
         } else {
             $price /= $c_rate;
         }
     }
     return $price;
 }
Exemple #20
0
 /**
  * Main
  *
  * @param object $order Order
  * @param string $mode Download or display (optional)
  */
 public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false)
 {
     global $cookie;
     if (!Validate::isLoadedObject($order) or !$cookie->id_employee and (!OrderState::invoiceAvailable($order->getCurrentState()) and !$order->invoice_number)) {
         die('Invalid order or invalid order state');
     }
     self::$order = $order;
     self::$orderSlip = $slip;
     self::$delivery = $delivery;
     self::$_iso = strtoupper(Language::getIsoById((int) self::$order->id_lang));
     if ((self::$_priceDisplayMethod = $order->getTaxCalculationMethod()) === false) {
         die(self::l('No price display method defined for the customer group'));
     }
     if (!$multiple) {
         $pdf = new PDF('P', 'mm', 'A4');
     }
     $pdf->SetAutoPageBreak(true, 35);
     $pdf->StartPageGroup();
     self::$currency = Currency::getCurrencyInstance((int) self::$order->id_currency);
     $pdf->AliasNbPages();
     $pdf->AddPage();
     $width = 100;
     $pdf->SetX(10);
     $pdf->SetY(25);
     $pdf->SetFont(self::fontname(), '', 12);
     $pdf->Cell($width, 10, self::l('Delivery'), 0, 'L');
     $pdf->Cell($width, 10, self::l('Invoicing'), 0, 'L');
     $pdf->Ln(5);
     $pdf->SetFont(self::fontname(), '', 9);
     $addressType = array('delivery' => array(), 'invoice' => array());
     $patternRules = array('optional' => array('address2', 'company'), 'avoid' => array('State:iso_code'));
     $addressType = self::generateHeaderAddresses($pdf, $order, $addressType, $patternRules, $width);
     if (Configuration::get('VATNUMBER_MANAGEMENT') and !empty($addressType['invoice']['addressObject']->vat_number)) {
         $vat_delivery = '';
         if ($addressType['invoice']['addressObject']->id != $addressType['delivery']['addressObject']->id) {
             $vat_delivery = $addressType['delivery']['addressObject']->vat_number;
         }
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $vat_delivery), 0, 'L');
         $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $addressType['invoice']['addressObject']->vat_number), 0, 'L');
         $pdf->Ln(5);
     }
     if ($addressType['invoice']['addressObject']->dni != NULL) {
         $pdf->Cell($width, 10, self::l('Tax ID number:') . ' ' . Tools::iconv('utf-8', self::encoding(), $addressType['invoice']['addressObject']->dni), 0, 'L');
     }
     /*
      * display order information
      */
     $carrier = new Carrier(self::$order->id_carrier);
     if ($carrier->name == '0') {
         $carrier->name = Configuration::get('PS_SHOP_NAME');
     }
     $history = self::$order->getHistory(self::$order->id_lang);
     foreach ($history as $h) {
         if ($h['id_order_state'] == Configuration::get('PS_OS_SHIPPING')) {
             $shipping_date = $h['date_add'];
         }
     }
     $pdf->Ln(12);
     $pdf->SetFillColor(240, 240, 240);
     $pdf->SetTextColor(0, 0, 0);
     $pdf->SetFont(self::fontname(), '', 9);
     if (self::$orderSlip) {
         $pdf->Cell(0, 6, self::l('SLIP #') . ' ' . sprintf('%06d', self::$orderSlip->id) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$orderSlip->date_upd, self::$order->id_lang), 1, 2, 'L', 1);
     } elseif (self::$delivery) {
         $pdf->Cell(0, 6, self::l('DELIVERY SLIP #') . Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', (int) $cookie->id_lang)) . sprintf('%06d', self::$delivery) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
     } elseif ((int) self::$order->invoice_date) {
         $pdf->Cell(0, 6, self::l('INVOICE #') . ' ' . Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', (int) $cookie->id_lang)) . sprintf('%06d', self::$order->invoice_number) . ' ' . self::l('from') . ' ' . Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
     } else {
         $pdf->Cell(0, 6, self::l('Invoice draft'), 1, 2, 'L', 1);
     }
     $pdf->Cell(55, 6, self::l('Order #') . ' ' . sprintf('%06d', self::$order->id), 'L', 0);
     $pdf->Cell(70, 6, self::l('Carrier:') . ($order->gift ? ' ' . Tools::iconv('utf-8', self::encoding(), $carrier->name) : ''), 'L');
     $pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
     $pdf->Ln(5);
     $pdf->Cell(55, 6, isset($shipping_date) ? self::l('Shipping date:') . ' ' . Tools::displayDate($shipping_date, self::$order->id_lang) : ' ', 'LB', 0);
     $pdf->Cell(70, 6, $order->gift ? self::l('Gift-wrapped order') : Tools::iconv('utf-8', self::encoding(), $carrier->name), 'LRB');
     $pdf->Cell(0, 6, Tools::iconv('utf-8', self::encoding(), $order->payment), 'LRB');
     $pdf->Ln(15);
     $pdf->ProdTab(self::$delivery ? true : '');
     /* Canada */
     $taxable_address = new Address((int) self::$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     if (!self::$delivery && strtoupper(Country::getIsoById((int) $taxable_address->id_country)) == 'CA') {
         $pdf->Ln(15);
         $taxToDisplay = Db::getInstance()->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'order_tax WHERE id_order = ' . (int) self::$order->id);
         foreach ($taxToDisplay as $t) {
             $pdf->Cell(0, 6, utf8_decode($t['tax_name']) . ' (' . number_format($t['tax_rate'], 2, '.', '') . '%)      ' . self::convertSign(Tools::displayPrice($t['amount'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(5);
         }
     }
     /* End */
     /* Exit if delivery */
     if (!self::$delivery) {
         if (!self::$orderSlip) {
             $pdf->DiscTab();
         }
         $priceBreakDown = array();
         $pdf->priceBreakDownCalculation($priceBreakDown);
         if (!self::$orderSlip or self::$orderSlip and self::$orderSlip->shipping_cost) {
             $priceBreakDown['totalWithoutTax'] += Tools::ps_round($priceBreakDown['shippingCostWithoutTax'], 2) + Tools::ps_round($priceBreakDown['wrappingCostWithoutTax'], 2);
             $priceBreakDown['totalWithTax'] += self::$order->total_shipping + self::$order->total_wrapping;
         }
         if (!self::$orderSlip) {
             $taxDiscount = self::$order->getTaxesAverageUsed();
             if ($taxDiscount != 0) {
                 $priceBreakDown['totalWithoutTax'] -= Tools::ps_round(self::$order->total_discounts / (1 + self::$order->getTaxesAverageUsed() * 0.01), 2);
             } else {
                 $priceBreakDown['totalWithoutTax'] -= self::$order->total_discounts;
             }
             $priceBreakDown['totalWithTax'] -= self::$order->total_discounts;
         }
         /*
          * Display price summation
          */
         if (Configuration::get('PS_TAX') or $order->total_products_wt != $order->total_products) {
             $pdf->Ln(5);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products (tax excl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithoutTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products (tax incl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
         } else {
             $pdf->Ln(5);
             $pdf->SetFont(self::fontname(), 'B', 8);
             $width = 165;
             $pdf->Cell($width, 0, self::l('Total products ') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalProductsWithoutTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         if (!self::$orderSlip and self::$order->total_discounts != '0.00') {
             $pdf->Cell($width, 0, self::l('Total discounts (tax incl.)') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (!self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_discounts, self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         if (isset(self::$order->total_wrapping) and (double) self::$order->total_wrapping > 0) {
             $pdf->Cell($width, 0, self::l('Total gift-wrapping') . ' : ', 0, 0, 'R');
             if (self::$_priceDisplayMethod == PS_TAX_EXC) {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['wrappingCostWithoutTax'], self::$currency, true)), 0, 0, 'R');
             } else {
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_wrapping, self::$currency, true)), 0, 0, 'R');
             }
             $pdf->Ln(4);
         }
         if (self::$order->total_shipping != '0.00' and (!self::$orderSlip or self::$orderSlip and self::$orderSlip->shipping_cost)) {
             if (self::$_priceDisplayMethod == PS_TAX_EXC) {
                 $pdf->Cell($width, 0, self::l('Total shipping (tax excl.)') . ' : ', 0, 0, 'R');
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(Tools::ps_round($priceBreakDown['shippingCostWithoutTax'], 2), self::$currency, true)), 0, 0, 'R');
             } else {
                 $pdf->Cell($width, 0, self::l('Total shipping (tax incl.)') . ' : ', 0, 0, 'R');
                 $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_shipping, self::$currency, true)), 0, 0, 'R');
             }
             $pdf->Ln(4);
         }
         if (Configuration::get('PS_TAX') or $order->total_products_wt != $order->total_products) {
             $pdf->Cell($width, 0, self::l('Total') . ' ' . (self::$_priceDisplayMethod == PS_TAX_EXC ? self::l(' (tax incl.)') : self::l(' (tax excl.)')) . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$_priceDisplayMethod == PS_TAX_EXC ? $priceBreakDown['totalWithTax'] : $priceBreakDown['totalWithoutTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
             $pdf->Cell($width, 0, self::l('Total') . ' ' . (self::$_priceDisplayMethod == PS_TAX_EXC ? self::l(' (tax excl.)') : self::l(' (tax incl.)')) . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$_priceDisplayMethod == PS_TAX_EXC ? $priceBreakDown['totalWithoutTax'] : $priceBreakDown['totalWithTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
         } else {
             $pdf->Cell($width, 0, self::l('Total') . ' : ', 0, 0, 'R');
             $pdf->Cell(0, 0, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalWithoutTax'], self::$currency, true)), 0, 0, 'R');
             $pdf->Ln(4);
         }
         $pdf->TaxTab($priceBreakDown);
     }
     Hook::PDFInvoice($pdf, self::$order->id);
     if (!$multiple) {
         return $pdf->Output(sprintf('%06d', self::$order->id) . '.pdf', $mode);
     }
 }
Exemple #21
0
 /**
  * Return shipping total
  *
  * @param integer $id_carrier Carrier ID (default : current carrier)
  * @return float Shipping total
  */
 function getOrderShippingCost($id_carrier = NULL, $useTax = true)
 {
     global $defaultCountry;
     if ($this->isVirtualCart()) {
         return 0;
     }
     // Checking discounts in cart
     $products = $this->getProducts();
     $discounts = $this->getDiscounts(true);
     if ($discounts) {
         foreach ($discounts as $id_discount) {
             if ($id_discount['id_discount_type'] == 3) {
                 if ($id_discount['minimal'] > 0) {
                     $total_cart = 0;
                     $categories = Discount::getCategories((int) $id_discount['id_discount']);
                     if (sizeof($categories)) {
                         foreach ($products as $product) {
                             if (Product::idIsOnCategoryId((int) $product['id_product'], $categories)) {
                                 $total_cart += $product['total_wt'];
                             }
                         }
                     }
                     if ($total_cart >= $id_discount['minimal']) {
                         return 0;
                     }
                 } else {
                     return 0;
                 }
             }
         }
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if ($order_total <= 0 and !(int) self::getNbProducts($this->id)) {
         return $shipping_cost;
     }
     // Get id zone
     if (isset($this->id_address_delivery) and $this->id_address_delivery and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
         $id_zone = Address::getZoneById((int) $this->id_address_delivery);
     } else {
         // This method can be called from the backend, and $defaultCountry won't be defined
         if (!Validate::isLoadedObject($defaultCountry)) {
             $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
         }
         $id_zone = (int) $defaultCountry->id_zone;
     }
     // If no carrier, select default one
     if (!$id_carrier) {
         $id_carrier = $this->id_carrier;
     }
     if ($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange(Configuration::get('PS_CARRIER_DEFAULT'), $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
             if (!isset($minShippingPrice)) {
                 $minShippingPrice = $shipping;
             }
             if ($shipping <= $minShippingPrice) {
                 $id_carrier = (int) $row['id_carrier'];
                 $minShippingPrice = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     if (!Validate::isLoadedObject($carrier)) {
         die(Tools::displayError('Fatal error: "no default carrier"'));
     }
     if (!$carrier->active) {
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         return 0;
     }
     // Select carrier tax
     if ($useTax and !Tax::excludeTaxeOption()) {
         $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     }
     $configuration = Configuration::getMultiple(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 = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
     if ($orderTotalwithDiscounts >= (double) $free_fees_price and (double) $free_fees_price > 0) {
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] and (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         // Get id zone
         if (isset($this->id_address_delivery) and $this->id_address_delivery and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             $id_zone = (int) $defaultCountry->id_zone;
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $moduleName = $carrier->external_module_name;
         $module = Module::getInstanceByName($moduleName);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $carrier->id;
             }
             if ($carrier->need_range) {
                 $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
             } else {
                 $shipping_cost = $module->getOrderShippingCostExternal($this);
             }
             // Check if carrier is available
             if ($shipping_cost === false) {
                 return false;
             }
         } else {
             return false;
         }
     }
     // Apply tax
     if (isset($carrierTax)) {
         $shipping_cost *= 1 + $carrierTax / 100;
     }
     return (double) Tools::ps_round((double) $shipping_cost, 2);
 }
 public function hookPayment($params)
 {
     $currency = Currency::getCurrencyInstance($this->context->cookie->id_currency);
     $isFailed = Tools::getValue('payfortforterror');
     $url = $this->_getUrl('fc=module&module=payfortfort&controller=payment&action=postPaymentForm');
     $SADAD = Configuration::get('PAYFORT_FORT_SADAD');
     $NAPS = Configuration::get('PAYFORT_FORT_NAPS');
     $credit_card = Configuration::get('PAYFORT_FORT_CREDIT_CARD');
     $integration_type = Configuration::get('PAYFORT_FORT_INTEGRATION_TYPE');
     $pfHelper = Payfort_Fort_Helper::getInstance();
     $frontCurrency = $pfHelper->getFrontCurrency();
     $baseCurrency = $pfHelper->getBaseCurrency();
     $fortCurrency = $pfHelper->getFortCurrency($baseCurrency, $frontCurrency);
     if ($fortCurrency != 'SAR') {
         $SADAD = 0;
     }
     if ($fortCurrency != 'QAR') {
         $NAPS = 0;
     }
     $this->context->smarty->assign('url', $url);
     $this->context->smarty->assign('SADAD', $SADAD);
     $this->context->smarty->assign('NAPS', $NAPS);
     $this->context->smarty->assign('credit_card', $credit_card);
     $this->context->smarty->assign('integration_type', $integration_type);
     $this->context->smarty->assign('payfort_path', $this->getPathUri());
     $arr_js_messages = array('error_invalid_card_number' => $this->l('error_invalid_card_number'), 'error_invalid_card_holder_name' => $this->l('error_invalid_card_holder_name'), 'error_invalid_expiry_date' => $this->l('error_invalid_expiry_date'), 'error_invalid_cvc_code' => $this->l('error_invalid_cvc_code'), 'error_invalid_cc_details' => $this->l('error_invalid_cc_details'));
     $js_msgs = $pfHelper->loadJsMessages($arr_js_messages);
     $this->context->smarty->assign('arr_js_messages', $js_msgs);
     return $this->display(__FILE__, 'views/templates/hook/payfortfort.tpl');
 }
 private function getSingleMapData($params)
 {
     $cart = Cart::getCartByOrderId((int) $params['id_order']);
     if (Validate::isLoadedObject($cart)) {
         $products = $cart->getProducts();
         if (count($products) == 0 && method_exists('Shop', 'getContextShopID') && Shop::getContextShopID() != (int) $cart->id_shop) {
             Shop::initialize();
             $products = $cart->getProducts(true);
         }
         $currency = Currency::getCurrencyInstance((int) $cart->id_currency);
         if (!is_null($products) && is_array($products) && Validate::isLoadedObject($currency)) {
             $data = array();
             $data['order_date'] = $params['date_add'];
             $data['email'] = $params['email'];
             $data['customer_name'] = $params['firstname'] . ' ' . $params['lastname'];
             $data['order_id'] = (int) $params['id_order'];
             $data['currency_iso'] = $currency->iso_code;
             $products_arr = array();
             foreach ($products as $product) {
                 $product_data = array();
                 $product_data['url'] = $this->getProductLink($product['id_product'], $product['link_rewrite']);
                 $product_data['name'] = $product['name'];
                 $product_data['image'] = $this->getProductImageUrl((int) $product['id_product']);
                 $product_data['description'] = $this->getDescritpion($product, (int) $params['id_lang']);
                 $product_data['price'] = $product['price'];
                 $products_arr[(int) $product['id_product']] = $product_data;
             }
             $data['products'] = $products_arr;
             return $data;
         }
     }
     return null;
 }
 protected function geolocationManagement()
 {
     global $cookie, $smarty;
     if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
         /* Check if Maxmind Database exists */
         if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) {
             if (!isset($cookie->iso_code_country) or isset($cookie->iso_code_country) and !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
                 include_once _PS_GEOIP_DIR_ . 'geoipcity.inc';
                 include_once _PS_GEOIP_DIR_ . 'geoipregionvars.php';
                 $gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD);
                 $record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
                 if (is_object($record) and !in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) and !self::isInWhitelistForGeolocation()) {
                     if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                         $this->restrictedCountry = true;
                     } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                         $smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name));
                     }
                 } elseif (is_object($record)) {
                     $cookie->iso_code_country = strtoupper($record->country_code);
                     $hasBeenSet = true;
                 }
             }
             if (isset($cookie->iso_code_country) and (int) ($id_country = Country::getByIso(strtoupper($cookie->iso_code_country)))) {
                 /* Update defaultCountry */
                 $defaultCountry = new Country($id_country);
                 if (isset($hasBeenSet) and $hasBeenSet) {
                     $cookie->id_currency = (int) Currency::getCurrencyInstance($defaultCountry->id_currency ? (int) $defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id;
                 }
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                 $this->restrictedCountry = true;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                 $smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined'));
             }
         } else {
             Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
         }
     }
 }
 protected function createShopOrder($order)
 {
     if (!is_array($order)) {
         $order = $this->getOrder($order);
     }
     $order_id = $order['id_order'];
     $currency = Currency::getCurrencyInstance((int) $order['id_currency']);
     $shop_order = YousticeShopOrder::create();
     $shop_order->setDescription('');
     if (empty($order)) {
         exit('Operation not allowed');
     }
     $shop_order->setName('#' . $order['reference']);
     $shop_order->setCurrency($currency->iso_code);
     $shop_order->setPrice((double) $order['total_paid']);
     $shop_order->setId($order_id);
     $shop_order->setDeliveryDate($order['delivery_date']);
     $shop_order->setOrderDate($order['date_add']);
     $shop_order->setHref($this->createOrderReportHref($order_id));
     $shop_order->setOrderDetailHref($this->createOrderDetailHref($order_id));
     if ($order['total_paid_real'] >= $order['total_paid']) {
         $shop_order->setPaymentState(YousticeShopOrder::PAID);
     }
     if (strtotime($order['delivery_date']) > 0) {
         $shop_order->setDeliveryState(YousticeShopOrder::DELIVERED);
     }
     $shop_order->setOtherInfo('');
     $order_object = new Order((int) $order_id);
     $products = $order_object->getProducts();
     foreach ($products as $product) {
         $shop_product = $this->createShopProduct($product, $order_id);
         $shop_product->setCurrency($currency->iso_code);
         $shop_product->setDeliveryDate($order['delivery_date']);
         $shop_product->setOrderDate($order['date_add']);
         $shop_order->addProduct($shop_product);
     }
     return $shop_order;
 }
Exemple #26
0
 public function displayListContent()
 {
     if ($this->position_identifier) {
         $id_category = (int) Tools::getValue('id_' . ($this->is_cms ? 'cms_' : '') . 'category', '1');
     } else {
         $id_category = Category::getRootCategory()->id;
     }
     if (isset($this->fields_list['position'])) {
         $positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list);
         sort($positions);
     }
     // key_to_get is used to display the correct product category or cms category after a position change
     $identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '';
     if ($identifier) {
         $key_to_get = 'id_' . ($this->is_cms ? 'cms_' : '') . 'category' . $identifier;
     }
     foreach ($this->_list as $index => $tr) {
         $id = $tr[$this->identifier];
         $name = isset($tr['name']) ? $tr['name'] : null;
         if ($this->shopLinkType) {
             $this->_list[$index]['short_shop_name'] = Tools::strlen($tr['shop_name']) > 15 ? Tools::substr($tr['shop_name'], 0, 15) . '...' : $tr['shop_name'];
         }
         // Check all available actions to add to the current list row
         foreach ($this->actions as $action) {
             //Check if the action is available for the current row
             if (!array_key_exists($action, $this->list_skip_actions) || !in_array($id, $this->list_skip_actions[$action])) {
                 $method_name = 'display' . ucfirst($action) . 'Link';
                 if (method_exists($this->context->controller, $method_name)) {
                     $this->_list[$index][$action] = $this->context->controller->{$method_name}($this->token, $id, $name);
                 } elseif (method_exists($this, $method_name)) {
                     $this->_list[$index][$action] = $this->{$method_name}($this->token, $id, $name);
                 }
             }
         }
         // @todo skip action for bulk actions
         // $this->_list[$index]['has_bulk_actions'] = true;
         foreach ($this->fields_list as $key => $params) {
             $tmp = explode('!', $key);
             $key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
             if (isset($params['active'])) {
                 // If method is defined in calling controller, use it instead of the Helper method
                 if (method_exists($this->context->controller, 'displayEnableLink')) {
                     $calling_obj = $this->context->controller;
                 } else {
                     $calling_obj = $this;
                 }
                 $this->_list[$index][$key] = $calling_obj->displayEnableLink($this->token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product'));
             } elseif (isset($params['activeVisu'])) {
                 $this->_list[$index][$key] = (bool) $tr[$key];
             } elseif (isset($params['position'])) {
                 $this->_list[$index][$key] = array('position' => $tr[$key], 'position_url_down' => $this->currentIndex . (isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $id_category : '') . '&' . $this->position_identifier . '=' . $id . '&way=1&position=' . ((int) $tr['position'] + 1) . '&token=' . $this->token, 'position_url_up' => $this->currentIndex . (isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $id_category : '') . '&' . $this->position_identifier . '=' . $id . '&way=0&position=' . ((int) $tr['position'] - 1) . '&token=' . $this->token);
             } elseif (isset($params['image'])) {
                 // item_id is the product id in a product image context, else it is the image id.
                 $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
                 if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES')) {
                     $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType;
                 } else {
                     $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . Image::getImgFolderStatic($tr['id_image']) . (int) $tr['id_image'] . '.' . $this->imageType;
                 }
                 $this->_list[$index][$key] = ImageManager::thumbnail($path_to_image, $this->table . '_mini_' . $item_id . '.' . $this->imageType, 45, $this->imageType);
             } elseif (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) {
                 if (isset($params['icon'][$tr[$key]]) && is_array($params['icon'][$tr[$key]])) {
                     $this->_list[$index][$key] = array('src' => $params['icon'][$tr[$key]]['src'], 'alt' => $params['icon'][$tr[$key]]['alt']);
                 } else {
                     $this->_list[$index][$key] = array('src' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'], 'alt' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default']);
                 }
             } elseif (isset($params['type']) && $params['type'] == 'float') {
                 $this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
             } elseif (isset($params['type']) && $params['type'] == 'price') {
                 $currency = isset($params['currency']) && $params['currency'] ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency;
                 $this->_list[$index][$key] = Tools::displayPrice($tr[$key], $currency, false);
             } elseif (isset($params['type']) && $params['type'] == 'date') {
                 $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id);
             } elseif (isset($params['type']) && $params['type'] == 'datetime') {
                 $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true);
             } elseif (isset($tr[$key])) {
                 $echo = $tr[$key];
                 if (isset($params['callback'])) {
                     $callback_obj = isset($params['callback_object']) ? $params['callback_object'] : $this->context->controller;
                     $this->_list[$index][$key] = call_user_func_array(array($callback_obj, $params['callback']), array($echo, $tr));
                 } else {
                     $this->_list[$index][$key] = $echo;
                 }
             }
         }
     }
     $this->content_tpl->assign(array_merge($this->tpl_vars, array('shop_link_type' => $this->shopLinkType, 'name' => isset($name) ? $name : null, 'position_identifier' => $this->position_identifier, 'identifier' => $this->identifier, 'table' => $this->table, 'token' => $this->token, 'color_on_bg' => $this->colorOnBackground, 'id_category' => $id_category, 'bulk_actions' => $this->bulk_actions, 'positions' => isset($positions) ? $positions : null, 'order_by' => $this->orderBy, 'order_way' => $this->orderWay, 'is_cms' => $this->is_cms, 'fields_display' => $this->fields_list, 'list' => $this->_list, 'actions' => $this->actions, 'no_link' => $this->no_link, 'current_index' => $this->currentIndex, 'view' => in_array('view', $this->actions), 'edit' => in_array('edit', $this->actions), 'has_actions' => !empty($this->actions), 'has_bulk_actions' => !empty($this->bulk_actions), 'list_skip_actions' => $this->list_skip_actions, 'row_hover' => $this->row_hover)));
     return $this->content_tpl->fetch();
 }
Exemple #27
0
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 {
     if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
         return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
     }
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     if (!is_null($product_list)) {
         foreach ($product_list as $key => $value) {
             if ($value['is_virtual'] == 1) {
                 unset($product_list[$key]);
             }
         }
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::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)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (!isset($id_zone)) {
         // Get id zone
         if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             if (!Validate::isLoadedObject($default_country)) {
                 $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
             }
             $id_zone = (int) $default_country->id_zone;
         }
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $total_package_without_shipping_tax_inc;
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     // No valid Carrier or $id_carrier <= 0 ?
     if (!Validate::isLoadedObject($carrier)) {
         Cache::store($cache_id, 0);
         return 0;
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(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 = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::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) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         if (!isset($id_zone)) {
             // Get id zone
             if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
                 $id_zone = Address::getZoneById((int) $this->id_address_delivery);
             } else {
                 $id_zone = (int) $default_country->id_zone;
             }
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // 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 = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $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) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
    /**
     * Return available currencies
     *
     * @return array Currencies
     */
    public static function getCurrencies($object = false, $active = 1)
    {
        $tab = Db::getInstance()->ExecuteS('
		SELECT *
		FROM `' . _DB_PREFIX_ . 'currency`
		WHERE `deleted` = 0
		' . ($active == 1 ? 'AND `active` = 1' : '') . '
		ORDER BY `name` ASC');
        if ($object) {
            foreach ($tab as $key => $currency) {
                $tab[$key] = Currency::getCurrencyInstance($currency['id_currency']);
            }
        }
        return $tab;
    }
Exemple #29
0
 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
 {
     $totalAmount = 0;
     $cart = new Cart((int) $idCart);
     if (!Validate::isLoadedObject($cart)) {
         return 0;
     }
     if (!$this->cumulable and (int) $nb_discounts > 1 or !$this->active or !$this->quantity and !$cart->OrderExists()) {
         return 0;
     }
     if ($this->usedByCustomer((int) $cart->id_customer) >= $this->quantity_per_user and !$cart->OrderExists()) {
         return 0;
     }
     $date_start = strtotime($this->date_from);
     $date_end = strtotime($this->date_to);
     if ((time() < $date_start or time() > $date_end) and !$cart->OrderExists()) {
         return 0;
     }
     $products = $cart->getProducts();
     $categories = Discount::getCategories((int) $this->id);
     foreach ($products as $product) {
         if (count($categories) and Product::idIsOnCategoryId($product['id_product'], $categories)) {
             $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
         }
     }
     if ($this->minimal > 0 and $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         /* Relative value (% of the order total) */
         case 1:
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     if ($this->cumulable_reduction or !$product['reduction_applies'] and !$product['on_sale']) {
                         $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
                     }
                 }
             }
             return $amount;
             /* Absolute value */
         /* Absolute value */
         case 2:
             // An "absolute" voucher is available in one currency only
             $currency = (int) $cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent();
             if ($this->id_currency != $currency->id) {
                 return 0;
             }
             $taxDiscount = Cart::getTaxesAverageUsed((int) $cart->id);
             if (!$useTax and isset($taxDiscount) and $taxDiscount != 1) {
                 $this->value = abs($this->value / (1 + $taxDiscount * 0.01));
             }
             // Main return
             $value = 0;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $value = $this->value;
                 }
             }
             // Return 0 if there are no applicable categories
             return $value;
             /* Free shipping (does not return a value but a special code) */
         /* Free shipping (does not return a value but a special code) */
         case 3:
             return '!';
     }
     return 0;
 }
Exemple #30
0
 public function getOrderShippingCostPerSellerCarrier($id_seller, $use_tax, $id_zone, $id_carrier, $carrier_amount, $carrier_weight)
 {
     $shipping_cost = 0;
     $carrier = new Carrier($id_carrier, $this->id_lang);
     if ($carrier->is_free == 1) {
         return 0;
     }
     if ($use_tax and !Tax::excludeTaxeOption()) {
         $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_FREE_WEIGHT'));
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $free_fees_weight = 0;
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT'])) {
         $free_fees_weight = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_WEIGHT'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $shipping_method = $carrier->getShippingMethod();
     if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE and $carrier_amount >= (double) $free_fees_price and (double) $free_fees_price > 0) {
     } else {
         if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT and $carrier_weight >= (double) $free_fees_weight and (double) $free_fees_weight > 0) {
         } else {
             if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $seller_shipping = $carrier->getDeliveryPriceByWeight($carrier_weight, $id_zone);
                 $shipping_cost += $seller_shipping;
             } else {
                 $seller_shipping = $carrier->getDeliveryPriceByPrice($carrier_amount, $id_zone, (int) $this->id_currency);
                 $shipping_cost += $seller_shipping;
             }
         }
     }
     $shipping_cost += $this->getAdditionalShippingCostOfSeller($id_carrier);
     if ($carrier->shipping_handling) {
         $shipping_cost += (double) Configuration::get('PS_SHIPPING_HANDLING');
     }
     if (isset($carrierTax)) {
         $shipping_cost *= 1 + $carrierTax / 100;
     }
     $shipping_cost = Tools::convertPrice($shipping_cost);
     return $shipping_cost;
 }