/** * Add order items to the ship group for each item shipping to the address. * * @return self */ protected function _injectItemData() { $orderItemIterable = $this->_shipGroup->getItems(); // The first item needs to include shipping totals, use this flag to // track when item is the first item. $first = true; foreach ($this->_address->getAllVisibleItems() as $item) { // Add shipping amounts to the first item - necessary way of sending // address level shipping totals which is the only way Magento can // report shipping totals. if ($first) { $item->setIncludeShippingTotals(true); } $itemBuilder = $this->_taxFactory->createRequestBuilderItem($orderItemIterable, $this->_address, $item); $itemPayload = $itemBuilder->getOrderItemPayload(); if ($itemPayload) { $orderItemIterable[$itemPayload] = null; } // After the first iteration, this should always be false. $first = false; } return $this; }