Beispiel #1
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $currentShippingZone = null;
     $currentCurrencyId = null;
     $currencyClass = hikashop_get('class.currency');
     foreach ($local_usable_rates as $k => $rate) {
         if (empty($rate->shipping_params->methodsList)) {
             $messages['no_shipping_methods_configured'] = 'No shipping methods configured in the FedEx shipping plugin options';
             continue;
         }
         $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList);
         if ($order->weight <= 0 || $order->volume <= 0 && @$rate->shipping_params->use_dimensions == 1) {
             continue;
         }
         $this->freight = false;
         $this->classicMethod = false;
         $heavyProduct = false;
         $weightTotal = 0;
         if (!empty($rate->shipping_params->methods)) {
             foreach ($rate->shipping_params->methods as $method) {
                 if ($method == 'TDCB' || $method == 'TDA' || $method == 'TDO' || $method == '308' || $method == '309' || $method == '310') {
                     $this->freight = true;
                 } else {
                     $this->classicMethod = true;
                 }
             }
         }
         $data = null;
         if (empty($order->shipping_address)) {
             $messages['no_shipping_methods_configured'] = 'No shipping address is configured.';
             return true;
         }
         $this->shipping_currency_id = $currency = hikashop_getCurrency();
         $db = JFactory::getDBO();
         $query = 'SELECT currency_code FROM ' . hikashop_table('currency') . ' WHERE currency_id IN (' . $this->shipping_currency_id . ')';
         $db->setQuery($query);
         $this->shipping_currency_code = $db->loadResult();
         $cart = hikashop_get('class.cart');
         $null = null;
         $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping');
         $currency = hikashop_get('class.currency');
         $receivedMethods = $this->_getRates($rate, $order, $heavyProduct, $null);
         if (empty($receivedMethods)) {
             $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
             continue;
         }
         $i = 0;
         $local_usable_rates = array();
         foreach ($receivedMethods as $method) {
             $usableMethods[] = $method;
             $local_usable_rates[$i] = !HIKASHOP_PHP5 ? $rate : clone $rate;
             $local_usable_rates[$i]->shipping_price += round($method['value'], 2);
             $selected_method = '';
             $name = '';
             foreach ($this->fedex_methods as $fedex_method) {
                 if ($fedex_method['code'] == $method['code'] && ($method['old_currency_code'] == 'CAD' || !isset($fedex_method['double']))) {
                     $name = $fedex_method['name'];
                     $selected_method = $fedex_method['key'];
                     break;
                 }
             }
             $local_usable_rates[$i]->shipping_name = $name;
             if (!empty($selected_method)) {
                 $local_usable_rates[$i]->shipping_id .= '-' . $selected_method;
             }
             $sep = '';
             if (@$rate->shipping_params->show_eta) {
                 if (@$rate->shipping_params->show_eta_delay) {
                     if ($method['delivery_delay'] != -1 && $method['day'] > 0) {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('ESTIMATED_TIME_AFTER_SEND', $method['delivery_delay']);
                     } else {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_ESTIMATED_TIME_AFTER_SEND');
                     }
                 } else {
                     if ($method['delivery_day'] != -1 && $method['day'] > 0) {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('ESTIMATED_TIME_AFTER_SEND', $method['delivery_day']);
                     } else {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_ESTIMATED_TIME_AFTER_SEND');
                     }
                 }
                 $sep = '<br/>';
                 if ($method['delivery_time'] != -1 && $method['day'] > 0) {
                     if (@$rate->shipping_params->show_eta_format == '12') {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('DELIVERY_HOUR', date('h:i:s a', strtotime($method['delivery_time'])));
                     } else {
                         $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('DELIVERY_HOUR', $method['delivery_time']);
                     }
                 } else {
                     $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_DELIVERY_HOUR');
                 }
             }
             if (@$rate->shipping_params->show_notes && !empty($method['notes'])) {
                 foreach ($method['notes'] as $note) {
                     if ($note->Code != '820' && $note->Code != '819' && !empty($note->LocalizedMessage)) {
                         $local_usable_rates[$i]->shipping_description .= $sep . implode('<br/>', $note->LocalizedMessage);
                         $sep = '<br/>';
                     }
                 }
             }
             if ($rate->shipping_params->group_package && $this->nbpackage > 0) {
                 $local_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('X_PACKAGES', $this->nbpackage);
             }
             $i++;
         }
         foreach ($local_usable_rates as $i => $finalRate) {
             if (isset($finalRate->shipping_price_orig) || isset($finalRate->shipping_currency_id_orig)) {
                 if ($finalRate->shipping_currency_id_orig == $finalRate->shipping_currency_id) {
                     $finalRate->shipping_price_orig = $finalRate->shipping_price;
                 } else {
                     $finalRate->shipping_price_orig = $currencyClass->convertUniquePrice($finalRate->shipping_price, $finalRate->shipping_currency_id, $finalRate->shipping_currency_id_orig);
                 }
             }
             $usable_rates[$finalRate->shipping_id] = $finalRate;
         }
     }
 }
