/**
  * @param \Magento\Quote\Model\Quote $quote
  * @param array $total
  * @return array
  */
 public function fetch(\Magento\Quote\Model\Quote $quote, array $total)
 {
     $output = [];
     $total = $this->totalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total')->setData($total);
     /** @var ReaderInterface $reader */
     foreach ($this->collectorList->getCollectors($quote->getStoreId()) as $reader) {
         $data = $reader->fetch($quote, $total);
         if ($data === null || empty($data)) {
             continue;
         }
         $totalInstance = $this->convert($data);
         if (is_array($totalInstance)) {
             foreach ($totalInstance as $item) {
                 $output = $this->merge($item, $output);
             }
         } else {
             $output = $this->merge($totalInstance, $output);
         }
     }
     return $output;
 }
 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @param Address $address
  * @return Address\Total
  */
 public function collectAddressTotals(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address $address)
 {
     /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
     $shippingAssignment = $this->shippingAssignmentFactory->create();
     /** @var \Magento\Quote\Api\Data\ShippingInterface $shipping */
     $shipping = $this->shippingFactory->create();
     $shipping->setMethod($address->getShippingMethod());
     $shipping->setAddress($address);
     $shippingAssignment->setShipping($shipping);
     $shippingAssignment->setItems($address->getAllItems());
     /** @var \Magento\Quote\Model\Quote\Address\Total $total */
     $total = $this->totalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total');
     $this->eventManager->dispatch('sales_quote_address_collect_totals_before', ['quote' => $quote, 'shipping_assignment' => $shippingAssignment, 'total' => $total]);
     foreach ($this->collectorList->getCollectors($quote->getStoreId()) as $collector) {
         /** @var CollectorInterface $collector */
         $collector->collect($quote, $shippingAssignment, $total);
     }
     $this->eventManager->dispatch('sales_quote_address_collect_totals_after', ['quote' => $quote, 'shipping_assignment' => $shippingAssignment, 'total' => $total]);
     $address->addData($total->getData());
     $address->setAppliedTaxes($total->getAppliedTaxes());
     return $total;
 }