@@ -34,9 +34,10 @@ class Shipping {
3434 */
3535 private $ total ;
3636
37- /**
38- * @var bool $include_vat
39- */
37+ /** @var float $total_tax */
38+ private $ total_tax ;
39+
40+ /** @var bool $include_vat */
4041 private $ include_vat ;
4142
4243 /** @var array|\WC_Shipping_Rate $shipping_rate */
@@ -52,11 +53,12 @@ class Shipping {
5253 * @param bool $include_vat
5354 */
5455 public function __construct ( $ sf_order , $ include_vat = false ) {
55- $ this ->sf_order = $ sf_order ;
56+ $ this ->sf_order = $ sf_order ;
5657 $ this ->include_vat = $ include_vat ;
5758
5859 $ this ->set_shipping_method_and_colis_number ();
5960 $ this ->set_total ();
61+ $ this ->set_total_tax ();
6062 }
6163
6264 /**
@@ -101,11 +103,11 @@ private function set_shipping_rate() {
101103 $ shipping_rate = $ default_shipping_method ;
102104 }
103105
104- $ vat = [];
105- if ( $ this ->include_vat && isset ( $ this ->sf_order -> toArray ()[ ' additionalFields ' ][ ' shipping_tax ' ] ) ) {
106- $ vat = [
106+ $ taxes = [];
107+ if ( $ this ->include_vat && $ this ->get_total_tax () > 0 ) {
108+ $ taxes = [
107109 'total ' => [
108- Order::RATE_ID => ( float ) $ this ->sf_order -> toArray ()[ ' additionalFields ' ][ ' shipping_tax ' ] ,
110+ Order::RATE_ID => $ this ->get_total_tax () ,
109111 ],
110112 ];
111113 }
@@ -114,7 +116,7 @@ private function set_shipping_rate() {
114116 $ shipping_rate ['method_rate_id ' ],
115117 $ shipping_rate ['method_title ' ],
116118 $ this ->get_total_shipping () ? $ this ->get_total_shipping () : ShoppingFeedHelper::get_sf_default_shipping_fees (),
117- $ vat ,
119+ $ taxes ,
118120 $ shipping_rate ['method_rate_id ' ],
119121 $ shipping_rate ['method_id ' ]
120122 );
@@ -123,19 +125,37 @@ private function set_shipping_rate() {
123125 }
124126
125127 /**
128+ * Get total shipping amount.
129+ *
126130 * @return float
127131 */
128132 public function get_total () {
129133 return $ this ->total ;
130134 }
131135
132136 /**
133- * Set total
137+ * Set total shipping amount.
134138 */
135139 public function set_total () {
136140 $ this ->total = $ this ->get_total_shipping ();
137141 }
138142
143+ /**
144+ * Get total shipping tax amount.
145+ *
146+ * @return float
147+ */
148+ public function get_total_tax () {
149+ return $ this ->total_tax ;
150+ }
151+
152+ /**
153+ * Set total shipping tax amount.
154+ */
155+ public function set_total_tax () {
156+ $ this ->total_tax = isset ( $ this ->sf_order ->toArray ()['additionalFields ' ]['shipping_tax ' ] ) ? (float ) $ this ->sf_order ->toArray ()['additionalFields ' ]['shipping_tax ' ] : 0 ;
157+ }
158+
139159 /**
140160 * @return array|\WC_Shipping_Rate $shipping_rate
141161 */
0 commit comments