Beispiel #2
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     $local_usable_rates = array();
     $this->setLocalUsableRates($local_usable_rates);
     $local_messages = array();
     $notUsable = array();
     // Get installation information for parent products
     $parentProductInstallations = array();
     if (self::getParam('prodinstall')) {
         foreach ($order->products as $product) {
             if ($product->product_parent_id) {
                 continue;
             }
             if (empty($product->product_installation)) {
                 continue;
             }
             $parentProductInstallations[$product->product_id] = trim($product->product_installation);
         }
     }
     if (self::getParam('categorychk')) {
         $categoryClass = hikashop_get('class.category');
         $productClass = hikashop_get('class.product');
         foreach ($order->products as $k => $product) {
             if ($product->cart_product_quantity > 0 && empty($product->categories)) {
                 $categories = $productClass->getCategories($product->product_id);
                 if (empty($categories)) {
                     $categories = $productClass->getCategories($product->product_parent_id);
                 }
                 $order->products[$k]->categories = $categories;
             }
         }
         foreach ($dbrates as $k => $dbrate) {
             $dbrates[$k]->products = array();
             if ($dbrate->shipping_type == $this->name) {
                 $products = array();
                 // Check if this method usable with any ordered product categories
                 $shipping_categories = @$dbrate->shipping_params->shipping_categories;
                 if (!empty($shipping_categories)) {
                     if (!empty($dbrate->shipping_params->shipping_incsubcategories)) {
                         foreach ($categoryClass->getChildren($shipping_categories, true, array(), '', 0, 0, false, 'a.category_id') as $category) {
                             $shipping_categories[] = $category->category_id;
                         }
                     }
                     foreach ($order->products as $product) {
                         if (!empty($product->categories)) {
                             $catmatch = array_intersect($product->categories, $shipping_categories);
                             if (!empty($catmatch)) {
                                 $products[] = $product->product_id;
                             }
                         }
                     }
                     if (empty($products)) {
                         // Method not found for any ordered product categories
                         $notUsable[] = $k;
                     }
                 }
                 // Used to calculate total shipping price per product
                 $dbrates[$k]->products = $products;
                 // Check if this method excluded with any ordered product categories
                 $products = array();
                 $shipping_categories = @$dbrate->shipping_params->shipping_exclude_categories;
                 if (!empty($shipping_categories)) {
                     if (!empty($dbrate->shipping_params->shipping_excsubcategories)) {
                         foreach ($categoryClass->getChildren($shipping_categories, true, array(), '', 0, 0, false, 'a.category_id') as $category) {
                             $shipping_categories[] = $category->category_id;
                         }
                     }
                     foreach ($order->products as $product) {
                         if (!empty($product->categories)) {
                             $catmatch = array_intersect($product->categories, $shipping_categories);
                             if (!empty($catmatch)) {
                                 $products[] = $product->product_id;
                             }
                         }
                     }
                     if (!empty($products)) {
                         // Method found for excluded ordered product categories
                         $notUsable[] = $k;
                     }
                 }
             }
         }
     }
     if (jPluginHelper::importPlugin('utilitybrain', 'test')) {
         plgUtilitybrainTest::onShippingDisplay($this, $order, $dbrates, $usable_rates, $messages);
     }
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $availablechk = self::getParam('availablechk');
     $productqtychk = self::getParam('productqtychk');
     $ordertimechk = self::getParam('ordertimechk');
     $sizeweightpricecalc = self::getParam('sizeweightpricecalc');
     foreach ($local_usable_rates as $k => $rate) {
         if ($availablechk) {
             if (!empty($rate->shipping_params->shipping_available_from)) {
                 if (time() < strtotime($rate->shipping_params->shipping_available_from)) {
                     $notUsable[] = $k;
                     continue;
                 }
             }
             if (!empty($rate->shipping_params->shipping_available_to)) {
                 if (time() > strtotime($rate->shipping_params->shipping_available_to)) {
                     $notUsable[] = $k;
                     continue;
                 }
             }
         }
         $found = 0;
         if ($ordertimechk) {
             if (!empty($rate->shipping_params->shipping_ordertime_before)) {
                 if (date('h:i') > $rate->shipping_params->shipping_ordertime_before) {
                     $found += 1;
                 }
             }
             if (!empty($rate->shipping_params->shipping_ordertime_after)) {
                 if (date('h:i') < $rate->shipping_params->shipping_ordertime_after) {
                     $found -= 1;
                 }
             }
         }
         if ($found != 0) {
             $notUsable[] = $k;
             continue;
         }
         if ($sizeweightpricecalc) {
             if (@$rate->shipping_params->shipping_require_sizeweight) {
                 if (empty($order->volume) || empty($order->weight)) {
                     $notUsable[] = $k;
                     continue;
                 }
             }
         }
         if ($productqtychk) {
             $minquantity = $rate->shipping_params->shipping_minquantity;
             $maxquantity = $rate->shipping_params->shipping_maxquantity;
             if ($minquantity && $minquantity > $order->total_quantity || $maxquantity && $maxquantity < $order->total_quantity) {
                 $notUsable[] = $k;
                 continue;
             }
         }
         if ($sizeweightpricecalc) {
             if (!self::SizeWeightPriceCalculation($order, $rate)) {
                 $notUsable[] = $k;
                 continue;
             }
         }
     }
     foreach ($notUsable as $item) {
         unset($local_usable_rates[$item]);
     }
     $app = JFactory::getApplication();
     $orderFields = $app->getUserState(HIKASHOP_COMPONENT . '.checkout_fields', null);
     $fieldsClass = hikashop_get('class.field');
     $extraFields = $fieldsClass->getFields('frontcomp', $orderFields, 'order');
     $delivdate = self::getParam('delivdate');
     if (isset($extraFields['order_delivery_date'])) {
         $checkMaxDay = false;
     } else {
         $checkMaxDay = true;
     }
     $earliest_delivery_day = @$orderFields->order_delivery_date;
     if ($delivdate && !empty($order->products)) {
         foreach ($order->products as $product) {
             if (!empty($product->item_delivery_date)) {
                 if (empty($earliest_delivery_day) || $earliest_delivery_day > $product->item_delivery_date) {
                     $earliest_delivery_day = $product->item_delivery_date;
                 }
             }
         }
     }
     $productfieldname = self::getParam('productfieldname');
     $notUsable = array();
     foreach ($local_usable_rates as $k => $rate) {
         $local_usable_rates[$k]->shipping_params->productfieldname = $productfieldname;
         if (!empty($productfieldname) && !empty($rate->shipping_params->{$productfieldname})) {
             $fieldvalues = preg_split('/[,;]+/', $rate->shipping_params->{$productfieldname});
             $fieldmatch = false;
             foreach ($order->products as $product) {
                 if (!isset($product->{$productfieldname})) {
                     $fieldmatch = true;
                     break;
                 }
                 if (in_array($product->{$productfieldname}, $fieldvalues)) {
                     $fieldmatch = true;
                     break;
                 }
                 if (!empty($product->variants)) {
                     foreach ($product->variants as $variant) {
                         if (in_array($variant->{$productfieldname}, $fieldvalues)) {
                             $fieldmatch = true;
                             break 2;
                         }
                     }
                 }
             }
             if (!$fieldmatch) {
                 $notUsable[] = $k;
                 continue;
             }
         }
         if (self::getParam('productchk') && !empty($rate->shipping_params->shipping_products)) {
             $fieldmatch = false;
             foreach ($order->products as $product) {
                 if (in_array($product->product_id, $rate->shipping_params->shipping_products) || in_array($product->product_parent_id, $rate->shipping_params->shipping_products)) {
                     $fieldmatch = true;
                     break;
                 }
                 if (!empty($product->variants)) {
                     foreach ($product->variants as $variant) {
                         if (in_array($variant->product_id, $rate->shipping_params->shipping_products) || in_array($variant->product_parent_id, $rate->shipping_params->shipping_products)) {
                             $fieldmatch = true;
                             break 2;
                         }
                     }
                 }
             }
             if (!$fieldmatch) {
                 $notUsable[] = $k;
                 continue;
             }
         }
         if (!self::validDeliveryDay($earliest_delivery_day, $rate->shipping_params, $checkMaxDay)) {
             $notUsable[] = $k;
             continue;
         }
     }
     foreach ($notUsable as $item) {
         unset($local_usable_rates[$item]);
     }
     if (empty($local_usable_rates)) {
         $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
         return false;
     }
     if (class_exists('plgHikashopBFOrderDeliveryDate') && !empty(plgHikashopBFOrderDeliveryDate::$_current)) {
         $earliest_delivery_date = plgHikashopBFOrderDeliveryDate::$_current;
     }
     if (self::getParam('delivtime')) {
         $earliest_delivery_date = preg_replace('/@.*$/', '', $earliest_delivery_day);
         $current_delivery_day = preg_replace('/@.*$/', '', $this->getOrderDeliveryDate($order));
         if (empty($earliest_delivery_date) || $earliest_delivery_date > $current_delivery_day) {
             $earliest_delivery_date = $current_delivery_day;
         }
         $notUsable = self::unusableDeliveryRates($earliest_delivery_date, $local_usable_rates);
         foreach ($notUsable as $item) {
             unset($local_usable_rates[$item]);
         }
     }
     if (empty($local_usable_rates)) {
         $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
         return false;
     }
     if (self::getParam('proddelivery')) {
         $notFreeDelivery = $this->hasProductDelivery($order->products, '!free');
         $notUsable = array();
         foreach ($local_usable_rates as $k => $rate) {
             if ($notFreeDelivery == 1) {
                 switch ($rate->shipping_params->shipping_price_type) {
                     case 'free':
                         $deliverable = true;
                         break;
                     case 'maintenance':
                     default:
                         $deliverable = false;
                         $rate->shipping_params->shipping_with_delivery = true;
                         break;
                 }
             } else {
                 $deliverable = $this->hasProductDelivery($order->products, $rate->shipping_params->shipping_price_type);
                 if ($deliverable) {
                     switch (@$rate->shipping_params->shipping_price_type) {
                         case 'free':
                             if ($notFreeDelivery == 1) {
                                 break;
                             }
                         case 'quote':
                             if ($deliverable) {
                                 $deliverable = 0;
                             } else {
                                 $deliverable = 1;
                             }
                             $rate->shipping_price = 0;
                             break;
                         case 'from':
                             if ($deliverable) {
                                 $deliverable = 0;
                             } else {
                                 $deliverable = 1;
                             }
                             if (!empty($rate->shipping_price)) {
                                 $rate->shipping_params->shipping_price_from = $rate->shipping_price;
                                 $rate->shipping_price = 0;
                             }
                             if (!isset($rate->shipping_params->shipping_price_from)) {
                                 $rate->shipping_params->shipping_price_from = 0;
                             }
                             break;
                         case 'maintenance':
                         default:
                             break;
                     }
                     if ($deliverable == 0) {
                         $rate->shipping_params->shipping_with_delivery = true;
                     }
                 } else {
                     if (!empty($rate->shipping_params->shipping_price_type) && empty($rate->shipping_params->shipping_with_delivery)) {
                         $deliverable = true;
                     }
                 }
             }
             if ($deliverable) {
                 $notUsable[] = $k;
             }
         }
         foreach ($notUsable as $item) {
             unset($local_usable_rates[$item]);
         }
         if (empty($local_usable_rates)) {
             $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
             return false;
         }
     }
     if (self::getParam('prodinstall')) {
         $notUsable = array();
         foreach ($local_usable_rates as $k => &$rate) {
             if (!empty($rate->shipping_params->shipping_with_installation)) {
                 $installable = $this->hasProductInstallation($order->products, $rate, $parentProductInstallations);
                 if ($installable == 2) {
                     $installable = 0;
                 } else {
                     if (!empty($rate->shipping_params->shipping_with_installation)) {
                         switch (@$rate->shipping_params->shipping_price_type) {
                             case 'quote':
                                 if ($installable) {
                                     $installable = 0;
                                 } else {
                                     $installable = 1;
                                 }
                                 $rate->shipping_price = 0;
                                 break;
                             case 'from':
                                 if ($installable) {
                                     $installable = 0;
                                 } else {
                                     $installable = 1;
                                 }
                                 if (!empty($rate->shipping_price)) {
                                     $rate->shipping_params->shipping_price_from = $rate->shipping_price;
                                     $rate->shipping_price = 0;
                                 }
                                 if (!isset($rate->shipping_params->shipping_price_from)) {
                                     $rate->shipping_params->shipping_price_from = 0;
                                 }
                                 break;
                             case 'maintenance':
                                 $installable = 0;
                                 break;
                             default:
                                 if ($installable == 0) {
                                     $installable = 1;
                                 }
                                 break;
                         }
                     } else {
                         if (!empty($rate->shipping_params->shipping_with_delivery)) {
                             $installable = 0;
                         } else {
                         }
                     }
                 }
                 if ($installable) {
                     $notUsable[] = $k;
                 }
             }
         }
         foreach ($notUsable as $item) {
             unset($local_usable_rates[$item]);
         }
         if (empty($local_usable_rates)) {
             $messages['no_rates'] = JText::_('NO_INSTALLATION_METHOD_FOUND');
             return false;
         }
     }
     if (self::getParam('delivslots', 0)) {
         $order_delivery_slot = isset($order->order_delivery_slot) ? @$order->order_delivery_slot : @$_REQUEST["data"]["order"]["order_delivery_slot"];
         if ($order_delivery_slot) {
             $delivslotsFound = false;
             foreach ($local_usable_rates as $k => &$rate) {
                 $shipping_ignore_delivslots = !empty($rate->shipping_params->shipping_ignore_delivslots);
                 if ($delivslotsFound && $shipping_ignore_delivslots) {
                     $notUsable[] = $k;
                     continue;
                 }
                 $shipping_delivslots = trim(@$rate->shipping_params->shipping_delivslots);
                 if (empty($shipping_delivslots)) {
                     continue;
                 }
                 $shipping_delivslots = explode("\n", $shipping_delivslots);
                 if (in_array($order_delivery_slot, $shipping_delivslots)) {
                     $delivslotsFound = true;
                     continue;
                 }
                 $notUsable[] = $k;
             }
             foreach ($notUsable as $item) {
                 unset($local_usable_rates[$item]);
             }
             if (empty($local_usable_rates)) {
                 $messages['no_rates'] = self::trans('PLG_BF_MANUAL_NO_SHIPPING_FOR_THIS_DELIVSLOT');
                 return false;
             }
         }
     }
     $postcodehandler = self::getParam('postcodehandler', 0);
     if (is_object($order->shipping_address)) {
         $postcodesFound = false;
         foreach ($local_usable_rates as $k => &$rate) {
             $shipping_ignore_postcodes = !empty($rate->shipping_params->shipping_ignore_postcodes);
             if ($postcodesFound && $shipping_ignore_postcodes) {
                 $notUsable[] = $k;
                 continue;
             }
             $shipping_postcodes = trim(@$rate->shipping_params->shipping_postcodes);
             if (empty($shipping_postcodes)) {
                 continue;
             }
             switch ($postcodehandler) {
                 case 0:
                     break 2;
                 case 1:
                     // UK
                 // UK
                 case 2:
                     // NL
                     $address_postcode = trim($order->shipping_address->address_post_code, " ^\t\n\r\v");
                     $address_postcode = preg_replace('/[^0-9A-Z]+/', ' ', strtoupper($address_postcode));
                     if (!empty($address_postcode) && strpos($address_postcode, ' ') === false) {
                         if (preg_match('/[0-9A-Z][0-9][A-Z][A-Z]$/', $address_postcode)) {
                             $len = strlen($address_postcode);
                             $address_postcode = substr($address_postcode, 0, $len - 3) . ' ' . substr($address_postcode, $len - 3);
                         }
                     }
                     if (preg_match('/[a-zA-Z0-9]/', @$shipping_postcodes)) {
                         $checkDone = false;
                         if (!empty($address_postcode)) {
                             $shipping_postcodes = strtoupper(@$shipping_postcodes);
                             foreach (preg_split('/[;,\\s]/', $shipping_postcodes) as $shipping_postcode) {
                                 if (!empty($shipping_postcode)) {
                                     if (preg_match('/^' . $shipping_postcode . '/', $address_postcode)) {
                                         $checkDone = true;
                                         $postcodesFound = true;
                                         break;
                                     }
                                 }
                             }
                         }
                         if (!$checkDone) {
                             $notUsable[] = $k;
                             continue;
                         }
                     }
                     break;
                 case 3:
                     // CAN
                     $address_postcode = trim($order->shipping_address->address_post_code, " ^\t\n\r\v");
                     if (strlen($address_postcode) == 6) {
                         $address_postcode = preg_replace('/[^0-9A-Z]+/', '', strtoupper($address_postcode));
                     }
                     $shipping_postcodes = strtoupper(@$shipping_postcodes);
                     if (preg_match('/[A-Z0-9]/', $shipping_postcodes)) {
                         $checkDone = false;
                         if (strlen($address_postcode) == 6) {
                             foreach (preg_split('/[;,\\s]/', $shipping_postcodes) as $shipping_postcode) {
                                 if (!empty($shipping_postcode)) {
                                     if (preg_match('/^' . $shipping_postcode . '/', $address_postcode)) {
                                         $checkDone = true;
                                         $postcodesFound = true;
                                         break;
                                     }
                                 }
                             }
                         }
                         if (!$checkDone) {
                             $notUsable[] = $k;
                             continue;
                         }
                     }
                     break;
                 default:
                     if ($postcodehandler > 900) {
                         // Numeric
                         $pclen = $postcodehandler - 900;
                         $address_postcode = preg_replace('/[^0-9]+/', '', $order->shipping_address->address_post_code);
                         if (strlen($address_postcode) < $pclen) {
                             $address_postcode = str_pad($address_postcode, $pclen, '0', STR_PAD_LEFT);
                         }
                         if (preg_match('/[0-9]/', @$shipping_postcodes)) {
                             $checkDone = false;
                             foreach (preg_split('/[^.0-9]/', $shipping_postcodes) as $postcode) {
                                 if (!empty($postcode)) {
                                     if (strpos($postcode, '.') !== false) {
                                         if (!preg_match('/' . $postcode . '/', $address_postcode)) {
                                             continue;
                                         }
                                     } else {
                                         if ($address_postcode != $postcode) {
                                             continue;
                                         }
                                     }
                                     $checkDone = true;
                                     $postcodesFound = true;
                                     break;
                                 }
                             }
                             if (!$checkDone) {
                                 $notUsable[] = $k;
                                 continue;
                             }
                         }
                     }
                     break;
             }
         }
         foreach ($notUsable as $item) {
             unset($local_usable_rates[$item]);
         }
         if (empty($local_usable_rates)) {
             $messages['no_rates'] = self::trans('PLG_BF_MANUAL_NO_SHIPPING_TO_YOUR_POSTCODE');
             return false;
         }
     }
     if (plgHikashopshippingBFManual::$_params->get('addresschk', 0)) {
         foreach ($local_usable_rates as $k => &$rate) {
             for ($f = 1; $f < 3; $f++) {
                 $field = 'shipping_address' . $f . '_field';
                 $values = 'shipping_address' . $f . '_values';
                 $addressfield = trim(@$rate->shipping_params->{$field});
                 $addressvalues = trim(@$rate->shipping_params->{$values});
                 if (!empty($addressfield) && !empty($addressvalues)) {
                     $addressvalue = @$order->shipping_address->{$addressfield};
                     if (!empty($addressvalue)) {
                         $checkDone = false;
                         foreach (preg_split('/[,\\n\\r]/', $addressvalues) as $value) {
                             if (!empty($value) && preg_match('/' . $value . '/i', $addressvalue)) {
                                 $checkDone = true;
                                 break;
                             }
                         }
                     }
                     if (!$checkDone) {
                         $notUsable[] = $k;
                         continue;
                     }
                 }
             }
         }
     }
     foreach ($notUsable as $item) {
         unset($local_usable_rates[$item]);
     }
     if (empty($local_usable_rates) && !empty($notUsable)) {
         if (hikashop_loadUser()) {
             $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
         }
         return false;
     }
     $this->setLocalUsableRates($local_usable_rates);
     foreach ($local_usable_rates as $id => $usable_rate) {
         $usable_rates[$usable_rate->shipping_id] = $usable_rate;
     }
     return true;
 }
