@@ -112,66 +112,69 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
112
112
113
113
foreach ($ taxes as $ row ) {
114
114
$ id = $ row ['id ' ];
115
- foreach ($ row ['rates ' ] as $ tax ) {
116
- if ($ row ['percent ' ] == null ) {
117
- $ baseRealAmount = $ row ['base_amount ' ];
118
- } else {
119
- if ($ row ['percent ' ] == 0 || $ tax ['percent ' ] == 0 ) {
120
- continue ;
115
+ // @todo: should be refactored as part of MAGETWO-53366
116
+ if (isset ($ row ['rates ' ])) {
117
+ foreach ($ row ['rates ' ] as $ tax ) {
118
+ if ($ row ['percent ' ] == null ) {
119
+ $ baseRealAmount = $ row ['base_amount ' ];
120
+ } else {
121
+ if ($ row ['percent ' ] == 0 || $ tax ['percent ' ] == 0 ) {
122
+ continue ;
123
+ }
124
+ $ baseRealAmount = $ row ['base_amount ' ] / $ row ['percent ' ] * $ tax ['percent ' ];
121
125
}
122
- $ baseRealAmount = $ row ['base_amount ' ] / $ row ['percent ' ] * $ tax ['percent ' ];
123
- }
124
- $ hidden = isset ($ row ['hidden ' ]) ? $ row ['hidden ' ] : 0 ;
125
- $ priority = isset ($ tax ['priority ' ]) ? $ tax ['priority ' ] : 0 ;
126
- $ position = isset ($ tax ['position ' ]) ? $ tax ['position ' ] : 0 ;
127
- $ process = isset ($ row ['process ' ]) ? $ row ['process ' ] : 0 ;
128
- $ data = [
129
- 'order_id ' => $ order ->getEntityId (),
130
- 'code ' => $ tax ['code ' ],
131
- 'title ' => $ tax ['title ' ],
132
- 'hidden ' => $ hidden ,
133
- 'percent ' => $ tax ['percent ' ],
134
- 'priority ' => $ priority ,
135
- 'position ' => $ position ,
136
- 'amount ' => $ row ['amount ' ],
137
- 'base_amount ' => $ row ['base_amount ' ],
138
- 'process ' => $ process ,
139
- 'base_real_amount ' => $ baseRealAmount ,
140
- ];
126
+ $ hidden = isset ($ row ['hidden ' ]) ? $ row ['hidden ' ] : 0 ;
127
+ $ priority = isset ($ tax ['priority ' ]) ? $ tax ['priority ' ] : 0 ;
128
+ $ position = isset ($ tax ['position ' ]) ? $ tax ['position ' ] : 0 ;
129
+ $ process = isset ($ row ['process ' ]) ? $ row ['process ' ] : 0 ;
130
+ $ data = [
131
+ 'order_id ' => $ order ->getEntityId (),
132
+ 'code ' => $ tax ['code ' ],
133
+ 'title ' => $ tax ['title ' ],
134
+ 'hidden ' => $ hidden ,
135
+ 'percent ' => $ tax ['percent ' ],
136
+ 'priority ' => $ priority ,
137
+ 'position ' => $ position ,
138
+ 'amount ' => $ row ['amount ' ],
139
+ 'base_amount ' => $ row ['base_amount ' ],
140
+ 'process ' => $ process ,
141
+ 'base_real_amount ' => $ baseRealAmount ,
142
+ ];
141
143
142
- /** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
143
- $ orderTax = $ this ->orderTaxFactory ->create ();
144
- $ result = $ orderTax ->setData ($ data )->save ();
144
+ /** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
145
+ $ orderTax = $ this ->orderTaxFactory ->create ();
146
+ $ result = $ orderTax ->setData ($ data )->save ();
145
147
146
- if (isset ($ ratesIdQuoteItemId [$ id ])) {
147
- foreach ($ ratesIdQuoteItemId [$ id ] as $ quoteItemId ) {
148
- if ($ quoteItemId ['code ' ] == $ tax ['code ' ]) {
149
- $ itemId = null ;
150
- $ associatedItemId = null ;
151
- if (isset ($ quoteItemId ['id ' ])) {
152
- //This is a product item
153
- $ item = $ order ->getItemByQuoteItemId ($ quoteItemId ['id ' ]);
154
- $ itemId = $ item ->getId ();
155
- } elseif (isset ($ quoteItemId ['associated_item_id ' ])) {
156
- //This item is associated with a product item
157
- $ item = $ order ->getItemByQuoteItemId ($ quoteItemId ['associated_item_id ' ]);
158
- $ associatedItemId = $ item ->getId ();
159
- }
148
+ if (isset ($ ratesIdQuoteItemId [$ id ])) {
149
+ foreach ($ ratesIdQuoteItemId [$ id ] as $ quoteItemId ) {
150
+ if ($ quoteItemId ['code ' ] == $ tax ['code ' ]) {
151
+ $ itemId = null ;
152
+ $ associatedItemId = null ;
153
+ if (isset ($ quoteItemId ['id ' ])) {
154
+ //This is a product item
155
+ $ item = $ order ->getItemByQuoteItemId ($ quoteItemId ['id ' ]);
156
+ $ itemId = $ item ->getId ();
157
+ } elseif (isset ($ quoteItemId ['associated_item_id ' ])) {
158
+ //This item is associated with a product item
159
+ $ item = $ order ->getItemByQuoteItemId ($ quoteItemId ['associated_item_id ' ]);
160
+ $ associatedItemId = $ item ->getId ();
161
+ }
160
162
161
- $ data = [
162
- 'item_id ' => $ itemId ,
163
- 'tax_id ' => $ result ->getTaxId (),
164
- 'tax_percent ' => $ quoteItemId ['percent ' ],
165
- 'associated_item_id ' => $ associatedItemId ,
166
- 'amount ' => $ quoteItemId ['amount ' ],
167
- 'base_amount ' => $ quoteItemId ['base_amount ' ],
168
- 'real_amount ' => $ quoteItemId ['real_amount ' ],
169
- 'real_base_amount ' => $ quoteItemId ['real_base_amount ' ],
170
- 'taxable_item_type ' => $ quoteItemId ['item_type ' ],
171
- ];
172
- /** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
173
- $ taxItem = $ this ->taxItemFactory ->create ();
174
- $ taxItem ->setData ($ data )->save ();
163
+ $ data = [
164
+ 'item_id ' => $ itemId ,
165
+ 'tax_id ' => $ result ->getTaxId (),
166
+ 'tax_percent ' => $ quoteItemId ['percent ' ],
167
+ 'associated_item_id ' => $ associatedItemId ,
168
+ 'amount ' => $ quoteItemId ['amount ' ],
169
+ 'base_amount ' => $ quoteItemId ['base_amount ' ],
170
+ 'real_amount ' => $ quoteItemId ['real_amount ' ],
171
+ 'real_base_amount ' => $ quoteItemId ['real_base_amount ' ],
172
+ 'taxable_item_type ' => $ quoteItemId ['item_type ' ],
173
+ ];
174
+ /** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
175
+ $ taxItem = $ this ->taxItemFactory ->create ();
176
+ $ taxItem ->setData ($ data )->save ();
177
+ }
175
178
}
176
179
}
177
180
}
0 commit comments