Housekeeping: offene Dev-Dateien eingecheckt + Sidebar „Bestellungen"→„Versand"
- Sidebar-Menü „Bestellungen" in „Versand" umbenannt (layout-sidenav), sonst nur Blade-Formatierung. - Entwicklungspläne in ISO-Datumsformat umbenannt (entwicklungsplan-aktualisiert-*). - dev/dhl-for-woocommerce/ (DHL-Plugin) + dev/partnercenter-api.zip + PastedGraphic hinzugefügt. - .claude/ bewusst NICHT eingecheckt (lokale Claude-Code-Konfiguration). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7
dev/dhl-for-woocommerce/assets/css/jquery-ui-tooltip.css
Normal file
359
dev/dhl-for-woocommerce/assets/css/jquery.fancybox-1.3.4.css
Normal file
|
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
* FancyBox - jQuery Plugin
|
||||
* Simple and fancy lightbox alternative
|
||||
*
|
||||
* Examples and documentation at: http://fancybox.net
|
||||
*
|
||||
* Copyright (c) 2008 - 2010 Janis Skarnelis
|
||||
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
|
||||
*
|
||||
* Version: 1.3.4 (11/11/2010)
|
||||
* Requires: jQuery v1.3+
|
||||
*
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
#fancybox-loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin-top: -20px;
|
||||
margin-left: -20px;
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
z-index: 1104;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-loading div {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 40px;
|
||||
height: 480px;
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
}
|
||||
|
||||
#fancybox-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 1100;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-tmp {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
overflow: auto;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-wrap {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 20px;
|
||||
z-index: 1101;
|
||||
outline: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-outer {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
#fancybox-content {
|
||||
width: 0;
|
||||
height: 0;
|
||||
padding: 0;
|
||||
outline: none;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
z-index: 1102;
|
||||
border: 0px solid #fff;
|
||||
}
|
||||
|
||||
#fancybox-hide-sel-frame {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: transparent;
|
||||
z-index: 1101;
|
||||
}
|
||||
|
||||
#fancybox-close {
|
||||
position: absolute;
|
||||
top: -15px;
|
||||
right: -15px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: transparent url('../img/fancybox/fancybox.png') -40px 0px;
|
||||
cursor: pointer;
|
||||
z-index: 1103;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-error {
|
||||
color: #444;
|
||||
font: normal 12px/20px Arial;
|
||||
padding: 14px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#fancybox-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
outline: none;
|
||||
line-height: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#fancybox-frame {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#fancybox-left, #fancybox-right {
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
height: 100%;
|
||||
width: 35%;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
background: transparent url('../img/fancybox/blank.gif');
|
||||
z-index: 1102;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fancybox-left {
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
#fancybox-right {
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
#fancybox-left-ico, #fancybox-right-ico {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: -9999px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin-top: -15px;
|
||||
cursor: pointer;
|
||||
z-index: 1102;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#fancybox-left-ico {
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -30px;
|
||||
}
|
||||
|
||||
#fancybox-right-ico {
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -60px;
|
||||
}
|
||||
|
||||
#fancybox-left:hover, #fancybox-right:hover {
|
||||
visibility: visible; /* IE6 */
|
||||
}
|
||||
|
||||
#fancybox-left:hover span {
|
||||
left: 20px;
|
||||
}
|
||||
|
||||
#fancybox-right:hover span {
|
||||
left: auto;
|
||||
right: 20px;
|
||||
}
|
||||
|
||||
.fancybox-bg {
|
||||
position: absolute;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
z-index: 1001;
|
||||
}
|
||||
|
||||
#fancybox-bg-n {
|
||||
top: -20px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background-image: url('../img/fancybox/fancybox-x.png');
|
||||
}
|
||||
|
||||
#fancybox-bg-ne {
|
||||
top: -20px;
|
||||
right: -20px;
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -162px;
|
||||
}
|
||||
|
||||
#fancybox-bg-e {
|
||||
top: 0;
|
||||
right: -20px;
|
||||
height: 100%;
|
||||
background-image: url('../img/fancybox/fancybox-y.png');
|
||||
background-position: -20px 0px;
|
||||
}
|
||||
|
||||
#fancybox-bg-se {
|
||||
bottom: -20px;
|
||||
right: -20px;
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -182px;
|
||||
}
|
||||
|
||||
#fancybox-bg-s {
|
||||
bottom: -20px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background-image: url('../img/fancybox/fancybox-x.png');
|
||||
background-position: 0px -20px;
|
||||
}
|
||||
|
||||
#fancybox-bg-sw {
|
||||
bottom: -20px;
|
||||
left: -20px;
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -142px;
|
||||
}
|
||||
|
||||
#fancybox-bg-w {
|
||||
top: 0;
|
||||
left: -20px;
|
||||
height: 100%;
|
||||
background-image: url('../img/fancybox/fancybox-y.png');
|
||||
}
|
||||
|
||||
#fancybox-bg-nw {
|
||||
top: -20px;
|
||||
left: -20px;
|
||||
background-image: url('../img/fancybox/fancybox.png');
|
||||
background-position: -40px -122px;
|
||||
}
|
||||
|
||||
#fancybox-title {
|
||||
font-family: Helvetica;
|
||||
font-size: 12px;
|
||||
z-index: 1102;
|
||||
}
|
||||
|
||||
.fancybox-title-inside {
|
||||
padding-bottom: 10px;
|
||||
text-align: center;
|
||||
color: #333;
|
||||
background: #fff;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fancybox-title-outside {
|
||||
padding-top: 10px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.fancybox-title-over {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
color: #FFF;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#fancybox-title-over {
|
||||
padding: 10px;
|
||||
background-image: url('../img/fancybox/fancy_title_over.png');
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fancybox-title-float {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: -20px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
#fancybox-title-float-wrap {
|
||||
border: none;
|
||||
border-collapse: collapse;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#fancybox-title-float-wrap td {
|
||||
border: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#fancybox-title-float-left {
|
||||
padding: 0 0 0 15px;
|
||||
background: url('../img/fancybox/fancybox.png') -40px -90px no-repeat;
|
||||
}
|
||||
|
||||
#fancybox-title-float-main {
|
||||
color: #FFF;
|
||||
line-height: 29px;
|
||||
font-weight: bold;
|
||||
padding: 0 0 3px 0;
|
||||
background: url('../img/fancybox/fancybox-x.png') 0px -40px;
|
||||
}
|
||||
|
||||
#fancybox-title-float-right {
|
||||
padding: 0 0 0 15px;
|
||||
background: url('../img/fancybox/fancybox.png') -55px -90px no-repeat;
|
||||
}
|
||||
|
||||
/* IE6 */
|
||||
|
||||
.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); }
|
||||
|
||||
.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); }
|
||||
.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); }
|
||||
|
||||
.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
|
||||
.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); }
|
||||
.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); }
|
||||
.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); }
|
||||
|
||||
.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame {
|
||||
height: expression(this.parentNode.clientHeight + "px");
|
||||
}
|
||||
|
||||
#fancybox-loading.fancybox-ie6 {
|
||||
position: absolute; margin-top: 0;
|
||||
top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px');
|
||||
}
|
||||
|
||||
#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); }
|
||||
|
||||
/* IE6, IE7, IE8 */
|
||||
|
||||
.fancybox-ie .fancybox-bg { background: transparent !important; }
|
||||
|
||||
.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); }
|
||||
.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); }
|
||||
1
dev/dhl-for-woocommerce/assets/css/jquery.fancybox.min.css
vendored
Normal file
486
dev/dhl-for-woocommerce/assets/css/pr-dhl-admin.css
Normal file
|
|
@ -0,0 +1,486 @@
|
|||
.wc_dhl_error,
|
||||
.wc_dhl_delete #dhl_delete_label,
|
||||
.wc_dhl_delete #pr_dhl_dp_delete_label {
|
||||
color: #a00;
|
||||
}
|
||||
|
||||
span.wc_dhl_delete,
|
||||
span.wc_dhl_error {
|
||||
float:right;
|
||||
}
|
||||
|
||||
ul.wc_dhl_error{
|
||||
list-style-type: disc;
|
||||
padding-left:20px;
|
||||
}
|
||||
|
||||
.dhl_connection_succeeded {
|
||||
color: #008000;
|
||||
margin-left: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.dhl_connection_error {
|
||||
color: #a00;
|
||||
margin-left: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#dhl_label_created {
|
||||
width: 10ch;
|
||||
min-width: 55px;
|
||||
/*text-align:center*/
|
||||
}
|
||||
|
||||
#dhl-optin-notice {
|
||||
padding: 8px 15px;
|
||||
}
|
||||
|
||||
#pr_dhl_create_order {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#pr_dhl_order_items_table a.pr_dhl_order_remove_item {
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 transparent;
|
||||
}
|
||||
#pr_dhl_order_items_table a.pr_dhl_order_remove_item[disabled] {
|
||||
color: #777;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#pr_dhl_order_gen_label_message,
|
||||
#pr_dhl_reset_order,
|
||||
#pr_dhl_dp_error {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#pr_dhl_dp_error {
|
||||
color: red;
|
||||
}
|
||||
|
||||
#woocommerce-shipment-dhl-label,
|
||||
#woocommerce-dhl-dp-order,
|
||||
#woocommerce-shipment-internetmarke-label {
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(50%,#fc0),to(rgba(255,204,0,0)));
|
||||
background-image: linear-gradient(#fc0 50%,rgba(255,204,0,0));
|
||||
background-size: auto 36px;
|
||||
background-repeat:repeat-x;
|
||||
}
|
||||
|
||||
|
||||
#woocommerce-shipment-dhl-label h2.hndle.ui-sortable-handle {
|
||||
background: url(../img/dhl-official.png);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: left 14px top;
|
||||
font-size: 0;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
#woocommerce-shipment-internetmarke-label h2.hndle.ui-sortable-handle {
|
||||
background: url(../img/dp-logo.svg);
|
||||
background-size: auto 48px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: left 14px center;
|
||||
padding-left: 70px;
|
||||
}
|
||||
|
||||
div#shipment-dhl-label-form > div:nth-of-type(even),
|
||||
div#shipment-im-label-form > div:nth-of-type(even) {
|
||||
background: #F9F9F9;
|
||||
}
|
||||
#woocommerce-shipment-dhl-label .inside,
|
||||
#woocommerce-shipment-internetmarke-label .inside {
|
||||
padding: 0;
|
||||
border-bottom: 5px solid #FFCC00;
|
||||
}
|
||||
#shipment-dhl-label-form > div,
|
||||
#shipment-im-label-form > div {
|
||||
padding: 10px 15px;
|
||||
}
|
||||
#shipment-dhl-label-form > hr,
|
||||
.shipment-dhl-row-additional-services > hr {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#shipment-dhl-label-form #dhl-label-button,
|
||||
#shipment-dhl-label-form #dhl-label-print,
|
||||
#shipment-dhl-label-form .dhl-return-label-link,
|
||||
#shipment-dhl-label-form .wc_dhl_delete,
|
||||
#shipment-im-label-form #im-label-button,
|
||||
#shipment-im-label-form #im-label-print,
|
||||
#shipment-im-label-form .wc_dhl_delete {
|
||||
margin: 0 15px 20px;
|
||||
}
|
||||
|
||||
#shipment-dhl-label-form .dhl-return-label-link {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
|
||||
.pr_dhl_weight_field,
|
||||
.pr_dhl_cdp_delivery_display_field,
|
||||
.pr_dhl_multi_packages_enabled_field,
|
||||
.pr_dhl_named_person_field,
|
||||
.pr_dhl_no_neighbor_field,
|
||||
.pr_dhl_additional_insurance_field,
|
||||
.pr_dhl_premium_field,
|
||||
.pr_dhl_bulky_goods_field,
|
||||
.pr_dhl_identcheck_field,
|
||||
.pr_dhl_is_codeable_field,
|
||||
.pr_dhl_routing_field,
|
||||
.pr_dhl_PDDP_field,
|
||||
.pr_dhl_go_green_plus_field,
|
||||
.pr_dhl_signature_service_field{
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.pr_dhl_weight_field input#pr_dhl_weight {
|
||||
order: 1;
|
||||
width: 50px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.pr_dhl_weight_field label,
|
||||
.pr_dhl_cdp_delivery_display_field label,
|
||||
.pr_dhl_multi_packages_enabled_field label,
|
||||
.pr_dhl_named_person_field label,
|
||||
.pr_dhl_no_neighbor_field label,
|
||||
.pr_dhl_additional_insurance_field label,
|
||||
.pr_dhl_premium_field label,
|
||||
.pr_dhl_bulky_goods_field label,
|
||||
.pr_dhl_identcheck_field label,
|
||||
.pr_dhl_is_codeable_field label,
|
||||
.pr_dhl_routing_field label,
|
||||
.pr_dhl_PDDP_field label,
|
||||
.pr_dhl_go_green_plus_field label,
|
||||
.pr_dhl_signature_service_field label{
|
||||
order: 2;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
|
||||
.pr_dhl_multi_packages_enabled_field input,
|
||||
.pr_dhl_PDDP_field input{
|
||||
margin: 10px 10px 15px 0;
|
||||
}
|
||||
|
||||
.pr_dhl_preferred_day_field label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pr_dhl_preferred_day_field select,
|
||||
.pr_dhl_age_visual_field select,
|
||||
.pr_dhl_identcheck_age_field select,
|
||||
.pr_dhl_identcheck_dob_field input[type=text] {
|
||||
display: block;
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.shipment-dhl-row-container select,
|
||||
.shipment-dhl-row-container input {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
|
||||
.dhl-total-packages #pr_dhl_total_packages {
|
||||
width: 100px !important;
|
||||
margin-top: -7px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
p.dhl-total-packages > label {
|
||||
padding-bottom: 10px !important;
|
||||
}
|
||||
|
||||
.package_header_field,
|
||||
.package_item_field {
|
||||
display: inline-block;
|
||||
width: 45px !important;
|
||||
}
|
||||
|
||||
.package_header_field.first,
|
||||
.package_item_field.first {
|
||||
width: 55px !important;
|
||||
}
|
||||
|
||||
.package_item input {
|
||||
width: 40px !important;
|
||||
|
||||
}
|
||||
|
||||
.dhl-awb-filter-container{
|
||||
clear:both;
|
||||
margin-top:9px;
|
||||
margin-bottom:9px;
|
||||
}
|
||||
|
||||
#dhl-paket-action-request-pickup {
|
||||
padding: 0 10px;
|
||||
}
|
||||
#dhl-paket-action-request-pickup h3 {
|
||||
margin: 10px 0;
|
||||
padding: 0 0;
|
||||
}
|
||||
|
||||
#dhl-paket-action-request-pickup p.form-field {
|
||||
margin: 5px 0;
|
||||
}
|
||||
#dhl-paket-action-request-pickup p.pr_dhl_request_pickup_date_modal_field {
|
||||
margin: 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 782px) {
|
||||
#dhl-paket-action-request-pickup {
|
||||
padding: 0;
|
||||
}
|
||||
#dhl-paket-action-request-pickup p.form-field {
|
||||
padding: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container {
|
||||
font-size:14px;
|
||||
font-weight:500;
|
||||
}
|
||||
|
||||
.shipment-dhl-crossborder-domestic .shipment-dhl-icon-container {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon {
|
||||
display: inline-block;
|
||||
width: 21px;
|
||||
height: 16px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: bottom left;
|
||||
margin: 2px 2px -2px 0;
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-service {
|
||||
background-image: url(../img/order-icons/service.png);
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-weight {
|
||||
background-image: url(../img/order-icons/weight.png);
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-packages {
|
||||
background-image: url(../img/order-icons/multiple.png);
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-return-addr {
|
||||
background-image: url(../img/order-icons/return.png);
|
||||
}
|
||||
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-delivery-options {
|
||||
background-image: url(../img/order-icons/delivery.png);
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-additional-services {
|
||||
background-image: url(../img/order-icons/additional.png);
|
||||
}
|
||||
|
||||
.shipment-dhl-icon-container .shipment-dhl-icon-crossborder-domestic {
|
||||
background-image: url(../img/order-icons/plane.png);
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings {
|
||||
display:flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu {
|
||||
width:250px;
|
||||
background-color:transparent;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu .dhlpaket_tab_menu_item {
|
||||
display:block;
|
||||
width:250px;
|
||||
color:#777B7D;
|
||||
box-sizing:border-box;
|
||||
padding:15px 10px 15px 40px;
|
||||
text-decoration: none !important;
|
||||
font-size:14px;
|
||||
font-weight:500;
|
||||
letter-spacing: 0px;
|
||||
border-bottom:2px solid #f0f0f1;
|
||||
background: #FFF;
|
||||
position:relative;
|
||||
outline:none !important;
|
||||
box-shadow:none !important;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu .dhlpaket_tab_menu_item:before {
|
||||
content:"";
|
||||
display:block;
|
||||
position:absolute;
|
||||
top:15px;
|
||||
left:13px;
|
||||
font-family:dashicons;
|
||||
font-size:18px;
|
||||
margin-right:7px;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu .dhlpaket_tab_menu_item.dhlpaket-active {
|
||||
color:#d30512;
|
||||
border-bottom:2px solid #ffcc01;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_0:before {
|
||||
content:"\f110";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_1:before {
|
||||
content:"\f15f";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_2:before {
|
||||
content:"\f481";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_3:before {
|
||||
content:"\f323";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_4:before {
|
||||
content:"\f154";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_5:before {
|
||||
content:"\f230";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_6:before {
|
||||
content:"\f231";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_7:before {
|
||||
content:"\f531";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_8:before {
|
||||
content:"\f16a";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_9:before {
|
||||
content:"\f469";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_menu #dhlpaket_tab_menu_item_10:before {
|
||||
content:"\f15c";
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content {
|
||||
width:auto;
|
||||
padding:0px 40px;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content > * {
|
||||
display:none;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content .wc-shipping-zone-method-fields {
|
||||
display:block;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content .wc-shipping-zone-method-fields > * {
|
||||
display:none;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content .dhlpaket-active {
|
||||
display:block;
|
||||
}
|
||||
|
||||
#dhlpaket_shipping_method_settings .dhlpaket_tab_content table.dhlpaket-active {
|
||||
display:table;
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_pickup_api_dist,
|
||||
h3#woocommerce_pr_dhl_paket_internetmarke_api_title,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_participation_title,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_general,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_preferred,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_parcel_finder,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_shipper,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_return,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_bank,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_business_hours {
|
||||
font-size: 22px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_pickup_api_dist:before,
|
||||
h3#woocommerce_pr_dhl_paket_internetmarke_api_title:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_participation_title:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_general:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_preferred:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_parcel_finder:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_shipper:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_return:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_bank:before,
|
||||
h3#woocommerce_pr_dhl_paket_dhl_business_hours:before {
|
||||
font-family:dashicons;
|
||||
font-size:18px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_pickup_api_dist:before {
|
||||
content:"\f110";
|
||||
}
|
||||
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_internetmarke_api_title:before {
|
||||
content:"\f15f";
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_participation_title:before {
|
||||
content:"\f481";
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_general:before {
|
||||
content:"\f323";
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_preferred:before {
|
||||
content:"\f154";
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_parcel_finder:before {
|
||||
content:"\f230";
|
||||
}
|
||||
|
||||
h3#woocommerce_pr_dhl_paket_dhl_shipper:before {
|
||||
content:"\f231";
|
||||
}
|
||||
h3#woocommerce_pr_dhl_paket_dhl_return:before {
|
||||
content:"\f531";
|
||||
}
|
||||
h3#woocommerce_pr_dhl_paket_dhl_bank:before {
|
||||
content:"\f16a";
|
||||
}
|
||||
h3#woocommerce_pr_dhl_paket_dhl_business_hours:before {
|
||||
content:"\f469";
|
||||
}
|
||||
|
||||
body.woocommerce_page_wc-settings.pr_dhl_paket p.submit button.woocommerce-save-button {
|
||||
margin-left:290px;
|
||||
}
|
||||
|
||||
body.woocommerce_page_wc-settings.pr_dhl_paket #dhlpaket_shipping_method_settings .dhlpaket_tab_content .wc-shipping-zone-method-fields p.submit {
|
||||
display:block;
|
||||
}
|
||||
|
||||
body.woocommerce_page_wc-settings.pr_dhl_paket .wc-shipping-zone-method-fields p.submit button.woocommerce-save-button {
|
||||
margin-left:0px;
|
||||
}
|
||||
|
||||
381
dev/dhl-for-woocommerce/assets/css/pr-dhl-frontend.css
Normal file
|
|
@ -0,0 +1,381 @@
|
|||
.dhl-co-tr {
|
||||
border: 0;
|
||||
border-left: 1px solid #FFCC00;
|
||||
border-right: 1px solid #FFCC00;
|
||||
}
|
||||
|
||||
.dhl-co-tr.dhl-co-tr-first,
|
||||
.dhl-co-tr.dhl-co-tr-last {
|
||||
border-top: 1px solid #FFCC00;
|
||||
border-bottom: 1px solid #FFCC00;
|
||||
}
|
||||
|
||||
.dhl-co-tr.dhl-co-tr-last {
|
||||
border-top: 0;
|
||||
height: 5px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dhl-co-tr.dhl-co-tr-first td,
|
||||
.dhl-co-tr.dhl-co-tr-last td {
|
||||
padding: 0;
|
||||
max-height: 0;
|
||||
border-color: #FFCC00;
|
||||
}
|
||||
|
||||
tr.dhl-co-tr.dhl-co-tr-fist > td:last-child {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
img.dhl-co-logo {
|
||||
padding: 0;
|
||||
max-height: 100px;
|
||||
max-width: 35%;
|
||||
margin: 5px 10px;
|
||||
background: #FFCC00;
|
||||
}
|
||||
|
||||
body table, .woocommerce table.shop_table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.dhl-co-tr th,
|
||||
.dhl-co-tr th:first-child,
|
||||
.dhl-co-tr td,
|
||||
.woocommerce-page.woocommerce-checkout table.shop_table .dhl-co-tr th,
|
||||
.woocommerce-page.woocommerce-checkout form #order_review .dhl-co-tr th,
|
||||
.woocommerce-page.woocommerce-checkout form #order_review .dhl-co-tr td,
|
||||
.woocommerce-page.woocommerce-checkout table.shop_table .dhl-co-tr td{
|
||||
padding: 5px 15px;
|
||||
border-bottom: 0;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.woocommerce table.shop_table tfoot th {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.dhl-co-tr,
|
||||
.dhl-co-tr th,
|
||||
.dhl-co-tr td,
|
||||
.dhl-co-tr:hover td,
|
||||
.hentry table .dhl-co-tr:hover td,
|
||||
.woocommerce-checkout-review-order-table tfoot .dhl-co-tr th {
|
||||
background: none;
|
||||
}
|
||||
|
||||
.dhl-co-tr td:first-child,
|
||||
.woocommerce-page.woocommerce-checkout table.shop_table .dhl-co-tr td:first-child,
|
||||
.woocommerce-page.woocommerce-checkout form #order_review .dhl-co-tr td:first-child {
|
||||
padding-left: 15px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.dhl-co-tr td:last-child,
|
||||
.woocommerce-page.woocommerce-checkout table.shop_table .dhl-co-tr td:last-child {
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.dhl-co-tr hr {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.dhl-pt {
|
||||
padding-top: 20px !important;
|
||||
}
|
||||
|
||||
.woocommerce #order_review table.shop_table tfoot tr.dhl-co-tr td {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
tr.dhl-co-tr.dhl-co-tr-fist > td,
|
||||
.woocommerce #order_review table.shop_table tr.dhl-co-tr.dhl-co-tr-fist > td {
|
||||
width: 100% !important;
|
||||
border-top: 1px solid #FFCC00;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-times {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-preffered-time {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-times > li,
|
||||
ul.dhl-co-preffered-time > li {
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.woocommerce #order_review table.shop_table ul.dhl-co-times > li label,
|
||||
.woocommerce #order_review table.shop_table ul.dhl-co-preffered-time > li label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
ul.dhl-co-times > li {
|
||||
flex-grow: 1;
|
||||
flex-basis: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-preffered-time > li:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-preffered-time > li:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-times > li {
|
||||
border-top: 10px solid #ccc;
|
||||
}
|
||||
|
||||
ul.dhl-co-times input,
|
||||
ul.dhl-co-preffered-time input {
|
||||
/*visibility: hidden;*/
|
||||
opacity: 0;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
ul.dhl-co-times label,
|
||||
ul.dhl-co-preffered-time label {
|
||||
position: relative;
|
||||
display: block;
|
||||
padding: 15px 10px;
|
||||
font-size: 1em;
|
||||
font-weight: normal;
|
||||
background: #ecf5f2;
|
||||
cursor: pointer;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
ul.dhl-co-times label {
|
||||
padding: 15px 5px;
|
||||
}
|
||||
|
||||
ul.dhl-co-times input[type=radio]:checked ~ label,
|
||||
ul.dhl-co-preffered-time input[type=radio]:checked ~ label {
|
||||
background: #FFCC00;
|
||||
}
|
||||
|
||||
ul.dhl-co-times input[type=radio]:active ~ label,
|
||||
ul.dhl-co-preffered-time input[type=radio]:active ~ label {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
ul.dhl-preferred-location {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.dhl-preferred-location li {
|
||||
display: inline-block;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
ul.dhl-preferred-location li:last-child {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
ul.dhl-preferred-location li input,
|
||||
ul.dhl-preferred-location li label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#pr_dhl_preferred_location::placeholder,
|
||||
#pr_dhl_preferred_neighbour_name::placeholder,
|
||||
#pr_dhl_preferred_neighbour_address::placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.dhl-preferred_neighbor input, .dhl-preferred_location input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dhl-tooltip {
|
||||
display: inline-block;
|
||||
background: #ffcc00;
|
||||
border-radius: 50%;
|
||||
height: 1.5em;
|
||||
width: 1.5em;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shipping-dhl-postnum {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.shipping-dhl-postnum span.optional {
|
||||
display: none;
|
||||
}
|
||||
|
||||
a#dhl_parcel_finder {
|
||||
padding: .125rem;
|
||||
border-radius: 3px;
|
||||
background-clip: padding-box;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
font-size: .875rem;
|
||||
background-color: #fff;
|
||||
-webkit-font-smoothing: inherit;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border: 1px solid #dadae5;
|
||||
margin-bottom: 10px;
|
||||
-webkit-box-shadow: 2px 2px #dadae5;
|
||||
box-shadow: 2px 2px #dadae5;
|
||||
color: inherit;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
a#dhl_parcel_finder:hover {
|
||||
border: 1px solid #B1B1B1;
|
||||
-webkit-box-shadow: 2px 2px #B1B1B1;
|
||||
box-shadow: 2px 2px #B1B1B1;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder img {
|
||||
width: 25%;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#dhl_google_map {
|
||||
/*width: 90%;*/
|
||||
height: 85%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form {
|
||||
width: 90%;
|
||||
height: 90%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .woocommerce-error {
|
||||
padding: 1em 3.5em;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .parcel-title {
|
||||
padding-top: 0px;
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
|
||||
#dhl_parcel_finder_form form #dhl_seach_button {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-field {
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-field.extra-small {
|
||||
width: 7%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-field.small {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-field.large {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-row label {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin: 0 0 0 10px;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-field.packstation {
|
||||
margin-right: 25px;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-row span.icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: inline-block;
|
||||
background-repeat: no-repeat;
|
||||
background-size: contain;
|
||||
margin-bottom: -15px;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form .form-row .input-checkbox {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .parcelshop-select-btn {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .parcel_subtitle {
|
||||
font-size: 0.8125rem;
|
||||
color: #767676;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
padding: 1.5em 0 0;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .dhl_shop_img {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.registration_info {
|
||||
font-size:.95rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
ul.dhl-co-times > li {
|
||||
min-width: 30%;
|
||||
width: 30%;
|
||||
}
|
||||
#dhl_parcel_finder_form form .form-field.small, #dhl_parcel_finder_form form .form-field.large {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form form #dhl_seach_button {
|
||||
float: left;
|
||||
margin: 30px 0 40px;
|
||||
}
|
||||
|
||||
#dhl_parcel_finder_form .woocommerce-error {
|
||||
padding: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.shipping-dhl-drop-off-points .select2-selection {
|
||||
max-width: 90vw !important;
|
||||
}
|
||||
|
||||
.shipping-dhl-address-type .select2-container,
|
||||
.shipping-dhl-drop-off-points .select2-container{
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.select2-full-width + .select2-container {
|
||||
width: 100% !important;
|
||||
}
|
||||
141
dev/dhl-for-woocommerce/assets/css/pr-dhl-wizard.css
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
.pr-dhl-wc-wizard-overlay {
|
||||
position:fixed;
|
||||
top:0px;
|
||||
bottom:0px;
|
||||
left:0px;
|
||||
right:0px;
|
||||
z-index:999;
|
||||
background-color:rgba( 0, 0, 0, 0.5 );
|
||||
display:block;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard-overlay.hidden{
|
||||
display:none;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard-container {
|
||||
position:absolute;
|
||||
top:50%;
|
||||
left:50%;
|
||||
transform: translate( -50%, -50% );
|
||||
-moz-transform: translate( -50%, -50% );
|
||||
-webkit-transform: translate( -50%, -50% );
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard {
|
||||
width: 500px;
|
||||
min-height: 400px;
|
||||
background-color:#fff;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-header {
|
||||
padding:20px 10px;
|
||||
text-align:center;
|
||||
background-color:#facc0f;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-nav .wizard-step {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-content.container {
|
||||
width:390px;
|
||||
margin:0px auto;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-title {
|
||||
font-weight:bold;
|
||||
font-size:14px;
|
||||
color:#000;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-description {
|
||||
font-size:14px;
|
||||
color:#333;
|
||||
margin-bottom:20px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-content.container .form-group {
|
||||
margin-bottom:13px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard-content.container input {
|
||||
width:100%;
|
||||
padding:4px 8px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .button-next,
|
||||
.pr-dhl-wc-wizard .button-finish {
|
||||
margin-top:8px;
|
||||
position:relative;
|
||||
cursor:pointer;
|
||||
background-color:#d40009;
|
||||
color:#fff;
|
||||
text-transform: uppercase;
|
||||
padding:8px 30px 8px 13px;
|
||||
font-size:13px;
|
||||
font-weight:700;
|
||||
border:1px solid #d40009;
|
||||
border-radius:3px;
|
||||
-moz-border-radius:3px;
|
||||
-webkit-border-radius:3px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .button-next:after,
|
||||
.pr-dhl-wc-wizard .button-finish:after {
|
||||
font-family: dashicons;
|
||||
font-size:14px;
|
||||
line-height:1em;
|
||||
position:absolute;
|
||||
top:9px;
|
||||
right:11px;
|
||||
display:inline-block;
|
||||
margin-left:7px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .button-next:after {
|
||||
content:"\f345";
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .button-finish:after {
|
||||
content:"\f15e";
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard .wizard-buttons .wizard-btn.btn {
|
||||
position:absolute;
|
||||
top:50%;
|
||||
margin-top:-20px;
|
||||
left:auto;
|
||||
right:auto;
|
||||
color:#fff;
|
||||
background-color:transparent;
|
||||
border:0px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard .wizard-buttons .wizard-btn.btn.prev {
|
||||
left: -70px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard .wizard-buttons .wizard-btn.btn.next {
|
||||
right: -70px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard .wizard .wizard-buttons .wizard-btn.btn span {
|
||||
color:#fff;
|
||||
font-size:30px;
|
||||
width:30px;
|
||||
height:30px;
|
||||
}
|
||||
|
||||
.pr-dhl-wc-wizard-container .pr-dhl-wc-skip-wizard {
|
||||
position:absolute;
|
||||
top:5px;
|
||||
right:5px;
|
||||
line-height:1em;
|
||||
font-size:18px;
|
||||
font-weight:700;
|
||||
color:#fff;
|
||||
text-decoration:none;
|
||||
}
|
||||
1
dev/dhl-for-woocommerce/assets/css/wizard.library.css
Normal file
BIN
dev/dhl-for-woocommerce/assets/img/dhl-official.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
16
dev/dhl-for-woocommerce/assets/img/dp-logo.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<svg viewBox="0 0 56 56" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<g id="brand-dp-logo-superzeichen" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="DP_Logo_SZ_rgb_schwarz-Copy">
|
||||
<g id="Boundingbox">
|
||||
<rect id="Rectangle" x="0" y="0" width="56" height="56"></rect>
|
||||
</g>
|
||||
<g id="DP_Logo_SZ" transform="translate(10.650000, 12.500000)" fill="#000000"
|
||||
fill-rule="nonzero">
|
||||
<path
|
||||
d="M12.0530276,24.0248552 L16.9321951,24.0248552 L12.0044542,29 L7.12474093,29 L12.0530276,24.0248552 Z M0.542449215,29 L5.42325405,29 L10.3493577,24.0248552 L5.47073589,24.0248552 L0.542449215,29 Z M22.9449232,24.0248552 L18.0646641,24.0248552 L22.9929508,29 L27.8726641,29 L22.9449232,24.0248552 Z M29.5272149,24.0248552 L24.6469558,24.0248552 L29.5746967,29 L34.4538643,29 L29.5272149,24.0248552 Z M36.747526,4.11941638 C36.0549462,14.256233 28.4343851,23.134265 17.1277057,23.1299034 C4.33762836,23.126084 -0.607031354,12.0326346 0.0588058263,3.62691959 L3.81532821,2.43467374 C3.20461362,7.21838293 4.68910307,10.6685875 5.71241841,12.249704 C4.49371806,5.48237263 9.6146609,0.00436840288 16.0241624,2.59702948e-06 C21.7896575,-0.00381260702 26.5580341,4.19631787 26.5351118,10.2219044 C27.3810525,7.92194978 27.9699363,4.42047755 28.0910969,1.96944698 L36.747526,4.11941638 Z M22.970154,10.4346106 C22.970154,6.6173514 19.8690992,3.52329346 16.0410812,3.52329346 C12.215792,3.52329346 9.11419148,6.6173514 9.11419148,10.4346106 C9.11419148,14.2518698 12.215792,17.3459278 16.0410812,17.3459278 C19.8690829,17.3459278 22.970154,14.2518753 22.970154,10.4345997 L22.970154,10.4346106 Z"
|
||||
id="Shape"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/blank.gif
Normal file
|
After Width: | Height: | Size: 43 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_close.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_loading.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_nav_left.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_nav_right.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_e.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_n.png
Normal file
|
After Width: | Height: | Size: 106 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_ne.png
Normal file
|
After Width: | Height: | Size: 347 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_nw.png
Normal file
|
After Width: | Height: | Size: 324 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_s.png
Normal file
|
After Width: | Height: | Size: 111 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_se.png
Normal file
|
After Width: | Height: | Size: 352 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_sw.png
Normal file
|
After Width: | Height: | Size: 340 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_shadow_w.png
Normal file
|
After Width: | Height: | Size: 103 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_title_left.png
Normal file
|
After Width: | Height: | Size: 503 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_title_main.png
Normal file
|
After Width: | Height: | Size: 96 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancy_title_over.png
Normal file
|
After Width: | Height: | Size: 70 B |
|
After Width: | Height: | Size: 506 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancybox-x.png
Normal file
|
After Width: | Height: | Size: 203 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancybox-y.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
dev/dhl-for-woocommerce/assets/img/fancybox/fancybox.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
168
dev/dhl-for-woocommerce/assets/img/icon.svg
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="256"
|
||||
height="256"
|
||||
id="svg3381"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
viewBox="0 0 256 256"
|
||||
sodipodi:docname="icon.svg">
|
||||
<defs
|
||||
id="defs3383">
|
||||
<clipPath
|
||||
id="SVGID_2_">
|
||||
<use
|
||||
xlink:href="#SVGID_1_"
|
||||
overflow="visible"
|
||||
id="use9"
|
||||
style="overflow:visible"
|
||||
x="0"
|
||||
y="0"
|
||||
width="100%"
|
||||
height="100%" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="1.375"
|
||||
inkscape:cx="136.7152"
|
||||
inkscape:cy="111.7671"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="true"
|
||||
inkscape:document-units="px"
|
||||
inkscape:grid-bbox="true"
|
||||
inkscape:window-width="1500"
|
||||
inkscape:window-height="977"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata3386">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1"
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
transform="translate(0,192)">
|
||||
<g
|
||||
id="g3"
|
||||
transform="matrix(1.5033741,0,0,6.7146232,-0.019091,-192.81002)">
|
||||
<defs
|
||||
id="defs5">
|
||||
<rect
|
||||
id="SVGID_1_"
|
||||
width="170.27901"
|
||||
height="38.279999"
|
||||
x="0"
|
||||
y="0" />
|
||||
</defs>
|
||||
<clipPath
|
||||
id="clipPath3402">
|
||||
<use
|
||||
xlink:href="#SVGID_1_"
|
||||
overflow="visible"
|
||||
id="use3404"
|
||||
style="overflow:visible"
|
||||
x="0"
|
||||
y="0"
|
||||
width="100%"
|
||||
height="100%" />
|
||||
</clipPath>
|
||||
<path
|
||||
clip-path="url(#SVGID_2_)"
|
||||
d="m 170.22,-0.06 0,38.34 -21.24,0 c -42.58,0 -85.16,0 -127.74,0 l -21.24,0 0,-38.34 21.239,0 c 42.58,0 85.16,0 127.74,0 l 21.241,0"
|
||||
id="path11"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffcc00" />
|
||||
</g>
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
d="m 54.716787,-81.067071 -7.380748,10.334954 40.847684,0 c 0.47027,0.173626 1.293239,-0.03957 1.312376,0.738211 l 0,0.328107 c -1.402602,2.464803 -3.388934,4.745057 -4.922772,7.136041 l 0,0.24609 -0.08202,0.164034 0.08202,0.08202 c 0.02718,0.802466 1.673278,0.77376 2.214633,0.738215 l 16.56873,0 4.92141,-6.80795 0.24745,-0.410116 c 1.29324,-2.13124 1.14423,-4.928243 -0.0834,-7.054016 l -0.24605,-0.574165 -0.41012,-0.492141 c -2.24884,-3.331535 -6.36095,-4.377332 -10.170936,-4.42928 l -42.898271,0"
|
||||
id="path13" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
d="m 44.299808,-47.519477 14.928268,-20.669913 18.866763,0 c 1.691048,0.144889 1.630899,0.894059 0.654823,2.132612 l -3.773082,5.331524 -0.164034,0.246091 -0.24609,0.328107 -0.08338,0.164033 0,0.656182 0.08338,0.164034 0.164034,0.164033 0.24609,0.08202 0.329466,0.08202 0.410116,0.08202 0.164033,0 0.24609,0.08202 25.345245,0 -0.41011,0.574169 c -4.689012,6.328108 -12.351371,10.818889 -20.341821,10.581025 l -36.419783,0"
|
||||
id="path15" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="84.899,23.22 78.96,31.38 63.359,31.38 69.239,23.22 84.899,23.22 "
|
||||
id="polyline17" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="108.84,21.3 70.56,21.3 81.06,6.84 96.659,6.84 90.659,15.18 97.619,15.18 103.619,6.84 119.279,6.84 108.84,21.3 "
|
||||
id="polyline19" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="107.46,23.22 101.52,31.38 85.92,31.38 91.859,23.22 107.46,23.22 "
|
||||
id="polyline21" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="0,26.4 23.04,26.4 21.779,28.2 0,28.2 0,26.4 "
|
||||
id="polyline23" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="0,23.22 25.38,23.22 24.119,24.9 0,24.9 0,23.22 "
|
||||
id="polyline25" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="0,29.64 20.699,29.64 19.439,31.38 0,31.38 0,29.64 "
|
||||
id="polyline27" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="170.22,28.2 147.3,28.2 148.56,26.4 170.22,26.4 170.22,28.2 "
|
||||
id="polyline29" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="170.22,31.38 144.96,31.38 146.279,29.64 170.22,29.64 170.22,31.38 "
|
||||
id="polyline31" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="150.899,23.22 170.22,23.22 170.22,24.9 149.699,24.9 150.899,23.22 "
|
||||
id="polyline33" />
|
||||
<polyline
|
||||
transform="matrix(1.3670577,0,0,1.3670577,13.788446,-90.417744)"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
points="140.939,6.84 130.439,21.3 113.88,21.3 124.38,6.84 140.939,6.84 "
|
||||
id="polyline35" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
style="clip-rule:evenodd;fill:#d40511;fill-rule:evenodd"
|
||||
d="m 167.66446,-58.674671 -2.29666,3.198917 c -3.9795,5.820931 3.91389,8.280267 8.44842,7.956277 l 34.2858,0 8.12032,-11.155194 -48.55788,0"
|
||||
id="path37" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.9 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/additional.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/delivery.png
Normal file
|
After Width: | Height: | Size: 613 B |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/multiple.png
Normal file
|
After Width: | Height: | Size: 805 B |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/plane.png
Normal file
|
After Width: | Height: | Size: 1,008 B |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/return.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/service.png
Normal file
|
After Width: | Height: | Size: 630 B |
BIN
dev/dhl-for-woocommerce/assets/img/order-icons/weight.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/packstation.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/parcelshop.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
dev/dhl-for-woocommerce/assets/img/post_office.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* FancyBox - jQuery Plugin
|
||||
* Simple and fancy lightbox alternative
|
||||
*
|
||||
* Examples and documentation at: http://fancybox.net
|
||||
*
|
||||
* Copyright (c) 2008 - 2010 Janis Skarnelis
|
||||
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
|
||||
*
|
||||
* Version: 1.3.4 (11/11/2010)
|
||||
* Requires: jQuery v1.3+
|
||||
*
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
|
||||
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
|
||||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
|
||||
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
|
||||
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
|
||||
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
|
||||
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
|
||||
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
|
||||
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
|
||||
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
|
||||
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
|
||||
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
|
||||
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
|
||||
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
|
||||
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
|
||||
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
|
||||
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
|
||||
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
|
||||
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
|
||||
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
|
||||
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
|
||||
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
|
||||
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
|
||||
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
|
||||
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
|
||||
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
|
||||
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
|
||||
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
|
||||
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);
|
||||
12
dev/dhl-for-woocommerce/assets/js/jquery.fancybox.min.js
vendored
Normal file
864
dev/dhl-for-woocommerce/assets/js/pr-dhl-checkout-frontend.js
Normal file
|
|
@ -0,0 +1,864 @@
|
|||
jQuery( function ( $ ) {
|
||||
var $doc = $( document )
|
||||
var $body = $( document.body )
|
||||
$doc.on( 'updated_checkout', function () {
|
||||
|
||||
$( '.pr_dhl_preferred_day' ).on( 'change', function () {
|
||||
$body.trigger( 'update_checkout' )
|
||||
} )
|
||||
|
||||
$( '.pr_dhl_preferred_time' ).on( 'change', function () {
|
||||
$body.trigger( 'update_checkout' )
|
||||
} )
|
||||
|
||||
if ( pr_dhl_checkout_frontend.cod_enabled ) {
|
||||
jQuery( '.woocommerce' ).on( 'change', '.payment_methods .input-radio', function () {
|
||||
$body.trigger( 'update_checkout' )
|
||||
} )
|
||||
}
|
||||
|
||||
if ( $( '.dhl-tooltip' ).length > 0 ) {
|
||||
// reveal tooltips on hover
|
||||
$( '.dhl-tooltip' ).tooltip()
|
||||
// no blacklist strings in DHL inputs
|
||||
var blacklist = [
|
||||
'Paketbox',
|
||||
'Packstation',
|
||||
'Postfach',
|
||||
'Postfiliale',
|
||||
'Filiale',
|
||||
'Postfiliale Direkt',
|
||||
'Filiale Direkt',
|
||||
'Paketkasten',
|
||||
'DHL',
|
||||
'P-A-C-K-S-T-A-T-I-O-N',
|
||||
'Paketstation',
|
||||
'Pack Station',
|
||||
'P.A.C.K.S.T.A.T.I.O.N.',
|
||||
'Pakcstation',
|
||||
'Paackstation',
|
||||
'Pakstation',
|
||||
'Backstation',
|
||||
'Bakstation',
|
||||
'P A C K S T A T I O N',
|
||||
'Wunschfiliale',
|
||||
'Deutsche Post',
|
||||
'<',
|
||||
'>',
|
||||
'\\n',
|
||||
'\\r',
|
||||
/\\/,
|
||||
'\'',
|
||||
'"',
|
||||
';',
|
||||
/\+/,
|
||||
]
|
||||
var textInputs = $( '#pr_dhl_preferred_neighbour_name, #pr_dhl_preferred_neighbour_address, #pr_dhl_preferred_location' )
|
||||
textInputs.keyup( function ( e ) {
|
||||
var val = e.target.value
|
||||
for ( var i = 0, len = blacklist.length; i < len; i ++ ) {
|
||||
var item = blacklist[i]
|
||||
if ( val.match( item ) !== null ) {
|
||||
val = val.replace( item, '' )
|
||||
i --
|
||||
}
|
||||
}
|
||||
e.target.value = val
|
||||
} )
|
||||
|
||||
// reveal the location or neighbor section on radio change
|
||||
var LONselector = 'input[name="pr_dhl_preferred_location_neighbor"]'
|
||||
var LONradioButtons = $( LONselector )
|
||||
// toggle location / locatoin sections if user has a choice
|
||||
if ( LONradioButtons.length > 0 ) {
|
||||
var initialLONvalue = $( LONselector + ':checked' ).val()
|
||||
var LONsections = $( '.dhl-co-tr.dhl-radio-toggle' )
|
||||
LONsections.each( function ( i, el ) {
|
||||
var section = $( el )
|
||||
if ( !section.hasClass( 'dhl-' + initialLONvalue ) ) {
|
||||
section.hide()
|
||||
}
|
||||
} )
|
||||
LONradioButtons.on( 'change', function ( e ) {
|
||||
var classToMatch = 'dhl-' + e.target.value
|
||||
LONsections.each( function ( i, sect ) {
|
||||
var section = $( sect )
|
||||
if ( section.hasClass( classToMatch ) ) {
|
||||
var inputs = section.find( 'input' )
|
||||
inputs.each( function ( i, el ) {
|
||||
if ( el.dataset.onhold ) {
|
||||
el.value = el.dataset.onhold
|
||||
}
|
||||
} )
|
||||
section.show()
|
||||
} else {
|
||||
section.hide()
|
||||
section.find( 'input' ).each( function ( i, el ) {
|
||||
if ( el.value.length > 0 ) {
|
||||
el.dataset.onhold = el.value
|
||||
el.value = ''
|
||||
}
|
||||
} )
|
||||
}
|
||||
} )
|
||||
} )
|
||||
}
|
||||
}
|
||||
} )
|
||||
} )
|
||||
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
var wc_checkout_dhl_parcelfinder = {
|
||||
updateTimer: false,
|
||||
skipPopulateDropdown: false,
|
||||
init: function () {
|
||||
// $( document.body ).on( 'click', 'a.showcoupon', this.show_coupon_form );
|
||||
$( document.body ).on( 'click', '#dhl_parcel_finder', this.init_form )
|
||||
|
||||
$( document.body ).on( 'click', '.parcelshop-select-btn', this.selectedShop )
|
||||
|
||||
$( document.body ).on( 'change', '#shipping_dhl_address_type', this.address_type )
|
||||
$( document.body ).on( 'change', '#shipping_dhl_address_type', this.populateDropdown )
|
||||
$( document.body ).on( 'change', '#shipping-pr-dhl-address_type', this.populateDropdown )
|
||||
$( document.body ).on( 'change', '#shipping_dhl_drop_off', this.selectedDropOff )
|
||||
|
||||
$( document.body ).on( 'update_checkout', this.toggleDhlParcelFinder )
|
||||
$( document.body ).on( 'update_checkout', this.populateDropdown )
|
||||
|
||||
wc_checkout_dhl_parcelfinder.toggleDhlParcelFinder()
|
||||
wc_checkout_dhl_parcelfinder.address_type()
|
||||
setTimeout(function() {
|
||||
wc_checkout_dhl_parcelfinder.populateDropdown();
|
||||
}, 500);
|
||||
|
||||
$(document.body).on('click', '#dhl_seach_button input[type="submit"]', function (e) {
|
||||
e.preventDefault();
|
||||
wc_checkout_dhl_parcelfinder.submit();
|
||||
});
|
||||
},
|
||||
address_type: function () {
|
||||
var address_type = $( '.woocommerce-checkout #shipping_dhl_address_type' ).val()
|
||||
|
||||
if ( address_type == 'dhl_packstation' ) {
|
||||
$( '.woocommerce-checkout #shipping_dhl_postnum_field' ).show()
|
||||
$( '.woocommerce-checkout #shipping_dhl_drop_off_field' ).show()
|
||||
// If does not have span or span with "required" class, add it
|
||||
if ( !$( '.woocommerce-checkout #shipping_dhl_postnum_field label span' ).length ||
|
||||
(
|
||||
!$( '.woocommerce-checkout #shipping_dhl_postnum_field label span' ).hasClass( 'required' )
|
||||
) ) {
|
||||
$( '.woocommerce-checkout #shipping_dhl_postnum_field label' ).append( ' <span class="required">*</span>' )
|
||||
}
|
||||
} else if ( address_type == 'dhl_branch' ) {
|
||||
$( '.woocommerce-checkout #shipping_dhl_postnum_field' ).show()
|
||||
$( '.woocommerce-checkout #shipping_dhl_drop_off_field' ).show()
|
||||
// remove "required" span tag
|
||||
$( '.woocommerce-checkout #shipping_dhl_postnum_field label .required' ).remove()
|
||||
} else {
|
||||
$( '.woocommerce-checkout #shipping_dhl_postnum_field' ).hide()
|
||||
$( '.woocommerce-checkout #shipping_dhl_drop_off_field' ).hide()
|
||||
}
|
||||
},
|
||||
init_form: function () {
|
||||
|
||||
var gmap_country = $('.woocommerce-checkout #shipping_country').val()
|
||||
|| $('.woocommerce-checkout #shipping-country').val()
|
||||
|| $('.woocommerce-checkout #billing_country').val()
|
||||
|| $('.woocommerce-checkout #billing-country').val()
|
||||
|| '';
|
||||
$('#dhl_parcelfinder_country').val(gmap_country);
|
||||
|
||||
var gmap_postcode = $('.woocommerce-checkout #shipping_postcode').val()
|
||||
|| $('.woocommerce-checkout #shipping-postcode').val()
|
||||
|| $('.woocommerce-checkout #billing_postcode').val()
|
||||
|| $('.woocommerce-checkout #billing-postcode').val()
|
||||
|| '';
|
||||
$('#dhl_parcelfinder_postcode').val(gmap_postcode);
|
||||
|
||||
var gmap_city = $('.woocommerce-checkout #shipping_city').val()
|
||||
|| $('.woocommerce-checkout #shipping-city').val()
|
||||
|| $('.woocommerce-checkout #billing_city').val()
|
||||
|| $('.woocommerce-checkout #billing-city').val()
|
||||
|| '';
|
||||
$('#dhl_parcelfinder_city').val(gmap_city);
|
||||
|
||||
var gmap_address_1 = $('.woocommerce-checkout #shipping_address_1').val()
|
||||
|| $('.woocommerce-checkout #shipping-address_1').val()
|
||||
|| $('.woocommerce-checkout #billing_address_1').val()
|
||||
|| $('.woocommerce-checkout #billing-address_1').val()
|
||||
|| '';
|
||||
|
||||
var gmap_address_2 = $('.woocommerce-checkout #shipping_address_2').val()
|
||||
|| $('.woocommerce-checkout #shipping-address_2').val()
|
||||
|| $('.woocommerce-checkout #billing_address_2').val()
|
||||
|| $('.woocommerce-checkout #billing-address_2').val()
|
||||
|| '';
|
||||
|
||||
var gmap_address = gmap_address_1 + ' ' + gmap_address_2
|
||||
gmap_address = gmap_address.trim()
|
||||
|
||||
$( '#dhl_parcelfinder_address' ).val( gmap_address )
|
||||
|
||||
$('#dhl_seach_button input[type="submit"]').trigger('click');
|
||||
|
||||
},
|
||||
submit: function () {
|
||||
var $form = $('#checkout_dhl_parcel_finder');
|
||||
|
||||
$( '#dhl_parcel_finder_form #checkout_dhl_parcel_finder .woocommerce-error' ).remove()
|
||||
|
||||
if ( $form.is( '.processing' ) ) {
|
||||
return false
|
||||
}
|
||||
|
||||
var pf_post_code = $( '#dhl_parcelfinder_postcode' ).val()
|
||||
if ( !pf_post_code ) {
|
||||
$( '#dhl_parcel_finder_form #checkout_dhl_parcel_finder' ).append( '<div class="woocommerce-error">' + pr_dhl_checkout_frontend.post_code_error + '</div>' )
|
||||
return false
|
||||
}
|
||||
|
||||
$form.addClass( 'processing' ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6,
|
||||
},
|
||||
} )
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_parcelfinder_search',
|
||||
parcelfinder_country: $( '#dhl_parcelfinder_country' ).val(),
|
||||
parcelfinder_postcode: pf_post_code,
|
||||
parcelfinder_city: $( '#dhl_parcelfinder_city' ).val(),
|
||||
parcelfinder_address: $( '#dhl_parcelfinder_address' ).val(),
|
||||
packstation_filter: $( '#dhl_packstation_filter' ).is( ':checked' ),
|
||||
branch_filter: $( '#dhl_branch_filter' ).is( ':checked' ),
|
||||
security: prDhlGlobals.parcel_nonce
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: pr_dhl_checkout_frontend.ajax_url,
|
||||
data: data,
|
||||
success: function ( parcelShopsJSON ) {
|
||||
$( '.woocommerce-error, .woocommerce-message' ).remove()
|
||||
$form.removeClass( 'processing' ).unblock()
|
||||
if ( parcelShopsJSON ) {
|
||||
var parcelShopsRes = JSON.parse( parcelShopsJSON )
|
||||
|
||||
if ( parcelShopsRes.error ) {
|
||||
$( '#dhl_parcel_finder_form #checkout_dhl_parcel_finder' ).append( '<div class="woocommerce-error">' + parcelShopsRes.error + '</div>' )
|
||||
} else {
|
||||
// JSON parse returned results
|
||||
wc_checkout_dhl_parcelfinder.parcelShops = parcelShopsRes.parcel_res
|
||||
wc_checkout_dhl_parcelfinder.populateDropdown();
|
||||
if ( 'osm' === pr_dhl_checkout_frontend.map_type ) {
|
||||
wc_checkout_dhl_parcelfinder.populateOsmMap()
|
||||
} else {
|
||||
wc_checkout_dhl_parcelfinder.populateGoogleMap()
|
||||
}
|
||||
}
|
||||
// $( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
|
||||
}
|
||||
},
|
||||
dataType: 'html',
|
||||
} )
|
||||
|
||||
return false
|
||||
},
|
||||
populateDropdown: function () {
|
||||
// If this function was triggered due to a change on #shipping_dhl_drop_off, do nothing.
|
||||
if ( wc_checkout_dhl_parcelfinder.skipPopulateDropdown ) {
|
||||
wc_checkout_dhl_parcelfinder.skipPopulateDropdown = false
|
||||
return
|
||||
}
|
||||
|
||||
let address_type = $( '.woocommerce-checkout #shipping_dhl_address_type' ).val() || $('.woocommerce-checkout #shipping-pr-dhl-address_type').val();
|
||||
if ( 'normal' === address_type ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let packstation_address = 'dhl_packstation' === address_type;
|
||||
let branch_address = 'dhl_branch' === address_type;
|
||||
|
||||
if ( ! wc_checkout_dhl_parcelfinder.parcelShops ) {
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_parcelfinder_search',
|
||||
parcelfinder_country: $( '#billing_country' ).val(),
|
||||
parcelfinder_postcode: $( '#billing_postcode' ).val(),
|
||||
parcelfinder_city: $( '#billing_city' ).val(),
|
||||
parcelfinder_address: $( '#billing_address_1' ).val()+' '+$( 'billing_address_2').val(),
|
||||
packstation_filter: packstation_address,
|
||||
branch_filter: branch_address,
|
||||
security: $( 'form#checkout_dhl_parcel_finder' ).find( 'input[name="dhl_parcelfinder_nonce"]' ).val(),
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: pr_dhl_checkout_frontend.ajax_url,
|
||||
data: data,
|
||||
beforeSend: function() {
|
||||
$('#shipping_dhl_drop_off').prop('disabled', true);
|
||||
},
|
||||
success: function ( parcelShopsJSON ) {
|
||||
$( '.woocommerce-error, .woocommerce-message' ).remove()
|
||||
$('#shipping_dhl_drop_off').prop('disabled', false);
|
||||
|
||||
if ( parcelShopsJSON ) {
|
||||
var parcelShopsRes = JSON.parse( parcelShopsJSON )
|
||||
|
||||
if ( parcelShopsRes.error ) {
|
||||
wc_checkout_dhl_parcelfinder.emptyDropdown()
|
||||
} else {
|
||||
// JSON parse returned results
|
||||
// Find the dropdown element in the DOM
|
||||
const dropdown = document.getElementById( 'shipping_dhl_drop_off' )
|
||||
if ( dropdown ) {
|
||||
wc_checkout_dhl_parcelfinder.emptyDropdown()
|
||||
// Populate the dropdown with parcel shop names
|
||||
wc_checkout_dhl_parcelfinder.parcelPoints = parcelShopsRes.parcel_res
|
||||
wc_checkout_dhl_parcelfinder.parcelPoints.forEach( element => {
|
||||
// Create a new option element
|
||||
const option = document.createElement( 'option' )
|
||||
option.value = element.location.ids[0].locationId // Use a relevant value if needed
|
||||
option.text = element.name + ' - ' + element.place.address.addressLocality + ', ' + element.place.address.streetAddress
|
||||
|
||||
// Add the new option to the dropdown
|
||||
dropdown.add( option )
|
||||
} )
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
wc_checkout_dhl_parcelfinder.emptyDropdown()
|
||||
}
|
||||
},
|
||||
dataType: 'html',
|
||||
} )
|
||||
|
||||
return false
|
||||
} else {
|
||||
const dropdown = document.getElementById( 'shipping_dhl_drop_off' )
|
||||
if ( dropdown ) {
|
||||
wc_checkout_dhl_parcelfinder.emptyDropdown()
|
||||
wc_checkout_dhl_parcelfinder.parcelPoints = wc_checkout_dhl_parcelfinder.parcelShops
|
||||
wc_checkout_dhl_parcelfinder.parcelPoints.forEach( element => {
|
||||
if ( (
|
||||
packstation_address && 'locker' !== element.location.type
|
||||
) ||
|
||||
(
|
||||
branch_address && 'locker' === element.location.type
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create a new option element
|
||||
const option = document.createElement( 'option' )
|
||||
option.value = element.location.ids[0].locationId // Use a relevant value if needed
|
||||
option.text = element.name + ' - ' + element.place.address.addressLocality + ', ' + element.place.address.streetAddress // Display the name as the text of the option
|
||||
|
||||
// Add the new option to the dropdown
|
||||
dropdown.add( option )
|
||||
} )
|
||||
}
|
||||
}
|
||||
},
|
||||
emptyDropdown: function () {
|
||||
const dropdown = document.getElementById( 'shipping_dhl_drop_off' )
|
||||
if ( dropdown ) {
|
||||
$( dropdown ).empty()
|
||||
const option = document.createElement( 'option' )
|
||||
option.text = pr_dhl_checkout_frontend.select_drop;
|
||||
option.value = '';
|
||||
option.disabled = true;
|
||||
dropdown.add( option )
|
||||
}
|
||||
},
|
||||
selectedDropOff: function () {
|
||||
// Do not get the drop-off points.
|
||||
wc_checkout_dhl_parcelfinder.skipPopulateDropdown = true;
|
||||
|
||||
var parcelShopId = $( this ).val()
|
||||
$.each( wc_checkout_dhl_parcelfinder.parcelPoints, function ( key, value ) {
|
||||
|
||||
if ( value.location.ids[0].locationId == parcelShopId ) {
|
||||
|
||||
switch ( value.location.type ) {
|
||||
case 'locker':
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_packstation' ).trigger( 'change' )
|
||||
break
|
||||
case 'servicepoint':
|
||||
var shop_name = pr_dhl_checkout_frontend.parcelShop
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
case 'postoffice':
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
case 'postbank':
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
default:
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_packstation' ).trigger( 'change' )
|
||||
break
|
||||
}
|
||||
|
||||
$( '.woocommerce-checkout #shipping_first_name' ).val( $( '.woocommerce-checkout #billing_first_name' ).val() )
|
||||
$( '.woocommerce-checkout #shipping_last_name' ).val( $( '.woocommerce-checkout #billing_last_name' ).val() )
|
||||
// $('.woocommerce-checkout #shipping_company').val( '' );
|
||||
$( '.woocommerce-checkout #shipping_address_1' ).val( shop_name + ' ' + value.location.keywordId )
|
||||
$( '.woocommerce-checkout #shipping_address_2' ).val( '' )
|
||||
$( '.woocommerce-checkout #shipping_postcode' ).val( value.place.address.postalCode )
|
||||
$( '.woocommerce-checkout #shipping_city' ).val( value.place.address.addressLocality )
|
||||
|
||||
$.fancybox.close()
|
||||
}
|
||||
} )
|
||||
},
|
||||
populateGoogleMap: function () {
|
||||
if ( !wc_checkout_dhl_parcelfinder.parcelShops ) {
|
||||
return
|
||||
}
|
||||
|
||||
var uluru = {
|
||||
lat: wc_checkout_dhl_parcelfinder.parcelShops[0].place.geo.latitude,
|
||||
lng: wc_checkout_dhl_parcelfinder.parcelShops[0].place.geo.longitude
|
||||
}
|
||||
var map = new google.maps.Map( document.getElementById( 'dhl_google_map' ), {
|
||||
zoom: 13,
|
||||
center: uluru,
|
||||
} )
|
||||
|
||||
var infoWinArray = []
|
||||
$.each( wc_checkout_dhl_parcelfinder.parcelShops, function ( key, value ) {
|
||||
var uluru = { lat: value.place.geo.latitude, lng: value.place.geo.longitude }
|
||||
|
||||
// Get opening times
|
||||
var openingTimes = '<h5 class="parcel_subtitle">' + pr_dhl_checkout_frontend.opening_times + '</h5>'
|
||||
var prev_day = 0
|
||||
var day_of_week
|
||||
$.each( value.openingHours, function ( key_times, value_times ) {
|
||||
|
||||
switch ( value_times.dayOfWeek ) {
|
||||
case 'http://schema.org/Monday':
|
||||
day_of_week = pr_dhl_checkout_frontend.monday
|
||||
break
|
||||
case 'http://schema.org/Tuesday':
|
||||
day_of_week = pr_dhl_checkout_frontend.tueday
|
||||
break
|
||||
case 'http://schema.org/Wednesday':
|
||||
day_of_week = pr_dhl_checkout_frontend.wednesday
|
||||
break
|
||||
case 'http://schema.org/Thursday':
|
||||
day_of_week = pr_dhl_checkout_frontend.thrusday
|
||||
break
|
||||
case 'http://schema.org/Friday':
|
||||
day_of_week = pr_dhl_checkout_frontend.friday
|
||||
break
|
||||
case 'http://schema.org/Saturday':
|
||||
day_of_week = pr_dhl_checkout_frontend.satuday
|
||||
break
|
||||
case 'http://schema.org/Sunday':
|
||||
day_of_week = pr_dhl_checkout_frontend.sunday
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
if ( prev_day ) {
|
||||
if ( prev_day == value_times.dayOfWeek ) {
|
||||
openingTimes += ', '
|
||||
} else {
|
||||
openingTimes += '<br/>' + day_of_week + ': '
|
||||
}
|
||||
} else {
|
||||
openingTimes += day_of_week + ': '
|
||||
}
|
||||
|
||||
prev_day = value_times.dayOfWeek
|
||||
|
||||
var opens = value_times.opens.slice( 0, -3 );
|
||||
var closes = value_times.closes.slice( 0, -3 );
|
||||
openingTimes += opens + ' - ' + closes;
|
||||
} )
|
||||
|
||||
// Get services
|
||||
var shopServices = '<h5 class="parcel_subtitle">' + pr_dhl_checkout_frontend.services + '</h5>'
|
||||
var shopServicesParking = ': ' + pr_dhl_checkout_frontend.no
|
||||
var shopServicesHandicap = ': ' + pr_dhl_checkout_frontend.no
|
||||
$.each( value.serviceTypes, function ( key_services, value_services ) {
|
||||
switch ( value_services ) {
|
||||
case 'parking':
|
||||
shopServicesParking = ': ' + pr_dhl_checkout_frontend.yes
|
||||
break
|
||||
case 'handicapped-access':
|
||||
shopServicesHandicap = ': ' + pr_dhl_checkout_frontend.yes
|
||||
break
|
||||
}
|
||||
|
||||
} )
|
||||
|
||||
shopServices += pr_dhl_checkout_frontend.parking + shopServicesParking + '<br/>'
|
||||
shopServices += pr_dhl_checkout_frontend.handicap + shopServicesHandicap + '<br/>'
|
||||
|
||||
switch ( value.location.type ) {
|
||||
case 'locker':
|
||||
var gmap_marker_icon = pr_dhl_checkout_frontend.packstation_icon
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
var shop_label = pr_dhl_checkout_frontend.packstation
|
||||
break
|
||||
case 'servicepoint':
|
||||
var gmap_marker_icon = pr_dhl_checkout_frontend.parcelshop_icon
|
||||
var shop_name = pr_dhl_checkout_frontend.parcelShop
|
||||
var shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
case 'postoffice':
|
||||
var gmap_marker_icon = pr_dhl_checkout_frontend.post_office_icon
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
var shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
case 'postbank':
|
||||
var gmap_marker_icon = pr_dhl_checkout_frontend.post_office_icon
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
var shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
default:
|
||||
var gmap_marker_icon = pr_dhl_checkout_frontend.packstation_icon
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
var shop_label = pr_dhl_checkout_frontend.packstation
|
||||
break
|
||||
}
|
||||
|
||||
shop_name += ' ' + value.location.keywordId
|
||||
|
||||
var contentString = '<div id="parcel-content">' +
|
||||
'<div id="site-notice">' +
|
||||
'</div>' +
|
||||
'<h4 class="parcel-title">' + shop_name + '</h4>' +
|
||||
'<div id="bodyContent">' +
|
||||
'<div>' + value.place.address.streetAddress + '</br>' + value.place.address.addressLocality + ' ' + value.place.address.postalCode + '</div>' +
|
||||
openingTimes +
|
||||
shopServices +
|
||||
'<button type="button" class="parcelshop-select-btn" id="' + value.location.ids[0].locationId + '">' + pr_dhl_checkout_frontend.select + '</button>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
|
||||
var infowindow = new google.maps.InfoWindow( {
|
||||
content: contentString,
|
||||
maxWidth: 300,
|
||||
} )
|
||||
|
||||
infoWinArray.push( infowindow )
|
||||
|
||||
var marker = new google.maps.Marker( {
|
||||
position: uluru,
|
||||
map: map,
|
||||
title: shop_label,
|
||||
animation: google.maps.Animation.DROP,
|
||||
icon: gmap_marker_icon,
|
||||
} )
|
||||
|
||||
marker.addListener( 'click', function () {
|
||||
clearOverlays()
|
||||
infowindow.open( map, marker )
|
||||
} )
|
||||
|
||||
} )
|
||||
|
||||
// Clear all info windows
|
||||
function clearOverlays() {
|
||||
for ( var i = 0; i < infoWinArray.length; i ++ ) {
|
||||
infoWinArray[i].close()
|
||||
}
|
||||
// infoWinArray.length = 0;
|
||||
}
|
||||
|
||||
// marker.addListener('click', toggleBounce);
|
||||
},
|
||||
populateOsmMap: function () {
|
||||
if ( !wc_checkout_dhl_parcelfinder.parcelShops ) {
|
||||
return
|
||||
}
|
||||
// Remove existing map instance if it exists
|
||||
if ( wc_checkout_dhl_parcelfinder.osmMap ) {
|
||||
wc_checkout_dhl_parcelfinder.osmMap.remove() // Remove the map
|
||||
}
|
||||
// OSM Map
|
||||
var uluru = [
|
||||
wc_checkout_dhl_parcelfinder.parcelShops[0].place.geo.latitude,
|
||||
wc_checkout_dhl_parcelfinder.parcelShops[0].place.geo.longitude,
|
||||
]
|
||||
wc_checkout_dhl_parcelfinder.osmMap = L.map( 'dhl_google_map' ).setView( uluru, 13 )
|
||||
|
||||
L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
maxZoom: 19,
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
||||
} ).addTo( wc_checkout_dhl_parcelfinder.osmMap )
|
||||
|
||||
var infoWinArray = []
|
||||
|
||||
// Loop through each parcel shop
|
||||
$.each( wc_checkout_dhl_parcelfinder.parcelShops, function ( key, value ) {
|
||||
var uluru = [
|
||||
value.place.geo.latitude,
|
||||
value.place.geo.longitude,
|
||||
] // Leaflet uses [lat, lng]
|
||||
|
||||
// Get opening times
|
||||
var openingTimes = '<h5 class="parcel_subtitle">' + pr_dhl_checkout_frontend.opening_times + '</h5>'
|
||||
var prev_day = 0
|
||||
var day_of_week
|
||||
$.each( value.openingHours, function ( key_times, value_times ) {
|
||||
switch ( value_times.dayOfWeek ) {
|
||||
case 'http://schema.org/Monday':
|
||||
day_of_week = pr_dhl_checkout_frontend.monday
|
||||
break
|
||||
case 'http://schema.org/Tuesday':
|
||||
day_of_week = pr_dhl_checkout_frontend.tueday
|
||||
break
|
||||
case 'http://schema.org/Wednesday':
|
||||
day_of_week = pr_dhl_checkout_frontend.wednesday
|
||||
break
|
||||
case 'http://schema.org/Thursday':
|
||||
day_of_week = pr_dhl_checkout_frontend.thrusday
|
||||
break
|
||||
case 'http://schema.org/Friday':
|
||||
day_of_week = pr_dhl_checkout_frontend.friday
|
||||
break
|
||||
case 'http://schema.org/Saturday':
|
||||
day_of_week = pr_dhl_checkout_frontend.satuday
|
||||
break
|
||||
case 'http://schema.org/Sunday':
|
||||
day_of_week = pr_dhl_checkout_frontend.sunday
|
||||
break
|
||||
}
|
||||
|
||||
if ( prev_day ) {
|
||||
if ( prev_day == value_times.dayOfWeek ) {
|
||||
openingTimes += ', '
|
||||
} else {
|
||||
openingTimes += '<br/>' + day_of_week + ': '
|
||||
}
|
||||
} else {
|
||||
openingTimes += day_of_week + ': '
|
||||
}
|
||||
|
||||
prev_day = value_times.dayOfWeek
|
||||
|
||||
var opens = value_times.opens.slice( 0, -3 );
|
||||
var closes = value_times.closes.slice( 0, -3 );
|
||||
openingTimes += opens + ' - ' + closes;
|
||||
} )
|
||||
|
||||
// Get services
|
||||
var shopServices = '<h5 class="parcel_subtitle">' + pr_dhl_checkout_frontend.services + '</h5>'
|
||||
var shopServicesParking = ': ' + pr_dhl_checkout_frontend.no
|
||||
var shopServicesHandicap = ': ' + pr_dhl_checkout_frontend.no
|
||||
$.each( value.serviceTypes, function ( key_services, value_services ) {
|
||||
switch ( value_services ) {
|
||||
case 'parking':
|
||||
shopServicesParking = ': ' + pr_dhl_checkout_frontend.yes
|
||||
break
|
||||
case 'handicapped-access':
|
||||
shopServicesHandicap = ': ' + pr_dhl_checkout_frontend.yes
|
||||
break
|
||||
}
|
||||
} )
|
||||
|
||||
shopServices += pr_dhl_checkout_frontend.parking + shopServicesParking + '<br/>'
|
||||
shopServices += pr_dhl_checkout_frontend.handicap + shopServicesHandicap + '<br/>'
|
||||
|
||||
// Determine shop type and icons
|
||||
var gmap_marker_icon, shop_name, shop_label
|
||||
switch ( value.location.type ) {
|
||||
case 'locker':
|
||||
gmap_marker_icon = pr_dhl_checkout_frontend.packstation_icon
|
||||
shop_name = pr_dhl_checkout_frontend.packstation
|
||||
shop_label = pr_dhl_checkout_frontend.packstation
|
||||
break
|
||||
case 'servicepoint':
|
||||
gmap_marker_icon = pr_dhl_checkout_frontend.parcelshop_icon
|
||||
shop_name = pr_dhl_checkout_frontend.parcelShop
|
||||
shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
case 'postoffice':
|
||||
gmap_marker_icon = pr_dhl_checkout_frontend.post_office_icon
|
||||
shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
case 'postbank':
|
||||
gmap_marker_icon = pr_dhl_checkout_frontend.post_office_icon
|
||||
shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
shop_label = pr_dhl_checkout_frontend.branch
|
||||
break
|
||||
default:
|
||||
gmap_marker_icon = pr_dhl_checkout_frontend.packstation_icon
|
||||
shop_name = pr_dhl_checkout_frontend.packstation
|
||||
shop_label = pr_dhl_checkout_frontend.packstation
|
||||
break
|
||||
}
|
||||
|
||||
shop_name += ' ' + value.location.keywordId
|
||||
|
||||
var contentString = '<div id="parcel-content">' +
|
||||
'<div id="site-notice">' +
|
||||
'</div>' +
|
||||
'<h4 class="parcel-title">' + shop_name + '</h4>' +
|
||||
'<div id="bodyContent">' +
|
||||
'<div>' + value.place.address.streetAddress + '</br>' + value.place.address.addressLocality + ' ' + value.place.address.postalCode + '</div>' +
|
||||
openingTimes +
|
||||
shopServices +
|
||||
'<button type="button" class="parcelshop-select-btn" id="' + value.location.ids[0].locationId + '">' + pr_dhl_checkout_frontend.select + '</button>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
|
||||
// Create a Leaflet marker
|
||||
var marker = L.marker( uluru, {
|
||||
icon: L.icon( {
|
||||
iconUrl: gmap_marker_icon,
|
||||
} ),
|
||||
title: shop_label,
|
||||
} ).addTo( wc_checkout_dhl_parcelfinder.osmMap )
|
||||
|
||||
// Create a popup
|
||||
marker.bindPopup( contentString, { maxWidth: 300 } )
|
||||
|
||||
// Add click event listener
|
||||
marker.on( 'click', function () {
|
||||
clearOverlays()
|
||||
marker.openPopup()
|
||||
} )
|
||||
|
||||
// Add to the info window array
|
||||
infoWinArray.push( marker )
|
||||
|
||||
} )
|
||||
|
||||
// Clear all popups
|
||||
function clearOverlays() {
|
||||
for ( var i = 0; i < infoWinArray.length; i ++ ) {
|
||||
infoWinArray[i].closePopup()
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
selectedShop: function () {
|
||||
|
||||
var parcelShopId = $( this ).attr( 'id' )
|
||||
|
||||
$.each( wc_checkout_dhl_parcelfinder.parcelShops, function ( key, value ) {
|
||||
|
||||
if ( value.location.ids[0].locationId == parcelShopId ) {
|
||||
switch ( value.location.type ) {
|
||||
case 'locker':
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
address_type = 'dhl_packstation';
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_packstation' ).trigger( 'change' )
|
||||
break
|
||||
case 'servicepoint':
|
||||
var shop_name = pr_dhl_checkout_frontend.parcelShop
|
||||
address_type = 'dhl_branch';
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
case 'postoffice':
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
address_type = 'dhl_branch';
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
case 'postbank':
|
||||
var shop_name = pr_dhl_checkout_frontend.postoffice
|
||||
address_type = 'dhl_branch';
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_branch' ).trigger( 'change' )
|
||||
break
|
||||
default:
|
||||
var shop_name = pr_dhl_checkout_frontend.packstation
|
||||
address_type = 'dhl_packstation';
|
||||
$( '.woocommerce-checkout #shipping_dhl_address_type' ).val( 'dhl_packstation' ).trigger( 'change' )
|
||||
break
|
||||
}
|
||||
|
||||
$( '.woocommerce-checkout #shipping_first_name' ).val( $( '.woocommerce-checkout #billing_first_name' ).val() )
|
||||
$( '.woocommerce-checkout #shipping_last_name' ).val( $( '.woocommerce-checkout #billing_last_name' ).val() )
|
||||
// $('.woocommerce-checkout #shipping_company').val( '' );
|
||||
$( '.woocommerce-checkout #shipping_address_1' ).val( shop_name + ' ' + value.location.keywordId )
|
||||
$( '.woocommerce-checkout #shipping_address_2' ).val( '' )
|
||||
$( '.woocommerce-checkout #shipping_postcode' ).val( value.place.address.postalCode )
|
||||
$( '.woocommerce-checkout #shipping_city' ).val( value.place.address.addressLocality )
|
||||
$('.woocommerce-checkout #shipping_dhl_drop_off').val(parcelShopId).trigger('change');
|
||||
|
||||
var event = new CustomEvent('dhl-shop-selected', {
|
||||
detail: {
|
||||
address_1: shop_name + ' ' + value.location.keywordId,
|
||||
address_2: '',
|
||||
postcode: value.place.address.postalCode,
|
||||
city: value.place.address.addressLocality,
|
||||
parcel_ID: parcelShopId,
|
||||
address_type: address_type
|
||||
}
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
|
||||
$.fancybox.close()
|
||||
}
|
||||
} )
|
||||
},
|
||||
toggleDhlParcelFinder: function () {
|
||||
let selectedCountry
|
||||
|
||||
const $shipToCheckbox = $( '#ship-to-different-address-checkbox' )
|
||||
|
||||
if ( $shipToCheckbox.length ) {
|
||||
// Classic checkout
|
||||
selectedCountry = $shipToCheckbox.is( ':checked' )
|
||||
? $( '.woocommerce-checkout #shipping_country' ).val()
|
||||
: $( '.woocommerce-checkout #billing_country' ).val()
|
||||
} else {
|
||||
// Block-based checkout.
|
||||
selectedCountry = $( '.woocommerce-checkout #shipping-country' ).val()
|
||||
}
|
||||
|
||||
const parcelFinder = $( '#dhl_parcel_finder' )
|
||||
const dropOffField = $( '#shipping_dhl_drop_off_field' )
|
||||
const addressTypeField = $( '#shipping_dhl_address_type_field' )
|
||||
const registrationInfo = $( '.registration_info' )
|
||||
const shipToText = $( '#ship-to-different-address span' )
|
||||
|
||||
if ( !shipToText.data( 'original' ) ) {
|
||||
shipToText.data( 'original', shipToText.text() )
|
||||
}
|
||||
|
||||
if ( selectedCountry === 'DE' ) {
|
||||
parcelFinder.show()
|
||||
dropOffField.show()
|
||||
addressTypeField.show()
|
||||
registrationInfo.show()
|
||||
shipToText.text( pr_dhl_checkout_frontend.ship_to_different_address_text )
|
||||
} else {
|
||||
parcelFinder.hide()
|
||||
dropOffField.hide()
|
||||
addressTypeField.hide()
|
||||
registrationInfo.hide()
|
||||
shipToText.text( shipToText.data( 'original' ) )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( jQuery( '[data-fancybox]' ).length > 0 ) {
|
||||
|
||||
jQuery( '[data-fancybox]' ).fancybox( {
|
||||
modal: true,
|
||||
} )
|
||||
|
||||
}
|
||||
|
||||
wc_checkout_dhl_parcelfinder.init()
|
||||
|
||||
if ($.fn.selectWoo) {
|
||||
$('#shipping_dhl_address_type').selectWoo();
|
||||
$('#shipping_dhl_drop_off').selectWoo();
|
||||
}
|
||||
|
||||
} )
|
||||
38
dev/dhl-for-woocommerce/assets/js/pr-dhl-dp-orderlist.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
( function( $ ) {
|
||||
|
||||
var wc_dhl_dp_order_lists = {
|
||||
// init Class
|
||||
init: function() {
|
||||
$( '#posts-filter' )
|
||||
.on( 'change', '#bulk-action-selector-top', this.toggle_awb_copy_count );
|
||||
|
||||
$( '#wc-orders-filter' )
|
||||
.on( 'change', '#bulk-action-selector-top', this.toggle_awb_copy_count );
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
update: function () {
|
||||
$( '.dhl-awb-filter-container' ).hide();
|
||||
},
|
||||
|
||||
toggle_awb_copy_count: function( evt ){
|
||||
evt.preventDefault();
|
||||
|
||||
var value = jQuery( this ).val();
|
||||
var post_form = jQuery( this ).parents();
|
||||
|
||||
post_form.find('.tablenav.bottom .dhl-awb-filter-container').remove();
|
||||
|
||||
if( 'pr_dhl_create_orders' == value ){
|
||||
post_form.find( '.dhl-awb-filter-container' ).show();
|
||||
}else{
|
||||
post_form.find( '.dhl-awb-filter-container' ).hide();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_lists.init();
|
||||
|
||||
} )( jQuery );
|
||||
203
dev/dhl-for-woocommerce/assets/js/pr-dhl-dp.js
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
( function( $, PR_DHL_DP ) {
|
||||
|
||||
var wc_dhl_dp_order_items = {
|
||||
// init Class
|
||||
init: function() {
|
||||
$( '#woocommerce-dhl-dp-order' )
|
||||
.on( 'click', '#pr_dhl_add_to_order', this.add_item_to_order );
|
||||
|
||||
$( '#woocommerce-dhl-dp-order' )
|
||||
.on( 'click', '.pr_dhl_order_remove_item', this.remove_item_from_order );
|
||||
|
||||
$( '#woocommerce-dhl-dp-order' )
|
||||
.on( 'click', '#pr_dhl_create_order', this.create_order );
|
||||
|
||||
$( '#woocommerce-dhl-dp-order' )
|
||||
.on( 'click', '#pr_dhl_dp_download_awb_label', this.download_awb_label );
|
||||
|
||||
$( '#woocommerce-dhl-dp-order' )
|
||||
.on( 'click', '#pr_dhl_dp_delete_label', this.reset_order );
|
||||
|
||||
$( document ).on( 'pr_dhl_saved_label', this.get_order_items );
|
||||
$( document ).on( 'pr_dhl_deleted_label', this.get_order_items );
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
update: function ( response ) {
|
||||
// Re-enable the "remove item" links
|
||||
$( '.pr_dhl_order_remove_item').removeAttr( 'disabled' );
|
||||
|
||||
if ( response && response.html ) {
|
||||
$( '#woocommerce-dhl-dp-order .inside' ).html( response.html );
|
||||
}
|
||||
|
||||
if ( response && response.error ) {
|
||||
$( '#pr_dhl_dp_error' ).text( response.error ).show();
|
||||
} else {
|
||||
$( '#pr_dhl_dp_error' ).hide();
|
||||
}
|
||||
|
||||
var create_order_button = $( '#pr_dhl_create_order' ),
|
||||
add_item_button = $( '#pr_dhl_add_to_order' ),
|
||||
gen_label_message = $( '#pr_dhl_order_gen_label_message' ),
|
||||
reset_order_button = $( '#pr_dhl_reset_order' );
|
||||
|
||||
// Check if download label button is found on the page
|
||||
var has_label = $( '#dhl-label-print' ).length > 0;
|
||||
// Check if showing the shipments table
|
||||
var showing_shipments = $( '#pr_dhl_order_shipments_table' ).length > 0;
|
||||
|
||||
// Enable the "add" button if the item has a label and not showing the shipments
|
||||
add_item_button.toggleClass( 'disabled', !(has_label && !showing_shipments) );
|
||||
// Show the generate label message if the item has no label and not showing the shipments
|
||||
gen_label_message.toggle( !has_label && !showing_shipments );
|
||||
// Hide the "create order" button if showing the shipments table
|
||||
create_order_button.toggle( !showing_shipments );
|
||||
// Show the reset order button if showing the shipments table
|
||||
reset_order_button.toggle( showing_shipments );
|
||||
|
||||
// Check if there are items in the items table
|
||||
var has_items = $( '#pr_dhl_order_items_table tbody tr:not("#pr_dhl_no_items_msg")' ).length;
|
||||
// If there are items in the items table, enable the create order button. Otherwise disable it
|
||||
create_order_button.toggleClass( 'disabled', !has_items );
|
||||
},
|
||||
|
||||
lock_order_controls: function () {
|
||||
// Disable the buttons
|
||||
$( '#pr_dhl_add_to_order, #pr_dhl_create_order' ).addClass( 'disabled' );
|
||||
// Disable the "remove item" links
|
||||
$( '.pr_dhl_order_remove_item').attr( 'disabled', 'disabled' );
|
||||
},
|
||||
|
||||
get_order_items: function () {
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_get_order_items',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
} );
|
||||
},
|
||||
|
||||
add_item_to_order: function () {
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_add_order_item',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
} );
|
||||
},
|
||||
|
||||
remove_item_from_order: function ( event ) {
|
||||
var click_target = $( event.target );
|
||||
var item_row = click_target.closest('tr');
|
||||
var item_barcode = item_row.find('.pr_dhl_item_barcode').val();
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_remove_order_item',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
item_barcode: item_barcode,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
} );
|
||||
},
|
||||
|
||||
create_order: function () {
|
||||
if (!confirm(PR_DHL_DP.create_order_confirmation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var copy_count = 1;
|
||||
if( $('#pr_dhl_awb_copy_count').length > 0 ){
|
||||
copy_count = $('#pr_dhl_awb_copy_count').val();
|
||||
}
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_create_order',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
awb_copy_count: copy_count,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
|
||||
if (response.tracking) {
|
||||
$('a#dhl_delete_label').parent().remove();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
reset_order: function () {
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_reset_order',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
} );
|
||||
},
|
||||
|
||||
download_awb_label: function () {
|
||||
// Get the AWB from the sibling table cell's text
|
||||
var awb = $(this).closest('tr').find('.pr_dhl_shipment_awb').text();
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_download_awb_label',
|
||||
awb: awb,
|
||||
pr_dhl_order_nonce: $( '#pr_dhl_order_nonce' ).val()
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.lock_order_controls();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
wc_dhl_dp_order_items.update( response );
|
||||
|
||||
if ( response.label_url ) {
|
||||
window.location = response.label_url;
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
add_wc_order_note: function (tracking_note, tracking_note_type) {
|
||||
$( '#woocommerce-order-notes' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_note',
|
||||
post_id: woocommerce_admin_meta_boxes.post_id,
|
||||
note_type: tracking_note_type,
|
||||
note: tracking_note,
|
||||
security: woocommerce_admin_meta_boxes.add_order_note_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response_note ) {
|
||||
// alert(response_note);
|
||||
$( 'ul.order_notes' ).prepend( response_note );
|
||||
$( '#woocommerce-order-notes' ).unblock();
|
||||
$( '#add_order_note' ).val( '' );
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
wc_dhl_dp_order_items.init();
|
||||
|
||||
} )(jQuery, PR_DHL_DP);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
s_date = new Date();
|
||||
s_rdm = s_date.getTime();
|
||||
s_url = escape(window.location.host);
|
||||
s_desturl='<img width="1" height="1" src="'+window.location.protocol+'//deutschepostag.112.2o7.net/b/ss/deutschepostdhlprod2/1/H.27.5--NS/'+s_rdm+'?events=event80&v80='+s_url+'" />';
|
||||
document.write(s_desturl);
|
||||
233
dev/dhl-for-woocommerce/assets/js/pr-dhl-internetmarke-order.js
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
/**
|
||||
* INTERNETMARKE order metabox JS.
|
||||
*
|
||||
* Follows the same structural pattern as pr-dhl.js (Paket metabox):
|
||||
* - Uses dhl_im_label_data for pre-translated button HTML (built in PHP).
|
||||
* - Error handling mirrors save_dhl_label / delete_dhl_label in pr-dhl.js.
|
||||
*
|
||||
* Handles:
|
||||
* - Product change → show/hide service checkboxes
|
||||
* - EINSCHREIBEN EINWURF / EINSCHREIBEN mutual exclusivity
|
||||
* - RÜCKSCHEIN visibility (only when EINSCHREIBEN is checked)
|
||||
* - Generate Label AJAX call
|
||||
* - Delete Label AJAX call
|
||||
*/
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
var imOrder = {
|
||||
|
||||
form: '#shipment-im-label-form',
|
||||
|
||||
init: function () {
|
||||
var self = this;
|
||||
|
||||
// Product dropdown change.
|
||||
$( self.form ).on( 'change', '#pr_dhl_im_product', function () {
|
||||
self.update_services();
|
||||
} );
|
||||
|
||||
// EINSCHREIBEN EINWURF → uncheck EINSCHREIBEN, hide RÜCKSCHEIN.
|
||||
$( self.form ).on( 'change', '#pr_dhl_im_service_einschreiben_einwurf', function () {
|
||||
if ( $( this ).prop( 'checked' ) ) {
|
||||
$( '#pr_dhl_im_service_einschreiben' ).prop( 'checked', false );
|
||||
self.update_rueckschein_visibility();
|
||||
}
|
||||
} );
|
||||
|
||||
// EINSCHREIBEN → uncheck EINSCHREIBEN EINWURF, toggle RÜCKSCHEIN.
|
||||
$( self.form ).on( 'change', '#pr_dhl_im_service_einschreiben', function () {
|
||||
if ( $( this ).prop( 'checked' ) ) {
|
||||
$( '#pr_dhl_im_service_einschreiben_einwurf' ).prop( 'checked', false );
|
||||
}
|
||||
self.update_rueckschein_visibility();
|
||||
} );
|
||||
|
||||
// Generate Label button.
|
||||
$( self.form ).on( 'click', '#im-label-button', function ( e ) {
|
||||
e.preventDefault();
|
||||
self.generate_label();
|
||||
} );
|
||||
|
||||
// Delete Label link — delegated so it also works on dynamically inserted links.
|
||||
$( self.form ).on( 'click', '#im-delete-label', function ( e ) {
|
||||
e.preventDefault();
|
||||
self.delete_label();
|
||||
} );
|
||||
|
||||
// Set initial service visibility for the currently selected product.
|
||||
self.update_services();
|
||||
},
|
||||
|
||||
/**
|
||||
* Show or hide service checkbox rows based on the selected product.
|
||||
* Re-runs RÜCKSCHEIN visibility afterwards.
|
||||
*/
|
||||
update_services: function () {
|
||||
var self = this;
|
||||
var product = $( '#pr_dhl_im_product' ).val();
|
||||
var servicesMap = ( typeof dhl_im_order_data !== 'undefined' ) ? dhl_im_order_data.services_map : {};
|
||||
var available = servicesMap[ product ] || [];
|
||||
|
||||
$( self.form + ' .im-service-row' ).each( function () {
|
||||
var service = $( this ).data( 'service' );
|
||||
if ( available.indexOf( service ) !== -1 ) {
|
||||
$( this ).show();
|
||||
} else {
|
||||
$( this ).hide();
|
||||
// Uncheck hidden services so they are not submitted.
|
||||
$( this ).find( 'input[type="checkbox"]' ).prop( 'checked', false );
|
||||
}
|
||||
} );
|
||||
|
||||
self.update_rueckschein_visibility();
|
||||
},
|
||||
|
||||
/**
|
||||
* RÜCKSCHEIN is only valid when EINSCHREIBEN (not EINWURF) is checked.
|
||||
* Availability is determined from the services map (not from CSS state)
|
||||
* so this works correctly whether the row is currently shown or hidden.
|
||||
*/
|
||||
update_rueckschein_visibility: function () {
|
||||
var product = $( '#pr_dhl_im_product' ).val();
|
||||
var servicesMap = ( typeof dhl_im_order_data !== 'undefined' ) ? dhl_im_order_data.services_map : {};
|
||||
var available = servicesMap[ product ] || [];
|
||||
|
||||
if ( available.indexOf( 'rueckschein' ) === -1 ) {
|
||||
return; // Not available for this product.
|
||||
}
|
||||
|
||||
var $einschreiben = $( '#pr_dhl_im_service_einschreiben' );
|
||||
var $rueckschein = $( '.im-service-row-rueckschein' );
|
||||
|
||||
if ( $einschreiben.prop( 'checked' ) ) {
|
||||
$rueckschein.show();
|
||||
} else {
|
||||
$rueckschein.hide();
|
||||
$( '#pr_dhl_im_service_rueckschein' ).prop( 'checked', false );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Append an error as text, never HTML, so a server-provided string cannot
|
||||
* inject markup into the metabox.
|
||||
*/
|
||||
show_error: function ( message ) {
|
||||
if ( ! message ) {
|
||||
return;
|
||||
}
|
||||
$( this.form ).append( $( '<p class="wc_dhl_error"/>' ).text( message ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Collect form inputs and POST to the generate-label AJAX action.
|
||||
* Mirrors save_dhl_label() in pr-dhl.js.
|
||||
*/
|
||||
generate_label: function () {
|
||||
var self = this;
|
||||
|
||||
if ( typeof dhl_im_order_data === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $form = $( self.form );
|
||||
var data = {
|
||||
action: 'wc_shipment_internetmarke_gen_label',
|
||||
order_id: dhl_im_order_data.order_id,
|
||||
pr_dhl_im_label_nonce: dhl_im_order_data.nonce,
|
||||
pr_dhl_im_product: $( '#pr_dhl_im_product' ).val(),
|
||||
pr_dhl_im_services: [],
|
||||
};
|
||||
|
||||
// Collect checked service checkboxes.
|
||||
$form.find( 'input[name="pr_dhl_im_services[]"]:checked' ).each( function () {
|
||||
data.pr_dhl_im_services.push( $( this ).val() );
|
||||
} );
|
||||
|
||||
// Remove errors from any previous attempt — same as Paket.
|
||||
$form.find( '.wc_dhl_error' ).remove();
|
||||
|
||||
$form.block( {
|
||||
message: null,
|
||||
overlayCSS: { background: '#fff', opacity: 0.6 },
|
||||
} );
|
||||
|
||||
$.post( dhl_im_order_data.ajax_url, data, function ( response ) {
|
||||
$form.unblock();
|
||||
|
||||
if ( ! response || response.error ) {
|
||||
self.show_error( response ? response.error : dhl_im_order_data.ajax_error );
|
||||
return;
|
||||
}
|
||||
|
||||
// Success: clear the purchased-but-not-downloaded state and lock the form.
|
||||
$form.find( '.im-pending-notice' ).remove();
|
||||
$form.find( 'input, select, textarea' ).prop( 'disabled', true );
|
||||
$( '#im-label-button' ).remove();
|
||||
// Drop any Delete link already shown in the pending state so it isn't duplicated.
|
||||
$form.find( '.wc_dhl_delete' ).remove();
|
||||
|
||||
// Inject pre-translated button HTML (built in PHP, same pattern as dhl_label_data).
|
||||
if ( typeof dhl_im_label_data !== 'undefined' ) {
|
||||
$form.append( dhl_im_label_data.print_button );
|
||||
$( '#im-label-print' ).attr( 'href', response.label_url || '#' );
|
||||
$form.append( dhl_im_label_data.delete_label );
|
||||
}
|
||||
|
||||
$( document ).trigger( 'pr_dhl_im_saved_label' );
|
||||
} ).fail( function () {
|
||||
$form.unblock();
|
||||
if ( typeof dhl_im_order_data !== 'undefined' ) {
|
||||
self.show_error( dhl_im_order_data.ajax_error );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* DELETE the stored label and revert the metabox.
|
||||
* Mirrors delete_dhl_label() in pr-dhl.js.
|
||||
*/
|
||||
delete_label: function () {
|
||||
var self = this;
|
||||
|
||||
if ( typeof dhl_im_order_data === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $form = $( self.form );
|
||||
$form.find( '.wc_dhl_error' ).remove();
|
||||
|
||||
$form.block( {
|
||||
message: null,
|
||||
overlayCSS: { background: '#fff', opacity: 0.6 },
|
||||
} );
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_internetmarke_delete_label',
|
||||
order_id: dhl_im_order_data.order_id,
|
||||
pr_dhl_im_label_nonce: dhl_im_order_data.nonce,
|
||||
};
|
||||
|
||||
$.post( dhl_im_order_data.ajax_url, data, function ( response ) {
|
||||
$form.unblock();
|
||||
|
||||
if ( ! response || response.error ) {
|
||||
self.show_error( response ? response.error : dhl_im_order_data.ajax_error );
|
||||
return;
|
||||
}
|
||||
|
||||
// Reload so the metabox reverts to its initial state — same as Paket delete flow.
|
||||
window.location.reload();
|
||||
} ).fail( function () {
|
||||
$form.unblock();
|
||||
if ( typeof dhl_im_order_data !== 'undefined' ) {
|
||||
self.show_error( dhl_im_order_data.ajax_error );
|
||||
}
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
if ( $( '#shipment-im-label-form' ).length ) {
|
||||
imOrder.init();
|
||||
}
|
||||
|
||||
} );
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Internetmarke "Test Account Connection" button.
|
||||
*
|
||||
* Reads the Internetmarke credential fields, saves them and tests the
|
||||
* connection to Deutsche Post in a single AJAX call. Mirrors the response
|
||||
* shape (connection_success / connection_error) used by the Paket test
|
||||
* connection button so the existing CSS classes apply.
|
||||
*/
|
||||
function dhlInternetmarkeTestConnection( btn_id ) {
|
||||
var $ = jQuery;
|
||||
var btn = $( btn_id );
|
||||
|
||||
// Remove any result from a previous attempt.
|
||||
btn.nextAll().remove();
|
||||
|
||||
var original = btn.text();
|
||||
btn.attr( 'disabled', true );
|
||||
btn.text( dhl_im_test_con_obj.testing_txt );
|
||||
|
||||
var loaderContainer = $( '<span/>', { 'class': 'loader-image-container' } ).insertAfter( btn );
|
||||
$( '<img/>', { src: dhl_im_test_con_obj.loader_image, 'class': 'loader-image' } ).appendTo( loaderContainer );
|
||||
|
||||
var data = {
|
||||
action: 'test_dhl_internetmarke_connection',
|
||||
im_test_con_nonce: dhl_im_test_con_obj.nonce,
|
||||
username: $( '#woocommerce_pr_dhl_paket_internetmarke_api_user' ).val(),
|
||||
password: $( '#woocommerce_pr_dhl_paket_internetmarke_api_password' ).val(),
|
||||
portokasse_id: $( '#woocommerce_pr_dhl_paket_internetmarke_portokasse_id' ).val()
|
||||
};
|
||||
|
||||
var genericError = dhl_im_test_con_obj.error_txt || 'Connection test failed. Please try again.';
|
||||
|
||||
$.post( dhl_im_test_con_obj.ajax_url, data, function ( response ) {
|
||||
btn.attr( 'disabled', false );
|
||||
btn.text( ( response && response.button_txt ) || original );
|
||||
loaderContainer.remove();
|
||||
|
||||
var success = response && response.connection_success;
|
||||
var cssClass = 'dhl_connection_' + ( success ? 'succeeded' : 'error' );
|
||||
// On a -1/0 body (nonce failure / not logged in) neither field is set, so fall
|
||||
// back to a generic message instead of rendering an empty error span.
|
||||
var text = success
|
||||
? response.connection_success
|
||||
: ( ( response && response.connection_error ) || genericError );
|
||||
|
||||
$( '<span/>', { 'class': cssClass, text: text } ).insertAfter( btn );
|
||||
} ).fail( function () {
|
||||
// On a timeout or HTTP error the success callback never runs. Without this the
|
||||
// button stays disabled on the spinner forever, even though the credentials were
|
||||
// already saved server-side.
|
||||
btn.attr( 'disabled', false );
|
||||
btn.text( original );
|
||||
loaderContainer.remove();
|
||||
$( '<span/>', { 'class': 'dhl_connection_error', text: genericError } ).insertAfter( btn );
|
||||
} );
|
||||
}
|
||||
49
dev/dhl-for-woocommerce/assets/js/pr-dhl-my-account.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Ajax call to sync orders!
|
||||
*/
|
||||
function dhlMyAccount(btn_id) {
|
||||
var $ = jQuery;
|
||||
var btn = $(btn_id);
|
||||
|
||||
// Remove elements after button
|
||||
btn.nextAll().remove();
|
||||
|
||||
btn.attr('disabled', true);
|
||||
// btn.text('Testing Connection...');
|
||||
|
||||
var loaderContainer = $('<span/>', {
|
||||
'class': 'loader-image-container'
|
||||
}).insertAfter(btn);
|
||||
|
||||
var loader = $('<img/>', {
|
||||
src: dhl_myaccount_obj.loader_image,
|
||||
'class': 'loader-image'
|
||||
}).appendTo(loaderContainer);
|
||||
|
||||
var data = {
|
||||
'action': 'dhl_get_myaccount',
|
||||
'myaccount_nonce': dhl_myaccount_obj.myaccount_nonce
|
||||
};
|
||||
|
||||
// We can also pass the url value separately from ajaxurl for front end AJAX implementations
|
||||
$.post(dhl_myaccount_obj.ajax_url, data, function(response) {
|
||||
btn.attr('disabled', false);
|
||||
btn.text(response.button_txt);
|
||||
loaderContainer.remove();
|
||||
|
||||
var success = response.connection_success;
|
||||
var test_connection_class = 'dhl_connection_' + (success ? 'succeeded' : 'error');
|
||||
var test_connection_text = success ? response.connection_success : response.connection_error;
|
||||
|
||||
loaderContainer = $('<span/>', {
|
||||
'class': test_connection_class
|
||||
}).insertAfter(btn);
|
||||
|
||||
loaderContainer.append(test_connection_text);
|
||||
|
||||
if ( success ) {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// shorthand no-conflict safe document-ready function
|
||||
jQuery(document).ready(function($) {
|
||||
$(document.body).on('click', 'div.dhl-legacy-parcel-dismiss-migrate-notice button.notice-dismiss', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
'action': 'dhl_legacy_parcel_dismiss_migrate_notice',
|
||||
'security': dhl_legacy_parcel_dismiss_notice.security,
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data);
|
||||
|
||||
}).on('click', 'a#dhl-legacy-parcel-dismiss-migrate-notice-forever', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
'action': 'dhl_legacy_parcel_dismiss_migrate_notice_forever',
|
||||
'security': dhl_legacy_parcel_dismiss_notice.security,
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data);
|
||||
|
||||
$('div.dhl-legacy-parcel-dismiss-migrate-notice button.notice-dismiss').trigger('click');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Persist dismissal of the "SOAP API removed" migration notice.
|
||||
*
|
||||
* When the admin clicks the core dismiss (X) on the notice, record it server-side so
|
||||
* the notice does not come back on the next page load.
|
||||
*/
|
||||
jQuery( function ( $ ) {
|
||||
$( document ).on( 'click', '.pr-dhl-soap-removed-notice .notice-dismiss', function () {
|
||||
if ( typeof pr_dhl_soap_removed_notice === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post( pr_dhl_soap_removed_notice.ajax_url, {
|
||||
action: 'pr_dhl_dismiss_soap_removed_notice',
|
||||
nonce: pr_dhl_soap_removed_notice.nonce,
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
14
dev/dhl-for-woocommerce/assets/js/pr-dhl-notice.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// shorthand no-conflict safe document-ready function
|
||||
jQuery(function($) {
|
||||
$( document ).on( 'click', '#dhl-optin-notice .notice-dismiss', function () {
|
||||
// is being dismissed and send it via AJAX
|
||||
$.ajax( dhl_dismiss_notice.ajax_url,
|
||||
{
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'dhl_dismissed_notice_handler',
|
||||
security: dhl_dismiss_notice.security,
|
||||
}
|
||||
} );
|
||||
} );
|
||||
});
|
||||
82
dev/dhl-for-woocommerce/assets/js/pr-dhl-paket-order-bulk.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
( function( $ ) {
|
||||
var posts_filter = jQuery( '#posts-filter, #wc-orders-filter' );
|
||||
|
||||
var wc_dhl_paket_order_bulk = {
|
||||
// init Class
|
||||
init: function() {
|
||||
posts_filter.on( 'change', '#bulk-action-selector-top', this.toggle_paket_pickup_modal );
|
||||
posts_filter.on( 'change', '#bulk-action-selector-bottom', this.toggle_paket_pickup_modal );
|
||||
posts_filter.on( 'click', '.button.action', this.disable_submit_button );
|
||||
|
||||
$( '#dhl-paket-action-request-pickup' )
|
||||
.on( 'change', '[name=pr_dhl_request_pickup_modal]', this.show_hide_request_pickup_date_asap );
|
||||
this.show_hide_request_pickup_date_asap();
|
||||
|
||||
$( '#dhl-paket-action-request-pickup')
|
||||
.on( 'click', '#pr_dhl_pickup_proceed', this.submit_paket_pickup_modal );
|
||||
|
||||
},
|
||||
|
||||
disable_submit_button: function( evt ) {
|
||||
var bulkactions = jQuery( this ).closest( '.bulkactions' );
|
||||
var bulkdropdown = bulkactions.find( 'select[name=action]' );
|
||||
|
||||
if ( 'pr_dhl_create_labels' === bulkdropdown.val() || 'pr_dhl_delete_labels' === bulkdropdown.val() ) {
|
||||
jQuery( this ).prop( 'disabled', true );
|
||||
posts_filter.submit();
|
||||
}
|
||||
},
|
||||
|
||||
toggle_paket_pickup_modal: function( evt ){
|
||||
evt.preventDefault();
|
||||
|
||||
var value = jQuery( this ).val();
|
||||
var title = jQuery(':selected', this ).text();
|
||||
|
||||
if( 'pr_dhl_request_pickup' == value ){
|
||||
|
||||
// Show thickbox modal.
|
||||
tb_show( "", '/?TB_inline=true&width=320&height=290&inlineId=dhl-paket-pickup-modal' );
|
||||
jQuery("#TB_window #TB_ajaxWindowTitle").text(title); // Set title
|
||||
|
||||
}else{
|
||||
jQuery('#TB_closeWindowButton').click();
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
show_hide_request_pickup_date_asap: function () {
|
||||
var pickup_checked = $( '#dhl-paket-action-request-pickup [name=pr_dhl_request_pickup_modal]:checked' ).val();
|
||||
|
||||
//console.log('pickup_checked: '+ pickup_checked );
|
||||
|
||||
if ( pickup_checked == 'date' ) {
|
||||
$( '#dhl-paket-action-request-pickup #pr_dhl_request_pickup_date_modal').prop('disabled', false);
|
||||
$( '#dhl-paket-action-request-pickup .pr_dhl_request_pickup_date_field').show();
|
||||
} else {
|
||||
$( '#dhl-paket-action-request-pickup #pr_dhl_request_pickup_date_modal').prop('disabled', 'disabled');
|
||||
$( '#dhl-paket-action-request-pickup .pr_dhl_request_pickup_date_field').hide();
|
||||
}
|
||||
},
|
||||
|
||||
submit_paket_pickup_modal: function( evt ){
|
||||
evt.preventDefault();
|
||||
|
||||
var elemModal = jQuery('#dhl-paket-action-request-pickup');
|
||||
|
||||
var pickup_type = elemModal.find( 'input[name=pr_dhl_request_pickup_modal]:checked' ).val();
|
||||
var pickup_date = elemModal.find( 'input[name=pr_dhl_request_pickup_date_modal]' ).val();
|
||||
|
||||
jQuery('#posts-filter [name=dhlpickup], #wc-orders-filter [name=dhlpickup]').val(pickup_type);
|
||||
jQuery('#posts-filter [name=dhlpickup_d],#wc-orders-filter [name=dhlpickup_d]').val(pickup_date);
|
||||
|
||||
//Submit bulk action
|
||||
jQuery('#posts-filter #doaction, #wc-orders-filter #doaction').first().click();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
wc_dhl_paket_order_bulk.init();
|
||||
|
||||
} )( jQuery );
|
||||
183
dev/dhl-for-woocommerce/assets/js/pr-dhl-paket-settings.js
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
jQuery( document ).ready( function () {
|
||||
|
||||
var dhl_settings = {
|
||||
// init Class
|
||||
init: function () {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_map_type' ).on( 'change', this.display_api_key_field )
|
||||
this.display_api_key_field()
|
||||
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_display_google_maps' ).on( 'change', this.display_map_fields )
|
||||
this.display_map_fields()
|
||||
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_split_return_label' ).on( 'change', this.display_return_label_email_fields )
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_email_return_label' ).on( 'change', this.display_return_label_email_fields )
|
||||
this.display_return_label_email_fields()
|
||||
},
|
||||
|
||||
display_return_label_email_fields: function () {
|
||||
var split_enabled = jQuery( '#woocommerce_pr_dhl_paket_dhl_split_return_label' ).is( ':checked' )
|
||||
var email_checkbox = jQuery( '#woocommerce_pr_dhl_paket_dhl_email_return_label' )
|
||||
var email_select_row = jQuery( '#woocommerce_pr_dhl_paket_dhl_email_return_label_email' ).closest( 'tr' )
|
||||
|
||||
// Emailing the return label needs the separate return label PDF, so it can
|
||||
// only be enabled when "Save the return label as a separate PDF" is on.
|
||||
if ( split_enabled ) {
|
||||
email_checkbox.prop( 'disabled', false )
|
||||
} else {
|
||||
email_checkbox.prop( 'checked', false ).prop( 'disabled', true )
|
||||
}
|
||||
|
||||
if ( email_checkbox.is( ':checked' ) ) {
|
||||
email_select_row.show()
|
||||
} else {
|
||||
email_select_row.hide()
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
display_api_key_field: function () {
|
||||
var value = jQuery( '#woocommerce_pr_dhl_paket_dhl_map_type' ).val()
|
||||
if ( 'osm' === value ) {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_google_maps_api_key' ).closest( 'tr' ).hide()
|
||||
} else {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_google_maps_api_key' ).closest( 'tr' ).show()
|
||||
}
|
||||
},
|
||||
|
||||
display_map_fields: function () {
|
||||
if ( jQuery( '#woocommerce_pr_dhl_paket_dhl_display_google_maps' ).is( ':checked' ) ) {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_map_type' ).closest( 'tr' ).show()
|
||||
if ( 'gmaps' === jQuery( '#woocommerce_pr_dhl_paket_dhl_map_type' ).val() ) {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_google_maps_api_key' ).closest( 'tr' ).show()
|
||||
}
|
||||
} else {
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_map_type' ).closest( 'tr' ).hide()
|
||||
jQuery( '#woocommerce_pr_dhl_paket_dhl_google_maps_api_key' ).closest( 'tr' ).hide()
|
||||
}
|
||||
},
|
||||
}
|
||||
dhl_settings.init()
|
||||
|
||||
var sandbox_checkbox = jQuery( '#woocommerce_pr_dhl_paket_dhl_sandbox' )
|
||||
DHLSandboxEnabled( sandbox_checkbox )
|
||||
|
||||
sandbox_checkbox.on( 'click', function ( evt ) {
|
||||
DHLSandboxEnabled( jQuery( this ) )
|
||||
} )
|
||||
|
||||
var logo_checkbox = jQuery( '#woocommerce_pr_dhl_paket_dhl_add_logo' )
|
||||
DHLLogoEnabled( logo_checkbox )
|
||||
|
||||
logo_checkbox.on( 'click', function ( evt ) {
|
||||
DHLLogoEnabled( jQuery( this ) )
|
||||
} )
|
||||
|
||||
DHLPaketMenuBuilder()
|
||||
} )
|
||||
|
||||
function DHLLogoEnabled( logo_checkbox ) {
|
||||
var shipper_reference = jQuery( '#woocommerce_pr_dhl_paket_dhl_shipper_reference' )
|
||||
var tr_shipper_ref = shipper_reference.closest( 'tr' )
|
||||
|
||||
if ( logo_checkbox.prop( 'checked' ) == true ) {
|
||||
|
||||
tr_shipper_ref.show()
|
||||
|
||||
} else {
|
||||
|
||||
tr_shipper_ref.hide()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function DHLSandboxEnabled( sandbox_checkbox ) {
|
||||
var api_settings_username = jQuery( '#woocommerce_pr_dhl_paket_dhl_api_user' )
|
||||
var api_settings_password = jQuery( '#woocommerce_pr_dhl_paket_dhl_api_pwd' )
|
||||
var account_number = jQuery( '#woocommerce_pr_dhl_paket_dhl_account_num' )
|
||||
|
||||
if ( sandbox_checkbox.prop( 'checked' ) === true ) {
|
||||
api_settings_username.prop( 'readonly', true )
|
||||
api_settings_password.prop( 'readonly', true )
|
||||
account_number.prop( 'readonly', true )
|
||||
} else {
|
||||
api_settings_username.prop( 'readonly', false )
|
||||
api_settings_password.prop( 'readonly', false )
|
||||
account_number.prop( 'readonly', false )
|
||||
}
|
||||
}
|
||||
|
||||
function DHLPaketMenuBuilder() {
|
||||
var dhlpaket_settings_menu_collection = []
|
||||
var dhlpaket_tab_menu_container = jQuery( '.dhlpaket_tab_menu' )
|
||||
|
||||
jQuery( document.body ).on( 'dhlpaket:init_settings_menu', function () {
|
||||
jQuery( '#dhlpaket_shipping_method_settings' ).find( 'h3' ).each( function ( e ) {
|
||||
var tab_item = jQuery( '<a href="#" id="dhlpaket_tab_menu_item_' + e + '" class="dhlpaket_tab_menu_item">' + jQuery( this ).text() + '</a>' )
|
||||
dhlpaket_tab_menu_container.append( tab_item )
|
||||
|
||||
var dhlpaket_settings = {
|
||||
title: jQuery( this ),
|
||||
tab_item: dhlpaket_tab_menu_container.find( '#dhlpaket_tab_menu_item_' + e ),
|
||||
description: jQuery( this ).nextAll( 'p:first' ),
|
||||
settings: jQuery( this ).nextAll( 'table:first' )
|
||||
}
|
||||
|
||||
dhlpaket_settings.title.attr( 'data-index', e )
|
||||
dhlpaket_settings.tab_item.attr( 'data-index', e )
|
||||
dhlpaket_settings.description.attr( 'data-index', e )
|
||||
dhlpaket_settings.settings.attr( 'data-index', e )
|
||||
|
||||
// Add to collection
|
||||
dhlpaket_settings_menu_collection[e] = dhlpaket_settings
|
||||
|
||||
// Add triggers
|
||||
dhlpaket_settings.tab_item.hover( function () {
|
||||
jQuery( document.body ).trigger( 'dhlpaket:highlight_menu', [jQuery( this ).data( 'index' )] )
|
||||
}, function () {
|
||||
jQuery( document.body ).trigger( 'dhlpaket:unhighlight_menu', [jQuery( this ).data( 'index' )] )
|
||||
} )
|
||||
|
||||
dhlpaket_settings.description.hover( function () {
|
||||
jQuery( document.body ).trigger( 'dhlpaket:highlight_menu', [jQuery( this ).data( 'index' )] )
|
||||
}, function () {
|
||||
jQuery( document.body ).trigger( 'dhlpaket:unhighlight_menu', [jQuery( this ).data( 'index' )] )
|
||||
} )
|
||||
|
||||
dhlpaket_settings.tab_item.on( 'click', function ( e ) {
|
||||
e.preventDefault()
|
||||
|
||||
jQuery( document.body ).trigger( 'dhlpaket:deselect_settings' )
|
||||
jQuery( document.body ).trigger( 'dhlpaket:select_settings', [jQuery( this ).data( 'index' )] )
|
||||
} )
|
||||
|
||||
dhlpaket_settings.description.on( 'click', function () {
|
||||
jQuery( document.body ).trigger( 'dhlpaket:deselect_settings' )
|
||||
jQuery( document.body ).trigger( 'dhlpaket:select_settings', [jQuery( this ).data( 'index' )] )
|
||||
} )
|
||||
} )
|
||||
|
||||
// Select first setting
|
||||
jQuery( document.body ).trigger( 'dhlpaket:deselect_settings' )
|
||||
jQuery( document.body ).trigger( 'dhlpaket:select_settings', [0] )
|
||||
} ).on( 'dhlpaket:highlight_menu', function () {
|
||||
|
||||
} ).on( 'dhlpaket:unhighlight_menu', function () {
|
||||
|
||||
} ).on( 'dhlpaket:deselect_settings', function () {
|
||||
jQuery.each( dhlpaket_settings_menu_collection, function ( e, dhlpaket_settings ) {
|
||||
dhlpaket_settings.tab_item.removeClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings.title.removeClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings.description.removeClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings.settings.removeClass( 'dhlpaket-active' )
|
||||
} )
|
||||
} ).on( 'dhlpaket:select_settings', function ( e, index ) {
|
||||
dhlpaket_settings_menu_collection[index].tab_item.addClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings_menu_collection[index].title.addClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings_menu_collection[index].description.addClass( 'dhlpaket-active' )
|
||||
dhlpaket_settings_menu_collection[index].settings.addClass( 'dhlpaket-active' )
|
||||
// Sending out event for other scripts
|
||||
jQuery( document.body ).trigger( 'dhlpaket:settings_clicked', [dhlpaket_settings_menu_collection[index].title.attr( 'id' )] )
|
||||
} )
|
||||
|
||||
jQuery( document.body ).trigger( 'dhlpaket:init_settings_menu' )
|
||||
}
|
||||
36
dev/dhl-for-woocommerce/assets/js/pr-dhl-product-list.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
jQuery(function(){
|
||||
jQuery('#the-list').on('click', '.editinline', function(){
|
||||
|
||||
/**
|
||||
* Extract metadata and put it as the value for the custom field form
|
||||
*/
|
||||
inlineEditPost.revert();
|
||||
|
||||
var post_id = jQuery(this).closest('tr').attr('id');
|
||||
|
||||
post_id = post_id.replace("post-", "");
|
||||
|
||||
var dhl_hs_code_inline_data = jQuery('#dhl_hs_code_inline_' + post_id),
|
||||
dhl_hs_manuf_country_inline_data = jQuery('#dhl_manufacture_country_inline_' + post_id),
|
||||
$wc_inline_data = jQuery('#woocommerce_inline_' + post_id );
|
||||
|
||||
jQuery('input[name="change_dhl_hs_code"]', '.inline-edit-row').val(dhl_hs_code_inline_data.find("#dhl_hs_code").text());
|
||||
console.log( dhl_hs_manuf_country_inline_data.find('#dhl_manufacture_country').text() );
|
||||
jQuery('select.change_dhl_manufacture_country option', '.inline-edit-row').each(function(){
|
||||
|
||||
jQuery( this ).removeAttr('selected');
|
||||
|
||||
if( jQuery(this).prop('value') == dhl_hs_manuf_country_inline_data.find('#dhl_manufacture_country').text() ){
|
||||
jQuery( this ).attr('selected', 'selected' );
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Only show custom field for appropriate types of products (simple)
|
||||
*/
|
||||
//var product_type = $wc_inline_data.find('.product_type').text();
|
||||
|
||||
jQuery('.dhl_hs_code_inline', '.inline-edit-row').show();
|
||||
jQuery('.dhl_manufacture_country_inline', '.inline-edit-row').show();
|
||||
|
||||
});
|
||||
});
|
||||
44
dev/dhl-for-woocommerce/assets/js/pr-dhl-test-connection.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Ajax call to sync orders!
|
||||
*/
|
||||
function dhlTestConnection(btn_id) {
|
||||
var $ = jQuery;
|
||||
var btn = $(btn_id);
|
||||
|
||||
// Remove elements after button
|
||||
btn.nextAll().remove();
|
||||
|
||||
btn.attr('disabled', true);
|
||||
btn.text('Testing Connection...');
|
||||
|
||||
var loaderContainer = $('<span/>', {
|
||||
'class': 'loader-image-container'
|
||||
}).insertAfter(btn);
|
||||
|
||||
var loader = $('<img/>', {
|
||||
src: dhl_test_con_obj.loader_image,
|
||||
'class': 'loader-image'
|
||||
}).appendTo(loaderContainer);
|
||||
|
||||
var data = {
|
||||
'action': 'test_dhl_connection',
|
||||
'test_con_nonce': dhl_test_con_obj.test_con_nonce
|
||||
};
|
||||
|
||||
// We can also pass the url value separately from ajaxurl for front end AJAX implementations
|
||||
$.post(dhl_test_con_obj.ajax_url, data, function(response) {
|
||||
btn.attr('disabled', false);
|
||||
btn.text(response.button_txt);
|
||||
loaderContainer.remove();
|
||||
|
||||
var success = response.connection_success;
|
||||
var test_connection_class = 'dhl_connection_' + (success ? 'succeeded' : 'error');
|
||||
var test_connection_text = success ? response.connection_success : response.connection_error;
|
||||
|
||||
loaderContainer = $('<span/>', {
|
||||
'class': test_connection_class
|
||||
}).insertAfter(btn);
|
||||
|
||||
loaderContainer.append(test_connection_text);
|
||||
});
|
||||
}
|
||||
89
dev/dhl-for-woocommerce/assets/js/pr-dhl-wizard.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
|
||||
jQuery( document ).ready( function(){
|
||||
var wizard_overlay = jQuery( '.pr-dhl-wc-wizard-overlay' );
|
||||
|
||||
if ( 1 > wizard_overlay.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let args = {
|
||||
"wz_nav_style": "dots", // dots, tabs, progress
|
||||
"wz_ori" : "horizontal",
|
||||
"buttons": true,
|
||||
"navigation": 'all', // buttons, nav, all
|
||||
"next": '<span class="dashicons dashicons-arrow-right-alt2"></span>',
|
||||
"prev": '<span class="dashicons dashicons-arrow-left-alt2"></span>',
|
||||
};
|
||||
|
||||
const wizard = new Wizard(args);
|
||||
|
||||
wizard.init();
|
||||
|
||||
wizard_overlay.find( '#wizard_dhl_participation_V01PAK' ).on( 'change', function( evt ){
|
||||
var participant_value = jQuery( this ).val();
|
||||
wizard_overlay.find( '.wizard-dhl-field.participation-field' ).val( participant_value );
|
||||
} );
|
||||
|
||||
jQuery( document ).on( 'nextWizard', pr_dhl_wizard_update_fields );
|
||||
|
||||
jQuery( document ).on( 'submitWizard', function (e) {
|
||||
jQuery( 'p.submit button.woocommerce-save-button' ).click();
|
||||
});
|
||||
|
||||
var close_button = jQuery( '.pr-dhl-wc-skip-wizard' );
|
||||
close_button.on( 'click', function( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
wizard_overlay.addClass( 'hidden' );
|
||||
} );
|
||||
|
||||
var next_buttons = jQuery(".button-next");
|
||||
next_buttons.on( 'click', pr_dhl_wizard_next_button );
|
||||
|
||||
var finish_button = jQuery(".button-finish");
|
||||
finish_button.on( 'click', pr_dhl_wizard_finish_button );
|
||||
});
|
||||
|
||||
function pr_dhl_wizard_next_button( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
pr_dhl_wizard_update_fields();
|
||||
|
||||
jQuery('.wizard-btn.btn.next').click();
|
||||
}
|
||||
|
||||
function pr_dhl_wizard_finish_button( evt ) {
|
||||
evt.preventDefault();
|
||||
jQuery('.wizard-btn.btn.finish').click();
|
||||
jQuery( 'p.submit button.woocommerce-save-button' ).click();
|
||||
}
|
||||
|
||||
function pr_dhl_wizard_update_fields() {
|
||||
|
||||
var active_wizard = jQuery( '.wizard-content .wizard-step.active' );
|
||||
var active_fields = active_wizard.find( '.wizard-dhl-field' );
|
||||
|
||||
var field_values = [];
|
||||
|
||||
active_fields.each( function( idx ) {
|
||||
var field = jQuery( this );
|
||||
var field_name = field.prop( 'name' );
|
||||
var field_value = field.val();
|
||||
|
||||
field_values.push( {
|
||||
'name': field_name,
|
||||
'value': field_value
|
||||
} );
|
||||
} );
|
||||
|
||||
for( var idx = 0; idx < field_values.length; idx++ ) {
|
||||
var field_name = field_values[ idx ].name;
|
||||
var field_value = field_values[ idx ].value;
|
||||
var field = jQuery( '#woocommerce_pr_dhl_paket_' + field_name );
|
||||
|
||||
if ( 0 < field.length ) {
|
||||
field.val( field_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
600
dev/dhl-for-woocommerce/assets/js/pr-dhl.js
Normal file
|
|
@ -0,0 +1,600 @@
|
|||
jQuery( function( $ ) {
|
||||
|
||||
var wc_shipment_dhl_label_items = {
|
||||
|
||||
// init Class
|
||||
init: function() {
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'click', '#dhl-label-button', this.save_dhl_label );
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'click', 'a#dhl_delete_label', this.delete_dhl_label );
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_return_address_enabled', this.show_hide_return );
|
||||
wc_shipment_dhl_label_items.show_hide_return();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_identcheck', this.show_hide_ident );
|
||||
wc_shipment_dhl_label_items.show_hide_ident();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_routing', this.show_hide_routing);
|
||||
wc_shipment_dhl_label_items.show_hide_routing();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_product', this.validate_product_return )
|
||||
.on( 'change', '#pr_dhl_product', this.enable_disable_paket_international_fields )
|
||||
.on( 'change', '#pr_dhl_product', this.enable_disable_signature_service )
|
||||
.on( 'change', '#pr_dhl_product', this.enable_disable_mrn );
|
||||
|
||||
wc_shipment_dhl_label_items.enable_disable_paket_international_fields();
|
||||
wc_shipment_dhl_label_items.enable_disable_signature_service();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', 'select#pr_dhl_total_packages', this.process_package_action );
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_multi_packages_enabled', this.show_hide_packages );
|
||||
wc_shipment_dhl_label_items.show_hide_packages();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_PDDP', this.enable_disable_duties );
|
||||
wc_shipment_dhl_label_items.enable_disable_duties();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_duties', this.show_hide_incoterm_tax_id );
|
||||
wc_shipment_dhl_label_items.show_hide_incoterm_tax_id();
|
||||
|
||||
$( '#woocommerce-shipment-dhl-label' )
|
||||
.on( 'change', '#pr_dhl_tax_id_type', this.show_hide_tax_id );
|
||||
wc_shipment_dhl_label_items.show_hide_tax_id();
|
||||
$( '#_shipping_country' ).on( 'change', this.enable_disable_mrn );
|
||||
wc_shipment_dhl_label_items.enable_disable_mrn();
|
||||
|
||||
},
|
||||
|
||||
// Extract the entries for the given package attribute
|
||||
get_package_array: function($form, attrib) {
|
||||
var $element = $form.find('input[name="pr_dhl_packages_'+attrib+'[]"]');
|
||||
var result = [];
|
||||
|
||||
if ('undefined' !== typeof $element && $element) {
|
||||
result = $element.map(function() {
|
||||
return $(this).val();
|
||||
}).get();
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
// Extract all user inputted packages. Retrieving all available
|
||||
// package info or attributes.
|
||||
get_packages_for_saving: function($form, required) {
|
||||
var total = $form.find('select#pr_dhl_total_packages').val();
|
||||
var packages = [],
|
||||
error = false,
|
||||
invalid_number = false;
|
||||
|
||||
var numbers = this.get_package_array($form, 'number');
|
||||
var weights = this.get_package_array($form, 'weight');
|
||||
var lengths = this.get_package_array($form, 'length');
|
||||
var widths = this.get_package_array($form, 'width');
|
||||
var heights = this.get_package_array($form, 'height');
|
||||
|
||||
for (var i=0; i<parseInt(total); i++) {
|
||||
if (required) {
|
||||
if (!numbers[i].length || !weights[i].length || !lengths[i].length || !widths[i].length || !heights[i].length) {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packages.push({
|
||||
number: numbers[i], weight: weights[i], length: lengths[i], width: widths[i], height: heights[i]
|
||||
});
|
||||
}
|
||||
|
||||
if (invalid_number) {
|
||||
return 'invalid_number';
|
||||
}
|
||||
|
||||
return (!error) ? packages : false;
|
||||
},
|
||||
|
||||
// Process the cloning (adding) and removing of package entries based
|
||||
// on the total packages selected by the user.
|
||||
process_package_action: function() {
|
||||
var old_value = $(this).data('current');
|
||||
var value = $(this).val();
|
||||
var $container = $('.total_packages_container');
|
||||
|
||||
if (parseInt(old_value) < parseInt(value)) {
|
||||
var new_value = parseInt(value) - parseInt(old_value);
|
||||
var $clone, $package_number, new_number;
|
||||
|
||||
for (var i=0; i<new_value; i++) {
|
||||
$clone = $container.find('.package_item:last').clone();
|
||||
$package_number = parseInt($clone.find('.package_number > input').data('sequence'));
|
||||
new_number = parseInt($package_number)+1;
|
||||
|
||||
// We'll update both the cache and DOM to make sure that we get
|
||||
// the expected behaviour when pulling the sequence number for processing.
|
||||
$clone.find('.package_number > input').attr('data-sequence', new_number); // this updates the DOM
|
||||
$clone.find('.package_number > input').data('sequence', new_number); // this updates the jquery cache
|
||||
|
||||
$clone.find('.package_number > input').val(new_number);
|
||||
$clone.find('.package_item_field.clearable > input').val('');
|
||||
$container.append($clone);
|
||||
}
|
||||
} else {
|
||||
$container.find('.package_item').slice(value).remove();
|
||||
}
|
||||
|
||||
$(this).data('current', value);
|
||||
},
|
||||
|
||||
validate_product_return: function () {
|
||||
var selected_product = $( '#pr_dhl_product' ).val();
|
||||
|
||||
if( selected_product != 'V01PAK' && selected_product != 'V01PRIO' ) {
|
||||
$('#pr_dhl_return_address_enabled').prop('checked', false).trigger('change');
|
||||
$('#pr_dhl_return_address_enabled').prop('disabled', 'disabled');
|
||||
} else {
|
||||
$('#pr_dhl_return_address_enabled').removeAttr('disabled');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
show_hide_return: function () {
|
||||
var is_checked = $( '#pr_dhl_return_address_enabled' ).prop('checked');
|
||||
|
||||
$( '.shipment-dhl-row-return-addr' ).children().each( function () {
|
||||
|
||||
// If class exists, and is not 'pr_dhl_return_address_enabled' but is 'pr_dhl_return_' field
|
||||
if( ( $(this).attr("class") ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_return_address_enabled') == -1 ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_return') >= 0 )
|
||||
) {
|
||||
|
||||
if ( is_checked ) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
show_hide_tax_id: function () {
|
||||
var tax_id_type = $('select#pr_dhl_tax_id_type :selected').val();
|
||||
|
||||
// If type is IOSS (DHL), or none selected
|
||||
if ( tax_id_type == '4' || tax_id_type == 'none' || tax_id_type == '' ) {
|
||||
$('.pr_dhl_tax_id_field').hide();
|
||||
$('#pr_dhl_tax_id').val('');
|
||||
} else {
|
||||
$('.pr_dhl_tax_id_field').show();
|
||||
|
||||
// Country specific check based on tax id type selected
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_check_order_country_show_tax_id',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
tax_id_type: tax_id_type
|
||||
};
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
if ( response.hide_tax_id == true ) {
|
||||
$('.pr_dhl_tax_id_field').hide();
|
||||
$('#pr_dhl_tax_id').val('');
|
||||
} else {
|
||||
$('.pr_dhl_tax_id_field').show();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
show_hide_incoterm_tax_id: function () {
|
||||
var incoterm_selected = $('select#pr_dhl_duties :selected').val();
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_check_incoterm_tax_id',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
incoterm: incoterm_selected
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
if ( response.hide_tax_id == true ) {
|
||||
$('.pr_dhl_tax_id_field').hide();
|
||||
$('#pr_dhl_tax_id').val('');
|
||||
} else {
|
||||
$('.pr_dhl_tax_id_field').show();
|
||||
}
|
||||
|
||||
if ( response.hide_tax_type == true ) {
|
||||
$('.pr_dhl_tax_id_type_field').hide();
|
||||
$('#pr_dhl_tax_id_type').val('none');
|
||||
} else {
|
||||
$('.pr_dhl_tax_id_type_field').show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
show_hide_ident: function () {
|
||||
var is_checked = $( '#pr_dhl_identcheck' ).prop('checked');
|
||||
|
||||
$( '.shipment-dhl-row-additional-services' ).children().each( function () {
|
||||
|
||||
// If class exists, and is not 'pr_dhl_return_address_enabled' but is 'pr_dhl_return_' field
|
||||
if( ( $(this).attr("class") ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_identcheck_field ') == -1 ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_identcheck') >= 0 )
|
||||
) {
|
||||
|
||||
if ( is_checked ) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
show_hide_routing: function () {
|
||||
var is_checked = $( '#pr_dhl_routing' ).prop('checked');
|
||||
|
||||
$( '.shipment-dhl-row-additional-services' ).children().each( function () {
|
||||
|
||||
// If class exists, and is not 'pr_dhl_return_address_enabled' but is 'pr_dhl_return_' field
|
||||
if( ( $(this).attr("class") ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_routing_field ') == -1 ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_routing') >= 0 )
|
||||
) {
|
||||
|
||||
if ( is_checked ) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
show_hide_packages: function () {
|
||||
// Only relevant for Paket so check if exists
|
||||
if ( ! $( '#pr_dhl_multi_packages_enabled' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var is_checked = $( '#pr_dhl_multi_packages_enabled' ).prop('checked');
|
||||
|
||||
if ( is_checked ) {
|
||||
$('#pr_dhl_weight').prop('disabled', 'disabled');
|
||||
} else {
|
||||
$('#pr_dhl_weight').removeAttr('disabled');
|
||||
}
|
||||
|
||||
$( '.shipment-dhl-row-packages' ).children().each( function () {
|
||||
// If class exists, and is not 'pr_dhl_multi_packages_enabled' but is 'pr_dhl_total_packages' or 'total_packages_container' fields
|
||||
if( ( $(this).attr("class") ) &&
|
||||
( $(this).attr("class").indexOf('pr_dhl_multi_packages_enabled') == -1 ) &&
|
||||
( ( $(this).attr("class").indexOf('pr_dhl_total_packages') >= 0 ) ||
|
||||
( $(this).attr("class").indexOf('total_packages_container') >= 0 ) )
|
||||
) {
|
||||
|
||||
if ( is_checked ) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
save_dhl_label: function () {
|
||||
|
||||
// loop through inputs within id 'shipment-dhl-label-form'
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_gen_label',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
};
|
||||
|
||||
// In case an error has occured.
|
||||
var abort = false;
|
||||
var $form = $('#shipment-dhl-label-form');
|
||||
$form.each(function(i, div) {
|
||||
|
||||
$(div).find('input').each(function(j, element){
|
||||
if( $(element).attr('type') == 'checkbox' ) {
|
||||
if ( $(element).prop('checked') ) {
|
||||
data[ $(element).attr('name') ] = 'yes';
|
||||
} else {
|
||||
data[ $(element).attr('name') ] = 'no';
|
||||
}
|
||||
} else {
|
||||
var eName = $(element).attr('name');
|
||||
// Do NOT add array inputs here!
|
||||
if (eName.indexOf("[]") == -1) {
|
||||
data[ $(element).attr('name') ] = $(element).val();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(div).find('select').each(function(j, element){
|
||||
data[ $(element).attr('name') ] = $(element).val();
|
||||
});
|
||||
|
||||
$(div).find('textarea').each(function(j, element){
|
||||
data[ $(element).attr('name') ] = $(element).val();
|
||||
});
|
||||
});
|
||||
|
||||
// Since, we're not posting the form directly, rather we're using jquery to pull
|
||||
// the data individually, therefore, we're implementing a personalize API to extract
|
||||
// our packages and add it to the "pr_dhl_packages" field for saving.
|
||||
if( $( '#pr_dhl_multi_packages_enabled' ).prop('checked') ) {
|
||||
|
||||
var packages = wc_shipment_dhl_label_items.get_packages_for_saving($form, true);
|
||||
if (!packages) {
|
||||
alert('It appears that one or more of your packages contains empty information. Please make sure you fill the package number, weight, length, width and height of the package before submitting.');
|
||||
abort = true;
|
||||
} else {
|
||||
if (packages == 'invalid_number') {
|
||||
alert('One or more of your entries contains invalid values. Only numeric values are allowed in the package line items. Please kindly check your entries and try again.');
|
||||
abort = true;
|
||||
} else {
|
||||
|
||||
if (packages.length) {
|
||||
data [ 'pr_dhl_packages_number' ] = wc_shipment_dhl_label_items.get_package_array($form, 'number');
|
||||
data [ 'pr_dhl_packages_weight' ] = wc_shipment_dhl_label_items.get_package_array($form, 'weight');
|
||||
data [ 'pr_dhl_packages_length' ] = wc_shipment_dhl_label_items.get_package_array($form, 'length');
|
||||
data [ 'pr_dhl_packages_width' ] = wc_shipment_dhl_label_items.get_package_array($form, 'width');
|
||||
data [ 'pr_dhl_packages_height' ] = wc_shipment_dhl_label_items.get_package_array($form, 'height');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!abort) {
|
||||
// Remove any errors from last attempt to create label
|
||||
$( '#shipment-dhl-label-form .wc_dhl_error' ).remove();
|
||||
|
||||
$( '#shipment-dhl-label-form' ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
} );
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$( '#shipment-dhl-label-form' ).unblock();
|
||||
if ( response.error ) {
|
||||
$( '#shipment-dhl-label-form' ).append('<p class="wc_dhl_error">' + response.error + '</p>');
|
||||
} else {
|
||||
// Disable all form items
|
||||
$(function(){
|
||||
$('#shipment-dhl-label-form').each(function(i, div) {
|
||||
|
||||
$(div).find('input').each(function(j, element){
|
||||
$(element).prop('disabled', 'disabled');
|
||||
});
|
||||
|
||||
$(div).find('select').each(function(j, element){
|
||||
$(element).prop('disabled', 'disabled');
|
||||
});
|
||||
|
||||
$(div).find('textarea').each(function(j, element){
|
||||
$(element).prop('disabled','disabled');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$( '#dhl-label-button').remove();
|
||||
$( '#shipment-dhl-label-form' ).append(dhl_label_data.print_button);
|
||||
$( '#dhl-label-print').attr("href", response.label_url ); // update new url
|
||||
// Show the separate return label button when the API returned one.
|
||||
// Match by attribute (not #id) so every duplicate is cleared, since
|
||||
// jQuery's #id selector only returns the first matching element.
|
||||
$( "[id='dhl-return-label-print']" ).remove();
|
||||
if ( response.return_label_url ) {
|
||||
$( '#shipment-dhl-label-form' ).append('<a href="' + response.return_label_url + '" id="dhl-return-label-print" class="dhl-return-label-link" download target="_blank">' + dhl_label_data.return_label_text + '</a>');
|
||||
}
|
||||
$( '#shipment-dhl-label-form' ).append(dhl_label_data.delete_label);
|
||||
|
||||
if( response.tracking_note ) {
|
||||
|
||||
$( '#woocommerce-order-notes' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_note',
|
||||
post_id: woocommerce_admin_meta_boxes.post_id,
|
||||
note_type: response.tracking_note_type,
|
||||
note: response.tracking_note,
|
||||
security: woocommerce_admin_meta_boxes.add_order_note_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response_note ) {
|
||||
// alert(response_note);
|
||||
$( 'ul.order_notes' ).prepend( response_note );
|
||||
$( '#woocommerce-order-notes' ).unblock();
|
||||
$( '#add_order_note' ).val( '' );
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).trigger( 'pr_dhl_saved_label' );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
delete_dhl_label: function () {
|
||||
|
||||
$( '#shipment-dhl-label-form .wc_dhl_error' ).remove();
|
||||
|
||||
$( '#shipment-dhl-label-form' ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
} );
|
||||
|
||||
var data = {
|
||||
action: 'wc_shipment_dhl_delete_label',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
pr_dhl_label_nonce: $( '#pr_dhl_label_nonce' ).val()
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$( '#shipment-dhl-label-form' ).unblock();
|
||||
if ( response.error ) {
|
||||
$( '#shipment-dhl-label-form' ).append('<p class="wc_dhl_error">Error: ' + response.error + '</p>');
|
||||
} else {
|
||||
|
||||
$( '#shipment-dhl-label-form .wc_dhl_delete' ).remove();
|
||||
// Enable all form items
|
||||
$(function(){
|
||||
$('#shipment-dhl-label-form').each(function(i, div) {
|
||||
|
||||
$(div).find('input').each(function(j, element){
|
||||
$(element).removeAttr('disabled');
|
||||
});
|
||||
|
||||
$(div).find('select').each(function(j, element){
|
||||
$(element).removeAttr('disabled');
|
||||
});
|
||||
|
||||
$(div).find('textarea').each(function(j, element){
|
||||
$(element).removeAttr('disabled');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
//Check PDDP service
|
||||
wc_shipment_dhl_label_items.enable_disable_paket_international_fields();
|
||||
wc_shipment_dhl_label_items.enable_disable_duties();
|
||||
});
|
||||
|
||||
$( "[id='dhl-label-print']" ).remove();
|
||||
$( "[id='dhl-return-label-print']" ).remove();
|
||||
$( '#shipment-dhl-label-form' ).append(dhl_label_data.main_button);
|
||||
|
||||
if( response.dhl_tracking_num ) {
|
||||
var tracking_note;
|
||||
$('ul.order_notes li').each(function(i) {
|
||||
tracking_note = $(this);
|
||||
tracking_note_html = $(this).html()
|
||||
if (tracking_note_html.indexOf(response.dhl_tracking_num) >= 0) {
|
||||
|
||||
// var tracking_note = $( this ).closest( 'li.tracking_note' );
|
||||
$( tracking_note ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var data_note = {
|
||||
action: 'woocommerce_delete_order_note',
|
||||
note_id: $( tracking_note ).attr( 'rel' ),
|
||||
security: woocommerce_admin_meta_boxes.delete_order_note_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data_note, function() {
|
||||
$( tracking_note ).remove();
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).trigger( 'pr_dhl_deleted_label' );
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
enable_disable_paket_international_fields: function () {
|
||||
var selected_product = $( '#pr_dhl_product' ).val();
|
||||
|
||||
if( 'V53WPAK' === selected_product ) {
|
||||
$('#pr_dhl_PDDP').removeAttr('disabled');
|
||||
$('#pr_dhl_endorsement').removeAttr('disabled');
|
||||
} else {
|
||||
$('#pr_dhl_PDDP').prop('disabled', 'disabled');
|
||||
$('#pr_dhl_PDDP').prop( "checked", false ).change();
|
||||
|
||||
$('#pr_dhl_endorsement').prop('disabled', 'disabled').change();
|
||||
|
||||
$('#pr_dhl_duties').removeAttr('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
enable_disable_duties: function () {
|
||||
// Only relevant for international so check if exists
|
||||
if ( ! $( '#pr_dhl_PDDP' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var is_checked = $( '#pr_dhl_PDDP' ).prop('checked');
|
||||
|
||||
if ( is_checked ) {
|
||||
$('#pr_dhl_duties').prop('disabled', 'disabled');
|
||||
} else {
|
||||
$('#pr_dhl_duties').removeAttr('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
enable_disable_signature_service: function () {
|
||||
// Only relevant for international so check if exists
|
||||
if ( ! $( '#pr_dhl_signature_service' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var selected_product = $( '#pr_dhl_product' ).val();
|
||||
|
||||
if ( 'V01PAK' !== selected_product ) {
|
||||
$('#pr_dhl_signature_service').prop( 'checked', false ).change();
|
||||
$('#pr_dhl_signature_service').prop('disabled', 'disabled');
|
||||
} else {
|
||||
$('#pr_dhl_signature_service').removeAttr('disabled');
|
||||
}
|
||||
},
|
||||
enable_disable_mrn: function () {
|
||||
const mrn_field = $( '#pr_dhl_mrn' );
|
||||
const selected_product = $( '#pr_dhl_product' ).val();
|
||||
const shipping_country = $( '#_shipping_country' ).val().toUpperCase();
|
||||
const is_mrn_required = 'V54EPAK' === selected_product || (
|
||||
'CH' === shipping_country && 'V53WPAK' === selected_product
|
||||
);
|
||||
|
||||
if ( is_mrn_required ) {
|
||||
mrn_field.removeAttr( 'disabled' );
|
||||
} else {
|
||||
mrn_field.val( '' )
|
||||
mrn_field.prop( 'disabled', 'disabled' );
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
wc_shipment_dhl_label_items.init();
|
||||
|
||||
} );
|
||||
1
dev/dhl-for-woocommerce/assets/js/wizard.library.js
Normal file
1
dev/dhl-for-woocommerce/build/index.asset.php
Normal file
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => '32734dcf9d0ad9bf6662');
|
||||
1
dev/dhl-for-woocommerce/build/index.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-data-store', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '537a00d0ad2410375811');
|
||||
|
|
@ -0,0 +1 @@
|
|||
(()=>{"use strict";var e={20:(e,o,l)=>{var t=l(609),r=Symbol.for("react.element"),s=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function a(e,o,l){var t,a={},i=null,n=null;for(t in void 0!==l&&(i=""+l),void 0!==o.key&&(i=""+o.key),void 0!==o.ref&&(n=o.ref),o)s.call(o,t)&&!d.hasOwnProperty(t)&&(a[t]=o[t]);if(e&&e.defaultProps)for(t in o=e.defaultProps)void 0===a[t]&&(a[t]=o[t]);return{$$typeof:r,type:e,key:i,ref:n,props:a,_owner:c.current}}o.jsx=a,o.jsxs=a},609:e=>{e.exports=window.React},848:(e,o,l)=>{e.exports=l(20)}},o={};const l=window.wc.blocksCheckout,t=window.wp.element,r=window.wp.components,s=window.wp.data,c=window.wc.wcBlocksData,d=window.lodash,a=window.wp.i18n;var i=function l(t){var r=o[t];if(void 0!==r)return r.exports;var s=o[t]={exports:{}};return e[t](s,s.exports,l),s.exports}(848);const n=JSON.parse('{"apiVersion":3,"name":"pr-dhl/dhl-closest-drop-point","version":"1.0.0","title":"DHL Order Block","category":"woocommerce","description":"Adds DHL block to checkout.","supports":{"html":false,"align":true,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-order-summary-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"mainTitle":{"type":"string","default":"Closest drop-off point."},"infoText":{"type":"string","default":"Preferred delivery to a parcel shop/parcel locker close to the specified home address."},"homeDeliveryLabel":{"type":"string","default":"Home delivery"},"closestDropPointLabel":{"type":"string","default":"Closest Drop Point"}},"textdomain":"dhl-for-woocommerce","editorStyle":"file:../../../build/style-dhl-closest-drop-point.css"}');(0,l.registerCheckoutBlock)({metadata:n,component:({checkoutExtensionData:e})=>{const{setExtensionData:o}=e,l=prDhlGlobals?.pluginUrl+"/assets/img/dhl-official.png",n=prDhlGlobals.dhlSettings,[p,h]=(0,t.useState)(null),[m,u]=(0,t.useState)("no"),[_,f]=(0,t.useState)(!0),x=n?.closest_drop_point,w=prDhlGlobals?.valid_countries||[],y=(0,s.useSelect)(e=>e(c.CART_STORE_KEY).getCustomerData(),[]),v=y?y.shippingAddress:null,j=(0,t.useCallback)((0,d.debounce)((e,l,t)=>{o(e,l,t)},500),[o]),b=!0===((0,s.useSelect)(e=>e(c.CART_STORE_KEY).getCartData(),[])||{}).needsShipping;return(0,t.useEffect)(()=>v&&x&&w.includes(v.country)?void f(!0):void f(!1),[v,x]),(0,t.useEffect)(()=>{o("pr-dhl","closest_drop_point",m),j("pr-dhl","closest_drop_point",m)},[m]),!1===b?null:_?p?(0,i.jsx)(r.Notice,{status:"error",isDismissible:!1,children:(0,a.__)(p,"dhl-for-woocommerce")}):(0,i.jsx)("table",{className:"dhl-co-table",children:(0,i.jsxs)("tbody",{children:[(0,i.jsx)("tr",{className:"dhl-co-tr dhl-co-tr-first",children:(0,i.jsx)("td",{colSpan:2,children:(0,i.jsx)("img",{src:l,alt:"DHL logo",className:"dhl-co-logo"})})}),(0,i.jsx)("tr",{className:"dhl-co-tr",children:(0,i.jsxs)("th",{colSpan:2,children:[(0,a.__)("Closest drop-off point","dhl-for-woocommerce"),(0,i.jsx)("hr",{})]})}),(0,i.jsx)("tr",{className:"dhl-co-tr",children:(0,i.jsx)("td",{colSpan:2,children:(0,a.__)("Preferred delivery to a parcel shop/parcel locker close to the specified home address","dhl-for-woocommerce")})}),(0,i.jsxs)("tr",{className:"dhl-co-tr",children:[(0,i.jsx)("th",{className:"dhl-cdp",children:(0,a.__)("Delivery option","dhl-for-woocommerce")}),(0,i.jsx)("td",{className:"dhl-cdp",children:(0,i.jsxs)("ul",{className:"dhl-preferred-location",children:[(0,i.jsxs)("li",{children:[(0,i.jsx)("input",{defaultChecked:!0,type:"radio",name:"pr_dhl_cdp_delivery","data-index":0,id:"dhl_home_deliver_option",value:"no",className:"",onChange:e=>u(e.target.value)}),(0,i.jsx)("label",{htmlFor:"dhl_home_deliver_option",children:(0,a.__)("Home delivery","dhl-for-woocommerce")})]}),(0,i.jsxs)("li",{children:[(0,i.jsx)("input",{type:"radio",name:"pr_dhl_cdp_delivery","data-index":0,id:"dhl_cdp_option",value:"yes",className:"",onChange:e=>u(e.target.value)}),(0,i.jsx)("label",{htmlFor:"dhl_cdp_option",children:(0,a.__)("Closest Drop Point","dhl-for-woocommerce")})]})]})})]}),(0,i.jsx)("tr",{className:"dhl-co-tr dhl-co-tr-last",children:(0,i.jsx)("td",{colSpan:2})})]})}):null}})})();
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2a692506e6a18bd4c368');
|
||||
|
|
@ -0,0 +1 @@
|
|||
(()=>{"use strict";var e,o={20:(e,o,r)=>{var t=r(609),l=Symbol.for("react.element"),i=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),n=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};o.jsx=function(e,o,r){var t,a={},c=null,p=null;for(t in void 0!==r&&(c=""+r),void 0!==o.key&&(c=""+o.key),void 0!==o.ref&&(p=o.ref),o)i.call(o,t)&&!s.hasOwnProperty(t)&&(a[t]=o[t]);if(e&&e.defaultProps)for(t in o=e.defaultProps)void 0===a[t]&&(a[t]=o[t]);return{$$typeof:l,type:e,key:c,ref:p,props:a,_owner:n.current}}},407:(e,o,r)=>{r.d(o,{A:()=>l});const t=window.wp.element,l=(0,t.forwardRef)(function({icon:e,size:o=24,...r},l){return(0,t.cloneElement)(e,{width:o,height:o,...r,ref:l})})},427:e=>{e.exports=window.wp.components},540:(e,o,r)=>{var t=r(997),l=r(407),i=r(885);r(723),r(715),r(427),r(703);const n=JSON.parse('{"apiVersion":3,"name":"pr-dhl/dhl-closest-drop-point","version":"1.0.0","title":"DHL Order Block","category":"woocommerce","description":"Adds DHL block to checkout.","supports":{"html":false,"align":true,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-order-summary-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"mainTitle":{"type":"string","default":"Closest drop-off point."},"infoText":{"type":"string","default":"Preferred delivery to a parcel shop/parcel locker close to the specified home address."},"homeDeliveryLabel":{"type":"string","default":"Home delivery"},"closestDropPointLabel":{"type":"string","default":"Closest Drop Point"}},"textdomain":"dhl-for-woocommerce","editorStyle":"file:../../../build/style-dhl-closest-drop-point.css"}');var s=r(848);(0,t.registerBlockType)(n,{icon:{src:(0,s.jsx)(l.A,{icon:i.A})},edit:({attributes:e,setAttributes:o})=>null,save:({attributes:e})=>null})},609:e=>{e.exports=window.React},703:e=>{e.exports=window.wc.wcSettings},715:e=>{e.exports=window.wp.blockEditor},723:e=>{e.exports=window.wp.i18n},848:(e,o,r)=>{e.exports=r(20)},885:(e,o,r)=>{r.d(o,{A:()=>i});var t=r(609);const l=window.wp.primitives,i=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",d:"M5 5.5h14a.5.5 0 01.5.5v1.5a.5.5 0 01-.5.5H5a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 9.232A2 2 0 013 7.5V6a2 2 0 012-2h14a2 2 0 012 2v1.5a2 2 0 01-1 1.732V18a2 2 0 01-2 2H6a2 2 0 01-2-2V9.232zm1.5.268V18a.5.5 0 00.5.5h12a.5.5 0 00.5-.5V9.5h-13z",clipRule:"evenodd"}))},997:e=>{e.exports=window.wp.blocks}},r={};function t(e){var l=r[e];if(void 0!==l)return l.exports;var i=r[e]={exports:{}};return o[e](i,i.exports,t),i.exports}t.m=o,e=[],t.O=(o,r,l,i)=>{if(!r){var n=1/0;for(p=0;p<e.length;p++){for(var[r,l,i]=e[p],s=!0,a=0;a<r.length;a++)(!1&i||n>=i)&&Object.keys(t.O).every(e=>t.O[e](r[a]))?r.splice(a--,1):(s=!1,i<n&&(n=i));if(s){e.splice(p--,1);var c=l();void 0!==c&&(o=c)}}return o}i=i||0;for(var p=e.length;p>0&&e[p-1][2]>i;p--)e[p]=e[p-1];e[p]=[r,l,i]},t.d=(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),(()=>{var e={819:0,350:0};t.O.j=o=>0===e[o];var o=(o,r)=>{var l,i,[n,s,a]=r,c=0;if(n.some(o=>0!==e[o])){for(l in s)t.o(s,l)&&(t.m[l]=s[l]);if(a)var p=a(t)}for(o&&o(r);c<n.length;c++)i=n[c],t.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return t.O(p)},r=globalThis.webpackChunkdhl_for_woocommerce=globalThis.webpackChunkdhl_for_woocommerce||[];r.forEach(o.bind(null,0)),r.push=o.bind(null,r.push.bind(r))})();var l=t.O(void 0,[350],()=>t(540));l=t.O(l)})();
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('lodash', 'react', 'wc-blocks-checkout', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '5eb3c691fbde1bd617f6');
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '134950c0a67cc5535ba1');
|
||||
1
dev/dhl-for-woocommerce/build/pr-dhl-parcel-finder.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
(()=>{"use strict";var e,r={20:(e,r,t)=>{var o=t(609),n=Symbol.for("react.element"),i=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),l=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};r.jsx=function(e,r,t){var o,s={},c=null,p=null;for(o in void 0!==t&&(c=""+t),void 0!==r.key&&(c=""+r.key),void 0!==r.ref&&(p=r.ref),r)i.call(r,o)&&!a.hasOwnProperty(o)&&(s[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===s[o]&&(s[o]=r[o]);return{$$typeof:n,type:e,key:c,ref:p,props:s,_owner:l.current}}},407:(e,r,t)=>{t.d(r,{A:()=>n});const o=window.wp.element,n=(0,o.forwardRef)(function({icon:e,size:r=24,...t},n){return(0,o.cloneElement)(e,{width:r,height:r,...t,ref:n})})},427:e=>{e.exports=window.wp.components},609:e=>{e.exports=window.React},703:e=>{e.exports=window.wc.wcSettings},715:e=>{e.exports=window.wp.blockEditor},723:e=>{e.exports=window.wp.i18n},848:(e,r,t)=>{e.exports=t(20)},885:(e,r,t)=>{t.d(r,{A:()=>i});var o=t(609);const n=window.wp.primitives,i=(0,o.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(n.Path,{fillRule:"evenodd",d:"M5 5.5h14a.5.5 0 01.5.5v1.5a.5.5 0 01-.5.5H5a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 9.232A2 2 0 013 7.5V6a2 2 0 012-2h14a2 2 0 012 2v1.5a2 2 0 01-1 1.732V18a2 2 0 01-2 2H6a2 2 0 01-2-2V9.232zm1.5.268V18a.5.5 0 00.5.5h12a.5.5 0 00.5-.5V9.5h-13z",clipRule:"evenodd"}))},997:e=>{e.exports=window.wp.blocks},998:(e,r,t)=>{var o=t(997),n=t(407),i=t(885);t(723),t(715),t(427),t(703);const l=JSON.parse('{"apiVersion":3,"name":"pr-dhl/dhl-parcel-finder","version":"1.0.0","title":"DHL Order Block","category":"woocommerce","description":"Adds DHL block to checkout.","supports":{"html":false,"align":true,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-contact-information-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"addressType":{"type":"object","default":""},"dhlPostnum":{"type":"string","default":""},"pfPostcode":{"type":"string","default":""},"pfCity":{"type":"string","default":""},"pfAddress":{"type":"string","default":""}},"textdomain":"dhl-for-woocommerce","editorStyle":"file:../../../build/style-dhl-preferred-services.css"}');var a=t(848);(0,o.registerBlockType)(l,{icon:{src:(0,a.jsx)(n.A,{icon:i.A})},edit:({attributes:e,setAttributes:r})=>null,save:({attributes:e})=>null})}},t={};function o(e){var n=t[e];if(void 0!==n)return n.exports;var i=t[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.m=r,e=[],o.O=(r,t,n,i)=>{if(!t){var l=1/0;for(p=0;p<e.length;p++){for(var[t,n,i]=e[p],a=!0,s=0;s<t.length;s++)(!1&i||l>=i)&&Object.keys(o.O).every(e=>o.O[e](t[s]))?t.splice(s--,1):(a=!1,i<l&&(l=i));if(a){e.splice(p--,1);var c=n();void 0!==c&&(r=c)}}return r}i=i||0;for(var p=e.length;p>0&&e[p-1][2]>i;p--)e[p]=e[p-1];e[p]=[t,n,i]},o.d=(e,r)=>{for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={585:0,350:0};o.O.j=r=>0===e[r];var r=(r,t)=>{var n,i,[l,a,s]=t,c=0;if(l.some(r=>0!==e[r])){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(s)var p=s(o)}for(r&&r(t);c<l.length;c++)i=l[c],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return o.O(p)},t=globalThis.webpackChunkdhl_for_woocommerce=globalThis.webpackChunkdhl_for_woocommerce||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})();var n=o.O(void 0,[350],()=>o(998));n=o.O(n)})();
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-data-store', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '98f714c7b31155c6f905');
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '8394bda415ea213e8cb5');
|
||||
3
dev/dhl-for-woocommerce/build/style-index-rtl.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
|
||||
3
dev/dhl-for-woocommerce/build/style-index.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
|
||||
144
dev/dhl-for-woocommerce/includes/REST_API/API_Client.php
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
|
||||
/**
|
||||
* A generic REST API client implementation.
|
||||
*
|
||||
* This class does not expose any public methods. It is intended to be extended to create real client classes,
|
||||
* alleviating most of the work involved in using drivers, auth handlers, creating request and response objects as
|
||||
* well as ensuring proper request URL integrity.
|
||||
*
|
||||
* This class provides the following functionality:
|
||||
* - protected methods for sending GET, POST and DELETE requests
|
||||
* - a base URL property that is prepended to routes before creating and sending requests
|
||||
* - implements usage of a REST API driver for sending requests
|
||||
* - implements optional usage of an auth handler to authorize requests before sending them via the driver
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* class My_API_Client extends API_Client {
|
||||
*
|
||||
* public function do_foo_bar( ) {
|
||||
* $response = $this->post( 'foo/bar, array('some' => 'data') );
|
||||
*
|
||||
* if ($response->status === 200) {
|
||||
* return $response->body;
|
||||
* }
|
||||
*
|
||||
* throw new Exception($response->body->error_msg);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class API_Client
|
||||
{
|
||||
/**
|
||||
* The base URL for the REST API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $base_url;
|
||||
|
||||
/**
|
||||
* The REST API driver to use.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Driver_Interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* The authorization driver to use.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Auth_Interface|null
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $base_url The base URL for the REST API.
|
||||
* @param API_Driver_Interface $driver The REST API driver to use.
|
||||
* @param API_Auth_Interface|null $auth Optional authorization driver to use.
|
||||
*/
|
||||
public function __construct(string $base_url, API_Driver_Interface $driver, ?API_Auth_Interface $auth = null)
|
||||
{
|
||||
$this->base_url = $base_url;
|
||||
$this->driver = $driver;
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
protected function get($route, array $params = [], array $headers = [], array $cookies = [])
|
||||
{
|
||||
return $this->send_request(Request::TYPE_GET, $route, $params, '', $headers, $cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
protected function post($route, $body = '', array $headers = [], array $cookies = [])
|
||||
{
|
||||
return $this->send_request(Request::TYPE_POST, $route, [], $body, $headers, $cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
protected function delete($route, $body = '', array $headers = [], array $cookies = [])
|
||||
{
|
||||
return $this->send_request(Request::TYPE_DELETE, $route, [], $body, $headers, $cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request using the internal driver.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param int $type The request type, either {@link TYPE_GET} or {@link TYPE_POST}.
|
||||
* @param string $route The request route, relative to the REST API's base URL.
|
||||
* @param array $params The GET params for this request.
|
||||
* @param mixed|null $body The body of the request.
|
||||
* @param array $headers The request headers to send.
|
||||
* @param array $cookies The request cookies to send.
|
||||
* @return Response The response.
|
||||
*/
|
||||
protected function send_request(
|
||||
$type,
|
||||
$route,
|
||||
array $params = [],
|
||||
$body = '',
|
||||
array $headers = [],
|
||||
array $cookies = []
|
||||
) {
|
||||
// Generate the full URL and the request object
|
||||
$full_url = URL_Utils::merge_url_and_route($this->base_url, $route);
|
||||
$request = new Request($type, $full_url, $params, $body, $headers, $cookies);
|
||||
|
||||
// If we have an authorization driver, authorize the request
|
||||
if ($this->auth !== null) {
|
||||
$request = $this->auth->authorize($request);
|
||||
}
|
||||
|
||||
// Send the request using the driver and obtain the response
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
295
dev/dhl-for-woocommerce/includes/REST_API/Deutsche_Post/Auth.php
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Deutsche_Post;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\URL_Utils;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* The authorization controller for Deutsche Post.
|
||||
*
|
||||
* The Deutsche Post API requires that requests send an "Authorization: Bearer 123456" header, where "123456" is an
|
||||
* access code. That access code is obtained from the REST API itself by sending the client ID and client secret,
|
||||
* encoded in a base64 string. The REST API should respond with a token, which will contain the code, its expiry,
|
||||
* type, etc.
|
||||
*
|
||||
* So the process for authorization involves first obtaining the token, storing it locally and then using it to
|
||||
* authorize regular REST API requests. This class stores the token in a transient with an expiry time that matches
|
||||
* the expiry time of the token as indicated by the Deutsche Post REST API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see https://api-qa.deutschepost.com/dpi-apidoc/#/reference/authentication/access-token/get-access-token
|
||||
*/
|
||||
class Auth implements API_Auth_Interface
|
||||
{
|
||||
/**
|
||||
* The Deutsche POST route for obtaining an access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const AUTH_ROUTE = 'dpi/v1/auth/accesstoken';
|
||||
|
||||
/**
|
||||
* The Deutsche POST route for revoking an access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const REVOKE_ROUTE = 'dpi/v1/auth/accesstoken/revoke';
|
||||
|
||||
/**
|
||||
* The Deutsche POST header where the client ID and secret are included when fetching the access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_AUTH_CREDENTIALS = 'Authorization';
|
||||
|
||||
/**
|
||||
* The Deutsche POST authorization header where request credentials and access tokens are included.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_AUTH_TOKEN = 'Authorization';
|
||||
|
||||
/**
|
||||
* The Deutsche Post authorization header where the 3rd party vendor ID is included.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_3PV_ID = 'ThirdPartyVendor-ID';
|
||||
|
||||
/**
|
||||
* The Deutsche Post 3rd party vendor ID to include in the corresponding header.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const V_3PV_ID = '3pv_woocommerce';
|
||||
|
||||
/**
|
||||
* The driver to use for obtaining and revoking the access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Driver_Interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* The client's ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $client_id;
|
||||
|
||||
/**
|
||||
* The authentication secret for the client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $client_secret;
|
||||
|
||||
/**
|
||||
* The name of the transient to use for caching the access token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $transient;
|
||||
|
||||
/**
|
||||
* The cached access token.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* The Deutsche Post REST API base URL.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_url;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param API_Driver_Interface $driver The driver to use for obtaining and revoking the access token.
|
||||
* @param string $api_url The Deutsche Post REST API base URL.
|
||||
* @param string $client_id The client's ID.
|
||||
* @param string $client_secret The authentication secret for the client.
|
||||
* @param string $transient The name of the transient to use for caching the access token.
|
||||
*/
|
||||
public function __construct(API_Driver_Interface $driver, $api_url, $client_id, $client_secret, $transient)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->api_url = $api_url;
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->transient = $transient;
|
||||
|
||||
// Load the token from the transient cache
|
||||
$this->load_token();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
// Check if we have a token - a token is ALWAYS needed
|
||||
if (empty($this->token)) {
|
||||
// If not, request one from the REST API
|
||||
$token = $this->request_token();
|
||||
// Cache it for subsequent requests
|
||||
$this->save_token($token);
|
||||
}
|
||||
|
||||
$type = $this->token->token_type;
|
||||
$code = $this->token->access_token;
|
||||
|
||||
$request->headers[static::H_AUTH_TOKEN] = $type.' '.$code;
|
||||
$request->headers[static::H_3PV_ID] = static::V_3PV_ID;
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests an access token from the API.
|
||||
*
|
||||
* Sends the client ID and client secret to the REST API to obtain the access token. The access token is then
|
||||
* used to authorize all other requests.
|
||||
* See https://api-qa.deutschepost.com/dpi-apidoc/#/reference/authentication/access-token/get-access-token
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return object The token object.
|
||||
*
|
||||
* @throws RuntimeException If failed to retrieve the access token.
|
||||
*/
|
||||
public function request_token()
|
||||
{
|
||||
// Base64 encode the "<client_id>:<client_secret>" and send as the "Authorization" header
|
||||
$auth_str_64 = base64_encode($this->client_id.':'.$this->client_secret);
|
||||
$headers = [static::H_AUTH_CREDENTIALS => 'Basic '.$auth_str_64];
|
||||
|
||||
// Prepare the full request URL
|
||||
$full_url = URL_Utils::merge_url_and_route($this->api_url, static::AUTH_ROUTE);
|
||||
|
||||
// Send the authorization request to obtain the access token
|
||||
$request = new Request(Request::TYPE_GET, $full_url, [], '', $headers);
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
// If the status code is not 200, throw an error with the raw response body
|
||||
if ($response->status !== 200) {
|
||||
$response_body = json_decode($response->body);
|
||||
throw new RuntimeException(esc_html($response_body->detail));
|
||||
}
|
||||
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes the access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return string The response body.
|
||||
*/
|
||||
public function revoke()
|
||||
{
|
||||
// Do nothing if we didn't already have a token
|
||||
if (empty($this->token) || empty($this->token->access_token)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Prepare the full request URL
|
||||
$full_url = URL_Utils::merge_url_and_route($this->api_url, static::REVOKE_ROUTE);
|
||||
// Create the request
|
||||
$params = ['token' => $this->token->access_token];
|
||||
$request = new Request(Request::TYPE_GET, $full_url, $params);
|
||||
|
||||
// Send the request
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
if ($response->status !== 200 && $response->status !== 401) {
|
||||
throw new RuntimeException('Failed to revoke the Deutsche Post access token');
|
||||
}
|
||||
|
||||
// Delete the cached token
|
||||
$this->delete_token();
|
||||
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with a given client ID and secret.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $client_id The client ID.
|
||||
* @param string $client_secret The client secret.
|
||||
* @return object
|
||||
*/
|
||||
public function test_connection($client_id, $client_secret)
|
||||
{
|
||||
// Backup the client credentials
|
||||
$backup_client_id = $this->client_id;
|
||||
$backup_client_secret = $this->client_secret;
|
||||
|
||||
// Set params as credentials
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
|
||||
// Send the request
|
||||
$token = $this->request_token();
|
||||
|
||||
// Restore the credentials
|
||||
$this->client_id = $backup_client_id;
|
||||
$this->client_secret = $backup_client_secret;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the access token.
|
||||
*
|
||||
* @param object $token The token to save.
|
||||
*/
|
||||
public function save_token($token)
|
||||
{
|
||||
$expires_in = isset($token->expires_in)
|
||||
? $token->expires_in
|
||||
: time() + DAY_IN_SECONDS;
|
||||
|
||||
set_transient($this->transient, $token, $expires_in);
|
||||
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the access token.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function load_token()
|
||||
{
|
||||
return $this->token = get_transient($this->transient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the cached access token.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function delete_token()
|
||||
{
|
||||
return delete_transient($this->transient);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,465 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Deutsche_Post;
|
||||
|
||||
use Exception;
|
||||
use PR\DHL\REST_API\API_Client;
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* The API client for Deutsche Post.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class Client extends API_Client
|
||||
{
|
||||
/**
|
||||
* The customer EKP.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ekp;
|
||||
|
||||
/**
|
||||
* The contact name to use for creating orders.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contact_name;
|
||||
|
||||
/**
|
||||
* The contact phone number to use for creating orders for "Express" customers
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contact_phone;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $ekp The customer EKP.
|
||||
* @param string $contact_name The contact name to use for creating orders.
|
||||
* @param string $contact_phone The contact phone number to use for creating orders.
|
||||
*/
|
||||
public function __construct($ekp, $contact_name, $contact_phone, $base_url, API_Driver_Interface $driver, ?API_Auth_Interface $auth = null)
|
||||
{
|
||||
parent::__construct($base_url, $driver, $auth);
|
||||
|
||||
$this->ekp = $ekp;
|
||||
$this->contact_name = $contact_name;
|
||||
$this->contact_phone = $contact_phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an item on the remote API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param Item_Info $item_info The information of the item to be created.
|
||||
* @return stdClass The item information as returned by the remote API.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create_item(Item_Info $item_info)
|
||||
{
|
||||
// Prepare the request route and data
|
||||
$route = $this->customer_route('items');
|
||||
$data = $this->item_info_to_request_data($item_info);
|
||||
|
||||
// Send the request and get the response
|
||||
$response = $this->post($route, $data);
|
||||
|
||||
// Return the response body on success
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
// Otherwise throw an exception using the response's error messages
|
||||
$message = ! empty($response->body->messages)
|
||||
? implode(', ', $response->body->messages)
|
||||
: strval($response->body);
|
||||
|
||||
throw new Exception(
|
||||
// Translators: %s is the error message from the API.
|
||||
sprintf(esc_html__('API error: %s', 'dhl-for-woocommerce'), esc_html($message))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item from the remote API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param int $item_id The ID of the item to delete.
|
||||
* @return stdClass The response.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete_item($item_id)
|
||||
{
|
||||
// Compute the route to the API endpoint
|
||||
$route = $this->customer_route('items/'.$item_id);
|
||||
|
||||
// Send the DELETE request
|
||||
$response = $this->delete($route);
|
||||
|
||||
// Return the response body on success
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
// Otherwise throw an exception using the response's error messages
|
||||
$message = ! empty($response->body->messages)
|
||||
? implode(', ', $response->body->messages)
|
||||
: strval($response->body);
|
||||
|
||||
throw new Exception(
|
||||
// Translators: %s is the error message from the API.
|
||||
sprintf(esc_html__('API error: %s', 'dhl-for-woocommerce'), esc_html($message))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the label for a DHL item, by its barcode.
|
||||
*
|
||||
* @param string $item_barcode The barcode of the item whose label to retrieve.
|
||||
* @return string The raw PDF data for the item's label.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get_item_label($item_barcode)
|
||||
{
|
||||
$route = sprintf('items/%s/label', $item_barcode);
|
||||
|
||||
$response = $this->get(
|
||||
$this->customer_route($route),
|
||||
[],
|
||||
[
|
||||
'Accept' => 'application/pdf',
|
||||
]
|
||||
);
|
||||
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
$message = ! empty($response->body->messages)
|
||||
? implode(', ', $response->body->messages)
|
||||
: strval($response->body);
|
||||
|
||||
throw new Exception(
|
||||
// Translators: %s is the error message from the API.
|
||||
sprintf(esc_html__('API error: %s', 'dhl-for-woocommerce'), esc_html($message))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves items from the remote API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return array The list of items.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get_items()
|
||||
{
|
||||
$response = $this->get($this->customer_route('items'));
|
||||
|
||||
if ($response->status === 200) {
|
||||
return (array) $response->body;
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
// Translators: %s is the error message from the API.
|
||||
esc_html__('Failed to get items from the API: %s', 'dhl-for-woocommerce'),
|
||||
esc_html(implode(', ', $response->body->messages))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current DHL order, or an existing one if an ID is given.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param int|null $orderId Optional DHL order ID.
|
||||
* @return array
|
||||
*/
|
||||
public function get_order($orderId = null)
|
||||
{
|
||||
$current = get_option('pr_dhl_dp_order', $this->get_default_order_info());
|
||||
|
||||
if (empty($orderId)) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
return get_option('pr_dhl_dp_order_'.$orderId, $current);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the current DHL order.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $item_barcode The barcode of the item to add.
|
||||
* @param string $wc_order The ID of the WooCommerce order.
|
||||
*/
|
||||
public function add_item_to_order($item_barcode, $wc_order)
|
||||
{
|
||||
$order = $this->get_order();
|
||||
|
||||
$order['items'][$item_barcode] = $wc_order;
|
||||
|
||||
update_option('pr_dhl_dp_order', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the current DHL order.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $item_barcode The barcode of the item to add.
|
||||
*/
|
||||
public function remove_item_from_order($item_barcode)
|
||||
{
|
||||
$order = $this->get_order();
|
||||
|
||||
unset($order['items'][$item_barcode]);
|
||||
|
||||
update_option('pr_dhl_dp_order', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the current order.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function reset_current_order()
|
||||
{
|
||||
update_option('pr_dhl_dp_order', $this->get_default_order_info());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Deutsche Post order for the current local order of items.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return object The response data.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create_order($copy_count = 1)
|
||||
{
|
||||
$order = $this->get_order();
|
||||
$items = $order['items'];
|
||||
$barcodes = array_keys($items);
|
||||
$copy_count = intval($copy_count);
|
||||
|
||||
$route = $this->customer_route('orders');
|
||||
$data = [
|
||||
'itemBarcodes' => $barcodes,
|
||||
'paperwork' => [
|
||||
'awbCopyCount' => $copy_count,
|
||||
'contactName' => $this->contact_name,
|
||||
'telephoneNumber' => $this->contact_phone,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->post($route, $data);
|
||||
|
||||
if ($response->status === 200) {
|
||||
$this->close_order($response->body);
|
||||
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
// Translators: %s is the error message from the API.
|
||||
esc_html__('Failed to create order: %s', 'dhl-for-woocommerce'),
|
||||
esc_html(implode(', ', $response->body->messages))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the current order with information received from the REST API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param object $info The information received from the REST API.
|
||||
*/
|
||||
protected function close_order($info)
|
||||
{
|
||||
// Get the current order from the options
|
||||
$order = $this->get_order();
|
||||
// Save the response info in the order
|
||||
$order['id'] = $info->orderId;
|
||||
$order['shipments'] = $info->shipments;
|
||||
// Save the order status if it's given
|
||||
if (! empty($info->orderStatus)) {
|
||||
$order['status'] = $info->orderStatus;
|
||||
}
|
||||
// Save the order in a new option
|
||||
update_option('pr_dhl_dp_order_'.$info->orderId, $order);
|
||||
// Reset the current order
|
||||
$this->reset_current_order();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the label for a given AWB
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $awb The AWB of the shipment.
|
||||
* @return string The raw PDF data for the AWB label.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get_awb_label($awb)
|
||||
{
|
||||
$response = $this->get(
|
||||
sprintf('dpi/shipping/v1/shipments/%s/awblabels', $awb),
|
||||
[],
|
||||
[
|
||||
'Accept' => 'application/pdf',
|
||||
]
|
||||
);
|
||||
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
$message = ! empty($response->body->messages)
|
||||
? implode(', ', $response->body->messages)
|
||||
: strval($response->body);
|
||||
|
||||
throw new Exception(
|
||||
// Translators: %s is the error message from the API.
|
||||
sprintf(esc_html__('API error: %s', 'dhl-for-woocommerce'), esc_html($message))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves tracking info for a shipment by its AWB
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $awb The AWB of the shipment.
|
||||
* @return object The tracking info as returned by the remote API.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get_shipment_tracking_info($awb)
|
||||
{
|
||||
$response = $this->get(sprintf('dpi/tracking/v1/trackings/awb/%s', $awb));
|
||||
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
$message = ! empty($response->body->messages)
|
||||
? implode(', ', $response->body->messages)
|
||||
: strval($response->body);
|
||||
|
||||
throw new Exception(
|
||||
// Translators: %s is the error message from the API.
|
||||
sprintf(esc_html__('API error: %s', 'dhl-for-woocommerce'), esc_html($message))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an item info object into a request data array.
|
||||
*
|
||||
* @param Item_Info $item_info The item info object to transform.
|
||||
* @return array The request data for the given item info object.
|
||||
*/
|
||||
protected function item_info_to_request_data(Item_Info $item_info)
|
||||
{
|
||||
$contents = [];
|
||||
foreach ($item_info->contents as $content_info) {
|
||||
|
||||
$item_desc = $content_info['description'];
|
||||
if (! empty($content_info['description_export'])) {
|
||||
$item_desc = $content_info['description_export'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'contentPieceAmount' => $content_info['qty'],
|
||||
'contentPieceDescription' => $item_desc,
|
||||
'contentPieceIndexNumber' => $content_info['product_id'],
|
||||
'contentPieceNetweight' => $content_info['weight'],
|
||||
'contentPieceOrigin' => $content_info['origin'],
|
||||
'contentPieceValue' => $content_info['value'],
|
||||
'contentPieceHsCode' => trim($content_info['hs_code']),
|
||||
];
|
||||
// Only include HS code if it's not empty
|
||||
if (empty($data['contentPieceHsCode'])) {
|
||||
unset($data['contentPieceHsCode']);
|
||||
}
|
||||
$contents[] = $data;
|
||||
}
|
||||
|
||||
return [
|
||||
'serviceLevel' => $item_info->shipment['service_level'],
|
||||
'product' => $item_info->shipment['product'],
|
||||
'custRef' => $item_info->shipment['label_ref'],
|
||||
'custRef2' => $item_info->shipment['label_ref_2'],
|
||||
'shipmentAmount' => $item_info->shipment['value'],
|
||||
'shipmentCurrency' => $item_info->shipment['currency'],
|
||||
'shipmentGrossWeight' => $item_info->shipment['weight'],
|
||||
'shipmentNaturetype' => $item_info->shipment['nature_type'],
|
||||
'returnItemWanted' => $item_info->shipment['packet_return'],
|
||||
'importerTaxId' => $item_info->shipment['importer_taxid'],
|
||||
'senderTaxId' => $item_info->shipment['sender_taxid'],
|
||||
'recipient' => $item_info->recipient['name'],
|
||||
'recipientPhone' => $item_info->recipient['phone'],
|
||||
'recipientEmail' => $item_info->recipient['email'],
|
||||
'addressLine1' => $item_info->recipient['address_1'],
|
||||
'addressLine2' => $item_info->recipient['address_2'],
|
||||
'city' => $item_info->recipient['city'],
|
||||
'postalCode' => $item_info->recipient['postcode'],
|
||||
'state' => $item_info->recipient['state'],
|
||||
'destinationCountry' => $item_info->recipient['country'],
|
||||
'contents' => $contents,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_order_info()
|
||||
{
|
||||
return [
|
||||
'id' => null,
|
||||
'status' => null,
|
||||
'items' => [],
|
||||
'shipments' => [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an API route with the customer namespace and EKP.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $route The route to prepare.
|
||||
* @return string
|
||||
*/
|
||||
protected function customer_route($route)
|
||||
{
|
||||
return sprintf('dpi/shipping/v1/customers/%s/%s', $this->ekp, $route);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,401 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Deutsche_Post;
|
||||
|
||||
use Exception;
|
||||
use PR\DHL\Utils\Args_Parser;
|
||||
|
||||
/**
|
||||
* A class that represents a Deutsche Post item, which corresponds to a WooCommerce order.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class Item_Info
|
||||
{
|
||||
/**
|
||||
* The array of shipment information.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $shipment;
|
||||
|
||||
/**
|
||||
* The array of order recipient information.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $recipient;
|
||||
|
||||
/**
|
||||
* The array of content item information sub-arrays.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
public $contents;
|
||||
|
||||
/**
|
||||
* The units of measurement used for weights in the input args.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $weightUom;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array $args The arguments to parse.
|
||||
* @param string $weightUom The units of measurement used for weights in the input args.
|
||||
*
|
||||
* @throws Exception If some data in $args did not pass validation.
|
||||
*/
|
||||
public function __construct($args, $weightUom = 'g')
|
||||
{
|
||||
$this->weightUom = $weightUom;
|
||||
$this->parse_args($args, $weightUom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the arguments and sets the instance's properties.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array $args The arguments to parse.
|
||||
*
|
||||
* @throws Exception If some data in $args did not pass validation.
|
||||
*/
|
||||
protected function parse_args($args)
|
||||
{
|
||||
$settings = $args['dhl_settings'];
|
||||
$recipient_info = $args['shipping_address'] + $settings;
|
||||
$shipping_info = $args['order_details'] + $settings;
|
||||
$items_info = $args['items'];
|
||||
|
||||
$this->shipment = Args_Parser::parse_args($shipping_info, $this->get_shipment_info_schema());
|
||||
$this->recipient = Args_Parser::parse_args($recipient_info, $this->get_recipient_info_schema());
|
||||
$this->contents = [];
|
||||
|
||||
$this->contents = [];
|
||||
foreach ($items_info as $item_info) {
|
||||
$this->contents[] = Args_Parser::parse_args($item_info, $this->get_content_item_info_schema());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the args scheme to use with {@link Args_Parser} for parsing shipment info.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_shipment_info_schema()
|
||||
{
|
||||
// Closures in PHP 5.3 do not inherit class context
|
||||
// So we need to copy $this into a lexical variable and pass it to closures manually
|
||||
$self = $this;
|
||||
|
||||
return [
|
||||
'dhl_label_ref' => [
|
||||
'rename' => 'label_ref',
|
||||
'sanitize' => function ($label_ref) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($label_ref, 28);
|
||||
},
|
||||
],
|
||||
'dhl_label_ref_2' => [
|
||||
'rename' => 'label_ref_2',
|
||||
'sanitize' => function ($label_ref_2) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($label_ref_2, 28);
|
||||
},
|
||||
],
|
||||
'dhl_product' => [
|
||||
'rename' => 'product',
|
||||
'error' => esc_html__('DHL "Product" is empty!', 'dhl-for-woocommerce'),
|
||||
'sanitize' => function ($product) {
|
||||
|
||||
$product_info = explode('-', $product);
|
||||
$product = $product_info[0];
|
||||
|
||||
return $product;
|
||||
},
|
||||
],
|
||||
'dhl_service_level' => [
|
||||
'rename' => 'service_level',
|
||||
'default' => 'PRIORITY',
|
||||
'validate' => function ($level) {
|
||||
if ($level !== 'STANDARD' && $level !== 'PRIORITY' && $level !== 'REGISTERED') {
|
||||
throw new Exception(esc_html__('Order "Service Level" is invalid', 'dhl-for-woocommerce'));
|
||||
}
|
||||
},
|
||||
],
|
||||
'weight' => [
|
||||
'error' => esc_html__('Order "Weight" is empty!', 'dhl-for-woocommerce'),
|
||||
'validate' => function ($weight) {
|
||||
if (! is_numeric(wc_format_decimal($weight))) {
|
||||
throw new Exception(esc_html__('The order "Weight" must be a number', 'dhl-for-woocommerce'));
|
||||
}
|
||||
},
|
||||
'sanitize' => function ($weight) use ($self) {
|
||||
$weight = $self->maybe_convert_to_grams($weight, $self->weightUom);
|
||||
|
||||
return $weight;
|
||||
},
|
||||
],
|
||||
'currency' => [
|
||||
'error' => esc_html__('Shop "Currency" is empty!', 'dhl-for-woocommerce'),
|
||||
],
|
||||
'total_value' => [
|
||||
'rename' => 'value',
|
||||
'error' => esc_html__('Shipment "Value" is empty!', 'dhl-for-woocommerce'),
|
||||
'validate' => function ($value) {
|
||||
if (! is_numeric($value)) {
|
||||
throw new Exception(esc_html__('The order "value" must be a number', 'dhl-for-woocommerce'));
|
||||
}
|
||||
},
|
||||
'sanitize' => function ($value) use ($self) {
|
||||
|
||||
return $self->float_round_sanitization($value, 2);
|
||||
},
|
||||
],
|
||||
'nature_type' => [
|
||||
'rename' => 'nature_type',
|
||||
'default' => 'SALE_GOODS',
|
||||
],
|
||||
'packet_return' => [
|
||||
'default' => false,
|
||||
'sanitize' => function ($return) {
|
||||
|
||||
return ($return == 'yes') ? true : false;
|
||||
},
|
||||
],
|
||||
'importer_taxid' => [
|
||||
'default' => '',
|
||||
'validate' => function ($value) {
|
||||
|
||||
if (! empty($value)) {
|
||||
|
||||
if (! ctype_alnum($value)) {
|
||||
throw new Exception(esc_html__('The importer customs reference "value" must be an alphanumeric', 'dhl-for-woocommerce'));
|
||||
}
|
||||
|
||||
if (strlen($value) > 35) {
|
||||
throw new Exception(esc_html__('The importer customs reference "value" must be between 1 and 35 characters long', 'dhl-for-woocommerce'));
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
'sender_taxid' => [
|
||||
'default' => '',
|
||||
'validate' => function ($value) {
|
||||
|
||||
if (! empty($value)) {
|
||||
|
||||
if (! ctype_alnum($value)) {
|
||||
throw new Exception(esc_html__('The sender customs reference "value" must be an alphanumeric', 'dhl-for-woocommerce'));
|
||||
}
|
||||
|
||||
if (strlen($value) > 35) {
|
||||
throw new Exception(esc_html__('The sender customs reference "value" must be between 1 and 35 characters long', 'dhl-for-woocommerce'));
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the args scheme to use with {@link Args_Parser} for parsing order recipient info.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_recipient_info_schema()
|
||||
{
|
||||
|
||||
// Closures in PHP 5.3 do not inherit class context
|
||||
// So we need to copy $this into a lexical variable and pass it to closures manually
|
||||
$self = $this;
|
||||
|
||||
return [
|
||||
'name' => [
|
||||
'default' => '',
|
||||
'error' => esc_html__('Recipient is empty!', 'dhl-for-woocommerce'),
|
||||
'sanitize' => function ($name) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($name, 30);
|
||||
},
|
||||
],
|
||||
'phone' => [
|
||||
'default' => '',
|
||||
'sanitize' => function ($phone) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($phone, 15);
|
||||
},
|
||||
],
|
||||
'email' => [
|
||||
'default' => '',
|
||||
],
|
||||
'address_1' => [
|
||||
'error' => esc_html__('Shipping "Address 1" is empty!', 'dhl-for-woocommerce'),
|
||||
],
|
||||
'address_2' => [
|
||||
'default' => '',
|
||||
],
|
||||
'city' => [
|
||||
'error' => esc_html__('Shipping "City" is empty!', 'dhl-for-woocommerce'),
|
||||
],
|
||||
'postcode' => [
|
||||
'default' => '',
|
||||
],
|
||||
'state' => [
|
||||
'default' => '',
|
||||
],
|
||||
'country' => [
|
||||
'error' => esc_html__('Shipping "Country" is empty!', 'dhl-for-woocommerce'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the args scheme to use with {@link Args_Parser} for parsing order content item info.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_content_item_info_schema()
|
||||
{
|
||||
// Closures in PHP 5.3 do not inherit class context
|
||||
// So we need to copy $this into a lexical variable and pass it to closures manually
|
||||
$self = $this;
|
||||
|
||||
return [
|
||||
'hs_code' => [
|
||||
'default' => '',
|
||||
'validate' => function ($hs_code) {
|
||||
$length = is_string($hs_code) ? strlen($hs_code) : 0;
|
||||
|
||||
if (empty($length)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($length < 4 || $length > 20) {
|
||||
throw new Exception(
|
||||
esc_html__('Item HS Code must be between 4 and 20 characters long', 'dhl-for-woocommerce')
|
||||
);
|
||||
}
|
||||
},
|
||||
],
|
||||
'item_description' => [
|
||||
'rename' => 'description',
|
||||
'default' => '',
|
||||
'sanitize' => function ($description) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($description, 33);
|
||||
},
|
||||
],
|
||||
'item_export' => [
|
||||
'rename' => 'description_export',
|
||||
'default' => '',
|
||||
'sanitize' => function ($description_export) use ($self) {
|
||||
|
||||
return $self->string_length_sanitization($description_export, 33);
|
||||
},
|
||||
],
|
||||
'product_id' => [
|
||||
'default' => '',
|
||||
],
|
||||
'sku' => [
|
||||
'default' => '',
|
||||
],
|
||||
'item_value' => [
|
||||
'rename' => 'value',
|
||||
'default' => 0,
|
||||
'sanitize' => function ($value, $args) use ($self) {
|
||||
|
||||
$qty = isset($args['qty']) && is_numeric($args['qty']) ? floatval($args['qty']) : 1;
|
||||
$total_value = floatval($value) * $qty;
|
||||
|
||||
return (string) $self->float_round_sanitization($total_value, 2);
|
||||
},
|
||||
],
|
||||
'country_origin' => [
|
||||
'rename' => 'origin',
|
||||
'default' => PR_DHL()->get_base_country(),
|
||||
],
|
||||
'qty' => [
|
||||
'default' => 1,
|
||||
],
|
||||
'item_weight' => [
|
||||
'rename' => 'weight',
|
||||
'default' => 1,
|
||||
'sanitize' => function ($weight) use ($self) {
|
||||
|
||||
$weight = $self->maybe_convert_to_grams($weight, $self->weightUom);
|
||||
|
||||
return $weight;
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given weight into grams, if necessary.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param float $weight The weight amount.
|
||||
* @param string $uom The unit of measurement of the $weight parameter..
|
||||
* @return float The potentially converted weight.
|
||||
*/
|
||||
protected function maybe_convert_to_grams($weight, $uom)
|
||||
{
|
||||
$weight = floatval(wc_format_decimal($weight));
|
||||
|
||||
switch ($uom) {
|
||||
case 'kg':
|
||||
$weight = $weight * 1000;
|
||||
break;
|
||||
case 'lb':
|
||||
$weight = $weight / 2.2;
|
||||
break;
|
||||
case 'oz':
|
||||
$weight = $weight / 35.274;
|
||||
break;
|
||||
}
|
||||
|
||||
return round($weight);
|
||||
}
|
||||
|
||||
protected function float_round_sanitization($float, $numcomma)
|
||||
{
|
||||
|
||||
$float = round(floatval($float), $numcomma);
|
||||
|
||||
return number_format($float, 2, '.', '');
|
||||
}
|
||||
|
||||
protected function string_length_sanitization($string, $max)
|
||||
{
|
||||
|
||||
$max = intval($max);
|
||||
|
||||
if (strlen($string) <= $max) {
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
return substr($string, 0, ($max - 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Drivers;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\Response;
|
||||
|
||||
/**
|
||||
* A REST API driver decorator that automatically encodes/decodes JSON in POST requests/responses respectively.
|
||||
*
|
||||
* This is a REST API driver DECORATOR class, which means that it is not a standalone driver but instead decorates
|
||||
* another driver. It does so to add JSON encoding and parsing functionality to that "inner" driver.
|
||||
*
|
||||
* It ensures that the necessary headers are sent to the remote resource that indicate that the content body is a
|
||||
* JSON string and it also ensures that incoming responses are correctly parsed as JSON strings if the remote
|
||||
* resource indicates that it is such.
|
||||
*
|
||||
* For more information on REST API drivers, refer to the documentation for the {@link API_Driver_Interface}.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see API_Driver_Interface
|
||||
*/
|
||||
class JSON_API_Driver implements API_Driver_Interface
|
||||
{
|
||||
/**
|
||||
* The HTTP content type header.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_CONTENT_TYPE = 'Content-Type';
|
||||
|
||||
/**
|
||||
* The HTTP content type acceptance header.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_ACCEPT = 'Accept';
|
||||
|
||||
/**
|
||||
* The HTTP content length header.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const H_CONTENT_LENGTH = 'Content-Length';
|
||||
|
||||
/**
|
||||
* The JSON HTTP content type string.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
const JSON_CONTENT_TYPE = 'application/json';
|
||||
|
||||
/**
|
||||
* The driver to decorate.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Driver_Interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param API_Driver_Interface $driver The driver instance to decorate.
|
||||
*/
|
||||
public function __construct(API_Driver_Interface $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Before invoking the inner driver's {@link send()} method, it creates a copy of the request to encode its body,
|
||||
* if necessary, and add the appropriate headers. The response from the inner driver is then decoded, if necessary,
|
||||
* and returned.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function send(Request $request)
|
||||
{
|
||||
// Encode the request before sending it
|
||||
$request = $this->encode_request($request);
|
||||
|
||||
// Delegate the actual sending to the internal driver
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
// Decode the response before returning it
|
||||
$response = $this->decode_response($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the request body into a JSON string and ensures the request headers are correctly set.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param Request $request The request to encode.
|
||||
* @return Request The encoded request.
|
||||
*/
|
||||
protected function encode_request(Request $request)
|
||||
{
|
||||
// Add the header that tells the remote that we accept JSON responses
|
||||
if (empty($request->headers[static::H_ACCEPT])) {
|
||||
$request->headers[static::H_ACCEPT] = static::JSON_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
// For POST requests, encode the body and set the content type and length
|
||||
if ($request->type === Request::TYPE_POST) {
|
||||
$request->body = wp_json_encode($request->body);
|
||||
$request->headers[static::H_CONTENT_TYPE] = static::JSON_CONTENT_TYPE;
|
||||
$request->headers[static::H_CONTENT_LENGTH] = strlen($request->body);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the response is decoded from JSON.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param Response $response The response.
|
||||
* @return Response The decoded response.
|
||||
*/
|
||||
protected function decode_response(Response $response)
|
||||
{
|
||||
// Get the content type header
|
||||
$content_type = isset($response->headers[static::H_CONTENT_TYPE])
|
||||
? $response->headers[static::H_CONTENT_TYPE]
|
||||
: '';
|
||||
|
||||
// If the content type is JSON, decode the body
|
||||
if ($content_type === static::JSON_CONTENT_TYPE) {
|
||||
$response->body = json_decode($response->body);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Drivers;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\Response;
|
||||
use PR_DHL_WC;
|
||||
|
||||
/**
|
||||
* A REST API driver decorator that automatically logs requests and responses.
|
||||
*
|
||||
* This is a REST API driver DECORATOR class, which means that it is not a standalone driver but instead decorates
|
||||
* another driver. It does so to log the parameters and return values of the "inner" driver.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see API_Driver_Interface
|
||||
*/
|
||||
class Logging_Driver implements API_Driver_Interface
|
||||
{
|
||||
/**
|
||||
* The plugin instance.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PR_DHL_WC
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* The driver to decorate.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Driver_Interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PR_DHL_WC $plugin The plugin instance to use for logging.
|
||||
* @param API_Driver_Interface $driver The driver instance to decorate.
|
||||
*/
|
||||
public function __construct(PR_DHL_WC $plugin, API_Driver_Interface $driver)
|
||||
{
|
||||
$this->plugin = $plugin;
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Before invoking the inner driver's {@link send()} method, it logs the request data.
|
||||
* The response returned from the inner driver is also logged, after which it is returned.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function send(Request $request)
|
||||
{
|
||||
// Log the request
|
||||
$this->log_request('Request:', $request);
|
||||
|
||||
// Send the request using the inner driver
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
// Log the response
|
||||
$this->log_response('Response:', $response);
|
||||
|
||||
// Return the response from the inner driver
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a request.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $message Prefix message to include in the log.
|
||||
* @param Request $request The request to log.
|
||||
*/
|
||||
protected function log_request(string $message, Request $request)
|
||||
{
|
||||
$request_info = [
|
||||
'type' => $this->get_request_type_name($request->type),
|
||||
'url' => $request->url,
|
||||
'params' => $request->params,
|
||||
'body' => empty($request->body) ? '' : $request->body,
|
||||
];
|
||||
|
||||
$this->plugin->log_msg(sprintf('%s %s', $message, print_r($request_info, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a response.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $message Prefix message to include in the log.
|
||||
* @param Response $response The response to log.
|
||||
*/
|
||||
protected function log_response(string $message, Response $response)
|
||||
{
|
||||
if (isset($response->headers['Content-Type']) && $response->headers['Content-Type'] === 'application/pdf') {
|
||||
$body = '[PDF data]';
|
||||
} else {
|
||||
$decoded = json_decode($response->body, true);
|
||||
$body = $decoded ?: $response->body;
|
||||
|
||||
// Remove b64 data from response body for cleaner logs.
|
||||
if (is_array($body)) {
|
||||
$body = $this->remove_b64_data($body);
|
||||
}
|
||||
}
|
||||
|
||||
$response_info = [
|
||||
'status' => $response->status,
|
||||
'body' => json_encode($body),
|
||||
];
|
||||
|
||||
$this->plugin->log_msg(sprintf('%s %s', $message, print_r($response_info, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name for a request type.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param int $type The request type. See the constants in the {@link Request} class.
|
||||
* @return string|int The name of the request type, or the parameter if the request type is unknown.
|
||||
*/
|
||||
protected function get_request_type_name($type)
|
||||
{
|
||||
if ($type === Request::TYPE_GET) {
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
if ($type === Request::TYPE_POST) {
|
||||
return 'POST';
|
||||
}
|
||||
|
||||
if ($type === Request::TYPE_DELETE) {
|
||||
return 'DELETE';
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes b64 data from response body to keep logs clean.
|
||||
*
|
||||
* @param array $data The response body array.
|
||||
* @return array The array with b64 data removed.
|
||||
*/
|
||||
protected function remove_b64_data(array $data): array
|
||||
{
|
||||
if (isset($data['items']) && is_array($data['items'])) {
|
||||
foreach ($data['items'] as $item_key => $item) {
|
||||
if (isset($item['label']['b64'])) {
|
||||
$data['items'][$item_key]['label']['b64'] = '[Base64 PDF data removed from log]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Drivers;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\Response;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* A REST API driver that uses WordPress's `wp_remote_*()` functions to make requests to a REST API.
|
||||
*
|
||||
* This is a relatively simply driver that encapsulates WordPress' `wp_remote_*()` family of functions into a driver
|
||||
* class, which can be used by API clients to dispatch request objects to the remote resource and receive full response
|
||||
* objects.
|
||||
*
|
||||
* For more information on REST API drivers, refer to the documentation for the {@link API_Driver_Interface}.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see API_Driver_Interface
|
||||
*/
|
||||
class WP_API_Driver implements API_Driver_Interface
|
||||
{
|
||||
// Set request timeout to 30 seconds, default of 5 is to small
|
||||
const WP_REQUEST_TIMEOUT = 30;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function send(Request $request)
|
||||
{
|
||||
// Send the request
|
||||
$response = wp_remote_request(
|
||||
$request->url,
|
||||
[
|
||||
'method' => $this->get_request_type($request),
|
||||
'body' => $request->body,
|
||||
'headers' => $request->headers,
|
||||
'cookies' => $request->cookies,
|
||||
'timeout' => self::WP_REQUEST_TIMEOUT,
|
||||
'user-agent' => 'WooCommerce/'.WC_VERSION.' (WordPress/'.get_bloginfo('version').') DHL-plug-in/'.PR_DHL_VERSION,
|
||||
]
|
||||
);
|
||||
|
||||
// Check if an error occurred
|
||||
if (is_wp_error($response)) {
|
||||
throw new RuntimeException(esc_html__($response->get_error_message(), 'dhl-for-woocommerce'));
|
||||
}
|
||||
|
||||
// Retrieve the headers from the response
|
||||
$raw_headers = wp_remote_retrieve_headers($response);
|
||||
$headers = [];
|
||||
|
||||
// Ensures that the headers use the correct casing
|
||||
foreach ($raw_headers as $header => $value) {
|
||||
// 1. split the header name by dashes
|
||||
$header_parts = explode('-', $header);
|
||||
// 2. upper-case the first letter of each part
|
||||
$uc_parts = array_map('ucfirst', $header_parts);
|
||||
// 3. combine the parts back again using dashes
|
||||
$fixed_header = implode('-', $uc_parts);
|
||||
|
||||
$headers[$fixed_header] = $value;
|
||||
}
|
||||
|
||||
// Create and return the response object
|
||||
return new Response(
|
||||
$request,
|
||||
wp_remote_retrieve_response_code($response),
|
||||
wp_remote_retrieve_body($response),
|
||||
$headers,
|
||||
wp_remote_retrieve_cookies($response)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Request type.
|
||||
*
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public function get_request_type(Request $request)
|
||||
{
|
||||
if ($request->type === Request::TYPE_GET) {
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
if ($request->type === Request::TYPE_DELETE) {
|
||||
return 'DELETE';
|
||||
}
|
||||
|
||||
return 'POST';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Interfaces;
|
||||
|
||||
use PR\DHL\REST_API\Request;
|
||||
|
||||
/**
|
||||
* Interface for objects that represent REST API authorization handlers.
|
||||
*
|
||||
* Auth handlers are classes that can take a normal request and add authorization and/or authentication information
|
||||
* to it. As such, auth handlers are used by API clients as a "filter"; the client's request is given to the auth
|
||||
* handler, which returns a new request. The client can then give that new request to its driver.
|
||||
*
|
||||
* Typical usage of an auth handler from an API client class:
|
||||
* ```
|
||||
* class Client {
|
||||
* protected $driver;
|
||||
* protected $auth;
|
||||
*
|
||||
* public function lorem_ipsum() {
|
||||
* $request = new Request( ... );
|
||||
* $request = $this->auth->authorize( $request );
|
||||
* $response = $this->driver->send( $request );
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* It's important to note that clients should ALWAYS use the request instance returned by the {@link authorize()}
|
||||
* method and should not assume that the auth handler will modify the request object given as argument. Auth handlers
|
||||
* MAY re-return the argument, but it's not guaranteed. Auth handler implementations are free to manipulate the request
|
||||
* however is necessary - add GET params, POST fields, cookies, headers, etc. - which may at times be easier done by
|
||||
* reusing the argument instance and at other times easier done by creating a brand new request instance.
|
||||
*
|
||||
* It may be the case that REST API authorization depends on some temporary token that is fetched from the REST
|
||||
* API itself. For these cases, auth handlers MAY use a driver to contact the REST API and receive said token(s).
|
||||
* This is best done in the {@link authorize()} method itself, by first checking if such a token needs to be
|
||||
* acquired and if so fetch it and save it.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see Request
|
||||
*/
|
||||
interface API_Auth_Interface
|
||||
{
|
||||
/**
|
||||
* Adds authentication details to a given request.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param Request $request The request to modify with authentication details.
|
||||
* @return Request The new request.
|
||||
*/
|
||||
public function authorize(Request $request);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Interfaces;
|
||||
|
||||
use PR\DHL\REST_API\API_Client;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\Response;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* An interface for objects that act as REST API drivers.
|
||||
*
|
||||
* A driver is simply a class that knows HOW to send requests to a remote API. Given a full {@link Request} object,
|
||||
* it can transmit it over the network to the remote API and then translate the HTTP response into a {@link Response}
|
||||
* object.
|
||||
*
|
||||
* The purpose of this abstraction is to hide the technicalities of how a request is sent, be it via a low level
|
||||
* library such as cURL, or using a framework's API such as WordPress' functions. API client classes should be the
|
||||
* main consumers of this interface.
|
||||
*
|
||||
* Implementing a new driver involves simply implementing the {@link send()} method. The {@link Request} object that is
|
||||
* received as the argument should contain all the necessary information for making the request, such as the full
|
||||
* URL, params, body, headers and cookies. Once the request is sent and a response is received, a {@link Response}
|
||||
* object should be created, containing the response information, and returned. The created response object should also
|
||||
* have a reference to the original request.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see Request
|
||||
* @see Response
|
||||
* @see API_Client
|
||||
*/
|
||||
interface API_Driver_Interface
|
||||
{
|
||||
/**
|
||||
* Sends a generic request to the REST API.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param Request $request The request to send.
|
||||
* @return Response The response.
|
||||
*
|
||||
* @throws RuntimeException If an error occurred and the request could not be sent.
|
||||
*/
|
||||
public function send(Request $request);
|
||||
}
|
||||
153
dev/dhl-for-woocommerce/includes/REST_API/Internetmarke/Auth.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Internetmarke;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
use PR\DHL\REST_API\URL_Utils;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Authorization handler for Deutsche Post INTERNETMARKE.
|
||||
*/
|
||||
class Auth implements API_Auth_Interface
|
||||
{
|
||||
const AUTH_ROUTE = 'user';
|
||||
|
||||
protected $driver;
|
||||
|
||||
protected $api_url;
|
||||
|
||||
protected $client_id;
|
||||
|
||||
protected $client_secret;
|
||||
|
||||
protected $username;
|
||||
|
||||
protected $password;
|
||||
|
||||
protected $transient;
|
||||
|
||||
protected $token;
|
||||
|
||||
public function __construct(API_Driver_Interface $driver, $api_url, $client_id, $client_secret, $username, $password, $transient)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->api_url = $api_url;
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->transient = $transient;
|
||||
|
||||
$this->load_token();
|
||||
}
|
||||
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
if (empty($this->token) || empty($this->token->access_token)) {
|
||||
$this->save_token($this->request_token());
|
||||
}
|
||||
|
||||
$request->headers['Authorization'] = 'Bearer '.$this->token->access_token;
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function test_connection()
|
||||
{
|
||||
return $this->request_token();
|
||||
}
|
||||
|
||||
public function request_token()
|
||||
{
|
||||
$full_url = URL_Utils::merge_url_and_route($this->api_url, static::AUTH_ROUTE);
|
||||
|
||||
$body = [
|
||||
'client_id' => $this->client_id,
|
||||
'client_secret' => $this->client_secret,
|
||||
'username' => $this->username,
|
||||
'password' => $this->password,
|
||||
'grant_type' => 'client_credentials',
|
||||
];
|
||||
|
||||
$request = new Request(
|
||||
Request::TYPE_POST,
|
||||
$full_url,
|
||||
[],
|
||||
$body,
|
||||
[
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'Accept' => 'application/json',
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->driver->send($request);
|
||||
|
||||
if ((int) $response->status !== 200) {
|
||||
$message = $this->extract_error_message($response->body, $response->status);
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
|
||||
$token = is_object($response->body) ? $response->body : json_decode((string) $response->body);
|
||||
|
||||
if (empty($token) || empty($token->access_token)) {
|
||||
throw new RuntimeException(esc_html__('INTERNETMARKE authorization did not return an access token.', 'dhl-for-woocommerce'));
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function save_token($token)
|
||||
{
|
||||
$this->token = $token;
|
||||
|
||||
if (empty($token)) {
|
||||
delete_transient($this->transient);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$expires_in = ! empty($token->expires_in) ? absint($token->expires_in) : HOUR_IN_SECONDS;
|
||||
set_transient($this->transient, $token, $expires_in);
|
||||
}
|
||||
|
||||
public function delete_token()
|
||||
{
|
||||
$this->token = null;
|
||||
delete_transient($this->transient);
|
||||
}
|
||||
|
||||
protected function load_token()
|
||||
{
|
||||
$this->token = get_transient($this->transient);
|
||||
}
|
||||
|
||||
protected function extract_error_message($body, $status)
|
||||
{
|
||||
if (is_string($body)) {
|
||||
$decoded = json_decode($body);
|
||||
} else {
|
||||
$decoded = $body;
|
||||
}
|
||||
|
||||
if (! empty($decoded->detail)) {
|
||||
return sanitize_text_field($decoded->detail);
|
||||
}
|
||||
|
||||
if (! empty($decoded->message)) {
|
||||
return sanitize_text_field($decoded->message);
|
||||
}
|
||||
|
||||
if ((int) $status === 401) {
|
||||
return esc_html__('Authorization failed. Check the INTERNETMARKE credentials and confirm the business application in Portokasse if this is the first API use.', 'dhl-for-woocommerce');
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
/* translators: %d: HTTP response status code. */
|
||||
esc_html__('INTERNETMARKE authorization failed with HTTP %d.', 'dhl-for-woocommerce'),
|
||||
absint($status)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Internetmarke;
|
||||
|
||||
use Exception;
|
||||
use PR\DHL\REST_API\API_Client;
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
|
||||
/**
|
||||
* API client for Deutsche Post INTERNETMARKE.
|
||||
*/
|
||||
class Client extends API_Client
|
||||
{
|
||||
public function __construct($base_url, API_Driver_Interface $driver, ?API_Auth_Interface $auth = null)
|
||||
{
|
||||
parent::__construct($base_url, $driver, $auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout the shopping cart and retrieve the voucher PDF.
|
||||
*
|
||||
* Endpoint verified against the live API: POST /app/shoppingcart/pdf?directCheckout=true
|
||||
* (the previous /orders path does not exist on this API). The JSON_API_Driver
|
||||
* JSON-encodes the payload and decodes the response.
|
||||
*
|
||||
* @param array $payload ShoppingCartPDFRequest payload (pageFormatId, positions, total).
|
||||
* @return object Decoded CheckoutShoppingCartPDFResponse (link, shoppingCart, walletBalance).
|
||||
*
|
||||
* @throws Exception On non-2xx HTTP status.
|
||||
*/
|
||||
public function create_label(array $payload)
|
||||
{
|
||||
$response = $this->post('app/shoppingcart/pdf?directCheckout=true', $payload);
|
||||
|
||||
$status = (int) $response->status;
|
||||
if ($status !== 200 && $status !== 201) {
|
||||
throw new Exception($this->extract_error_message($response->body, $status, 'checkout'));
|
||||
}
|
||||
|
||||
return $this->decode_body($response->body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an already purchased shopping cart by its shop order ID.
|
||||
*
|
||||
* Documented read-only endpoint: GET /app/shoppingcart/{shopOrderId}. It returns
|
||||
* the same CheckoutShoppingCartPDFResponse as the checkout (including the PDF link)
|
||||
* WITHOUT charging the Portokasse again, so it is the safe way to recover a document
|
||||
* whose original link was lost or has expired after a successful purchase.
|
||||
*
|
||||
* @param string $shop_order_id The shopOrderId sent during checkout.
|
||||
* @return object Decoded CheckoutShoppingCartPDFResponse (link, shoppingCart, walletBallance).
|
||||
*
|
||||
* @throws Exception On non-2xx HTTP status.
|
||||
*/
|
||||
public function get_shopping_cart($shop_order_id)
|
||||
{
|
||||
$response = $this->get('app/shoppingcart/'.rawurlencode((string) $shop_order_id));
|
||||
|
||||
$status = (int) $response->status;
|
||||
if ($status !== 200 && $status !== 201) {
|
||||
throw new Exception($this->extract_error_message($response->body, $status, 'retrieve'));
|
||||
}
|
||||
|
||||
return $this->decode_body($response->body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a response body defensively.
|
||||
*
|
||||
* JSON_API_Driver only decodes when the Content-Type is exactly `application/json`.
|
||||
* The INTERNETMARKE gateway may return `application/json;charset=UTF-8`, which leaves
|
||||
* the body a raw JSON string — decode it here so callers always receive an object.
|
||||
* Mirrors the guard already used by Internetmarke\Auth::request_token().
|
||||
*
|
||||
* @param string|object $body Raw or already-decoded response body.
|
||||
* @return object|null Decoded object, or null when the body is not JSON.
|
||||
*/
|
||||
protected function decode_body($body)
|
||||
{
|
||||
return is_object($body) ? $body : json_decode((string) $body);
|
||||
}
|
||||
|
||||
protected function extract_error_message($body, $status, $operation)
|
||||
{
|
||||
if (is_string($body)) {
|
||||
$decoded = json_decode($body);
|
||||
} else {
|
||||
$decoded = $body;
|
||||
}
|
||||
|
||||
// INTERNETMARKE errors carry a machine-readable `title` plus a `description`.
|
||||
if (! empty($decoded->title)) {
|
||||
$friendly = $this->friendly_error($decoded->title);
|
||||
if ($friendly !== '') {
|
||||
return $friendly;
|
||||
}
|
||||
|
||||
$description = ! empty($decoded->description) ? ' ('.sanitize_text_field($decoded->description).')' : '';
|
||||
|
||||
return sanitize_text_field($decoded->title).$description;
|
||||
}
|
||||
|
||||
if (! empty($decoded->detail)) {
|
||||
return sanitize_text_field($decoded->detail);
|
||||
}
|
||||
|
||||
if (! empty($decoded->message)) {
|
||||
return sanitize_text_field($decoded->message);
|
||||
}
|
||||
|
||||
if ((int) $status === 401) {
|
||||
return esc_html__('Authorization failed. Check the INTERNETMARKE credentials and confirm the business application in Portokasse if this is the first API use.', 'dhl-for-woocommerce');
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
/* translators: 1: operation name, 2: HTTP status code. */
|
||||
esc_html__('INTERNETMARKE %1$s request failed with HTTP %2$d.', 'dhl-for-woocommerce'),
|
||||
sanitize_text_field($operation),
|
||||
absint($status)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map known INTERNETMARKE error titles to a human-readable message.
|
||||
*
|
||||
* @param string $title The `title` field from the API error body.
|
||||
* @return string A translated message, or '' if the title is unmapped.
|
||||
*/
|
||||
protected function friendly_error($title)
|
||||
{
|
||||
switch ($title) {
|
||||
case 'walletBalanceNotEnough':
|
||||
return esc_html__('Not enough balance in your Portokasse to buy this label. Please top up your Portokasse account and try again.', 'dhl-for-woocommerce');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
93
dev/dhl-for-woocommerce/includes/REST_API/Paket/Auth.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Paket;
|
||||
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
use PR\DHL\REST_API\Request;
|
||||
|
||||
/**
|
||||
* The authorization controller for DHL Paket
|
||||
*
|
||||
* The DHL Packet requires that requests send an Basic HTTP Authorization, ie. "Authorization: Basic 123456" header, where "123456" is an
|
||||
* base64 encoded username:password (or clientID: clientSecret).
|
||||
*
|
||||
* Also, for Pickup 360, a user/customer username and login must be passed in the header "DPDHL user authentication token" base64 encoded username:password
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see https://entwickler.dhl.de/en/group/ep/authentifizierung6
|
||||
*/
|
||||
class Auth implements API_Auth_Interface
|
||||
{
|
||||
/**
|
||||
* The driver to use for obtaining and revoking the access token.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var API_Driver_Interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* The client's ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $client_id;
|
||||
|
||||
/**
|
||||
* The authentication secret for the client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $client_secret;
|
||||
|
||||
/**
|
||||
* API key provided by DHL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_key;
|
||||
|
||||
/**
|
||||
* The REST API base URL.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_url;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param API_Driver_Interface $driver The driver to use for obtaining and revoking the access token.
|
||||
* @param string $api_url The REST API base URL.
|
||||
* @param string $client_id The client's ID.
|
||||
* @param string $client_secret The authentication secret for the client.
|
||||
* @param string $api_key The API key provided by DHL.
|
||||
*/
|
||||
public function __construct(API_Driver_Interface $driver, $api_url, $client_id, $client_secret, $api_key)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->api_url = $api_url;
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->api_key = $api_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
$request->headers['Authorization'] = 'Basic '.base64_encode($this->client_id.':'.$this->client_secret);
|
||||
$request->headers['dhl-api-key'] = $this->api_key;
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
257
dev/dhl-for-woocommerce/includes/REST_API/Paket/Client.php
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
|
||||
namespace PR\DHL\REST_API\Paket;
|
||||
|
||||
use Exception;
|
||||
use PR\DHL\REST_API\API_Client;
|
||||
use PR\DHL\REST_API\Interfaces\API_Auth_Interface;
|
||||
use PR\DHL\REST_API\Interfaces\API_Driver_Interface;
|
||||
|
||||
/**
|
||||
* The API client for DHL Paket.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class Client extends API_Client
|
||||
{
|
||||
/**
|
||||
* The DHL Customer Portal Username
|
||||
*/
|
||||
protected $customer_portal_user;
|
||||
|
||||
/**
|
||||
* The DHL Customer Portal Password
|
||||
*/
|
||||
protected $customer_portal_password;
|
||||
|
||||
/**
|
||||
* The language of the message
|
||||
*/
|
||||
protected $language = 'en';
|
||||
|
||||
/**
|
||||
* The version of the message
|
||||
*/
|
||||
protected $version = '1';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $customer_portal_user, $customer_portal_password The customer username and password
|
||||
*/
|
||||
public function __construct($customer_portal_user, $customer_portal_password, $base_url, API_Driver_Interface $driver, ?API_Auth_Interface $auth = null)
|
||||
{
|
||||
parent::__construct($base_url, $driver, $auth);
|
||||
|
||||
$this->customer_portal_user = $customer_portal_user;
|
||||
$this->customer_portal_password = $customer_portal_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create pickup_request
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param class $pickup_request_info Pickup_Request_Info
|
||||
*/
|
||||
public function create_pickup_request(Pickup_Request_Info $pickup_request_info)
|
||||
{
|
||||
$route = $this->request_pickup_route();
|
||||
|
||||
// Customer business portal user auth
|
||||
$headers = [
|
||||
'Authorization' => 'Basic '.base64_encode($this->customer_portal_user.':'.$this->customer_portal_password),
|
||||
'dhl-api-key' => defined('PR_DHL_GLOBAL_API') ? PR_DHL_GLOBAL_API : '',
|
||||
];
|
||||
|
||||
$data = $this->request_pickup_info_to_request_data($pickup_request_info);
|
||||
$response = $this->post($route, $data, $headers);
|
||||
|
||||
if ($response->status === 200) {
|
||||
$response->body = json_decode($response->body);
|
||||
if (isset($response->body->confirmation->value->orderID)) {
|
||||
return $response->body;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
wp_kses_post(
|
||||
sprintf(
|
||||
// Translators: %s is replaced with the error details returned from the API.
|
||||
__('Failed DHL Request Pickup1: %s', 'dhl-for-woocommerce'),
|
||||
$this->generate_error_details($response->body)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create get pickup locations request
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get_pickup_location($postalCode = '')
|
||||
{
|
||||
|
||||
$route = $this->get_pickup_location_route();
|
||||
$data = ['postalCode' => $postalCode];
|
||||
$response = $this->get($route, $data);
|
||||
|
||||
if ($response->status === 200) {
|
||||
return $response->body;
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
wp_kses_post(
|
||||
sprintf(
|
||||
// Translators: %s is replaced with the error details returned from the API.
|
||||
__('Failed DHL Request Pickup: %s', 'dhl-for-woocommerce'),
|
||||
$this->generate_error_details($response->body)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function generate_error_details($body)
|
||||
{
|
||||
$error_details = '';
|
||||
|
||||
if (isset($body->title)) {
|
||||
$error_details = $body->title;
|
||||
} elseif (is_string($body)) {
|
||||
$error_details = $body;
|
||||
} elseif (is_array($body)) {
|
||||
$error_details = '<br><ol>';
|
||||
foreach ($body as $error) {
|
||||
$error_details .= '<li>'.$error->title.'</li>';
|
||||
}
|
||||
$error_details .= '</ol>';
|
||||
}
|
||||
|
||||
return $error_details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date time.
|
||||
*
|
||||
* @return string The date and time of the message.
|
||||
*/
|
||||
protected function get_datetime()
|
||||
{
|
||||
return gmdate('c', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message language.
|
||||
*
|
||||
* @return string The language of the message.
|
||||
*/
|
||||
protected function get_language()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message version.
|
||||
*
|
||||
* @return string The version of the message.
|
||||
*/
|
||||
protected function get_version()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an item info object into a request data array.
|
||||
*
|
||||
* @param Pickup_Request_Info $request_pickup_info The item info object to transform.
|
||||
* @return array The request data for the given item info object.
|
||||
*/
|
||||
protected function request_pickup_info_to_request_data(Pickup_Request_Info $request_pickup_info)
|
||||
{
|
||||
// Pickup date
|
||||
if ($request_pickup_info->pickup_details['dhl_pickup_type'] === 'date') {
|
||||
$pickup_date = [
|
||||
'type' => 'Date',
|
||||
'value' => $request_pickup_info->pickup_details['dhl_pickup_date'],
|
||||
];
|
||||
} else {
|
||||
$pickup_date = [
|
||||
'type' => 'ASAP',
|
||||
];
|
||||
}
|
||||
|
||||
// Pickup location & business hours
|
||||
$pickup_location_array = [
|
||||
'type' => 'Address',
|
||||
'pickupAddress' => [
|
||||
'name1' => $request_pickup_info->pickup_contact['name'],
|
||||
'name2' => '',
|
||||
'addressStreet' => $request_pickup_info->pickup_address['addressStreet'],
|
||||
'addressHouse' => $request_pickup_info->pickup_address['addressHouse'],
|
||||
'city' => $request_pickup_info->pickup_address['city'],
|
||||
'postalCode' => $request_pickup_info->pickup_address['postalCode'],
|
||||
'state' => $request_pickup_info->pickup_address['state'],
|
||||
'country' => $request_pickup_info->pickup_address['country'],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($request_pickup_info->shipments as $key => $shipment) {
|
||||
if ($shipment['transportationType'] === 'SPERRGUT') {
|
||||
$request_pickup_info->shipments[$key]['pickupServices']['bulkyGood'] = [
|
||||
'comment' => 'Bulky Goods',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'customerDetails' => [
|
||||
'billingNumber' => $request_pickup_info->customer_details['billingNumber'],
|
||||
],
|
||||
'pickupLocation' => $pickup_location_array,
|
||||
'pickupDetails' => [
|
||||
'pickupDate' => $pickup_date,
|
||||
],
|
||||
'shipmentDetails' => [
|
||||
'shipments' => $request_pickup_info->shipments,
|
||||
],
|
||||
'contactPerson' => [
|
||||
[
|
||||
'name' => $request_pickup_info->pickup_contact['name'],
|
||||
'phone' => $request_pickup_info->pickup_contact['phone'],
|
||||
'email' => $request_pickup_info->pickup_contact['email'],
|
||||
'emailNotification' => [
|
||||
'sendPickupConfirmationEmail' => 'true',
|
||||
'sendPickupTimeWindowEmail' => 'true',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an API route with the customer namespace and EKP.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function request_pickup_route()
|
||||
{
|
||||
return '/orders';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an API route with the customer namespace and EKP.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_pickup_location_route()
|
||||
{
|
||||
return '/locations';
|
||||
}
|
||||
}
|
||||
1683
dev/dhl-for-woocommerce/includes/abstract-pr-dhl-wc-order.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PR_DHL_WC_Product_Editor class file.
|
||||
*/
|
||||
if (! defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface;
|
||||
|
||||
if (! class_exists('PR_DHL_WC_Product_Editor')) {
|
||||
/**
|
||||
* PR_DHL_WC_Product_Editor Class.
|
||||
*/
|
||||
abstract class PR_DHL_WC_Product_Editor
|
||||
{
|
||||
/**
|
||||
* Manufacture country tooltip.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $manufacture_tooltip = '';
|
||||
|
||||
/**
|
||||
* Manufacture country label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $manufacture_country_label = '';
|
||||
|
||||
/**
|
||||
* HS Code label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hs_code_label = '';
|
||||
|
||||
/**
|
||||
* HS Code description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hs_code_description = '';
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_action('woocommerce_block_template_area_product-form_after_add_block_product-shipping-dimensions', [$this, 'add_product_shipping_fields']);
|
||||
add_action('woocommerce_block_template_area_product-form_after_add_block_product-variation-shipping-dimensions', [$this, 'add_product_shipping_fields']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional product fields.
|
||||
*/
|
||||
abstract public function additional_product_fields($parent): void;
|
||||
|
||||
/**
|
||||
* Add DHL product fields.
|
||||
*/
|
||||
public function add_product_shipping_fields(BlockInterface $shipping_dimensions_block): void
|
||||
{
|
||||
if (! method_exists($shipping_dimensions_block, 'get_parent')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parent = $shipping_dimensions_block->get_parent();
|
||||
|
||||
// Add Country of Origin Select Block.
|
||||
$countries = WC()->countries->get_countries();
|
||||
$parent->add_block(
|
||||
[
|
||||
'id' => '_dhl_manufacture_country',
|
||||
'blockName' => 'woocommerce/product-select-field',
|
||||
'attributes' => [
|
||||
'label' => $this->manufacture_country_label,
|
||||
'property' => 'meta_data._dhl_manufacture_country',
|
||||
'options' => array_merge(
|
||||
[
|
||||
[
|
||||
'value' => '0',
|
||||
'label' => __('- select country -', 'dhl-for-woocommerce'),
|
||||
],
|
||||
],
|
||||
array_map(function ($key, $value) {
|
||||
return [
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
];
|
||||
}, array_keys($countries), $countries)
|
||||
),
|
||||
'tooltip' => $this->manufacture_tooltip,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Add HS Tariff Code Text Block.
|
||||
$parent->add_block(
|
||||
[
|
||||
'id' => '_dhl_hs_code',
|
||||
'blockName' => 'woocommerce/product-text-field',
|
||||
'attributes' => [
|
||||
'label' => $this->hs_code_label,
|
||||
'property' => 'meta_data._dhl_hs_code',
|
||||
'placeholder' => esc_html__('HS Code', 'dhl-for-woocommerce'),
|
||||
'tooltip' => $this->hs_code_description,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$this->additional_product_fields($parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
195
dev/dhl-for-woocommerce/includes/abstract-pr-dhl-wc-product.php
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
|
||||
if (! defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce DHL Shipping Order.
|
||||
*
|
||||
* @category Product
|
||||
*
|
||||
* @author Shadi Manna
|
||||
*/
|
||||
if (! class_exists('PR_DHL_WC_Product')) {
|
||||
|
||||
abstract class PR_DHL_WC_Product
|
||||
{
|
||||
protected $manufacture_country_label = '';
|
||||
|
||||
protected $hs_code_label = '';
|
||||
|
||||
protected $hs_code_description = '';
|
||||
|
||||
/**
|
||||
* Init and hook in the integration.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->manufacture_country_label = esc_html__('Country of Manufacture (DHL)', 'dhl-for-woocommerce');
|
||||
$this->hs_code_label = esc_html__('Harmonized Tariff Schedule (DHL)', 'dhl-for-woocommerce');
|
||||
$this->hs_code_description = esc_html__('Harmonized Tariff Schedule is a number assigned to every possible commodity that can be imported or exported from any country.', 'dhl-for-woocommerce');
|
||||
|
||||
// priority is '8' because WC Subscriptions hides fields in the shipping tabs which hide the DHL fields here
|
||||
add_action('woocommerce_product_options_shipping', [$this, 'additional_product_shipping_options'], 8);
|
||||
add_action('woocommerce_process_product_meta', [$this, 'save_additional_product_shipping_options']);
|
||||
add_action('woocommerce_product_bulk_edit_end', [$this, 'product_shipping_bulk_edit_input']);
|
||||
add_action('woocommerce_product_bulk_edit_save', [$this, 'save_product_shipping_bulk_edit']);
|
||||
add_action('woocommerce_product_quick_edit_end', [$this, 'product_shipping_bulk_edit_input']);
|
||||
add_action('woocommerce_product_quick_edit_save', [$this, 'save_product_shipping_bulk_edit']);
|
||||
add_action('manage_product_posts_custom_column', [$this, 'product_shipping_hidden_input_value'], 20, 2);
|
||||
add_action('admin_enqueue_scripts', [$this, 'product_enqueue_scripts'], 20, 1);
|
||||
}
|
||||
|
||||
public function product_enqueue_scripts($hook)
|
||||
{
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ($screen->id == 'edit-product') {
|
||||
|
||||
wp_enqueue_script(
|
||||
'wc-shipment-dhl-product-list-js',
|
||||
PR_DHL_PLUGIN_DIR_URL.'/assets/js/pr-dhl-product-list.js',
|
||||
['jquery'],
|
||||
PR_DHL_VERSION
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the meta box for shipment info on the order page
|
||||
*/
|
||||
public function additional_product_shipping_options()
|
||||
{
|
||||
global $thepostid, $post;
|
||||
|
||||
$thepostid = empty($thepostid) ? $post->ID : $thepostid;
|
||||
|
||||
// $countries_obj = new WC_Countries();
|
||||
// $countries = $countries_obj->esc_html__get('countries');
|
||||
$countries = WC()->countries->get_countries();
|
||||
|
||||
$manufacture_tip = $this->get_manufacture_tooltip();
|
||||
$countries = array_merge(['0' => esc_html__('- select country -', 'dhl-for-woocommerce')], $countries);
|
||||
|
||||
woocommerce_wp_select(
|
||||
[
|
||||
'id' => '_dhl_manufacture_country',
|
||||
'label' => $this->manufacture_country_label,
|
||||
'description' => $manufacture_tip,
|
||||
'desc_tip' => 'true',
|
||||
/* 'value' => $country_value, */
|
||||
'options' => $countries,
|
||||
]
|
||||
);
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
[
|
||||
'id' => '_dhl_hs_code',
|
||||
'label' => $this->hs_code_label,
|
||||
'description' => $this->hs_code_description,
|
||||
'desc_tip' => 'true',
|
||||
'placeholder' => esc_html__('HS Code', 'dhl-for-woocommerce'),
|
||||
]
|
||||
);
|
||||
|
||||
echo '<p class="description" style="margin: -8px 12px 12px;">'.wp_kses_post(
|
||||
sprintf(
|
||||
/* translators: %s is a link to the US HTSUS lookup tool */
|
||||
__('For shipments to the United States, enter the full 10-digit code — %s.', 'dhl-for-woocommerce'),
|
||||
'<a href="https://hts.usitc.gov/" target="_blank" rel="noopener noreferrer">'.esc_html__('look up the HTSUS code', 'dhl-for-woocommerce').'</a>'
|
||||
)
|
||||
).'</p>';
|
||||
|
||||
$this->additional_product_settings();
|
||||
}
|
||||
|
||||
public function product_shipping_bulk_edit_input()
|
||||
{
|
||||
|
||||
$countries = WC()->countries->get_countries();
|
||||
$countries = array_merge(['0' => esc_html__('- No change -', 'dhl-for-woocommerce')], $countries);
|
||||
?>
|
||||
<div class="inline-edit-group dhl_manufacture_country_inline">
|
||||
<label class="alignleft">
|
||||
<span class="title"><?php echo esc_html__('Country of Manufacture (DHL)', 'dhl-for-woocommerce'); ?></span>
|
||||
<span class="input-text-wrap">
|
||||
<select class="change_dhl_manufacture_country change_to" name="change_dhl_manufacture_country">
|
||||
<?php foreach ($countries as $value => $text) { ?>
|
||||
<option value="<?php echo esc_attr($value); ?>"><?php echo esc_attr($text); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="inline-edit-group dhl_hs_code_inline">
|
||||
<label class="alignleft">
|
||||
<span class="title"><?php echo esc_html__('Harmonized Tariff Schedule (DHL)', 'dhl-for-woocommerce'); ?></span>
|
||||
<span class="input-text-wrap">
|
||||
<input type="text" name="change_dhl_hs_code" class="change_dhl_hs_code text" value="" />
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
abstract public function get_manufacture_tooltip();
|
||||
|
||||
abstract public function additional_product_settings();
|
||||
|
||||
public function save_additional_product_shipping_options($post_id)
|
||||
{
|
||||
|
||||
// Country of manufacture
|
||||
if (isset($_POST['_dhl_manufacture_country'])) {
|
||||
update_post_meta($post_id, '_dhl_manufacture_country', wc_clean($_POST['_dhl_manufacture_country']));
|
||||
}
|
||||
|
||||
// HS code value
|
||||
if (isset($_POST['_dhl_hs_code'])) {
|
||||
update_post_meta($post_id, '_dhl_hs_code', wc_clean($_POST['_dhl_hs_code']));
|
||||
}
|
||||
|
||||
$this->save_additional_product_settings($post_id);
|
||||
}
|
||||
|
||||
public function save_product_shipping_bulk_edit($product)
|
||||
{
|
||||
$post_id = $product->get_id();
|
||||
if (! empty($_REQUEST['change_dhl_hs_code'])) {
|
||||
update_post_meta($post_id, '_dhl_hs_code', wc_clean($_REQUEST['change_dhl_hs_code']));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['change_dhl_manufacture_country']) && $_REQUEST['change_dhl_manufacture_country'] != '0') {
|
||||
update_post_meta($post_id, '_dhl_manufacture_country', wc_clean($_REQUEST['change_dhl_manufacture_country']));
|
||||
}
|
||||
}
|
||||
|
||||
public function product_shipping_hidden_input_value($column, $post_id)
|
||||
{
|
||||
switch ($column) {
|
||||
case 'name':
|
||||
?>
|
||||
<div class="hidden dhl_hs_code_inline" id="dhl_hs_code_inline_<?php echo esc_attr($post_id); ?>">
|
||||
<div id="dhl_hs_code"><?php echo esc_html(get_post_meta($post_id, '_dhl_hs_code', true)); ?></div>
|
||||
</div>
|
||||
<div class="hidden dhl_manufacture_country_inline" id="dhl_manufacture_country_inline_<?php echo esc_attr($post_id); ?>">
|
||||
<div id="dhl_manufacture_country"><?php echo esc_html(get_post_meta($post_id, '_dhl_manufacture_country', true)); ?></div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function save_additional_product_settings($post_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
import { useEffect, useState, useCallback } from '@wordpress/element';
|
||||
import { Notice } from '@wordpress/components';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { CART_STORE_KEY } from '@woocommerce/block-data';
|
||||
import { debounce } from 'lodash';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
export const Block = ({ checkoutExtensionData }) => {
|
||||
const { setExtensionData } = checkoutExtensionData;
|
||||
|
||||
// Access the localized data from prDhlGlobals
|
||||
const imgUrl = prDhlGlobals?.pluginUrl + "/assets/img/dhl-official.png";
|
||||
const dhlSettings = prDhlGlobals.dhlSettings;
|
||||
|
||||
const [error, setError] = useState( null );
|
||||
const [closestDP, setClosestDP] = useState('no');
|
||||
const [displayClosest, setDisplayClosest] = useState( true );
|
||||
|
||||
const closestAvailable = dhlSettings?.closest_drop_point;
|
||||
const validCountries = prDhlGlobals?.valid_countries || [];
|
||||
|
||||
|
||||
// Retrieve customer data
|
||||
const customerData = useSelect( ( select ) => select( CART_STORE_KEY ).getCustomerData(), [] );
|
||||
const shippingAddress = customerData ? customerData.shippingAddress : null;
|
||||
|
||||
// Debounce for reducing the number of updates to the extension data
|
||||
const debouncedSetExtensionData = useCallback( debounce( ( namespace, key, value ) => {
|
||||
setExtensionData( namespace, key, value );
|
||||
}, 500 ), [setExtensionData] );
|
||||
|
||||
const cart = useSelect(
|
||||
(select) => select(CART_STORE_KEY).getCartData(),
|
||||
[]
|
||||
) || {};
|
||||
|
||||
const cartNeedsShipping = cart.needsShipping === true;
|
||||
|
||||
useEffect( () => {
|
||||
if (
|
||||
! shippingAddress ||
|
||||
! closestAvailable ||
|
||||
! validCountries.includes( shippingAddress.country )
|
||||
) {
|
||||
setDisplayClosest( false );
|
||||
return;
|
||||
} else {
|
||||
setDisplayClosest( true );
|
||||
return;
|
||||
}
|
||||
|
||||
}, [ shippingAddress, closestAvailable ] );
|
||||
|
||||
// useEffect for closestDP
|
||||
useEffect( () => {
|
||||
setExtensionData( 'pr-dhl', 'closest_drop_point', closestDP );
|
||||
debouncedSetExtensionData( 'pr-dhl', 'closest_drop_point', closestDP );
|
||||
}, [ closestDP ] );
|
||||
|
||||
if ( cartNeedsShipping === false ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( ! displayClosest ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( error ) {
|
||||
return (
|
||||
<Notice status="error" isDismissible={false}>
|
||||
{__( error, 'dhl-for-woocommerce' )}
|
||||
</Notice>
|
||||
);
|
||||
}
|
||||
|
||||
// Render DHL logo dynamically from the localized data
|
||||
return (
|
||||
<table className="dhl-co-table">
|
||||
<tbody>
|
||||
{/* DHL logo */}
|
||||
<tr className="dhl-co-tr dhl-co-tr-first">
|
||||
<td colSpan={2}>
|
||||
<img src={imgUrl} alt="DHL logo" className="dhl-co-logo" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{/* Title and description */}
|
||||
<tr className="dhl-co-tr">
|
||||
<th colSpan={2}>
|
||||
{ __( 'Closest drop-off point', 'dhl-for-woocommerce' ) }
|
||||
<hr />
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<tr className="dhl-co-tr">
|
||||
<td colSpan={2}>
|
||||
{ __( 'Preferred delivery to a parcel shop/parcel locker close to the specified home address', 'dhl-for-woocommerce' ) }
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr className="dhl-co-tr">
|
||||
<th className="dhl-cdp">
|
||||
{ __( 'Delivery option', 'dhl-for-woocommerce' ) }
|
||||
</th>
|
||||
<td className="dhl-cdp">
|
||||
<ul className="dhl-preferred-location">
|
||||
<li>
|
||||
<input
|
||||
defaultChecked={true}
|
||||
type="radio"
|
||||
name="pr_dhl_cdp_delivery"
|
||||
data-index={0} id="dhl_home_deliver_option"
|
||||
value="no"
|
||||
className=""
|
||||
onChange={(e) => setClosestDP(e.target.value)} />
|
||||
<label htmlFor="dhl_home_deliver_option">{ __( 'Home delivery', 'dhl-for-woocommerce' ) }</label>
|
||||
</li>
|
||||
<li>
|
||||
<input
|
||||
type="radio"
|
||||
name="pr_dhl_cdp_delivery"
|
||||
data-index={0} id="dhl_cdp_option"
|
||||
value="yes"
|
||||
className=""
|
||||
onChange={(e) => setClosestDP(e.target.value)} />
|
||||
<label htmlFor="dhl_cdp_option">{ __( 'Closest Drop Point', 'dhl-for-woocommerce' ) }</label>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="dhl-co-tr dhl-co-tr-last">
|
||||
<td colSpan={2}></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"apiVersion": 3,
|
||||
"name": "pr-dhl/dhl-closest-drop-point",
|
||||
"version": "1.0.0",
|
||||
"title": "DHL Order Block",
|
||||
"category": "woocommerce",
|
||||
"description": "Adds DHL block to checkout.",
|
||||
"supports": {
|
||||
"html": false,
|
||||
"align": true,
|
||||
"multiple": false,
|
||||
"reusable": false
|
||||
},
|
||||
"parent": [
|
||||
"woocommerce/checkout-order-summary-block"
|
||||
],
|
||||
"attributes": {
|
||||
"lock": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"remove": true,
|
||||
"move": true
|
||||
}
|
||||
},
|
||||
"mainTitle": {
|
||||
"type": "string",
|
||||
"default": "Closest drop-off point."
|
||||
},
|
||||
"infoText": {
|
||||
"type": "string",
|
||||
"default": "Preferred delivery to a parcel shop/parcel locker close to the specified home address."
|
||||
},
|
||||
"homeDeliveryLabel": {
|
||||
"type": "string",
|
||||
"default": "Home delivery"
|
||||
},
|
||||
"closestDropPointLabel": {
|
||||
"type": "string",
|
||||
"default": "Closest Drop Point"
|
||||
}
|
||||
},
|
||||
"textdomain": "dhl-for-woocommerce",
|
||||
"editorStyle": "file:../../../build/style-dhl-closest-drop-point.css"
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import {__} from '@wordpress/i18n';
|
||||
import {
|
||||
useBlockProps,
|
||||
RichText,
|
||||
InspectorControls,
|
||||
} from '@wordpress/block-editor';
|
||||
import {PanelBody} from '@wordpress/components';
|
||||
import {getSetting} from '@woocommerce/settings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import './style.scss';
|
||||
|
||||
|
||||
export const Edit = ({attributes, setAttributes}) => {
|
||||
return (null);
|
||||
|
||||
};
|
||||
|
||||
export const Save = ({attributes}) => {
|
||||
return (null);
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { registerCheckoutBlock } from '@woocommerce/blocks-checkout';
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { Block } from './block';
|
||||
import metadata from './block.json';
|
||||
|
||||
registerCheckoutBlock({
|
||||
metadata,
|
||||
component: Block,
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { registerBlockType } from '@wordpress/blocks';
|
||||
import { Icon, box } from '@wordpress/icons';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { Edit, Save } from './edit';
|
||||
import metadata from './block.json';
|
||||
|
||||
registerBlockType(metadata, {
|
||||
icon: {
|
||||
src: <Icon icon={box} />,
|
||||
},
|
||||
edit: Edit,
|
||||
save: Save,
|
||||
});
|
||||