Beispiel #3
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $currentShippingZone = null;
     $currentCurrencyId = null;
     $found = true;
     $usableWarehouses = array();
     $zoneClass = hikashop_get('class.zone');
     $zones = $zoneClass->getOrderZones($order);
     foreach ($local_usable_rates as $k => $rate) {
         if (!empty($rate->shipping_params->warehousesList)) {
             $rate->shipping_params->warehouses = unserialize($rate->shipping_params->warehousesList);
         } else {
             $messages['no_warehouse_configured'] = 'No warehouse configured in the CANPAR shipping plugin options';
             continue;
         }
         foreach ($rate->shipping_params->warehouses as $warehouse) {
             if (empty($warehouse->zone) || $warehouse->zone == '-' || in_array($warehouse->zone, $zones)) {
                 $usableWarehouses[] = $warehouse;
             }
         }
         if (empty($usableWarehouses)) {
             $messages['no_warehouse_configured'] = 'No available warehouse found for your location';
             continue;
         }
         if (!empty($rate->shipping_params->methodsList)) {
             $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList);
         } else {
             $messages['no_shipping_methods_configured'] = 'No shipping methods configured in the CANPAR shipping plugin options';
             continue;
         }
         if ($order->weight <= 0 || $order->volume <= 0) {
             return true;
         }
         $data = null;
         if (empty($order->shipping_address)) {
             $messages['no_shipping_address_found'] = 'No shipping address entered';
             continue;
         }
         $this->shipping_currency_id = hikashop_getCurrency();
         $db = JFactory::getDBO();
         $query = 'SELECT currency_code FROM ' . hikashop_table('currency') . ' WHERE currency_id IN (' . $this->shipping_currency_id . ')';
         $db->setQuery($query);
         $this->shipping_currency_code = $db->loadResult();
         $cart = hikashop_get('class.cart');
         $null = null;
         $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping');
         $currency = hikashop_get('class.currency');
         $receivedMethods = $this->_getBestMethods($rate, $order, $usableWarehouses, $null);
         if (empty($receivedMethods)) {
             $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
             continue;
         }
         $i = 0;
         $local_usable_rates = array();
         foreach ($receivedMethods as $method) {
             $local_usable_rates[$i] = !HIKASHOP_PHP5 ? $rate : clone $rate;
             $local_usable_rates[$i]->shipping_price += $method['value'];
             $selected_method = '';
             $name = '';
             foreach ($this->canpar_methods as $canpar_method) {
                 if ($canpar_method['name'] == $method['name']) {
                     $name = $canpar_method['name'];
                     $selected_method = $canpar_method['key'];
                 }
             }
             $local_usable_rates[$i]->shipping_name = $name;
             if (!empty($selected_method)) {
                 $local_usable_rates[$i]->shipping_id .= '-' . $selected_method;
             }
             if ($method['deliveryDate'] != 'www.canpar.ca') {
                 if (is_numeric($method['deliveryDate'])) {
                     $timestamp = strtotime($method['deliveryDate']);
                     $time = parent::displayDelaySECtoDAY($timestamp - strtotime('now'), 2);
                     $local_usable_rates[$i]->shipping_description .= 'Estimated delivery date:  ' . $time;
                 } else {
                     $time = $method['deliveryDate'];
                     $local_usable_rates[$i]->shipping_description .= 'Estimated delivery date:  ' . $time;
                 }
             } else {
                 $local_usable_rates[$i]->shipping_description .= ' ' . JText::_('NO_ESTIMATED_TIME_AFTER_SEND');
             }
             if ($rate->shipping_params->group_package == 1 && $this->nbpackage > 1) {
                 $local_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('X_PACKAGES', $this->nbpackage);
             }
             $i++;
         }
         foreach ($local_usable_rates as $i => $rate) {
             $usable_rates[$rate->shipping_id] = $rate;
         }
     }
 }
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     $weightClass = hikashop_get('helper.weight');
     $volumeClass = hikashop_get('helper.volume');
     if (!hikashop_loadUser()) {
         return false;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $currencyClass = hikashop_get('class.currency');
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $currentShippingZone = null;
     $currentCurrencyId = null;
     foreach ($local_usable_rates as $rate) {
         if (!empty($rate->shipping_zone_namekey)) {
             $zoneClass = hikashop_get('class.zone');
             $zones = $zoneClass->getOrderZones($order);
             if (!in_array($rate->shipping_zone_namekey, $zones)) {
                 $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
                 continue;
             }
         }
         if (empty($order->shipping_address_full)) {
             $cart = hikashop_get('class.cart');
             $app = JFactory::getApplication();
             $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address');
             $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping');
         }
         if ($order->shipping_address_full->shipping_address->address_country->zone_code_3 != 'BRA') {
             continue;
         }
         $cepCliente = trim($order->shipping_address->address_post_code);
         $max_altura = 2;
         $max_largura = 11;
         $max_comprimento = 16;
         $orderWeight = 0;
         foreach ($order->products as $product) {
             $product_weight = $weightClass->convert($product->product_weight, $product->product_weight_unit, 'kg');
             $orderWeight += $product->cart_product_quantity * $product_weight;
             //Define medidas máximas
             if ($product->product_height > $max_altura) {
                 $max_altura = $product->product_height;
             }
             if ($product->product_width > $max_largura) {
                 $max_largura = $product->product_width;
             }
             if ($product->product_length > $max_comprimento) {
                 $max_comprimento = $product->product_length;
             }
         }
         // =============  Início Obtém o valor do frete do site dos Correios  =============
         //Monta URL para pegar os dados do site dos Correios
         $workstring = 'nCdEmpresa=' . $rate->shipping_params->correios_servico_empresa;
         $workstring .= '&sDsSenha=' . $rate->shipping_params->correios_servico_senha;
         $workstring .= '&sCepOrigem=' . $rate->shipping_params->correios_shop_post_code;
         $workstring .= '&sCepDestino=' . $cepCliente;
         $workstring .= '&nVlPeso=' . $orderWeight;
         $workstring .= '&nCdFormato=1';
         $workstring .= '&nVlAltura=' . number_format($max_altura, 2, ',', '');
         $workstring .= '&nVlLargura=' . number_format($max_largura, 2, ',', '');
         $workstring .= '&nVlComprimento=' . number_format($max_comprimento, 2, ',', '');
         $workstring .= '&sCdMaoPropria=' . $rate->shipping_params->correios_mao_propria;
         if ($rate->shipping_params->correios_declara_valor || $rate->shipping_params->correios_servico == 40045 || $rate->shipping_params->correios_servico == 40126) {
             $workstring .= '&nVlValorDeclarado=' . number_format(round($order->total->prices[0]->price_value_with_tax, 2), 2, ',', '.');
         } else {
             $workstring .= '&nVlValorDeclarado=0';
         }
         $workstring .= '&sCdAvisoRecebimento=' . $rate->shipping_params->correios_aviso_recebimento;
         $workstring .= '&nCdServico=' . $rate->shipping_params->correios_servico;
         $workstring .= '&nVlDiametro=0';
         $workstring .= '&StrRetorno=xml';
         $url_busca = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx";
         $url_busca .= "?" . $workstring;
         $conteudo = '';
         $conteudo = $this->_transmiteCorreios($url_busca);
         if (preg_match("/<Erro>99<\\/Erro>/i", $conteudo)) {
             $url_busca = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPreco";
             $url_busca .= "?" . $workstring;
             $conteudo = '';
             $conteudo = $this->_transmiteCorreios($url_busca);
         }
         if (strpos($conteudo, 'HTTP Error 503. The service is unavailable.') !== false) {
             $messages[] = 'HTTP Error 503. The Correios server is unavailable.';
             continue;
         }
         if ($conteudo) {
             $dadosCorreios = simplexml_load_string($conteudo);
         }
         if (is_object($dadosCorreios->cServico)) {
             $Valor = (string) $dadosCorreios->cServico->Valor;
             $Erro = (string) $dadosCorreios->cServico->Erro;
             $MsgErro = (string) $dadosCorreios->cServico->MsgErro;
             if ($Erro != 0) {
                 $messages[] = $MsgErro;
             }
             $Valor = str_replace(",", ".", $Valor);
         }
         if ($Valor > 0) {
             $rate->shipping_price = $Valor;
             //$rate -> shipping_price = 10.00;
             $rate->shipping_id = $rate->shipping_params->correios_servico;
             $usable_rates[] = $rate;
         }
     }
     return true;
 }
