Example #1
0
 private function formatPieces()
 {
     if (!$this->id_shipment) {
         self::$errors[] = $this->l('Shipment ID is missing');
         return false;
     }
     $pieces = array();
     if (!is_array($this->id_shipment)) {
         $this->id_shipment = array($this->id_shipment);
     }
     foreach ($this->id_shipment as $id_shipment) {
         $id_order = (int) DpdGroupShipment::getOrderIdByShipmentId($id_shipment);
         $shipment = new DpdGroupShipment($id_order);
         if (!(int) $shipment->id_order) {
             self::$errors[] = sprintf($this->l('Order #%d does not exists'), (int) $shipment->id_order);
             return false;
         }
         if (!isset($pieces[$shipment->receiver_country_code])) {
             $pieces[$shipment->receiver_country_code] = array();
         }
         $pieces[$shipment->receiver_country_code][] = array('serviceCode' => (int) $shipment->main_service_code, 'quantity' => count($shipment->parcels), 'weight' => (double) $shipment->getTotalParcelsWeight(), 'destinationCountryCode' => $shipment->receiver_country_code, 'id_shipment' => (int) $id_shipment);
     }
     return $pieces;
 }
Example #2
0
 private function getPriceByWebServicesCalculationType(Cart $cart, $is_cod_method, $order_total_price, $id_method, $id_address_delivery, $additional_shipping_cost, $handling_charges, DpdGroupConfiguration $configuration, $price_rule, $products)
 {
     $shipment = new DpdGroupShipment();
     $cart_products = empty($products) ? $cart->getProducts() : $products;
     if (!self::$parcels) {
         self::$parcels = $shipment->putProductsToParcels($cart_products);
     }
     $extra_params = array();
     if ($is_cod_method) {
         $extra_params['cod'] = array('total_paid' => $order_total_price, 'currency_iso_code' => $this->context->currency->iso_code, 'reference' => (int) $this->context->cart->id);
     }
     $product_names = '';
     if (count($cart_products)) {
         foreach ($cart_products as $product) {
             $product_names .= '|' . $product['name'];
         }
     }
     $extra_params['highInsurance'] = array('total_paid' => $order_total_price, 'currency_iso_code' => $this->context->currency->iso_code, 'content' => $product_names);
     $result = $shipment->calculate($id_method, $id_address_delivery, self::$parcels, null, $extra_params);
     if ($result === false || !isset($result['price']) || !isset($result['id_currency'])) {
         return false;
     }
     $result_price_in_default_currency = Tools::convertPrice($result['price'], new Currency((int) $result['id_currency']), false);
     $result['price'] = Tools::convertPrice($result_price_in_default_currency);
     $result['price'] += $additional_shipping_cost + $handling_charges;
     if (!empty($price_rule)) {
         if ($price_rule['shipping_price_percentage'] !== '') {
             $surcharge = $result['price'] * $price_rule['shipping_price_percentage'] / 100;
             $result['price'] += $surcharge;
         }
         if ($is_cod_method && $price_rule['cod_surcharge'] !== '') {
             $result['price'] += $this->convertPriceByCurrency($price_rule['cod_surcharge'], $price_rule['currency']);
         } elseif ($is_cod_method && $price_rule['cod_surcharge_percentage'] !== '') {
             $percentage_starting_price = $configuration->cod_percentage_calculation == DpdGroupConfiguration::COD_PERCENTAGE_CALCULATION_CART ? $order_total_price : $order_total_price + $result['price'];
             $result['price'] += $this->calculateCODSurchargePercentage($percentage_starting_price, $price_rule['cod_surcharge_percentage'], $price_rule['cod_min_surcharge'], $price_rule['currency']);
         }
     }
     return $result['price'];
 }
