From dde4546c585293a66a852b150dd5aeb010442c66 Mon Sep 17 00:00:00 2001 From: Richard Perdaan Date: Wed, 1 Feb 2023 10:12:54 +0100 Subject: [PATCH] fix: international shipments --- install.xml | 67 ++- upload/.DS_Store | Bin 6148 -> 0 bytes upload/admin/.DS_Store | Bin 6148 -> 0 bytes .../en-gb/extension/module/myparcelnl.php | 8 +- .../nl-nl/extension/module/myparcelnl.php | 8 +- .../model/extension/myparcelnl/helper.php | 5 + .../admin/model/extension/myparcelnl/init.php | 12 + .../model/extension/myparcelnl/shipment.php | 392 +++++++++--------- .../template/extension/module/myparcelnl.twig | 120 +++--- upload/catalog/.DS_Store | Bin 6148 -> 0 bytes .../model/extension/myparcelnl/helper.php | 2 +- .../model/extension/myparcelnl/shipment.php | 342 +++++++-------- .../library/myparcelnl/assets/js/checkout.js | 21 + .../assets/js/delivery-iframe/myparcel.js | 15 +- .../includes/class_myparcel_helper.php | 17 +- .../includes/class_myparcel_shipment.php | 48 ++- .../class_myparcel_shipment_helper.php | 90 +++- .../includes/class_myparcel_view.php | 39 +- .../myparcelnl/myparcel.checkout.ocmod.xml | 170 +++++++- .../library/myparcelnl/myparcel.ocmod.xml | 67 ++- .../views/view_edit_product_fields.php | 14 + .../view_iframe_delivery_checkout_header.php | 9 + 22 files changed, 980 insertions(+), 466 deletions(-) delete mode 100644 upload/.DS_Store delete mode 100644 upload/admin/.DS_Store delete mode 100644 upload/catalog/.DS_Store create mode 100644 upload/system/library/myparcelnl/views/view_edit_product_fields.php diff --git a/install.xml b/install.xml index 3945c01..643a8c2 100644 --- a/install.xml +++ b/install.xml @@ -5,7 +5,7 @@ --> MyParcel NL - 1.1.3 + 1.1.8 MyParcelNL MyParcel NL https://www.myparcel.nl/ @@ -167,7 +167,9 @@ load->model('extension/myparcelnl/helper'); $this->document->addStyle($this->model_extension_myparcelnl_helper->getCssUrl() . 'order.css'); + $this->document->addStyle($this->model_extension_myparcelnl_helper->getCssUrl() . 'sweetalert.min.css'); $this->document->addScript($this->model_extension_myparcelnl_helper->getJsUrl() . 'order.js'); + $this->document->addScript($this->model_extension_myparcelnl_helper->getJsUrl() . 'sweetalert.min.js'); ]]> @@ -178,7 +180,9 @@ load->model('extension/myparcelnl/helper'); $this->document->addStyle($this->model_extension_myparcelnl_helper->getCssUrl() . 'order.css'); + $this->document->addStyle($this->model_extension_myparcelnl_helper->getCssUrl() . 'sweetalert.min.css'); $this->document->addScript($this->model_extension_myparcelnl_helper->getJsUrl() . 'order.js'); + $this->document->addScript($this->model_extension_myparcelnl_helper->getJsUrl() . 'sweetalert.min.js'); $data['use_addition_address'] = Myparcel($this->registry)->settings->general->use_addition_address_as_number_suffix; ]]> @@ -1231,10 +1235,10 @@ ]]> - + - session->data['shipping_method']);]]> - session->data['order_id'] = $this->model_checkout_order->addOrder($order_data);]]> + session->data['myparcel_shipping_choosed']) && isset($this->session->data['shipping_method']['code']) && ($this->session->data['shipping_method']['code'] == ($this->session->data['myparcel_shipping_choosed']['code'] . '.' . $this->session->data['myparcel_shipping_choosed']['code']))){ if (!class_exists('MyParcel')) { @@ -1261,6 +1265,14 @@ $model_shipment->saveDeliveryOptions($this->session->data['order_id'], $myparcel_shipping_choosed, $signed, $recipient_only, $current_prices); $model_shipment->update($this->session->data['order_id'],'type',$myparcel_shipping_code . '.' . $myparcel_shipping_code); } + + ]]> + + + + + session->data['shipping_method']);]]> + session->data['myparcel_shipping_choosed'])){ unset($this->session->data['myparcel_shipping_choosed']); } @@ -1862,5 +1874,52 @@ ]]> + + + {{ tab_data }}]]> + My parcel + ]]> + + + ]]> + + + + + + + + + + response->setOutput($this->load->view('catalog/product_form', $data));]]> + load->model('extension/myparcelnl/helper'); + $product_id = (isset($this->request->get['product_id'])) ? $this->request->get['product_id'] : 0; + $data['myparcel_product_fields'] = $this->model_extension_myparcelnl_helper->getContent('edit_product_myparcel_fields', array('product_id' => $product_id)); + ]]> + + + + + + + + db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = " . (int)$product_id);]]> + db->query("UPDATE " . DB_PREFIX . "product SET myparcel_hs_code = '" . $this->db->escape($data['myparcel_hs_code']) . "', myparcel_country = '" . $this->db->escape($data['myparcel_country']) . "' WHERE product_id = '" . (int)$product_id . "'"); + ]]> + + + + db->query("UPDATE " . DB_PREFIX . "product SET myparcel_hs_code = '" . $this->db->escape($data['myparcel_hs_code']) . "', myparcel_country = '" . $this->db->escape($data['myparcel_country']) . "' WHERE product_id = '" . (int)$product_id . "'"); + ]]> + + diff --git a/upload/.DS_Store b/upload/.DS_Store deleted file mode 100644 index ec2c0924fff57044dd17a73275bd547da992adb8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A`?440XBzLkMZycHq!o*pXYA$`|Yhpe-6mEt#}&;FhmI+Kr#!j`#s?d<0*? zb7G;TTg71#5|b@CFLCU|eVyu=h|J`%8WRnPXaHqQjxlTz-e=vAL@cL3y}vbcJsVF;+syqFC10yJsIhro)V6>XzZ17Q`*^=>dsM%8 z%ciZY-KC<8k)AVqp`vhzuLfHI&A>>C68eMq5;-e~B{(J(%miIP>_AKi1%^-~Ertoox4D1yHrk_vq2_8vm>&C-ztxciVP!{%c0e?a; i@ue8PT#83fFR-UP0cL_OAS@95Bj9P!K^gc{2EGCMwr;Qh diff --git a/upload/admin/.DS_Store b/upload/admin/.DS_Store deleted file mode 100644 index 5f9e5d59555da84ded64489cc312663ab27f1bf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5Iwu5S;}hMWG2DrLT}1IFYH4XmWv&j{=g7qlkb+WIaX9qhG$Nz znzt#80b}5|F~DoLOH-`d8@k1+-L2nj(H~8Vd?^J#T(tS+MVd~sVgfsF5|1bEZ-aK< z*|&X{SNr)lm=g16bcs3_v<5C{9@hB$(&SUA?@8;c&6O8HZLNM`U7uXn5#``*hFvcU zD=J?@Yo(SgS9|f5DjGb({2R_6(H&hQ`+bnzoqz1xD!I4cw~MW0uGxdUZp?X2{x$zMeECv16fzDq6fDzPQFy>zhj)@f$#ZnL!h?7vDggU)q zI0=V7R=-5C6qImsJ~QUg%ua78&S!@{_U_~oLFregistry)->getJsUrl(); } + + function addDeliveryDataIntoOrder($order_info) + { + return MyParcel($this->registry)->shipment->checkout->addDeliveryDataIntoOrder($order_info); + } } \ No newline at end of file diff --git a/upload/admin/model/extension/myparcelnl/init.php b/upload/admin/model/extension/myparcelnl/init.php index a18bdf1..ebc91ce 100644 --- a/upload/admin/model/extension/myparcelnl/init.php +++ b/upload/admin/model/extension/myparcelnl/init.php @@ -24,6 +24,18 @@ function installDatabase() if(count($query->row) == 0 ){ $this->db->query("ALTER TABLE `" .DB_PREFIX. "myparcel_shipment` ADD COLUMN `type` VARCHAR(50) NULL DEFAULT NULL;"); } + + //add custom field myparcel_hs_code + $query = $this->db->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '". DB_PREFIX ."product' AND table_schema = '". DB_DATABASE ."' AND column_name = 'myparcel_hs_code'"); + if(count($query->row) == 0 ){ + $this->db->query("ALTER TABLE `" .DB_PREFIX. "product` ADD COLUMN `myparcel_hs_code` VARCHAR(50) NULL DEFAULT NULL;"); + } + + //add custom field myparcel_country + $query = $this->db->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '". DB_PREFIX ."product' AND table_schema = '". DB_DATABASE ."' AND column_name = 'myparcel_country'"); + if(count($query->row) == 0 ){ + $this->db->query("ALTER TABLE `" .DB_PREFIX. "product` ADD COLUMN `myparcel_country` VARCHAR(50) NULL DEFAULT NULL;"); + } } function installMyParcelTotal() diff --git a/upload/admin/model/extension/myparcelnl/shipment.php b/upload/admin/model/extension/myparcelnl/shipment.php index 54f21f0..0daf74c 100644 --- a/upload/admin/model/extension/myparcelnl/shipment.php +++ b/upload/admin/model/extension/myparcelnl/shipment.php @@ -1,7 +1,7 @@ db->query("SELECT " . $column_name . " FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); + $order_query = $this->db->query("SELECT " . $column_name . " FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); return $this->getValueFromQuery($column_name, $order_query); } - /** - * Get myparcel export settings saved from backoffice - * @param int $order_id - * @return array options - **/ - public function getSavedExportSettings($order_id) - { - $order_query = $this->db->query("SELECT export_settings FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - $result = $this->getValueFromQuery('export_settings', $order_query); - if (!$result) { - return array(); - } - return $result; - } - - /** - * Get myparcel delivery options saved from frontend checkout - * @param int $order_id - * @return array options - **/ - public function getMyParcelDeliveryOptions($order_id) - { - $order_query = $this->db->query("SELECT delivery_options FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - $result = $this->getValueFromQuery('delivery_options', $order_query); - - if (!$result) { - return array(); - } - return $result; - } - - /** - * Get myparcel delivery options saved from frontend checkout - * @param int $order_id - * @return array options - **/ - public function getMyParcelDeliveryOptionsSignedRecipientOnly($order_id) - { - $order_query = $this->db->query("SELECT delivery_options, signed, recipient_only FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - $result['data'] = $this->getValueFromQuery('delivery_options', $order_query); - $result['signed'] = $this->getValueFromQuery('signed', $order_query); - $result['recipient_only'] = $this->getValueFromQuery('recipient_only', $order_query); - - if (!$result) { - return array(); - } - return $result; - } - - /** - * Get myparcel shipments data saved from backoffice - * @param int $order_id - * @return array options - **/ - public function getSavedMyParcelShipments($order_id) - { - $order_query = $this->db->query("SELECT shipment_data FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - $result = $this->getValueFromQuery('shipment_data', $order_query); - - if (!$result) { - return array(); - } - return $result; - } - - /** - * Get myparcel_signed option from frontend checkout - * @param int $order_id - * @return array options - **/ - public function getMyParcelSigned($order_id) - { - $order_query = $this->db->query("SELECT signed FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - return $this->getValueFromQuery('signed', $order_query); - } - - /** - * Get myparcel_only_recipient option from frontend checkout - * @param int $order_id - * @return array options - **/ - public function getMyParcelOnlyRecipient($order_id) - { - $order_query = $this->db->query("SELECT recipient_only FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - return $this->getValueFromQuery('recipient_only', $order_query); - } - - /** - * Get myparcel_only_recipient option from frontend checkout - * @param int $order_id - * @return array options - **/ - public function getMyParcelOrderPrices($order_id) - { - $order_query = $this->db->query("SELECT prices FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - return $this->getValueFromQuery('prices', $order_query); - } - - /** - * Get extra settings saved from admin order overview - * @param int $order_id - * @return array options Array('number_of_copies' => 1) - **/ - public function getSavedExtraExportSettings($order_id) - { - $order_query = $this->db->query("SELECT extra_options FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . $order_id . " LIMIT 1"); - return $this->getValueFromQuery('extra_options', $order_query); - } - - /** - * Save export settings in database - * @param array $settings - **/ - public function saveExportSetting($settings) - { - - } - - /** - * Save shipment data - * @param int $order_id - * @param array $shipment - * @return boolean the update is successful or not - **/ - public function saveShipmentData ( $order_id, $shipment ) - { - if ( empty($shipment) || !isset($shipment['shipment_id']) ) { - return false; - } - - $shipment_id = $shipment['shipment_id']; - $shipments = array(); - $shipments[$shipment_id] = $shipment; + /** + * Get myparcel export settings saved from backoffice + * @param int $order_id + * @return array options + **/ + public function getSavedExportSettings($order_id) + { + $order_query = $this->db->query("SELECT export_settings FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + $result = $this->getValueFromQuery('export_settings', $order_query); + if (!$result) { + return array(); + } + return $result; + } + + /** + * Get myparcel delivery options saved from frontend checkout + * @param int $order_id + * @return array options + **/ + public function getMyParcelDeliveryOptions($order_id) + { + $order_query = $this->db->query("SELECT delivery_options FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + $result = $this->getValueFromQuery('delivery_options', $order_query); + + if (!$result) { + return array(); + } + return $result; + } + + /** + * Get myparcel delivery options saved from frontend checkout + * @param int $order_id + * @return array options + **/ + public function getMyParcelDeliveryOptionsSignedRecipientOnly($order_id) + { + $order_query = $this->db->query("SELECT delivery_options, signed, recipient_only FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + $result['data'] = $this->getValueFromQuery('delivery_options', $order_query); + $result['signed'] = $this->getValueFromQuery('signed', $order_query); + $result['recipient_only'] = $this->getValueFromQuery('recipient_only', $order_query); + + if (!$result) { + return array(); + } + return $result; + } + + /** + * Get myparcel shipments data saved from backoffice + * @param int $order_id + * @return array options + **/ + public function getSavedMyParcelShipments($order_id) + { + $order_query = $this->db->query("SELECT shipment_data FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + $result = $this->getValueFromQuery('shipment_data', $order_query); + + if (!$result) { + return array(); + } + return $result; + } + + /** + * Get myparcel_signed option from frontend checkout + * @param int $order_id + * @return array options + **/ + public function getMyParcelSigned($order_id) + { + $order_query = $this->db->query("SELECT signed FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + return $this->getValueFromQuery('signed', $order_query); + } + + /** + * Get myparcel_only_recipient option from frontend checkout + * @param int $order_id + * @return array options + **/ + public function getMyParcelOnlyRecipient($order_id) + { + $order_query = $this->db->query("SELECT recipient_only FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + return $this->getValueFromQuery('recipient_only', $order_query); + } + + /** + * Get myparcel_only_recipient option from frontend checkout + * @param int $order_id + * @return array options + **/ + public function getMyParcelOrderPrices($order_id) + { + $order_query = $this->db->query("SELECT prices FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + return $this->getValueFromQuery('prices', $order_query); + } + + /** + * Get extra settings saved from admin order overview + * @param int $order_id + * @return array options Array('number_of_copies' => 1) + **/ + public function getSavedExtraExportSettings($order_id) + { + $order_query = $this->db->query("SELECT extra_options FROM `" . DB_PREFIX . self::$table_name . "` WHERE order_id = " . (int)$order_id . " LIMIT 1"); + return $this->getValueFromQuery('extra_options', $order_query); + } + + /** + * Save export settings in database + * @param array $settings + **/ + public function saveExportSetting($settings) + { + + } + + /** + * Save shipment data + * @param int $order_id + * @param array $shipment + * @return boolean the update is successful or not + **/ + public function saveShipmentData ( $order_id, $shipment ) + { + if ( empty($shipment) || !isset($shipment['shipment_id']) ) { + return false; + } + + $shipment_id = $shipment['shipment_id']; + $shipments = array(); + $shipments[$shipment_id] = $shipment; $keep_old_shipments =intval(MyParcel()->settings->general->keep_old_shipments); - if ( !empty($keep_old_shipments) ) { - - if ( $old_shipments = $this->getSavedMyParcelShipments($order_id) ) { - - if (isset($old_shipments[$shipment_id])) { - unset($old_shipments[$shipment_id]); - } - - $shipments = $old_shipments + $shipments; - } - } - - $this->update( $order_id, 'shipment_data', $shipments ); - return true; - } - - /** - * Update data in one of the columns of the table - * @param string $column_name - * @param mixed $value - **/ - public function update($order_id, $column_name, $value) - { - if ( is_array( $value ) || is_object( $value ) ) - $data = $this->db->escape(json_encode($value, true)); - else - $data = $value; - - $query = $this->db->query("SELECT * FROM " . DB_PREFIX . self::$table_name . " WHERE order_id = " . (int)$order_id); - - if ($query->num_rows) { - $this->db->query("UPDATE " . DB_PREFIX . self::$table_name . " SET " . $column_name . "='" . $data . "' WHERE order_id =" . $order_id); - } else { - $this->db->query("INSERT INTO " . DB_PREFIX . self::$table_name . " SET order_id = " . intval($order_id) . ", " . $column_name . "='" . $data . "'"); - } - } - - /** - * Get column value from rows - * @param string $column_name - * @param array $order_query - * @return string column value - **/ - protected function getValueFromQuery($column_name, $order_query) - { - if ($order_query->num_rows) { - $order_row = current($order_query->rows); - $value = isset($order_row[$column_name]) ? $order_row[$column_name] : null; - if ($value) { - $decoded_value = json_decode($value, true); - if (!empty($decoded_value)) { - return $decoded_value; - } else { - return $value; - } - } else if ($value == '0') { - return 0; - } - } - return null; - } + if ( !empty($keep_old_shipments) ) { + + if ( $old_shipments = $this->getSavedMyParcelShipments($order_id) ) { + + if (isset($old_shipments[$shipment_id])) { + unset($old_shipments[$shipment_id]); + } + + $shipments = $old_shipments + $shipments; + } + } + + $this->update( $order_id, 'shipment_data', $shipments ); + return true; + } + + /** + * Update data in one of the columns of the table + * @param string $column_name + * @param mixed $value + **/ + public function update($order_id, $column_name, $value) + { + if ( is_array( $value ) || is_object( $value ) ) + $data = $this->db->escape(json_encode($value, true)); + else + $data = $value; + + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . self::$table_name . " WHERE order_id = " . (int)$order_id); + + if ($query->num_rows) { + $this->db->query("UPDATE " . DB_PREFIX . self::$table_name . " SET " . $column_name . "='" . $data . "' WHERE order_id =" . (int)$order_id); + } else { + $this->db->query("INSERT INTO " . DB_PREFIX . self::$table_name . " SET order_id = " . (int)$order_id . ", " . $column_name . "='" . $data . "'"); + } + } + + /** + * Get column value from rows + * @param string $column_name + * @param array $order_query + * @return string column value + **/ + protected function getValueFromQuery($column_name, $order_query) + { + if ($order_query->num_rows) { + $order_row = current($order_query->rows); + $value = isset($order_row[$column_name]) ? $order_row[$column_name] : null; + if ($value) { + $decoded_value = json_decode($value, true); + if (!empty($decoded_value)) { + return $decoded_value; + } else { + return $value; + } + } else if ($value == '0') { + return 0; + } + } + return null; + } } diff --git a/upload/admin/view/template/extension/module/myparcelnl.twig b/upload/admin/view/template/extension/module/myparcelnl.twig index 4d330ea..9a08056 100644 --- a/upload/admin/view/template/extension/module/myparcelnl.twig +++ b/upload/admin/view/template/extension/module/myparcelnl.twig @@ -76,6 +76,17 @@ +
+ +
+ +
+
@@ -84,7 +95,7 @@