Beispiel #5
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     if ($this->loadShippingCache($order, $usable_rates, $messages)) {
         return true;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     if (!function_exists('curl_init')) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('The USPS shipping plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error');
         return false;
     }
     $cache_rates = array();
     $cache_messages = array();
     $found = false;
     $currentShippingZone = null;
     $currentCurrencyId = null;
     foreach ($local_usable_rates as $rate) {
         if ($rate->shipping_type != 'usps') {
             continue;
         }
         if (empty($order->shipping_address)) {
             continue;
         }
         $found = true;
         $zones = null;
         if (!empty($rate->shipping_zone_namekey)) {
             if (empty($zones)) {
                 $zoneClass = hikashop_get('class.zone');
                 $zones = $zoneClass->getOrderZones($order);
             }
             if (!in_array($rate->shipping_zone_namekey, $zones)) {
                 $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
                 continue;
             }
             $db = JFactory::getDBO();
             if (is_array($order->shipping_address->address_country)) {
                 $address_country = reset($order->shipping_address->address_country);
             } else {
                 $address_country = $order->shipping_address->address_country;
             }
             $db->setQuery('SELECT * FROM ' . hikashop_table('zone') . ' WHERE zone_namekey=' . $db->Quote($address_country));
             $zone = $db->loadObject();
             if ($zone->zone_code_3 != 'USA') {
                 $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
                 continue;
             }
         }
         $check = false;
         if (empty($order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The USPS shipping plugin requires the user to enter a postal code when goods are shipped within the United States. Please go to "Display->Custom fields" and set the post code field to required.';
         } elseif (!preg_match('#^[0-9]{5}(-?[0-9]{4})?$#', $order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The post code entered is not valid';
         }
         if ($check) {
             if (empty($zones)) {
                 $zoneClass = hikashop_get('class.zone');
                 $zones = $zoneClass->getOrderZones($order);
             }
             $db = JFactory::getDBO();
             $db->setQuery('SELECT zone_namekey FROM ' . hikashop_table('zone') . ' WHERE zone_code_3=' . $db->Quote('USA'));
             $usa_zone = $db->loadResult();
             if (in_array($usa_zone, $zones)) {
                 $messages['post_code_missing'] = $message;
                 continue;
             }
         }
         foreach ($order->products as $product) {
             if (!empty($rate->shipping_params->weight_approximation)) {
                 if (isset($product->product_weight)) {
                     $product->product_weight = $product->product_weight + $product->product_weight * $rate->shipping_params->weight_approximation / 100;
                 }
                 if (isset($product->product_weight_orig)) {
                     $product->product_weight_orig = $product->product_weight_orig + $product->product_weight_orig * $rate->shipping_params->weight_approximation / 100;
                 }
             }
             if (!empty($rate->shipping_params->dim_approximation)) {
                 if (isset($product->product_height)) {
                     $product->product_height = $product->product_height + $product->product_height * $rate->shipping_params->dim_approximation / 100;
                 }
                 if (isset($product->product_length)) {
                     $product->product_length = $product->product_length + $product->product_length * $rate->shipping_params->dim_approximation / 100;
                 }
                 if (isset($product->product_width)) {
                     $product->product_width = $product->product_width + $product->product_width * $rate->shipping_params->dim_approximation / 100;
                 }
                 if (isset($product->product_total_volume)) {
                     $product->product_total_volume = $product->product_total_volume + $product->product_total_volume * $rate->shipping_params->dim_approximation / 100;
                 }
                 if (isset($product->product_total_volume_orig)) {
                     $product->product_total_volume_orig = $product->product_total_volume_orig + $product->product_total_volume_orig * $rate->shipping_params->dim_approximation / 100;
                 }
             }
             if (isset($product->variants)) {
                 foreach ($product->variants as $variant) {
                     if (!empty($rate->shipping_params->weight_approximation)) {
                         if (isset($variant->product_weight)) {
                             $variant->product_weight = $variant->product_weight + $variant->product_weight * $rate->shipping_params->weight_approximation / 100;
                         }
                         if (isset($variant->product_weight_orig)) {
                             $variant->product_weight_orig = $variant->product_weight_orig + $variant->product_weight_orig * $rate->shipping_params->weight_approximation / 100;
                         }
                     }
                     if (!empty($rate->shipping_params->dim_approximation)) {
                         if (isset($variant->product_height)) {
                             $variant->product_height = $variant->product_height + $variant->product_height * $rate->shipping_params->dim_approximation / 100;
                         }
                         if (isset($variant->product_length)) {
                             $variant->product_length = $variant->product_length + $variant->product_length * $rate->shipping_params->dim_approximation / 100;
                         }
                         if (isset($variant->product_width)) {
                             $variant->product_width = $variant->product_width + $variant->product_width * $rate->shipping_params->dim_approximation / 100;
                         }
                         if (isset($variant->product_total_volume)) {
                             $variant->product_total_volume = $variant->product_total_volume + $variant->product_total_volume * $rate->shipping_params->dim_approximation / 100;
                         }
                         if (isset($variant->product_total_volume_orig)) {
                             $variant->product_total_volume_orig = $variant->product_total_volume_orig + $variant->product_total_volume_orig * $rate->shipping_params->dim_approximation / 100;
                         }
                     }
                 }
             }
         }
         $package = $this->getOrderPackage($order, array('weight_unit' => 'oz', 'volume_unit' => 'in', 'required_dimensions' => array('w', 'x', 'y', 'z')));
         if (isset($package[0])) {
             $package = $package[0];
         }
         $max_weight = 1120;
         if ($package['w'] > $max_weight) {
             $messages['items_weight_over_limit'] = JText::_('ITEMS_WEIGHT_TOO_BIG_FOR_SHIPPING_METHODS');
             $cache_messages['items_weight_over_limit'] = JText::_('ITEMS_WEIGHT_TOO_BIG_FOR_SHIPPING_METHODS');
             $this->setShippingCache($order, null, $cache_messages);
             return true;
         }
         if ($package['w'] < 1) {
             $package['w'] = 1;
         }
         // Minimum 1oz
         if (empty($order->shipping_address_full)) {
             $cart = hikashop_get('class.cart');
             $app = JFactory::getApplication();
             $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address');
             $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping');
         }
         $query = 'SELECT currency_id FROM ' . hikashop_table('currency') . ' WHERE currency_code=\'USD\'';
         $db = JFactory::getDBO();
         $db->setQuery($query);
         $currency = $db->loadResult();
         $parcel = new stdClass();
         $parcel->Country = @$order->shipping_address_full->shipping_address->address_country->zone_code_2;
         if (empty($parcel->Country)) {
             $parcel->Country = 'US';
         }
         $parcel->Pickup_Postcode = substr(preg_replace('#[^a-z0-9]#i', '', @$rate->shipping_params->post_code), 0, 5);
         $parcel->Destination_Postcode = substr(preg_replace('#[^a-z0-9]#i', '', $order->shipping_address->address_post_code), 0, 5);
         $girth = array($package['y'], $package['x'], $package['z']);
         sort($girth);
         $parcel->Length = $girth[2];
         $parcel->Width = $girth[1];
         $parcel->Height = $girth[0];
         $parcel->Girth = ($parcel->Height + $parcel->Width) * 2 + $parcel->Length;
         $parcel->Quantity = 1;
         $parcel->Weight = $package['w'];
         $rates = array();
         if ($parcel->Country == 'US') {
             $modes = array('PRIORITY', 'MEDIA', 'EXPRESS', 'FIRST CLASS');
             foreach ($modes as $mode) {
                 if (!empty($rate->shipping_params->{$mode})) {
                     $this->addRate($rates, $mode, $parcel, $rate, $currency, false);
                 }
             }
         } else {
             $modes = array('INTERNATIONAL', 'PRIORITYINTSMALL', 'PRIORITYINTDVD', 'PRIORITYINTLARGEVIDEO', 'PRIORITYINTMEDIUM', 'PRIORITYINTLARGE', 'EXPRESSINTBOX', 'EXPRESSINT', 'FIRSTCLASSINT', 'ENVELOPE');
             foreach ($modes as $mode) {
                 if (!empty($rate->shipping_params->{$mode})) {
                     $this->addRate($rates, $mode, $parcel, $rate, $currency, true);
                 }
             }
         }
         if ($rate->shipping_params->sort_by_price == 'DESC') {
             $rates = $this->array_sort($rates, 'shipping_price', 'usps', SORT_DESC);
         } else {
             if ($rate->shipping_params->sort_by_price == 'ASC') {
                 $rates = $this->array_sort($rates, 'shipping_price', 'usps', SORT_ASC);
             }
         }
         $i = 0;
         if (empty($rates)) {
             $messages['no_shipping_quotes'] = 'Failed to obtain shipping quotes.';
             $cache_messages['no_shipping_quotes'] = 'Failed to obtain shipping quotes.';
             $this->setShippingCache($order, null, $cache_messages);
             return true;
         }
         foreach ($rates as $finalRate) {
             $finalRate->shipping_ordering .= '_' . $i++;
             $usable_rates[$finalRate->shipping_id] = $finalRate;
             $cache_rates[$finalRate->shipping_id] = $finalRate;
         }
     }
     if (!$found) {
         $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
         $cache_messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
     }
     $this->setShippingCache($order, $cache_rates, $cache_messages);
     return true;
 }
Beispiel #6
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     if (empty($order->shipping_address)) {
         return true;
     }
     if ($this->loadShippingCache($order, $usable_rates, $messages)) {
         return true;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     if (!function_exists('curl_init')) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('The UPS shipping plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error');
         return false;
     }
     $cache_usable_rates = array();
     $cache_messages = array();
     $currentShippingZone = null;
     $currentCurrencyId = null;
     $found = true;
     $usableWarehouses = array();
     $zoneClass = hikashop_get('class.zone');
     $zones = $zoneClass->getOrderZones($order);
     $this->error_messages = array();
     foreach ($local_usable_rates as $k => $rate) {
         if (empty($rate->shipping_params->warehousesList)) {
             $cache_messages['no_warehouse_configured'] = 'No warehouse configured in the UPS shipping plugin options';
             continue;
         }
         $rate->shipping_params->warehouses = unserialize($rate->shipping_params->warehousesList);
         foreach ($rate->shipping_params->warehouses as $warehouse) {
             if (!empty($warehouse->country) && empty($warehouse->zone) || $warehouse->zone == '-' || in_array($warehouse->zone, $zones)) {
                 $usableWarehouses[] = $warehouse;
             }
         }
         if (empty($usableWarehouses)) {
             $cache_messages['no_warehouse_configured'] = 'No available warehouse found for your location';
             continue;
         }
         if (empty($rate->shipping_params->methodsList)) {
             $cache_messages['no_shipping_methods_configured'] = 'No shipping methods configured in the UPS shipping plugin options';
             continue;
         }
         if ($order->weight <= 0 || $order->volume <= 0 && @$rate->shipping_params->exclude_dimensions != 1) {
             continue;
         }
         $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList);
         $this->freight = false;
         $this->classicMethod = false;
         $heavyProduct = false;
         $weightTotal = 0;
         if (!empty($rate->shipping_params->methods)) {
             foreach ($rate->shipping_params->methods as $method) {
                 if (in_array($method, array('TDCB', 'TDA', 'TDO', '308', '309', '310'))) {
                     $this->freight = true;
                 } else {
                     $this->classicMethod = true;
                 }
             }
         }
         $null = null;
         if (empty($this->shipping_currency_id)) {
             $this->shipping_currency_id = hikashop_getCurrency();
         }
         $currencyClass = hikashop_get('class.currency');
         $currencies = $currencyClass->getCurrencies(array($this->shipping_currency_id), $null);
         $this->shipping_currency_code = $currencies[$this->shipping_currency_id]->currency_code;
         $cart = hikashop_get('class.cart');
         $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping');
         $receivedMethods = $this->_getBestMethods($rate, $order, $usableWarehouses, $heavyProduct, $null);
         if (empty($receivedMethods)) {
             continue;
         }
         $i = 0;
         $new_usable_rates = array();
         foreach ($receivedMethods as $method) {
             $new_usable_rates[$i] = !HIKASHOP_PHP5 ? $rate : clone $rate;
             $new_usable_rates[$i]->shipping_price += round($method['value'], 2);
             $selected_method = '';
             $name = '';
             foreach ($this->ups_methods as $ups_method) {
                 if ($ups_method['code'] == $method['code'] && ($method['old_currency_code'] == 'CAD' || !isset($ups_method['double']))) {
                     $selected_method = $ups_method['key'];
                     $name = $ups_method['name'];
                     break;
                 }
             }
             $new_usable_rates[$i]->shipping_name = $name;
             if (!empty($selected_method)) {
                 $new_usable_rates[$i]->shipping_id .= '-' . $selected_method;
             }
             if (isset($rate->shipping_params->show_eta) && $rate->shipping_params->show_eta) {
                 if ($method['delivery_day'] != -1) {
                     $new_usable_rates[$i]->shipping_description .= ' ' . JText::sprintf('ESTIMATED_TIME_AFTER_SEND', $method['delivery_day']);
                 } else {
                     $new_usable_rates[$i]->shipping_description .= ' ' . JText::_('NO_ESTIMATED_TIME_AFTER_SEND');
                 }
                 if ($method['delivery_time'] != -1) {
                     $new_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('DELIVERY_HOUR', $method['delivery_time']);
                 } else {
                     $new_usable_rates[$i]->shipping_description .= '<br/>' . JText::_('NO_DELIVERY_HOUR');
                 }
             }
             if ($rate->shipping_params->group_package && $this->nbpackage > 1) {
                 $new_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('X_PACKAGES', $this->nbpackage);
             }
             $i++;
         }
         foreach ($new_usable_rates as $i => $rate) {
             if (isset($rate->shipping_price_orig) || isset($rate->shipping_currency_id_orig)) {
                 if ($rate->shipping_currency_id_orig == $rate->shipping_currency_id) {
                     $rate->shipping_price_orig = $rate->shipping_price;
                 } else {
                     $rate->shipping_price_orig = $currencyClass->convertUniquePrice($rate->shipping_price, $rate->shipping_currency_id, $rate->shipping_currency_id_orig);
                 }
             }
             $usable_rates[$rate->shipping_id] = $rate;
             $cache_usable_rates[$rate->shipping_id] = $rate;
         }
     }
     if (!empty($this->error_messages)) {
         foreach ($this->error_messages as $key => $value) {
             $cache_messages[$key] = $value;
         }
     }
     $this->setShippingCache($order, $cache_usable_rates, $cache_messages);
     if (!empty($cache_messages)) {
         foreach ($cache_messages as $k => $msg) {
             $messages[$k] = $msg;
         }
     }
 }