Example #3
0
    }
    $error_messages = '';
    if (DpdGroupShipment::$errors) {
        foreach (DpdGroupShipment::$errors as $error) {
            $error_messages .= $error . '<br />';
        }
    }
    if (DpdGroupShipment::$notices) {
        foreach (DpdGroupShipment::$notices as $error) {
            $error_messages .= $error . '<br />';
        }
    }
    die(Tools::jsonEncode(array('error' => $message && !$error_messages ? null : $error_messages)));
}
if (Tools::isSubmit('deleteShipment')) {
    $shipment = new DpdGroupShipment((int) Tools::getValue('id_order'));
    if ($result = $shipment->delete()) {
        $module_instance->addFlashMessage($module_instance->l('Shipment successfully deleted', $filename));
    }
    die(Tools::jsonEncode(array('error' => $result ? null : reset(DpdGroupShipment::$errors))));
}
if (Tools::isSubmit('arrangePickup')) {
    $pickup_data = Tools::getValue('dpdgroup_pickup_data');
    $pickup = new DpdGroupPickup();
    $pickup->id_shipment = Tools::getValue('shipmentIds');
    $pickup->date = isset($pickup_data['date']) ? $pickup_data['date'] : null;
    $pickup->from_time = isset($pickup_data['from_time']) ? $pickup_data['from_time'] : null;
    $pickup->to_time = isset($pickup_data['to_time']) ? $pickup_data['to_time'] : null;
    $pickup->contact_email = isset($pickup_data['contact_email']) ? $pickup_data['contact_email'] : null;
    $pickup->contact_name = isset($pickup_data['contact_name']) ? $pickup_data['contact_name'] : null;
    $pickup->contact_phone = isset($pickup_data['contact_phone']) ? $pickup_data['contact_phone'] : null;
 public function getShipmentList()
 {
     $keys_array = array('id_shipment', 'date_shipped', 'id_order', 'date_add', 'carrier', 'customer', 'quantity', 'manifest', 'label', 'date_pickup');
     if (Tools::isSubmit('submitFilterButtonShipments')) {
         foreach ($_POST as $key => $value) {
             if (strpos($key, 'ShipmentsFilter_') !== false) {
                 if (is_array($value)) {
                     $this->context->cookie->{$key} = Tools::jsonEncode($value);
                 } else {
                     $this->context->cookie->{$key} = $value;
                 }
             }
         }
     }
     if (Tools::isSubmit('submitResetShipments')) {
         foreach ($keys_array as $key) {
             if ($this->context->cookie->__isset('ShipmentsFilter_' . $key)) {
                 $this->context->cookie->__unset('ShipmentsFilter_' . $key);
                 unset($_POST['ShipmentsFilter_' . $key]);
             }
         }
     }
     $page = (int) Tools::getValue('submitFilterShipments');
     if (!$page) {
         $page = 1;
     }
     $selected_pagination = (int) Tools::getValue('pagination', $this->pagination[0]);
     $start = $selected_pagination * $page - $selected_pagination;
     $order_by = Tools::getValue('ShipmentOrderBy', self::DEFAULT_ORDER_BY);
     $order_way = Tools::getValue('ShipmentOrderWay', self::DEFAULT_ORDER_WAY);
     $filter = $this->getFilterQuery($keys_array, 'Shipments');
     $shipment = new DpdGroupShipment();
     $shipments = $shipment->getShipmentList($order_by, $order_way, $filter, $start, $selected_pagination);
     $list_total = count($shipment->getShipmentList($order_by, $order_way, $filter, null, null));
     $total_pages = ceil($list_total / $selected_pagination);
     if (!$total_pages) {
         $total_pages = 1;
     }
     $shipments_count = count($shipments);
     for ($i = 0; $i < $shipments_count; $i++) {
         $order = new Order((int) $shipments[$i]['id_order']);
         $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);
         $shipments[$i]['carrier_url'] = $carrier->url;
     }
     $this->context->smarty->assign(array('full_url' => $this->module_instance->module_url . '&menu=shipment_list&ShipmentOrderBy=' . $order_by . '&ShipmentOrderWay=' . $order_way, 'employee' => $this->context->employee, 'shipments' => $shipments, 'page' => $page, 'selected_pagination' => $selected_pagination, 'pagination' => $this->pagination, 'total_pages' => $total_pages, 'list_total' => $list_total, 'order_by' => $order_by, 'order_way' => $order_way, 'order_link' => DpdGroup::getAdminOrderLink()));
     $template_filename = version_compare(_PS_VERSION_, '1.6', '>=') ? 'shipment_list_16' : 'shipment_list';
     return $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'admin/' . $template_filename . '.tpl');
 }
Example #5
0
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to telco.csee@geopost.pl so we can send you a copy immediately.
 *
 *  @author    JSC INVERTUS www.invertus.lt <*****@*****.**>
 *  @copyright 2015 DPD Polska sp. z o.o.
 *  @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 *  International Registered Trademark & Property of DPD Polska sp. z o.o.
 */
include_once dirname(__FILE__) . '/../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../init.php';
$module_instance = Module::getInstanceByName('dpdgroup');
if (Tools::getValue('token') != sha1(_COOKIE_KEY_ . $module_instance->name)) {
    exit;
}
if (Tools::isSubmit('printLabels')) {
    $shipment = new DpdGroupShipment((int) Tools::getValue('id_order'));
    $pdf_file_contents = $shipment->getLabelsPdf();
    if ($pdf_file_contents) {
        ob_end_clean();
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="shipment_labels_' . (int) Tools::getValue('id_order') . '.pdf"');
        echo $pdf_file_contents;
    } else {
        echo reset(DpdGroupShipment::$errors);
        exit;
    }
}