Esempio n. 1
0
 public function hookAdminOrder($params)
 {
     $shipment = new DpdGroupShipment((int) $params['id_order']);
     if (Tools::isSubmit('printLabels')) {
         $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 {
             $this->addFlashError(reset(DpdGroupShipment::$errors));
             Tools::redirectAdmin(self::getAdminOrderLink() . '&id_order=' . (int) $params['id_order']);
         }
     }
     $this->displayFlashMessagesIfIsset();
     $order = new Order((int) $params['id_order']);
     $customer = new Customer($order->id_customer);
     $products = $shipment->getParcelsSetUp($order->getProductsDetail());
     if ($shipment->parcels) {
         DpdGroupParcel::addParcelDataToProducts($products, $order->id);
     }
     $id_method = self::getMethodIdByCarrierId($order->id_carrier);
     DpdGroupWS::$parcel_weight_warning_message = false;
     $price = $shipment->calculatePriceForOrder((int) $id_method, $order->id_address_delivery, $products);
     $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);
     $ws_shipping_price = $price !== false ? $price : '---';
     $total_shipping = version_compare(_PS_VERSION_, '1.5', '>=') ? $order->total_shipping_tax_incl : $order->total_shipping;
     $this->context->smarty->assign(array('order' => $order, 'module_link' => $this->getModuleLink('AdminModules'), 'settings' => new DpdGroupConfiguration(), 'total_weight' => DpdGroupShipment::convertWeight($order->getTotalWeight()), 'shipment' => $shipment, 'selected_shipping_method_id' => $id_method, 'ws_shippingPrice' => $price !== false ? $price : '---', 'products' => $products, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'carrier_url' => $carrier->url, 'order_link' => self::getAdminOrderLink() . '&id_order=' . (int) Tools::getValue('id_order'), 'errors' => $this->getErrorMessagesForOrderPage(), 'warnings' => $this->getWarningMessagesForOrderPage($shipment->id_shipment, $id_method, $ws_shipping_price, $total_shipping), 'force_enable_button' => DpdGroupWS::$parcel_weight_warning_message, 'display_product_weight_warning' => $this->orderProductsWithoutWeight($products)));
     if (!$this->ps_14) {
         $this->context->controller->addJS(_DPDGROUP_JS_URI_ . 'jquery.bpopup.min.js');
         $this->context->controller->addJS(_DPDGROUP_JS_URI_ . 'adminOrder.js');
         $css_filename = $this->bootstrap ? 'adminOrder_16' : 'adminOrder';
         $this->context->controller->addCSS(_DPDGROUP_CSS_URI_ . $css_filename . '.css');
     }
     $this->setGlobalVariablesForAjax();
     $template_filename = $this->bootstrap ? 'adminOrder_16' : 'adminOrder';
     return $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'hook/' . $template_filename . '.tpl');
 }
Esempio n. 2
0
 private function saveParcelsLocally($data, $id_order)
 {
     DpdGroupParcel::clearOrderParcels($id_order);
     foreach ($data as $parcel) {
         $products = explode(',', $parcel['products']);
         foreach ($products as $product) {
             list($id_product, $id_product_attribute) = explode('_', trim($product));
             $dpd_parcel = new DpdGroupParcel();
             $dpd_parcel->id_order = (int) $id_order;
             $dpd_parcel->parcel_reference_number = $parcel['parcelReferenceNumber'];
             $dpd_parcel->id_product = (int) $id_product;
             $dpd_parcel->id_product_attribute = (int) $id_product_attribute;
             if (!$dpd_parcel->save()) {
                 return false;
             }
         }
     }
     return true;
 }