Beispiel #7
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     if ($this->loadShippingCache($order, $usable_rates, $messages)) {
         return true;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     if (!function_exists('curl_init')) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('The AUPOST shipping plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error');
         return false;
     }
     $cache_usable_rates = array();
     $cache_messages = array();
     $currentCurrencyId = null;
     foreach ($local_usable_rates as $rate) {
         if (!empty($rate->shipping_zone_namekey)) {
             if (empty($rate->shipping_params->SEA) && empty($rate->shipping_params->AIR) && !empty($order->shipping_address->address_country)) {
                 $db = JFactory::getDBO();
                 if (is_array($order->shipping_address->address_country)) {
                     $address_country = reset($order->shipping_address->address_country);
                 } else {
                     $address_country = $order->shipping_address->address_country;
                 }
                 $db->setQuery('SELECT * FROM ' . hikashop_table('zone') . ' WHERE zone_namekey=' . $db->Quote($address_country));
                 $currentShippingZone = $db->loadObject();
                 if ($currentShippingZone->zone_code_3 != 'AUS') {
                     $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
                     continue;
                 }
             }
         }
         $check = false;
         if (empty($order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The Australia Post shipping plugin requires the user to enter a postal code when goods are shipped within Australia. Please go to "Display->Custom fields" and set the post code field to required.';
         } elseif (!preg_match('#[0-9]{4}#', $order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The post code entered is not valid';
             $order->shipping_address->address_post_code = preg_replace('#[^0-9A-Z]#', '', $order->shipping_address->address_post_code);
         }
         if ($check) {
             $zoneClass = hikashop_get('class.zone');
             $zones = $zoneClass->getOrderZones($order);
             $db = JFactory::getDBO();
             $db->setQuery('SELECT zone_namekey FROM ' . hikashop_table('zone') . ' WHERE zone_code_3=' . $db->Quote('AUS'));
             $australia_zone = $db->loadResult();
             if (in_array($australia_zone, $zones)) {
                 $cache_messages['post_code_missing'] = $message;
                 continue;
             }
         }
         if (empty($order->shipping_address_full)) {
             $cart = hikashop_get('class.cart');
             $app = JFactory::getApplication();
             $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address');
             $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping');
         }
         $rates = array();
         $this->getRates($rate, $order, $rates);
         if (!empty($rate->shipping_params->reverse_order)) {
             $rates = array_reverse($rates, true);
         }
         foreach ($rates as $finalRate) {
             $usable_rates[$finalRate->shipping_id] = $finalRate;
             $cache_usable_rates[$finalRate->shipping_id] = $finalRate;
         }
     }
     $this->setShippingCache($order, $cache_usable_rates, $cache_messages);
     if (!empty($cache_messages)) {
         foreach ($cache_messages as $k => $msg) {
             $messages[$k] = $msg;
         }
     }
     return true;
 }
 /**
  *
  */
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     if (empty($order->shipping_address)) {
         return true;
     }
     if ($this->loadShippingCache($order, $usable_rates, $messages)) {
         return true;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $currentShippingZone = null;
     $currentCurrencyId = null;
     $cache_usable_rates = array();
     $cache_messages = array();
     $found = true;
     $usableWarehouses = array();
     $zoneClass = hikashop_get('class.zone');
     $zones = $zoneClass->getOrderZones($order);
     if (!function_exists('curl_init')) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('The Envoimoinscher shipping plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error');
         return false;
     }
     $app = JFactory::getApplication();
     $order_clone = new stdClass();
     $variables = array('products', 'cart_id', 'coupon', 'shipping_address', 'volume', 'weight', 'volume_unit', 'weight_unit');
     foreach ($variables as $var) {
         if (isset($order->{$var})) {
             $order_clone->{$var} = $order->{$var};
         }
     }
     $shipping_key = sha1(serialize($order_clone) . serialize($local_usable_rates));
     $result = $app->getUserState(HIKASHOP_COMPONENT . '.shipping.envoimoinscher_result', $this->result);
     // when cache doesn't work we generate a key in order not to redo everything at each step
     if (isset($result['shipping_key']) && $result['shipping_key'] == $shipping_key) {
         return;
     }
     if (empty($order->shipping_address)) {
         return true;
     }
     foreach ($local_usable_rates as $k => $rate) {
         if (!empty($rate->shipping_params->methodsList)) {
             $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList);
         } else {
             $cache_messages['no_shipping_methods_configured'] = 'No shipping methods selected in the Envoimoinscher shipping plugin options';
             continue;
         }
         if ($order->weight <= 0 || $order->volume <= 0 && @$rate->shipping_params->exclude_dimensions != 1) {
             continue;
         }
         $currencyClass = hikashop_get('class.currency');
         $this->shipping_currency_id = hikashop_getCurrency();
         $currency = $currencyClass->get($this->shipping_currency_id);
         $this->shipping_currency_code = $currency->currency_code;
         $cart = hikashop_get('class.cart');
         $null = null;
         $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping');
         $sending_type = strtolower($rate->shipping_params->sending_type);
         // Get all data for send requests to envoimoinscher
         $this->getData($null, $rate, $order, $sending_type, false);
         if (empty($this->result)) {
             $cache_messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND');
             continue;
         }
         $new_usable_rates = array();
         foreach ($this->result as $key => $method) {
             if ($key === "shipping_key") {
                 continue;
             }
             $o = !HIKASHOP_PHP5 ? $rate : clone $rate;
             $o->shipping_price = $method["Prix"];
             $selected_method = '';
             $name = '';
             $selected_method = $method['Transporteur'];
             $name = $method['Service'];
             $o->shipping_name = $selected_method . " / " . $name;
             if (!empty($selected_method)) {
                 $o->shipping_id .= '-' . $selected_method . " / " . $name;
             }
             $new_usable_rates[] = $o;
         }
         foreach ($new_usable_rates as $i => $rate) {
             $usable_rates[$rate->shipping_id] = $rate;
             $cache_usable_rates[$rate->shipping_id] = $rate;
         }
         $this->result = array();
     }
     $this->setShippingCache($order, $cache_usable_rates, $cache_messages);
     if (!empty($cache_messages)) {
         foreach ($cache_messages as $k => $msg) {
             $messages[$k] = $msg;
         }
     }
 }
