Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /includes/modules/shipping/postino.php
- --------------------------------------
- <?php
- /*
- $Id$
- osCommerce, Open Source E-Commerce Solutions
- http://www.oscommerce.com
- Copyright (c) 2020 osCommerce
- Released under the GNU General Public License
- */
- class postino extends abstract_shipping_module {
- const CONFIG_KEY_BASE = 'MODULE_SHIPPING_POSTINO_';
- // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
- const ZONE_COUNT = 2;
- // class methods
- public function quote($method = '') {
- global $order;
- switch ($this->base_constant('MODE') ) {
- case 'price':
- $order_total = $this->get_shippable_total();
- break;
- case 'weight':
- $order_total = $GLOBALS['shipping_weight'];
- break;
- case 'quantity':
- $order_total = $this->count_items();
- break;
- }
- $dest_zone = false;
- $error = false;
- for ($i = 1; $i <= static::ZONE_COUNT; $i++) {
- if (in_array($order->delivery['country']['iso_code_2'], explode(';', $this->base_constant('COUNTRIES_' . $i)))) {
- $dest_zone = $i;
- break;
- }
- }
- if (false === $dest_zone) {
- $error = true;
- } else {
- $shipping = false;
- $zones_cost = $this->base_constant('COST_' . $dest_zone);
- $zones_table = preg_split('/[:,]/' , $zones_cost);
- for ($i = 0, $size = count($zones_table); $i < $size; $i += 2) {
- if ($order_total <= $zones_table[$i]) {
- $shipping = $zones_table[$i+1];
- $shipping_method = sprintf(MODULE_SHIPPING_POSTINO_TEXT_WAY, $order->delivery['country']['iso_code_2']);
- break;
- }
- }
- if (false === $shipping) {
- $shipping_cost = 0;
- $shipping_method = MODULE_SHIPPING_POSTINO_UNDEFINED_RATE;
- } else {
- $shipping_cost = ($shipping * $GLOBALS['shipping_num_boxes']) + $this->base_constant('HANDLING_' . $dest_zone);
- }
- }
- $this->quotes = [
- 'id' => $this->code,
- 'module' => MODULE_SHIPPING_POSTINO_TEXT_TITLE,
- 'methods' => [[
- 'id' => $this->code,
- 'title' => $shipping_method,
- 'cost' => $shipping_cost,
- ]],
- ];
- $this->quote_common();
- if ($error) {
- $this->quotes['error'] = MODULE_SHIPPING_POSTINO_INVALID_ZONE;
- }
- return $this->quotes;
- }
- protected function get_parameters() {
- $parameters = [
- $this->config_key_base . 'STATUS' => [
- 'title' => 'Enable Postino Method',
- 'value' => 'True',
- 'desc' => 'Do you want to offer this shipping method?',
- 'set_func' => "tep_cfg_select_option(['True', 'False'], ",
- ],
- $this->config_key_base . 'TAX_CLASS' => [
- 'title' => 'Tax Class',
- 'value' => '0',
- 'desc' => 'Use the following tax class on the shipping fee.',
- 'use_func' => 'tep_get_tax_class_title',
- 'set_func' => 'tep_cfg_pull_down_tax_classes(',
- ],
- $this->config_key_base . 'MODE' => [
- 'title' => 'Table Method',
- 'value' => 'weight',
- 'desc' => 'The shipping cost is based on the order total or the total weight of the items ordered.',
- 'set_func' => "tep_cfg_select_option(['weight', 'price', 'quantity'], ",
- ],
- $this->config_key_base . 'SORT_ORDER' => [
- 'title' => 'Sort Order',
- 'value' => '0',
- 'desc' => 'Sort order of display.',
- ],
- ];
- for ($i = 1; $i <= static::ZONE_COUNT; $i++) {
- $parameters = array_merge($parameters, [
- $this->config_key_base . 'COUNTRIES_' . $i => [
- 'title' => 'Zone ' . $i . ' Countries',
- 'value' => (($i == 1) ? 'US;CA' : ''),
- 'desc' => 'Semi-colon separated list of two character ISO country codes that are part of Zone ' . $i . '.',
- ],
- $this->config_key_base . 'COST_' . $i => [
- 'title' => 'Zone ' . $i . ' Shipping Table',
- 'value' => '3:8.50,7:10.50,99:20.00',
- 'desc' => 'Shipping rates to Zone ' . $i . ' destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weight/Price less than or equal to 3 would cost 8.50 for Zone ' . $i . ' destinations.',
- ],
- $this->config_key_base . 'HANDLING_' . $i => [
- 'title' => 'Zone ' . $i . ' Handling Fee',
- 'value' => '0',
- 'desc' => 'Handling Fee for this shipping zone',
- ],
- ]);
- }
- return $parameters;
- }
- protected function get_shippable_total() {
- global $order, $currencies;
- $order_total = (('physical' === $order->content_type) ? $_SESSION['cart']->show_total() : 0);
- if ('mixed' === $order->content_type) {
- foreach ($order->products as $product) {
- foreach (($product['attributes'] ?? []) as $option => $value) {
- $virtual_check_query = tep_db_query(sprintf(<<<'EOSQL'
- SELECT COUNT(*) AS total
- FROM products_attributes pa
- INNER JOIN products_attributes_download pad
- ON pa.products_attributes_id = pad.products_attributes_id
- WHERE pa.products_id = %d AND pa.options_values_id = %d
- EOSQL
- , (int)$product['id'], (int)$value['value_id']));
- $virtual_check = tep_db_fetch_array($virtual_check_query);
- if ($virtual_check['total'] > 0) {
- // if any attribute is downloadable, the product is virtual
- // and doesn't count; so skip to the next product
- // without adding the product quantity
- continue 2;
- }
- }
- $order_total += $currencies->calculate_price($product['final_price'], $product['tax'], $product['qty']);
- }
- }
- return $order_total;
- }
- function count_items() {
- global $order;
- $item_count = ('physical' === $order->content_type)
- ? ($GLOBALS['total_count'] ?? $_SESSION['cart']->count_contents())
- : 0;
- if ('mixed' === $order->content_type) {
- foreach ($order->products as $product) {
- foreach (($product['attributes'] ?? []) as $option => $value) {
- $virtual_check_query = tep_db_query(sprintf(<<<'EOSQL'
- SELECT COUNT(*) AS total
- FROM products_attributes pa INNER JOIN products_attributes_download pad
- ON pa.products_attributes_id = pad.products_attributes_id
- WHERE pa.products_id = %d AND pa.options_values_id = %d
- EOSQL
- , (int)$product['id'], (int)$value['value_id']));
- $virtual_check = tep_db_fetch_array($virtual_check_query);
- if ($virtual_check['total'] > 0) {
- // if any attribute is downloadable, the product is virtual
- // and doesn't count; so skip to the next product
- // without adding the product quantity
- continue 2;
- }
- }
- $item_count += $product['qty'];
- }
- }
- return $item_count;
- }
- }
- /includes/languages/english/modules/shipping/postino.php
- --------------------------------------------------------
- <?php
- /*
- $Id$
- osCommerce, Open Source E-Commerce Solutions
- http://www.oscommerce.com
- Copyright (c) 2020 osCommerce
- Released under the GNU General Public License
- */
- const MODULE_SHIPPING_POSTINO_TEXT_TITLE = 'Postino';
- const MODULE_SHIPPING_POSTINO_TEXT_DESCRIPTION = 'P&P';
- const MODULE_SHIPPING_POSTINO_TEXT_WAY = 'Delivery to %s';
- const MODULE_SHIPPING_POSTINO_INVALID_ZONE = 'No shipping available to the selected country';
- const MODULE_SHIPPING_POSTINO_UNDEFINED_RATE = 'The shipping rate cannot be determined at this time';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement