/**
  * Get request for fetching address tax rate
  *
  * @param QuoteDetails $quoteDetails
  * @param int $storeId
  * @param int $customerId
  * @return \Magento\Framework\Object
  */
 protected function getAddressTaxRequest(QuoteDetails $quoteDetails, $storeId, $customerId)
 {
     return $this->calculator->getRateRequest($quoteDetails->getShippingAddress(), $quoteDetails->getBillingAddress(), $quoteDetails->getCustomerTaxClassId(), $storeId, $customerId);
 }
 /**
  * {@inheritdoc}
  */
 public function calculateTax(QuoteDetails $quoteDetails, $storeId = null)
 {
     if (is_null($storeId)) {
         $storeId = $this->storeManager->getStore()->getStoreId();
     }
     // initial TaxDetails data
     $taxDetailsData = [TaxDetails::KEY_SUBTOTAL => 0.0, TaxDetails::KEY_TAX_AMOUNT => 0.0, TaxDetails::KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT => 0.0, TaxDetails::KEY_APPLIED_TAXES => [], TaxDetails::KEY_ITEMS => []];
     $items = $quoteDetails->getItems();
     if (empty($items)) {
         return $this->taxDetailsBuilder->populateWithArray($taxDetailsData)->create();
     }
     $this->computeRelationships($items);
     $calculator = $this->calculatorFactory->create($this->config->getAlgorithm($storeId), $storeId, $quoteDetails->getBillingAddress(), $quoteDetails->getShippingAddress(), $this->taxClassService->getTaxClassId($quoteDetails->getCustomerTaxClassKey(), 'customer'), $quoteDetails->getCustomerId());
     $processedItems = [];
     /** @var QuoteDetailsItem $item */
     foreach ($this->keyedItems as $item) {
         if (isset($this->parentToChildren[$item->getCode()])) {
             $processedChildren = [];
             foreach ($this->parentToChildren[$item->getCode()] as $child) {
                 $processedItem = $this->processItem($child, $calculator);
                 $taxDetailsData = $this->aggregateItemData($taxDetailsData, $processedItem);
                 $processedItems[$processedItem->getCode()] = $processedItem;
                 $processedChildren[] = $processedItem;
             }
             $processedItemBuilder = $this->calculateParent($processedChildren, $item->getQuantity());
             $processedItemBuilder->setCode($item->getCode());
             $processedItemBuilder->setType($item->getType());
             $processedItem = $processedItemBuilder->create();
         } else {
             $processedItem = $this->processItem($item, $calculator);
             $taxDetailsData = $this->aggregateItemData($taxDetailsData, $processedItem);
         }
         $processedItems[$processedItem->getCode()] = $processedItem;
     }
     return $this->taxDetailsBuilder->populateWithArray($taxDetailsData)->setItems($processedItems)->create();
 }