Beispiel #9
0
 function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages)
 {
     if (!hikashop_loadUser()) {
         return false;
     }
     if ($this->loadShippingCache($order, $usable_rates, $messages)) {
         return true;
     }
     $local_usable_rates = array();
     $local_messages = array();
     $currencyClass = hikashop_get('class.currency');
     $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
     if ($ret === false) {
         return false;
     }
     $cache_usable_rates = array();
     $cache_messages = array();
     $currentCurrencyId = null;
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $iAmSuperAdmin = false;
     if (!HIKASHOP_J16) {
         $iAmSuperAdmin = $user->get('gid') == 25;
     } else {
         $iAmSuperAdmin = $user->authorise('core.admin');
     }
     if ($iAmSuperAdmin) {
         $app->enqueueMessage('That Australia Post shipping version is deprecated and is using the old Australia post API, Please start using the new Australia Post v2 shipping method');
     }
     foreach ($local_usable_rates as $rate) {
         if (!empty($rate->shipping_zone_namekey)) {
             if (empty($rate->shipping_params->SEA) && empty($rate->shipping_params->AIR) && !empty($order->shipping_address->address_country)) {
                 $db = JFactory::getDBO();
                 if (is_array($order->shipping_address->address_country)) {
                     $address_country = reset($order->shipping_address->address_country);
                 } else {
                     $address_country = $order->shipping_address->address_country;
                 }
                 $db->setQuery('SELECT * FROM ' . hikashop_table('zone') . ' WHERE zone_namekey=' . $db->Quote($address_country));
                 $currentShippingZone = $db->loadObject();
                 if ($currentShippingZone->zone_code_3 != 'AUS') {
                     $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE');
                     continue;
                 }
             }
         }
         $check = false;
         if (empty($order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The Australia Post shipping plugin requires the user to enter a postal code when goods are shipped within Australia. Please go to "Display->Custom fields" and set the post code field to required.';
         } elseif (!preg_match('#[0-9]{4}#', $order->shipping_address->address_post_code)) {
             $check = true;
             $message = 'The post code entered is not valid';
             $order->shipping_address->address_post_code = preg_replace('#[^0-9A-Z]#', '', $order->shipping_address->address_post_code);
         }
         if ($check) {
             $zoneClass = hikashop_get('class.zone');
             $zones = $zoneClass->getOrderZones($order);
             $db = JFactory::getDBO();
             $db->setQuery('SELECT zone_namekey FROM ' . hikashop_table('zone') . ' WHERE zone_code_3=' . $db->Quote('AUS'));
             $australia_zone = $db->loadResult();
             if (in_array($australia_zone, $zones)) {
                 $cache_messages['post_code_missing'] = $message;
                 continue;
             }
         }
         if (empty($order->shipping_address_full)) {
             $cart = hikashop_get('class.cart');
             $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address');
             $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping');
         }
         $rates = array();
         $this->getRates($rate, $order, $rates);
         if (!empty($rate->shipping_params->reverse_order)) {
             $rates = array_reverse($rates, true);
         }
         foreach ($rates as $finalRate) {
             if (hikashop_getCurrency() != 6) {
                 $finalRate->shipping_price = $currencyClass->convertUniquePrice($finalRate->shipping_price, 6, hikashop_getCurrency());
             }
             $usable_rates[$finalRate->shipping_id] = $finalRate;
             $cache_usable_rates[$finalRate->shipping_id] = $finalRate;
         }
     }
     $this->setShippingCache($order, $cache_usable_rates, $cache_messages);
     if (!empty($cache_messages)) {
         foreach ($cache_messages as $k => $msg) {
             $messages[$k] = $msg;
         }
     }
     return true;
 }